Ejemplo n.º 1
0
def update_deliveries(patient, encounter):
    """
    From a patient object, update the list of deliveries.
    """
    assert is_delivery_encounter(encounter)
    # create a delivery if it is a new one.
    if is_new_delivery(encounter):
        new_delivery = Delivery(
            xform_id=encounter.get_xform()._id,
            date=get_delivery_date(encounter),
        )
        patient.deliveries.append(new_delivery)
        patient.cases.append(get_delivery_case(patient, encounter, new_delivery))

    return patient
Ejemplo n.º 2
0
def add_form_to_patient(patient_id, form):
    """
    Adds a clinic form to a patient, including all processing necessary.
    """
    
    patient = CPatient.get(patient_id)
    new_encounter = Encounter.from_xform(form)
    patient.encounters.append(new_encounter)
    
    encounter_info = ENCOUNTERS_BY_XMLNS.get(form.namespace)
    if not encounter_info:
        raise Exception("Attempt to add unknown form type: %s to patient %s!" % \
                        (form.namespace, patient_id))
    
    if encounter_info.classification == CLASSIFICATION_CLINIC:
        case = get_or_update_bhoma_case(form, new_encounter)
        if case:
            patient.cases.append(case)
        
        if is_pregnancy_encounter(new_encounter):
            update_pregnancies(patient, new_encounter)

        if is_delivery_encounter(new_encounter):
            update_deliveries(patient, new_encounter)

    elif encounter_info.classification == CLASSIFICATION_PHONE:
        # process phone form
        process_phone_form(patient, new_encounter)
    else:
        logging.error("Unknown classification %s for encounter: %s" % \
                      (encounter_info.classification, form.get_id))
    
    # finally close any previous cases we had open, according
    # to the complicated rules
    close_previous_cases_from_new_form(patient, form, new_encounter)
    patient.save()