Exemple #1
0
def parse_container(node):
    sda_bundle = SDABundle()

    patient_node = node.find('./Patient')

    sda_patient = parse_patient(patient_node)
    sda_bundle.sda_patient = sda_patient

    for medication_node in node.findall('./Medications/Medication'):
        sda_medication = parse_medication(medication_node)
        sda_bundle.sda_medications.append(sda_medication)

    for lab_order_node in node.findall('./LabOrders/LabOrder'):
        sda_lab_order = parse_lab_order(lab_order_node)
        sda_bundle.sda_lab_orders.append(sda_lab_order)

    for procedure_node in node.findall('./Procedures/Procedure'):
        sda_procedure = parse_lab_order(procedure_node)
        sda_bundle.sda_procedures.append(sda_procedure)

    for encounter_node in node.findall('./Encounters/Encounter'):
        sda_encounter = parse_lab_order(encounter_node)
        sda_bundle.sda_encounters.append(sda_encounter)

    return sda_bundle
Exemple #2
0
def demographics_to_sda_bundle(demographics):
    # TODO
    facility = Facility.query.filter(Facility.code == 'RADAR').first_or_404()

    sda_bundle = SDABundle(facility=facility, patient=demographics.patient)

    sda_patient = SDAPatient()

    if demographics.gender == 1:
        gender_code = 'M'
        gender_description = 'Male'
    else:
        gender_code = 'F'
        gender_description = 'Male'

    sda_patient.data = {
        'name': {
            'given_name': demographics.first_name,
            'family_name': demographics.last_name,
        },
        'birth_time': demographics.date_of_birth,
        'gender': {
            'code': gender_code,
            'description': gender_description,
        }
    }

    if demographics.date_of_death:
        sda_patient.data['death_time'] = demographics.date_of_death

    sda_bundle.sda_patient = sda_patient

    sda_patient_address = SDAPatientAddress()

    sda_patient_address.data = {
        'zip': {
            'description': demographics.postcode
        }
    }

    street = '; '.join(x for x in [demographics.address_line_1, demographics.address_line_2, demographics.address_line_3] if x)

    if street:
        sda_patient_address.data['street'] = street

    sda_patient.addresses.append(sda_patient_address)

    if demographics.home_number:
        set_path(sda_patient.data, ['contact_info', 'home_phone_number'], demographics.home_number)

    if demographics.work_number:
        set_path(sda_patient.data, ['contact_info', 'work_phone_number'], demographics.work_number)

    if demographics.mobile_number:
        set_path(sda_patient.data, ['contact_info', 'mobile_phone_number'], demographics.mobile_number)

    if demographics.email_address:
        set_path(sda_patient.data, ['contact_info', 'email_address'], demographics.email_address)

    if demographics.alias_first_name or demographics.alias_last_name:
        sda_patient_alias = SDAPatientAlias()
        sda_patient_alias.data = {}

        if demographics.alias_first_name:
            sda_patient_alias.data['given_name'] = demographics.first_name

        if demographics.alias_last_name:
            sda_patient_alias.data['family_name'] = demographics.last_name

        sda_patient.aliases.append(sda_patient_alias)

    return sda_bundle