pub fn parse_site_native_string(xml_str: &str) -> Result<SiteNative, Error>Expand description
Parse a string of Prelude native site XML into a SiteNative struct.
ยงExample
use chrono::{DateTime, Utc};
use prelude_xml_parser::parse_site_native_string;
use prelude_xml_parser::native::site_native::*;
let xml = r#"<?xml version="1.0" encoding="UTF-8"?>
<export_from_vision_EDC date="01-Jun-2024 18:17 -0500" createdBy="Paul Sanders" role="Project Manager" numberSubjectsProcessed="2">
<site name="Some Site" uniqueId="1681574834910" numberOfPatients="4" countOfRandomizedPatients="0" whenCreated="2023-04-15 12:08:19 -0400" creator="Paul Sanders" numberOfForms="1">
<form name="demographic.form.name.site.demographics" lastModified="2023-04-15 12:08:19 -0400" whoLastModifiedName="Paul Sanders" whoLastModifiedRole="Project Manager" whenCreated="1681574834930" hasErrors="false" hasWarnings="false" locked="false" user="" dateTimeChanged="" formTitle="Site Demographics" formIndex="1" formGroup="Demographic" formState="In-Work">
<state value="form.state.in.work" signer="Paul Sanders - Project Manager" signerUniqueId="1681162687395" dateSigned="2023-04-15 12:08:19 -0400" />
<category name="Demographics" type="normal" highestIndex="0">
<field name="address" type="text" dataType="string" errorCode="valid" whenCreated="2023-04-15 11:07:14 -0500" keepHistory="true" />
<field name="company" type="text" dataType="string" errorCode="valid" whenCreated="2023-04-15 11:07:14 -0500" keepHistory="true">
<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>
</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">
<value by="set from calculation" byUniqueId="" role="System" when="2023-04-15 12:08:19 -0400" xml:space="preserve">ABC-Some Site</value>
<reason by="set from calculation" byUniqueId="" role="System" when="2023-04-15 12:08:19 -0400" xml:space="preserve">calculated value</reason>
</entry>
<entry id="2">
<value by="set from calculation" byUniqueId="" role="System" when="2023-04-15 12:07:24 -0400" xml:space="preserve">Some Site</value>
<reason by="set from calculation" byUniqueId="" role="System" when="2023-04-15 12:07:24 -0400" xml:space="preserve">calculated value</reason>
</entry>
</field>
</category>
<category name="Enrollment" type="normal" highestIndex="0">
<field name="enrollment_closed_date" type="popUpCalendar" dataType="date" errorCode="valid" whenCreated="2023-04-15 11:07:14 -0500" keepHistory="true" />
<field name="enrollment_open" type="radio" dataType="string" errorCode="valid" whenCreated="2023-04-15 11:07:14 -0500" keepHistory="true">
<entry id="1">
<value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-04-15 12:08:19 -0400" xml:space="preserve">Yes</value>
</entry>
</field>
<field name="enrollment_open_date" type="popUpCalendar" dataType="date" errorCode="valid" whenCreated="2023-04-15 11:07:14 -0500" keepHistory="true" />
</category>
</form>
</site>
<site name="Artemis" uniqueId="1691420994591" numberOfPatients="0" countOfRandomizedPatients="0" whenCreated="2023-08-07 08:14:23 -0700" creator="Paul Sanders" numberOfForms="1">
<form name="demographic.form.name.site.demographics" lastModified="2023-08-07 08:14:23 -0700" whoLastModifiedName="Paul Sanders" whoLastModifiedRole="Project Manager" whenCreated="1691420994611" hasErrors="false" hasWarnings="false" locked="false" user="" dateTimeChanged="" formTitle="Site Demographics" formIndex="1" formGroup="Demographic" formState="In-Work">
<state value="form.state.in.work" signer="Paul Sanders - Project Manager" signerUniqueId="1681162687395" dateSigned="2023-08-07 08:14:23 -0700" />
<category name="Demographics" type="normal" highestIndex="0">
<field name="address" type="text" dataType="string" errorCode="valid" whenCreated="2023-08-07 10:09:54 -0500" keepHistory="true">
<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>
</site>
</export_from_vision_EDC>
"#;
let expected = SiteNative {
sites: vec![
Site {
name: "Some Site".into(),
unique_id: "1681574834910".into(),
number_of_patients: 4,
count_of_randomized_patients: 0,
when_created: Some(DateTime::parse_from_rfc3339("2023-04-15T16:08:19Z")
.unwrap()
.with_timezone(&Utc)),
creator: "Paul Sanders".into(),
number_of_forms: 1,
forms: Some(vec![Form {
name: "demographic.form.name.site.demographics".into(),
last_modified: Some(
DateTime::parse_from_rfc3339("2023-04-15T16:08:19Z")
.unwrap()
.with_timezone(&Utc),
),
who_last_modified_name: Some("Paul Sanders".into()),
who_last_modified_role: Some("Project Manager".into()),
when_created: 1681574834930,
has_errors: false,
has_warnings: false,
locked: false,
user: None,
date_time_changed: None,
form_title: "Site Demographics".into(),
form_index: 1,
form_group: Some("Demographic".into()),
form_state: "In-Work".into(),
lock_states: None,
states: Some(vec![State {
value: "form.state.in.work".into(),
signer: "Paul Sanders - Project Manager".into(),
signer_unique_id: "1681162687395".into(),
date_signed: Some(
DateTime::parse_from_rfc3339("2023-04-15T16:08:19Z")
.unwrap()
.with_timezone(&Utc),
),
}].into()),
categories: Some(vec![
Category {
name: "Demographics".into(),
category_type: "normal".into(),
highest_index: 0,
fields: Some(vec![
Field {
name: "address".into(),
field_type: "text".into(),
data_type: Some("string".into()),
error_code: "valid".into(),
when_created: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:07:14Z",
)
.unwrap()
.with_timezone(&Utc)),
keep_history: true,
entries: None,
comments: None,
queries: None,
},
Field {
name: "company".into(),
field_type: "text".into(),
data_type: Some("string".into()),
error_code: "valid".into(),
when_created: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:07:14Z",
)
.unwrap()
.with_timezone(&Utc)),
keep_history: true,
entries: Some(vec![Entry {
entry_id: "1".into(),
reviewed_by: None,
reviewed_by_unique_id: None,
reviewed_by_when: None,
value: Some(Value {
by: "Paul Sanders".into(),
by_unique_id: Some("1681162687395".into()),
role: "Project Manager".into(),
when: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:08:19Z",
)
.unwrap()
.with_timezone(&Utc)),
value: "Some Company".into(),
}),
reason: None,
}].into()),
comments: None,
queries: None,
},
Field {
name: "site_code_name".into(),
field_type: "hidden".into(),
data_type: Some("string".into()),
error_code: "valid".into(),
when_created: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:07:14Z",
)
.unwrap()
.with_timezone(&Utc)),
keep_history: true,
entries: Some(vec![
Entry {
entry_id: "1".into(),
reviewed_by: None,
reviewed_by_unique_id: None,
reviewed_by_when: None,
value: Some(Value {
by: "set from calculation".into(),
by_unique_id: None,
role: "System".into(),
when: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:08:19Z",
)
.unwrap()
.with_timezone(&Utc)),
value: "ABC-Some Site".into(),
}),
reason: Some(Reason {
by: "set from calculation".into(),
by_unique_id: None,
role: "System".into(),
when: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:08:19Z",
)
.unwrap()
.with_timezone(&Utc)),
value: "calculated value".into(),
}),
},
Entry {
entry_id: "2".into(),
reviewed_by: None,
reviewed_by_unique_id: None,
reviewed_by_when: None,
value: Some(Value {
by: "set from calculation".into(),
by_unique_id: None,
role: "System".into(),
when: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:07:24Z",
)
.unwrap()
.with_timezone(&Utc)),
value: "Some Site".into(),
}),
reason: Some(Reason {
by: "set from calculation".into(),
by_unique_id: None,
role: "System".into(),
when: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:07:24Z",
)
.unwrap()
.with_timezone(&Utc)),
value: "calculated value".into(),
}),
},
].into()),
comments: None,
queries: None,
},
].into()),
files: None,
obfuscated: false,
over_ride_highest_index: false,
},
Category {
name: "Enrollment".into(),
category_type: "normal".into(),
highest_index: 0,
fields: Some(vec![
Field {
name: "enrollment_closed_date".into(),
field_type: "popUpCalendar".into(),
data_type: Some("date".into()),
error_code: "valid".into(),
when_created: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:07:14Z",
)
.unwrap()
.with_timezone(&Utc)),
keep_history: true,
entries: None,
comments: None,
queries: None,
},
Field {
name: "enrollment_open".into(),
field_type: "radio".into(),
data_type: Some("string".into()),
error_code: "valid".into(),
when_created: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:07:14Z",
)
.unwrap()
.with_timezone(&Utc)),
keep_history: true,
entries: Some(vec![Entry {
entry_id: "1".into(),
reviewed_by: None,
reviewed_by_unique_id: None,
reviewed_by_when: None,
value: Some(Value {
by: "Paul Sanders".into(),
by_unique_id: Some("1681162687395".into()),
role: "Project Manager".into(),
when: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:08:19Z",
)
.unwrap()
.with_timezone(&Utc)),
value: "Yes".into(),
}),
reason: None,
}].into()),
comments: None,
queries: None,
},
Field {
name: "enrollment_open_date".into(),
field_type: "popUpCalendar".into(),
data_type: Some("date".into()),
error_code: "valid".into(),
when_created: Some(DateTime::parse_from_rfc3339(
"2023-04-15T16:07:14Z",
)
.unwrap()
.with_timezone(&Utc)),
keep_history: true,
entries: None,
comments: None,
queries: None,
},
].into()),
files: None,
obfuscated: false,
over_ride_highest_index: false,
},
].into()),
}].into()),
},
Site {
name: "Artemis".into(),
unique_id: "1691420994591".into(),
number_of_patients: 0,
count_of_randomized_patients: 0,
when_created: Some(DateTime::parse_from_rfc3339("2023-08-07T15:14:23Z")
.unwrap()
.with_timezone(&Utc)),
creator: "Paul Sanders".into(),
number_of_forms: 1,
forms: Some(vec![Form {
name: "demographic.form.name.site.demographics".into(),
last_modified: Some(
DateTime::parse_from_rfc3339("2023-08-07T15:14:23Z")
.unwrap()
.with_timezone(&Utc),
),
who_last_modified_name: Some("Paul Sanders".into()),
who_last_modified_role: Some("Project Manager".into()),
when_created: 1691420994611,
has_errors: false,
has_warnings: false,
locked: false,
user: None,
date_time_changed: None,
form_title: "Site Demographics".into(),
form_index: 1,
form_group: Some("Demographic".into()),
form_state: "In-Work".into(),
lock_states: None,
states: Some(vec![State {
value: "form.state.in.work".into(),
signer: "Paul Sanders - Project Manager".into(),
signer_unique_id: "1681162687395".into(),
date_signed: Some(
DateTime::parse_from_rfc3339("2023-08-07T15:14:23Z")
.unwrap()
.with_timezone(&Utc),
),
}].into()),
categories: Some(vec![Category {
name: "Demographics".into(),
category_type: "normal".into(),
highest_index: 0,
fields: Some(vec![Field {
name: "address".into(),
field_type: "text".into(),
data_type: Some("string".into()),
error_code: "valid".into(),
when_created: Some(DateTime::parse_from_rfc3339("2023-08-07T15:09:54Z")
.unwrap()
.with_timezone(&Utc)),
keep_history: true,
entries: Some(vec![Entry {
entry_id: "1".into(),
reviewed_by: None,
reviewed_by_unique_id: None,
reviewed_by_when: None,
value: Some(Value {
by: "Paul Sanders".into(),
by_unique_id: Some("1681162687395".into()),
role: "Project Manager".into(),
when: Some(DateTime::parse_from_rfc3339("2023-08-07T15:14:21Z")
.unwrap()
.with_timezone(&Utc)),
value: "1111 Moon Drive".into(),
}),
reason: None,
}].into()),
comments: Some(vec![Comment {
comment_id: "1".into(),
value: Some(Value {
by: "Paul Sanders".into(),
by_unique_id: Some("1681162687395".into()),
role: "Project Manager".into(),
when: Some(DateTime::parse_from_rfc3339("2023-08-07T15:14:21Z")
.unwrap()
.with_timezone(&Utc)),
value: "Some comment".into(),
}),
reviewed_by: None,
reviewed_by_unique_id: None,
reviewed_by_when: None,
}].into()),
queries: None,
}].into()),
files: None,
obfuscated: false,
over_ride_highest_index: false,
}].into()),
}].into()),
},
],
export: Some(Export {
date: Some(DateTime::parse_from_rfc3339("2024-06-01T23:17:00Z")
.unwrap()
.with_timezone(&Utc)),
created_by: Some("Paul Sanders".into()),
role: Some("Project Manager".into()),
number_subjects_processed: Some(2),
page_number: None,
}),
};
let result = parse_site_native_string(xml).unwrap();
assert_eq!(result, expected);