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
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// keep_history: true,
/// entries: Some(vec![Entry {
/// entry_id: "1".to_string(),
/// reviewed_by: None,
/// reviewed_by_unique_id: None,
/// reviewed_by_when: None,
/// value: Some(Value {
/// by: "Paul Sanders".to_string(),
/// by_unique_id: Some("1681162687395".to_string()),
Expand Down Expand Up @@ -209,6 +212,9 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// entries: Some(vec![
/// Entry {
/// entry_id: "1".to_string(),
/// reviewed_by: None,
/// reviewed_by_unique_id: None,
/// reviewed_by_when: None,
/// value: Some(Value {
/// by: "set from calculation".to_string(),
/// by_unique_id: None,
Expand All @@ -234,6 +240,9 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// },
/// Entry {
/// entry_id: "2".to_string(),
/// reviewed_by: None,
/// reviewed_by_unique_id: None,
/// reviewed_by_when: None,
/// value: Some(Value {
/// by: "set from calculation".to_string(),
/// by_unique_id: None,
Expand Down Expand Up @@ -294,6 +303,9 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// keep_history: true,
/// entries: Some(vec![Entry {
/// entry_id: "1".to_string(),
/// reviewed_by: None,
/// reviewed_by_unique_id: None,
/// reviewed_by_when: None,
/// value: Some(Value {
/// by: "Paul Sanders".to_string(),
/// by_unique_id: Some("1681162687395".to_string()),
Expand Down Expand Up @@ -383,6 +395,9 @@ pub fn parse_site_native_file(xml_path: &Path) -> Result<SiteNative, Error> {
/// keep_history: true,
/// entries: Some(vec![Entry {
/// entry_id: "1".to_string(),
/// reviewed_by: None,
/// reviewed_by_unique_id: None,
/// reviewed_by_when: None,
/// value: Some(Value {
/// by: "Paul Sanders".to_string(),
/// by_unique_id: Some("1681162687395".to_string()),
Expand Down Expand Up @@ -536,6 +551,9 @@ pub fn parse_subject_native_file(xml_path: &Path) -> Result<SubjectNative, Error
/// keep_history: true,
/// entries: Some(vec![Entry {
/// entry_id: "1".to_string(),
/// reviewed_by: None,
/// reviewed_by_unique_id: None,
/// reviewed_by_when: None,
/// value: Some(Value {
/// by: "Paul Sanders".to_string(),
/// by_unique_id: Some("1681162687395".to_string()),
Expand Down Expand Up @@ -606,6 +624,9 @@ pub fn parse_subject_native_file(xml_path: &Path) -> Result<SubjectNative, Error
/// keep_history: true,
/// entries: Some(vec![Entry {
/// entry_id: "1".to_string(),
/// reviewed_by: None,
/// reviewed_by_unique_id: None,
/// reviewed_by_when: None,
/// value: Some(Value {
/// by: "Paul Sanders".to_string(),
/// by_unique_id: Some("1681162687395".to_string()),
Expand Down Expand Up @@ -1015,6 +1036,9 @@ pub fn parse_user_native_file(xml_path: &Path) -> Result<UserNative, Error> {
/// keep_history: true,
/// entries: Some(vec![Entry {
/// entry_id: "1".to_string(),
/// reviewed_by: None,
/// reviewed_by_unique_id: None,
/// reviewed_by_when: None,
/// value: Some(Value {
/// by: "Paul Sanders".to_string(),
/// by_unique_id: Some("1681162687395".to_string()),
Expand Down Expand Up @@ -1047,6 +1071,9 @@ pub fn parse_user_native_file(xml_path: &Path) -> Result<UserNative, Error> {
/// entries: Some(vec![
/// Entry {
/// entry_id: "1".to_string(),
/// reviewed_by: None,
/// reviewed_by_unique_id: None,
/// reviewed_by_when: None,
/// value: Some(Value {
/// by: "set from calculation".to_string(),
/// by_unique_id: None,
Expand Down
98 changes: 97 additions & 1 deletion src/native/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,74 @@ pub struct Entry {
#[serde(alias = "@id")]
#[serde(alias = "entryId")]
pub entry_id: String,

#[serde(rename = "reviewedBy")]
#[serde(alias = "@reviewedBy")]
#[serde(alias = "reviewedBy")]
#[serde(
default = "default_string_none",
deserialize_with = "deserialize_empty_string_as_none"
)]
pub reviewed_by: Option<String>,

#[serde(rename = "reviewedByUniqueId")]
#[serde(alias = "@reviewedByUniqueId")]
#[serde(alias = "reviewedByUniqueId")]
#[serde(
default = "default_string_none",
deserialize_with = "deserialize_empty_string_as_none"
)]
pub reviewed_by_unique_id: Option<String>,

#[serde(rename = "reviewedByWhen")]
#[serde(alias = "@reviewedByWhen")]
#[serde(alias = "reviewedByWhen")]
#[serde(
default = "default_datetime_none",
deserialize_with = "deserialize_empty_string_as_none_datetime"
)]
pub reviewed_by_when: Option<DateTime<Utc>>,

pub value: Option<Value>,
pub reason: Option<Reason>,
}

#[cfg(feature = "python")]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[pyclass(get_all)]
#[pyclass]
pub struct Entry {
#[serde(rename = "entryId")]
#[serde(alias = "@id")]
#[serde(alias = "entryId")]
pub entry_id: String,

#[serde(rename = "reviewedBy")]
#[serde(alias = "@reviewedBy")]
#[serde(alias = "reviewedBy")]
#[serde(
default = "default_string_none",
deserialize_with = "deserialize_empty_string_as_none"
)]
pub reviewed_by: Option<String>,

#[serde(rename = "reviewedByUniqueId")]
#[serde(alias = "@reviewedByUniqueId")]
#[serde(alias = "reviewedByUniqueId")]
#[serde(
default = "default_string_none",
deserialize_with = "deserialize_empty_string_as_none"
)]
pub reviewed_by_unique_id: Option<String>,

#[serde(rename = "reviewedByWhen")]
#[serde(alias = "@reviewedByWhen")]
#[serde(alias = "reviewedByWhen")]
#[serde(
default = "default_datetime_none",
deserialize_with = "deserialize_empty_string_as_none_datetime"
)]
pub reviewed_by_when: Option<DateTime<Utc>>,

pub value: Option<Value>,
pub reason: Option<Reason>,
}
Expand All @@ -262,6 +318,21 @@ impl Entry {
Ok(self.entry_id.clone())
}

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

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

#[getter]
fn reviewed_by_when<'py>(&self, py: Python<'py>) -> PyResult<Option<Bound<'py, PyDateTime>>> {
to_py_datetime_option(py, &self.reviewed_by_when)
}

#[getter]
fn value(&self) -> PyResult<Option<Value>> {
Ok(self.value.clone())
Expand All @@ -275,6 +346,12 @@ impl Entry {
pub fn to_dict<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
let dict = PyDict::new(py);
dict.set_item("entry_id", &self.entry_id)?;
dict.set_item("reviewed_by", &self.reviewed_by)?;
dict.set_item("reviewed_by_unique_id", &self.reviewed_by_unique_id)?;
dict.set_item(
"reviewed_by_when",
to_py_datetime_option(py, &self.reviewed_by_when)?,
)?;
if let Some(value) = &self.value {
dict.set_item("value", value.to_dict(py)?)?;
} else {
Expand Down Expand Up @@ -1362,8 +1439,27 @@ impl Entry {
.cloned()
.unwrap_or_default();

let reviewed_by = attrs.get("reviewedBy").filter(|s| !s.is_empty()).cloned();
let reviewed_by_unique_id = attrs
.get("reviewedByUniqueId")
.filter(|s| !s.is_empty())
.cloned();

let reviewed_by_when = if let Some(rbw) = attrs.get("reviewedByWhen") {
if rbw.is_empty() {
None
} else {
parse_datetime_internal(rbw).ok()
}
} else {
None
};

Ok(Entry {
entry_id,
reviewed_by,
reviewed_by_unique_id,
reviewed_by_when,
value: None,
reason: None,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ patients:
keepHistory: true
entries:
- entryId: "1"
reviewedBy: ~
reviewedByUniqueId: ~
reviewedByWhen: ~
value:
by: Paul Sanders
byUniqueId: "1681162687395"
Expand Down Expand Up @@ -95,6 +98,9 @@ patients:
keepHistory: true
entries:
- entryId: "1"
reviewedBy: ~
reviewedByUniqueId: ~
reviewedByWhen: ~
value:
by: Paul Sanders
byUniqueId: "1681162687395"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ users:
keepHistory: true
entries:
- entryId: "1"
reviewedBy: ~
reviewedByUniqueId: ~
reviewedByWhen: ~
value:
by: Paul Sanders
byUniqueId: "1681162687395"
Expand All @@ -69,6 +72,9 @@ users:
keepHistory: true
entries:
- entryId: "1"
reviewedBy: ~
reviewedByUniqueId: ~
reviewedByWhen: ~
value:
by: set from calculation
byUniqueId: ~
Expand Down
Loading