Skip to content

Commit d8729b6

Browse files
authored
Merge pull request #67 from pbs-data-solutions/comments
Add missing comments
2 parents 823d190 + ff3fcbd commit d8729b6

13 files changed

+119
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "prelude-xml-parser"
3-
version = "0.7.1"
3+
version = "0.7.2"
44
edition = "2021"
55
authors = ["Paul Sanders <[email protected]>"]
66
description = "Deserialize Prelude EDC native XML files into Rust stucts."

src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
8686
/// <entry id="1">
8787
/// <value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-08-07 08:14:21 -0700" xml:space="preserve">1111 Moon Drive</value>
8888
/// </entry>
89+
/// <comment id="1">
90+
/// <value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-08-07 08:14:21 -0700" xml:space="preserve">Some comment</value>
91+
/// </comment>
8992
/// </field>
9093
/// </category>
9194
/// </form>
@@ -153,6 +156,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
153156
/// .with_timezone(&Utc),
154157
/// keep_history: true,
155158
/// entries: None,
159+
/// comments: None,
156160
/// },
157161
/// Field {
158162
/// name: "company".to_string(),
@@ -180,6 +184,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
180184
/// }),
181185
/// reason: None,
182186
/// }]),
187+
/// comments: None,
183188
/// },
184189
/// Field {
185190
/// name: "site_code_name".to_string(),
@@ -244,6 +249,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
244249
/// }),
245250
/// },
246251
/// ]),
252+
/// comments: None,
247253
/// },
248254
/// ]),
249255
/// },
@@ -264,6 +270,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
264270
/// .with_timezone(&Utc),
265271
/// keep_history: true,
266272
/// entries: None,
273+
/// comments: None,
267274
/// },
268275
/// Field {
269276
/// name: "enrollment_open".to_string(),
@@ -291,6 +298,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
291298
/// }),
292299
/// reason: None,
293300
/// }]),
301+
/// comments: None,
294302
/// },
295303
/// Field {
296304
/// name: "enrollment_open_date".to_string(),
@@ -304,6 +312,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
304312
/// .with_timezone(&Utc),
305313
/// keep_history: true,
306314
/// entries: None,
315+
/// comments: None,
307316
/// },
308317
/// ]),
309318
/// },
@@ -375,6 +384,18 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
375384
/// }),
376385
/// reason: None,
377386
/// }]),
387+
/// comments: Some(vec![Comment {
388+
/// comment_id: "1".to_string(),
389+
/// value: Some(Value {
390+
/// by: "Paul Sanders".to_string(),
391+
/// by_unique_id: Some("1681162687395".to_string()),
392+
/// role: "Project Manager".to_string(),
393+
/// when: DateTime::parse_from_rfc3339("2023-08-07T15:14:21Z")
394+
/// .unwrap()
395+
/// .with_timezone(&Utc),
396+
/// value: "Some comment".to_string(),
397+
/// }),
398+
/// }]),
378399
/// }]),
379400
/// }]),
380401
/// }]),
@@ -515,6 +536,7 @@ pub fn parse_subject_native_file(xml_path: &Path) -> Result<SubjectNative, Error
515536
/// }),
516537
/// reason: None,
517538
/// }]),
539+
/// comments: None,
518540
/// }]),
519541
/// }]),
520542
/// }]),
@@ -583,6 +605,7 @@ pub fn parse_subject_native_file(xml_path: &Path) -> Result<SubjectNative, Error
583605
/// }),
584606
/// reason: None,
585607
/// }]),
608+
/// comments: None,
586609
/// }]),
587610
/// }]),
588611
/// }]),
@@ -708,6 +731,7 @@ pub fn parse_user_native_file(xml_path: &Path) -> Result<UserNative, Error> {
708731
/// .with_timezone(&Utc),
709732
/// keep_history: true,
710733
/// entries: None,
734+
/// comments: None,
711735
/// },
712736
/// Field {
713737
/// name: "email".to_string(),
@@ -731,6 +755,7 @@ pub fn parse_user_native_file(xml_path: &Path) -> Result<UserNative, Error> {
731755
/// }),
732756
/// reason: None,
733757
/// }]),
758+
/// comments: None,
734759
/// },
735760
/// ]),
736761
/// },
@@ -771,6 +796,7 @@ pub fn parse_user_native_file(xml_path: &Path) -> Result<UserNative, Error> {
771796
/// }),
772797
/// },
773798
/// ]),
799+
/// comments: None,
774800
/// },
775801
/// ]),
776802
/// },

src/native/common.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,51 @@ impl Entry {
228228
}
229229
}
230230

231+
#[cfg(not(feature = "python"))]
232+
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
233+
#[serde(rename_all = "camelCase")]
234+
pub struct Comment {
235+
#[serde(alias = "id")]
236+
pub comment_id: String,
237+
pub value: Option<Value>,
238+
}
239+
240+
#[cfg(feature = "python")]
241+
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
242+
#[serde(rename_all = "camelCase")]
243+
#[pyclass(get_all)]
244+
pub struct Comment {
245+
#[serde(alias = "id")]
246+
pub comment_id: String,
247+
pub value: Option<Value>,
248+
}
249+
250+
#[cfg(feature = "python")]
251+
#[pymethods]
252+
impl Comment {
253+
#[getter]
254+
fn comment_id(&self) -> PyResult<String> {
255+
Ok(self.comment_id.clone())
256+
}
257+
258+
#[getter]
259+
fn value(&self) -> PyResult<Option<Value>> {
260+
Ok(self.value.clone())
261+
}
262+
263+
pub fn to_dict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
264+
let dict = PyDict::new_bound(py);
265+
dict.set_item("comment_id", &self.comment_id)?;
266+
if let Some(value) = &self.value {
267+
dict.set_item("value", value.to_dict(py)?)?;
268+
} else {
269+
dict.set_item("value", py.None())?;
270+
}
271+
272+
Ok(dict)
273+
}
274+
}
275+
231276
#[cfg(not(feature = "python"))]
232277
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
233278
#[serde(rename_all = "camelCase")]
@@ -248,6 +293,9 @@ pub struct Field {
248293

249294
#[serde(alias = "entry")]
250295
pub entries: Option<Vec<Entry>>,
296+
297+
#[serde(alias = "comment")]
298+
pub comments: Option<Vec<Comment>>,
251299
}
252300

253301
#[cfg(feature = "python")]
@@ -272,6 +320,9 @@ pub struct Field {
272320

273321
#[serde(alias = "entry")]
274322
pub entries: Option<Vec<Entry>>,
323+
324+
#[serde(alias = "comment")]
325+
pub comments: Option<Vec<Comment>>,
275326
}
276327

277328
#[cfg(feature = "python")]
@@ -312,6 +363,11 @@ impl Field {
312363
Ok(self.entries.clone())
313364
}
314365

366+
#[getter]
367+
fn comments(&self) -> PyResult<Option<Vec<Comment>>> {
368+
Ok(self.comments.clone())
369+
}
370+
315371
pub fn to_dict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
316372
let dict = PyDict::new_bound(py);
317373
dict.set_item("name", &self.name)?;
@@ -332,6 +388,17 @@ impl Field {
332388
dict.set_item("entries", py.None())?;
333389
}
334390

391+
let mut comment_dicts = Vec::new();
392+
if let Some(comments) = &self.comments {
393+
for comment in comments {
394+
let comment_dict = comment.to_dict(py)?;
395+
comment_dicts.push(comment_dict.to_object(py));
396+
}
397+
dict.set_item("comments", comment_dicts)?;
398+
} else {
399+
dict.set_item("comments", py.None())?;
400+
}
401+
335402
Ok(dict)
336403
}
337404
}

src/native/site_native.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use pyo3::{
99
use serde::{Deserialize, Serialize};
1010

1111
pub use crate::native::{
12-
common::{Category, Entry, Field, Form, Reason, State, Value},
12+
common::{Category, Comment, Entry, Field, Form, Reason, State, Value},
1313
deserializers::{
1414
default_datetime_none, default_string_none, deserialize_empty_string_as_none,
1515
deserialize_empty_string_as_none_datetime,

src/native/snapshots/prelude_xml_parser__native__site_native__tests__deserialize_site_native_json.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ sites:
4242
whenCreated: "2023-04-15T16:07:14Z"
4343
keepHistory: true
4444
entries: ~
45+
comments: ~
4546
- name: company
4647
fieldType: text
4748
dataType: string
@@ -57,6 +58,7 @@ sites:
5758
when: "2023-04-15T16:08:19Z"
5859
value: Some Company
5960
reason: ~
61+
comments: ~
6062
- name: site_code_name
6163
fieldType: hidden
6264
dataType: string
@@ -90,6 +92,7 @@ sites:
9092
role: System
9193
when: "2023-04-15T16:07:24Z"
9294
value: calculated value
95+
comments: ~
9396
- name: Enrollment
9497
categoryType: normal
9598
highestIndex: 0
@@ -101,6 +104,7 @@ sites:
101104
whenCreated: "2023-04-15T16:07:14Z"
102105
keepHistory: true
103106
entries: ~
107+
comments: ~
104108
- name: enrollment_open
105109
fieldType: radio
106110
dataType: string
@@ -116,13 +120,15 @@ sites:
116120
when: "2023-04-15T16:08:19Z"
117121
value: "Yes"
118122
reason: ~
123+
comments: ~
119124
- name: enrollment_open_date
120125
fieldType: popUpCalendar
121126
dataType: date
122127
errorCode: valid
123128
whenCreated: "2023-04-15T16:07:14Z"
124129
keepHistory: true
125130
entries: ~
131+
comments: ~
126132
- name: Artemis
127133
uniqueId: "1691420994591"
128134
numberOfPatients: 0
@@ -170,3 +176,4 @@ sites:
170176
when: "2023-08-07T15:14:21Z"
171177
value: 1111 Moon Drive
172178
reason: ~
179+
comments: ~

src/native/snapshots/prelude_xml_parser__native__subject_native__tests__deserialize_subject_native_json.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ patients:
5151
when: "2023-04-15T16:09:02Z"
5252
value: Labrador
5353
reason: ~
54+
comments: ~
5455
- patientId: DEF-002
5556
uniqueId: "1681574905820"
5657
whenCreated: "2023-04-16T16:10:02Z"
@@ -99,3 +100,4 @@ patients:
99100
when: "2023-04-15T16:09:02Z"
100101
value: Labrador
101102
reason: ~
103+
comments: ~

src/native/snapshots/prelude_xml_parser__native__user_native__tests__deserialize_user_native_json.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ users:
3939
whenCreated: "2024-01-12T20:14:09Z"
4040
keepHistory: true
4141
entries: ~
42+
comments: ~
4243
- name: email
4344
fieldType: text
4445
dataType: string
@@ -54,6 +55,7 @@ users:
5455
when: "2023-08-07T15:15:41Z"
5556
value: jazz@artemis.com
5657
reason: ~
58+
comments: ~
5759
- name: Administrative
5860
categoryType: normal
5961
highestIndex: 0
@@ -78,3 +80,4 @@ users:
7880
role: System
7981
when: "2023-08-07T15:15:41Z"
8082
value: calculated value
83+
comments: ~

src/native/subject_native.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::native::deserializers::to_py_datetime;
1212
use serde::{Deserialize, Serialize};
1313

1414
pub use crate::native::{
15-
common::{Category, Entry, Field, Form, Reason, State, Value},
15+
common::{Category, Comment, Entry, Field, Form, Reason, State, Value},
1616
deserializers::{
1717
default_datetime_none, default_string_none, deserialize_empty_string_as_none,
1818
deserialize_empty_string_as_none_datetime,

src/native/user_native.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
44
use pyo3::{prelude::*, types::PyDict};
55

66
pub use crate::native::{
7-
common::{Category, Entry, Field, Form, Reason, State, Value},
7+
common::{Category, Comment, Entry, Field, Form, Reason, State, Value},
88
deserializers::{
99
default_datetime_none, default_string_none, deserialize_empty_string_as_none,
1010
deserialize_empty_string_as_none_datetime,

0 commit comments

Comments
 (0)