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
6 changes: 3 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"] }
Expand Down
26 changes: 26 additions & 0 deletions prelude_parser/_prelude_parser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ class Value:
role: str
when: datetime

def to_dict(self) -> dict: ...

class Reason:
by: str
by_unique_id: str | None
role: str
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -80,22 +96,32 @@ class Site:
number_of_forms: int
forms: list[Form] | None

def to_dict(self) -> dict: ...

class User:
unique_id: str
last_language: str | None
creator: str
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]: ...
Expand Down
21 changes: 21 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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
Expand Down
Loading