Skip to main content

parse_subject_native_string

Function parse_subject_native_string 

Source
pub fn parse_subject_native_string(
    xml_str: &str,
) -> Result<SubjectNative, Error>
Expand description

Parse a string of Prelude native subject XML into a SubjectNative struct.

ยงExample

use chrono::{DateTime, Utc};
use prelude_xml_parser::parse_subject_native_string;
use prelude_xml_parser::native::common::LockState;
use prelude_xml_parser::native::subject_native::*;

let xml = r#"<export_from_vision_EDC date="30-May-2024 10:35 -0500" createdBy="Paul Sanders" role="Project Manager" numberSubjectsProcessed="4">
    <patient patientId="ABC-001" uniqueId="1681574905819" whenCreated="2023-04-15 12:09:02 -0400" creator="Paul Sanders" siteName="Some Site" siteUniqueId="1681574834910" lastLanguage="English" numberOfForms="6">
      <form name="day.0.form.name.demographics" lastModified="2023-04-15 12:09:15 -0400" whoLastModifiedName="Paul Sanders" whoLastModifiedRole="Project Manager" whenCreated="1681574905839" hasErrors="false" hasWarnings="false" locked="false" user="" dateTimeChanged="" formTitle="Demographics" formIndex="1" formGroup="Day 0" formState="In-Work">
        <state value="form.state.in.work" signer="Paul Sanders - Project Manager" signerUniqueId="1681162687395" dateSigned="2023-04-15 12:09:02 -0400"/>
        <category name="Demographics" type="normal" highestIndex="0">
          <field name="breed" type="combo-box" dataType="string" errorCode="valid" whenCreated="2023-04-15 12:08:26 -0400" keepHistory="true">
            <entry id="1">
              <value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-04-15 12:09:02 -0400" xml:space="preserve">Labrador</value>
            </entry>
          </field>
        </category>
      </form>
    </patient>
    <patient patientId="DEF-002" uniqueId="1681574905820" whenCreated="2023-04-16 12:10:02 -0400" creator="Wade Watts" siteName="Another Site" siteUniqueId="1681574834911" lastLanguage="" numberOfForms="8">
      <form name="day.0.form.name.demographics" lastModified="2023-04-16 12:10:15 -0400" whoLastModifiedName="Barney Rubble" whoLastModifiedRole="Technician" whenCreated="1681574905838" hasErrors="false" hasWarnings="false" locked="false" user="" dateTimeChanged="" formTitle="Demographics" formIndex="1" formGroup="Day 0" formState="In-Work">
        <state value="form.state.in.work" signer="Paul Sanders - Project Manager" signerUniqueId="1681162687395" dateSigned="2023-04-16 12:10:02 -0400"/>
        <category name="Demographics" type="normal" highestIndex="0">
          <field name="breed" type="combo-box" dataType="string" errorCode="valid" whenCreated="2023-04-15 12:08:26 -0400" keepHistory="true">
            <entry id="1">
              <value by="Paul Sanders" byUniqueId="1681162687395" role="Project Manager" when="2023-04-15 12:09:02 -0400" xml:space="preserve">Labrador</value>
            </entry>
          </field>
        </category>
      </form>
    </patient>
</export_from_vision_EDC>
"#;

let expected = SubjectNative {
    patients: vec![
        Patient {
            patient_id: "ABC-001".into(),
            unique_id: "1681574905819".into(),
            when_created: Some(DateTime::parse_from_rfc3339("2023-04-15T16:09:02Z")
                .unwrap()
                .with_timezone(&Utc)),
            creator: "Paul Sanders".into(),
            site_name: "Some Site".into(),
            site_unique_id: "1681574834910".into(),
            last_language: Some("English".into()),
            number_of_forms: 6,
            forms: Some(vec![Form {
                name: "day.0.form.name.demographics".into(),
                last_modified: Some(DateTime::parse_from_rfc3339("2023-04-15T16:09:15Z")
                    .unwrap()
                    .with_timezone(&Utc)),
                who_last_modified_name: Some("Paul Sanders".into()),
                who_last_modified_role: Some("Project Manager".into()),
                when_created: 1681574905839,
                has_errors: false,
                has_warnings: false,
                locked: false,
                user: None,
                date_time_changed: None,
                form_title: "Demographics".into(),
                form_index: 1,
                form_group: Some("Day 0".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:09:02Z")
                            .unwrap()
                            .with_timezone(&Utc),
                    ),
                }].into()),
                categories: Some(vec![Category {
                    name: "Demographics".into(),
                    category_type: "normal".into(),
                    highest_index: 0,
                    fields: Some(vec![Field {
                        name: "breed".into(),
                        field_type: "combo-box".into(),
                        data_type: Some("string".into()),
                        error_code: "valid".into(),
                        when_created: Some(DateTime::parse_from_rfc3339("2023-04-15T16:08:26Z")
                            .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:09:02Z")
                                    .unwrap()
                                    .with_timezone(&Utc)),
                                value: "Labrador".into(),
                            }),
                            reason: None,
                        }].into()),
                        comments: None,
                        queries: None,
                    }].into()),
                    files: None,
                    obfuscated: false,
                    over_ride_highest_index: false,
                }].into()),
            }].into()),
            password_change_date: None,
        },
        Patient {
            patient_id: "DEF-002".into(),
            unique_id: "1681574905820".into(),
            when_created: Some(DateTime::parse_from_rfc3339("2023-04-16T16:10:02Z")
                .unwrap()
                .with_timezone(&Utc)),
            creator: "Wade Watts".into(),
            site_name: "Another Site".into(),
            site_unique_id: "1681574834911".into(),
            last_language: None,
            number_of_forms: 8,
            forms: Some(vec![Form {
                name: "day.0.form.name.demographics".into(),
                last_modified: Some(DateTime::parse_from_rfc3339("2023-04-16T16:10:15Z")
                    .unwrap()
                    .with_timezone(&Utc)),
                who_last_modified_name: Some("Barney Rubble".into()),
                who_last_modified_role: Some("Technician".into()),
                when_created: 1681574905838,
                has_errors: false,
                has_warnings: false,
                locked: false,
                user: None,
                date_time_changed: None,
                form_title: "Demographics".into(),
                form_index: 1,
                form_group: Some("Day 0".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-16T16:10:02Z")
                            .unwrap()
                            .with_timezone(&Utc),
                    ),
                }].into()),
                categories: Some(vec![Category {
                    name: "Demographics".into(),
                    category_type: "normal".into(),
                    highest_index: 0,
                    fields: Some(vec![Field {
                        name: "breed".into(),
                        field_type: "combo-box".into(),
                        data_type: Some("string".into()),
                        error_code: "valid".into(),
                        when_created: Some(DateTime::parse_from_rfc3339("2023-04-15T16:08:26Z")
                            .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:09:02Z")
                                    .unwrap()
                                    .with_timezone(&Utc)),
                                value: "Labrador".into(),
                            }),
                            reason: None,
                        }].into()),
                        comments: None,
                        queries: None,
                    }].into()),
                    files: None,
                    obfuscated: false,
                    over_ride_highest_index: false,
                }].into()),
            }].into()),
            password_change_date: None,
        },
    ],
    export: Some(Export {
        date: Some(DateTime::parse_from_rfc3339("2024-05-30T15:35:00Z")
            .unwrap()
            .with_timezone(&Utc)),
        created_by: Some("Paul Sanders".into()),
        role: Some("Project Manager".into()),
        number_subjects_processed: Some(4),
        page_number: None,
    }),
};
let result = parse_subject_native_string(xml).unwrap();

assert_eq!(result, expected);