pub fn parse_user_native_string(xml_str: &str) -> Result<UserNative, Error>Expand description
Parse a string of Prelude native user XML into a UserNative struct.
ยงExample
use chrono::{DateTime, Utc};
use prelude_xml_parser::parse_user_native_string;
use prelude_xml_parser::native::user_native::*;
let xml = r#"<?xml version="1.0" encoding="UTF-8"?>
<export_from_vision_EDC date="02-Jun-2024 06:59 -0500" createdBy="Paul Sanders" role="Project Manager" numberSubjectsProcessed="3">
<user uniqueId="1691421275437" lastLanguage="" creator="Paul Sanders(1681162687395)" numberOfForms="1">
<form name="form.name.demographics" lastModified="2023-08-07 10:15:41 -0500" whoLastModifiedName="Paul Sanders" whoLastModifiedRole="Project Manager" whenCreated="1691421341578" hasErrors="false" hasWarnings="false" locked="false" user="" dateTimeChanged="" formTitle="User Demographics" formIndex="1" formGroup="" formState="In-Work">
<state value="form.state.in.work" signer="Paul Sanders - Project Manager" signerUniqueId="1681162687395" dateSigned="2023-08-07 10:15:41 -0500" />
<category name="demographics" type="normal" highestIndex="0">
<field name="address" type="text" dataType="string" errorCode="undefined" whenCreated="2024-01-12 14:14:09 -0600" keepHistory="true" />
<field name="email" type="text" dataType="string" errorCode="undefined" whenCreated="2023-08-07 10:15:41 -0500" keepHistory="true">
<entry id="1">
<value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-08-07 10:15:41 -0500" xml:space="preserve">jazz@artemis.com</value>
</entry>
</field>
</category>
<category name="Administrative" type="normal" highestIndex="0">
<field name="study_assignment" type="text" dataType="" errorCode="undefined" whenCreated="2023-08-07 10:15:41 -0500" keepHistory="true">
<entry id="1">
<value by="set from calculation" byUniqueId="" role="System" when="2023-08-07 10:15:41 -0500" xml:space="preserve">On 07-Aug-2023 10:15 -0500, Paul Sanders assigned user from another study</value>
<reason by="set from calculation" byUniqueId="" role="System" when="2023-08-07 10:15:41 -0500" xml:space="preserve">calculated value</reason>
</entry>
</field>
</category>
</form>
</user>
</export_from_vision_EDC>
"#;
let expected = UserNative {
users: vec![User {
unique_id: "1691421275437".into(),
last_language: None,
creator: "Paul Sanders(1681162687395)".into(),
number_of_forms: 1,
forms: Some(vec![Form {
name: "form.name.demographics".into(),
last_modified: Some(
DateTime::parse_from_rfc3339("2023-08-07T15:15:41Z")
.unwrap()
.with_timezone(&Utc),
),
who_last_modified_name: Some("Paul Sanders".into()),
who_last_modified_role: Some("Project Manager".into()),
when_created: 1691421341578,
has_errors: false,
has_warnings: false,
locked: false,
user: None,
date_time_changed: None,
form_title: "User Demographics".into(),
form_index: 1,
form_group: None,
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:15:41Z")
.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: "undefined".into(),
when_created: Some(DateTime::parse_from_rfc3339("2024-01-12T20:14:09Z")
.unwrap()
.with_timezone(&Utc)),
keep_history: true,
entries: None,
comments: None,
queries: None,
},
Field {
name: "email".into(),
field_type: "text".into(),
data_type: Some("string".into()),
error_code: "undefined".into(),
when_created: Some(DateTime::parse_from_rfc3339("2023-08-07T15:15:41Z")
.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:15:41Z")
.unwrap()
.with_timezone(&Utc)),
value: "jazz@artemis.com".into(),
}),
reason: None,
}].into()),
comments: None,
queries: None,
},
].into()),
files: None,
obfuscated: false,
over_ride_highest_index: false,
},
Category {
name: "Administrative".into(),
category_type: "normal".into(),
highest_index: 0,
fields: Some(vec![
Field {
name: "study_assignment".into(),
field_type: "text".into(),
data_type: None,
error_code: "undefined".into(),
when_created: Some(DateTime::parse_from_rfc3339("2023-08-07T15:15:41Z")
.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-08-07T15:15:41Z")
.unwrap()
.with_timezone(&Utc)),
value: "On 07-Aug-2023 10:15 -0500, Paul Sanders assigned user from another study".into(),
}),
reason: Some(Reason {
by: "set from calculation".into(),
by_unique_id: None,
role: "System".into(),
when: Some(DateTime::parse_from_rfc3339("2023-08-07T15:15:41Z")
.unwrap()
.with_timezone(&Utc)),
value: "calculated value".into(),
}),
},
].into()),
comments: None,
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-02T11:59:00Z")
.unwrap()
.with_timezone(&Utc)),
created_by: Some("Paul Sanders".into()),
role: Some("Project Manager".into()),
number_subjects_processed: Some(3),
page_number: None,
}),
};
let result = parse_user_native_string(xml).unwrap();
assert_eq!(result, expected);