Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prelude-xml-parser"
version = "0.7.1"
version = "0.7.2"
edition = "2021"
authors = ["Paul Sanders <[email protected]>"]
description = "Deserialize Prelude EDC native XML files into Rust stucts."
Expand Down
26 changes: 26 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// <entry id="1">
/// <value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-08-07 08:14:21 -0700" xml:space="preserve">1111 Moon Drive</value>
/// </entry>
/// <comment id="1">
/// <value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-08-07 08:14:21 -0700" xml:space="preserve">Some comment</value>
/// </comment>
/// </field>
/// </category>
/// </form>
Expand Down Expand Up @@ -153,6 +156,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// .with_timezone(&Utc),
/// keep_history: true,
/// entries: None,
/// comments: None,
/// },
/// Field {
/// name: "company".to_string(),
Expand Down Expand Up @@ -180,6 +184,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// }),
/// reason: None,
/// }]),
/// comments: None,
/// },
/// Field {
/// name: "site_code_name".to_string(),
Expand Down Expand Up @@ -244,6 +249,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// }),
/// },
/// ]),
/// comments: None,
/// },
/// ]),
/// },
Expand All @@ -264,6 +270,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// .with_timezone(&Utc),
/// keep_history: true,
/// entries: None,
/// comments: None,
/// },
/// Field {
/// name: "enrollment_open".to_string(),
Expand Down Expand Up @@ -291,6 +298,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// }),
/// reason: None,
/// }]),
/// comments: None,
/// },
/// Field {
/// name: "enrollment_open_date".to_string(),
Expand All @@ -304,6 +312,7 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// .with_timezone(&Utc),
/// keep_history: true,
/// entries: None,
/// comments: None,
/// },
/// ]),
/// },
Expand Down Expand Up @@ -375,6 +384,18 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// }),
/// reason: None,
/// }]),
/// comments: Some(vec![Comment {
/// comment_id: "1".to_string(),
/// value: Some(Value {
/// by: "Paul Sanders".to_string(),
/// by_unique_id: Some("1681162687395".to_string()),
/// role: "Project Manager".to_string(),
/// when: DateTime::parse_from_rfc3339("2023-08-07T15:14:21Z")
/// .unwrap()
/// .with_timezone(&Utc),
/// value: "Some comment".to_string(),
/// }),
/// }]),
/// }]),
/// }]),
/// }]),
Expand Down Expand Up @@ -515,6 +536,7 @@ pub fn parse_subject_native_file(xml_path: &Path) -> Result<SubjectNative, Error
/// }),
/// reason: None,
/// }]),
/// comments: None,
/// }]),
/// }]),
/// }]),
Expand Down Expand Up @@ -583,6 +605,7 @@ pub fn parse_subject_native_file(xml_path: &Path) -> Result<SubjectNative, Error
/// }),
/// reason: None,
/// }]),
/// comments: None,
/// }]),
/// }]),
/// }]),
Expand Down Expand Up @@ -708,6 +731,7 @@ pub fn parse_user_native_file(xml_path: &Path) -> Result<UserNative, Error> {
/// .with_timezone(&Utc),
/// keep_history: true,
/// entries: None,
/// comments: None,
/// },
/// Field {
/// name: "email".to_string(),
Expand All @@ -731,6 +755,7 @@ pub fn parse_user_native_file(xml_path: &Path) -> Result<UserNative, Error> {
/// }),
/// reason: None,
/// }]),
/// comments: None,
/// },
/// ]),
/// },
Expand Down Expand Up @@ -771,6 +796,7 @@ pub fn parse_user_native_file(xml_path: &Path) -> Result<UserNative, Error> {
/// }),
/// },
/// ]),
/// comments: None,
/// },
/// ]),
/// },
Expand Down
67 changes: 67 additions & 0 deletions src/native/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,51 @@ impl Entry {
}
}

#[cfg(not(feature = "python"))]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Comment {
#[serde(alias = "id")]
pub comment_id: String,
pub value: Option<Value>,
}

#[cfg(feature = "python")]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
#[pyclass(get_all)]
pub struct Comment {
#[serde(alias = "id")]
pub comment_id: String,
pub value: Option<Value>,
}

#[cfg(feature = "python")]
#[pymethods]
impl Comment {
#[getter]
fn comment_id(&self) -> PyResult<String> {
Ok(self.comment_id.clone())
}

#[getter]
fn value(&self) -> PyResult<Option<Value>> {
Ok(self.value.clone())
}

pub fn to_dict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let dict = PyDict::new_bound(py);
dict.set_item("comment_id", &self.comment_id)?;
if let Some(value) = &self.value {
dict.set_item("value", value.to_dict(py)?)?;
} else {
dict.set_item("value", py.None())?;
}

Ok(dict)
}
}

#[cfg(not(feature = "python"))]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
Expand All @@ -248,6 +293,9 @@ pub struct Field {

#[serde(alias = "entry")]
pub entries: Option<Vec<Entry>>,

#[serde(alias = "comment")]
pub comments: Option<Vec<Comment>>,
}

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

#[serde(alias = "entry")]
pub entries: Option<Vec<Entry>>,

#[serde(alias = "comment")]
pub comments: Option<Vec<Comment>>,
}

#[cfg(feature = "python")]
Expand Down Expand Up @@ -312,6 +363,11 @@ impl Field {
Ok(self.entries.clone())
}

#[getter]
fn comments(&self) -> PyResult<Option<Vec<Comment>>> {
Ok(self.comments.clone())
}

pub fn to_dict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let dict = PyDict::new_bound(py);
dict.set_item("name", &self.name)?;
Expand All @@ -332,6 +388,17 @@ impl Field {
dict.set_item("entries", py.None())?;
}

let mut comment_dicts = Vec::new();
if let Some(comments) = &self.comments {
for comment in comments {
let comment_dict = comment.to_dict(py)?;
comment_dicts.push(comment_dict.to_object(py));
}
dict.set_item("comments", comment_dicts)?;
} else {
dict.set_item("comments", py.None())?;
}

Ok(dict)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/native/site_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use pyo3::{
use serde::{Deserialize, Serialize};

pub use crate::native::{
common::{Category, Entry, Field, Form, Reason, State, Value},
common::{Category, Comment, Entry, Field, Form, Reason, State, Value},
deserializers::{
default_datetime_none, default_string_none, deserialize_empty_string_as_none,
deserialize_empty_string_as_none_datetime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ sites:
whenCreated: "2023-04-15T16:07:14Z"
keepHistory: true
entries: ~
comments: ~
- name: company
fieldType: text
dataType: string
Expand All @@ -57,6 +58,7 @@ sites:
when: "2023-04-15T16:08:19Z"
value: Some Company
reason: ~
comments: ~
- name: site_code_name
fieldType: hidden
dataType: string
Expand Down Expand Up @@ -90,6 +92,7 @@ sites:
role: System
when: "2023-04-15T16:07:24Z"
value: calculated value
comments: ~
- name: Enrollment
categoryType: normal
highestIndex: 0
Expand All @@ -101,6 +104,7 @@ sites:
whenCreated: "2023-04-15T16:07:14Z"
keepHistory: true
entries: ~
comments: ~
- name: enrollment_open
fieldType: radio
dataType: string
Expand All @@ -116,13 +120,15 @@ sites:
when: "2023-04-15T16:08:19Z"
value: "Yes"
reason: ~
comments: ~
- name: enrollment_open_date
fieldType: popUpCalendar
dataType: date
errorCode: valid
whenCreated: "2023-04-15T16:07:14Z"
keepHistory: true
entries: ~
comments: ~
- name: Artemis
uniqueId: "1691420994591"
numberOfPatients: 0
Expand Down Expand Up @@ -170,3 +176,4 @@ sites:
when: "2023-08-07T15:14:21Z"
value: 1111 Moon Drive
reason: ~
comments: ~
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ patients:
when: "2023-04-15T16:09:02Z"
value: Labrador
reason: ~
comments: ~
- patientId: DEF-002
uniqueId: "1681574905820"
whenCreated: "2023-04-16T16:10:02Z"
Expand Down Expand Up @@ -99,3 +100,4 @@ patients:
when: "2023-04-15T16:09:02Z"
value: Labrador
reason: ~
comments: ~
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ users:
whenCreated: "2024-01-12T20:14:09Z"
keepHistory: true
entries: ~
comments: ~
- name: email
fieldType: text
dataType: string
Expand All @@ -54,6 +55,7 @@ users:
when: "2023-08-07T15:15:41Z"
value: [email protected]
reason: ~
comments: ~
- name: Administrative
categoryType: normal
highestIndex: 0
Expand All @@ -78,3 +80,4 @@ users:
role: System
when: "2023-08-07T15:15:41Z"
value: calculated value
comments: ~
2 changes: 1 addition & 1 deletion src/native/subject_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::native::deserializers::to_py_datetime;
use serde::{Deserialize, Serialize};

pub use crate::native::{
common::{Category, Entry, Field, Form, Reason, State, Value},
common::{Category, Comment, Entry, Field, Form, Reason, State, Value},
deserializers::{
default_datetime_none, default_string_none, deserialize_empty_string_as_none,
deserialize_empty_string_as_none_datetime,
Expand Down
2 changes: 1 addition & 1 deletion src/native/user_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use pyo3::{prelude::*, types::PyDict};

pub use crate::native::{
common::{Category, Entry, Field, Form, Reason, State, Value},
common::{Category, Comment, Entry, Field, Form, Reason, State, Value},
deserializers::{
default_datetime_none, default_string_none, deserialize_empty_string_as_none,
deserialize_empty_string_as_none_datetime,
Expand Down
3 changes: 3 additions & 0 deletions tests/assets/site_native.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<entry id="1">
<value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-04-15 12:08:19 -0400" xml:space="preserve">Some Company</value>
</entry>
<comment id="1">
<value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-04-15 12:09:02 -0400" xml:space="preserve">Some Comment</value>
</comment>
</field>
<field name="site_code_name" type="hidden" dataType="string" errorCode="valid" whenCreated="2023-04-15 11:07:14 -0500" keepHistory="true">
<entry id="1">
Expand Down
3 changes: 3 additions & 0 deletions tests/assets/subject_native.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<entry id="1">
<value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-04-15 12:09:02 -0400" xml:space="preserve">Labrador</value>
</entry>
<comment id="1">
<value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-04-15 12:09:02 -0400" xml:space="preserve">Some Comment</value>
</comment>
</field>
<field name="dob" type="popUpCalendar" dataType="date" errorCode="valid" whenCreated="2023-04-15 12:08:26 -0400" keepHistory="true">
<entry id="1">
Expand Down
3 changes: 3 additions & 0 deletions tests/assets/user_native.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<entry id="1">
<value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-08-07 10:15:41 -0500" xml:space="preserve">[email protected]</value>
</entry>
<comment id="1">
<value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-04-15 12:09:02 -0400" xml:space="preserve">Some Comment</value>
</comment>
</field>
</category>
<category name="Administrative" type="normal" highestIndex="0">
Expand Down