diff --git a/Cargo.lock b/Cargo.lock index ddc74c4..3c1979e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,7 +171,7 @@ checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" [[package]] name = "prelude-parser" -version = "0.8.0" +version = "0.9.0" dependencies = [ "anyhow", "chrono", @@ -185,9 +185,9 @@ dependencies = [ [[package]] name = "prelude-xml-parser" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2acc00ccc3d4249013d22118d0c1d35f2798579a97f3851ed2c2520f4c69928f" +checksum = "1fd4b5e86427f084f49303cff4c17ff539ed7caf1f47c4f82a420448b09980eb" dependencies = [ "chrono", "pyo3", diff --git a/Cargo.toml b/Cargo.toml index bce2865..3ab1823 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "prelude-parser" -version = "0.8.0" +version = "0.9.0" description = "Parses XML files exported from Prelude EDC into formats usable by Python." edition = "2021" license = "MIT" @@ -16,7 +16,7 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1.0.89" chrono = "0.4.38" -prelude-xml-parser = { version = "0.6.1", features = ["python"] } +prelude-xml-parser = { version = "0.7.0", features = ["python"] } pyo3 = { version = "0.22.3", features = ["extension-module"] } roxmltree = "0.20.0" serde = { version = "1.0.210", features = ["derive"] } diff --git a/prelude_parser/_prelude_parser.pyi b/prelude_parser/_prelude_parser.pyi index dc6d1fe..eb729cf 100644 --- a/prelude_parser/_prelude_parser.pyi +++ b/prelude_parser/_prelude_parser.pyi @@ -11,6 +11,8 @@ class Value: role: str when: datetime + def to_dict(self) -> dict: ... + class Reason: by: str by_unique_id: str | None @@ -18,11 +20,15 @@ class Reason: when: datetime value: str + def to_dict(self) -> dict: ... + class Entry: entry_id: str value: Value | None reason: Reason | None + def to_dict(self) -> dict: ... + class Field: name: str data_type: str | None @@ -31,17 +37,23 @@ class Field: keep_history: bool entries: list[Entry] | None + def to_dict(self) -> dict: ... + class Category: name: str category_type: str highest_index: int fields: list[Field] | None + def to_dict(self) -> dict: ... + class State: value: str signer: str signer_unique_id: str + def to_dict(self) -> dict: ... + class Form: name: str last_modified: datetime | None @@ -60,6 +72,8 @@ class Form: states: list[State] | None categories: list[Category] | None + def to_dict(self) -> dict: ... + class Patient: patient_id: str unique_id: str @@ -70,6 +84,8 @@ class Patient: last_language: str | None forms: list[Form] | None + def to_dict(self) -> dict: ... + class Site: name: str unique_id: str @@ -80,6 +96,8 @@ class Site: number_of_forms: int forms: list[Form] | None + def to_dict(self) -> dict: ... + class User: unique_id: str last_language: str | None @@ -87,15 +105,23 @@ class User: number_of_forms: int forms: list[Form] | None + def to_dict(self) -> dict: ... + class SiteNative: sites: list[Site] + def to_dict(self) -> dict: ... + class SubjectNative: patients: list[Patient] + def to_dict(self) -> dict: ... + class UserNative: users: list[User] + def to_dict(self) -> dict: ... + def _parse_flat_file_to_dict( xml_file: str | Path, *, short_names: bool = False ) -> dict[str, FlatFormInfo]: ... diff --git a/tests/test_parser.py b/tests/test_parser.py index 042ed28..f56e0ed 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -29,6 +29,13 @@ def test_parse_site_native_string(site_native_xml): assert result.sites[0].name == "Some Site" +def test_site_native_to_dict(site_native_xml): + result = parse_site_native_file(site_native_xml) + result_dict = result.to_dict() + + assert result_dict["sites"][0]["name"] == "Some Site" + + def test_parse_subject_native_file(subject_native_xml): result = parse_subject_native_file(subject_native_xml) @@ -43,6 +50,13 @@ def test_parse_subject_native_string(subject_native_xml): assert result.patients[0].patient_id == "ABC-001" +def test_subject_native_to_dict(subject_native_xml): + result = parse_subject_native_file(subject_native_xml) + result_dict = result.to_dict() + + assert result_dict["patients"][0]["patient_id"] == "ABC-001" + + def test_parse_user_native_file(user_native_xml): result = parse_user_native_file(user_native_xml) @@ -57,6 +71,13 @@ def test_parse_user_native_string(user_native_xml): assert result.users[0].unique_id == "1691421275437" +def test_user_native_to_dict(user_native_xml): + result = parse_user_native_file(user_native_xml) + result_dict = result.to_dict() + + assert result_dict["users"][0]["unique_id"] == "1691421275437" + + def test_parse_to_classes(test_file_1): result = parse_to_classes(test_file_1) assert len(result) == 2