Exemplo n.º 1
0
Arquivo: case.py Projeto: dimagi/bhoma
def get_healthy_pregnancy_case(pregnancy, encounter):
    # Any pregnancy case that is created that hasn't been closed by a delivery 
    # gets a followup.  The followups become active at week 42 and expires in
    # week 46 of the pregnancy
    # The CHW should track the delivery and give an outcome to the pregnancy.
    
    lmp = pregnancy.lmp
    # TODO: is this check/logic necessary?
    if lmp:
        send_to_phone = True
        reason = "pregnancy_expecting_outcome"
    else:
        send_to_phone = False
        reason = "unknown_lmp"
    
    ltfu_date = lmp + timedelta(days=46*7) if lmp else None
    bhoma_case = PatientCase(_id=get_bhoma_case_id_from_pregnancy(pregnancy), 
                             opened_on=datetime.combine(encounter.visit_date, time()),
                             modified_on=datetime.utcnow(),
                             type=const.CASE_TYPE_PREGNANCY,
                             encounter_id=encounter.get_id,
                             patient_id=get_patient_id_from_form(encounter.get_xform()),
                             ltfu_date=ltfu_date,
                             outcome=pregnancy.outcome,
                             closed=pregnancy.closed,
                             closed_on=pregnancy.closed_on,
                             send_to_phone=send_to_phone,
                             send_to_phone_reason=reason)
    bhoma_case.status = "pending outcome"
    
    if send_to_phone and not bhoma_case.closed:
        cccase = get_first_commcare_case(encounter, bhoma_case=bhoma_case, 
                                     case_id=get_commcare_case_id_from_block(encounter,bhoma_case))
        cccase.followup_type = const.PHONE_FOLLOWUP_TYPE_PREGNANCY
    
        # starts and becomes active the same day, 42 weeks from LMP
        bhoma_case.lmp = lmp
        cccase.start_date = lmp + timedelta(days= 7 * 42)
        cccase.missed_appointment_date = cccase.start_date
        cccase.activation_date = cccase.start_date
        cccase.due_date = cccase.activation_date + timedelta(days=DAYS_AFTER_PREGNANCY_ACTIVE_DUE)
        bhoma_case.commcare_cases = [cccase]
    return bhoma_case
Exemplo n.º 2
0
def get_delivery_case(patient, encounter, delivery):
    # All deliveries get two follow ups.

    if delivery.date:
        send_to_phone = True
        reason = "delivery_needing_followup"
    else:
        send_to_phone = False
        reason = "unknown_delivery_date"

    # todo proper ltfu date
    ltfu_date = delivery.date + timedelta(days=7*42)
    bhoma_case = PatientCase(
        _id=get_bhoma_case_id_from_delivery(delivery),
        opened_on=datetime.combine(encounter.visit_date, time()),
        modified_on=datetime.utcnow(),
        type=const.CASE_TYPE_DELIVERY,
        encounter_id=encounter.get_id,
        patient_id=patient._id,
        ltfu_date=ltfu_date,
        status="pending outcome",
        outcome=delivery.outcome,
        closed=delivery.closed,
        closed_on=delivery.closed_on,
        send_to_phone=send_to_phone,
        send_to_phone_reason=reason,
    )

    if send_to_phone and not bhoma_case.closed:
        # we'll generate two commcare cases immedieately
        ccfu1 = get_first_commcare_case(
            encounter,
            bhoma_case=bhoma_case,
            case_id=get_commcare_case_id_from_delivery(delivery, 1)
        )
        ccfu1.followup_type = const.PHONE_FOLLOWUP_TYPE_DELIVERY

        # starts after 4 days, active after 6 days
        ccfu1.start_date = delivery.date + timedelta(days=1)
        ccfu1.orig_visit_date = delivery.date
        ccfu1.missed_appointment_date = None # TODO: do we need to change this so the phone can use it?
        ccfu1.activation_date = delivery.date + timedelta(days=2)
        ccfu1.due_date = ccfu1.activation_date + timedelta(days=14)
        ccfu1.ltfu_date = ccfu1.activation_date + timedelta(days=24)
        ccfu1.visit_number = '1'

        ccfu2 = get_first_commcare_case(
            encounter,
            bhoma_case=bhoma_case,
            case_id=get_commcare_case_id_from_delivery(delivery, 2)
        )
        ccfu2.followup_type = const.PHONE_FOLLOWUP_TYPE_DELIVERY

        # starts after 23 days, active after 28 days, due in 5, ltfu after 42
        ccfu2.start_date = delivery.date + timedelta(days=23)
        ccfu2.orig_visit_date = delivery.date
        ccfu2.missed_appointment_date = None # TODO: do we need to change this so the phone can use it?
        ccfu2.activation_date = delivery.date + timedelta(days=28)
        ccfu2.due_date = ccfu2.activation_date + timedelta(days=5)
        ccfu2.ltfu_date = ccfu2.activation_date + timedelta(days=42)
        ccfu2.visit_number = '2'


        bhoma_case.commcare_cases = [ccfu1, ccfu2]
    return bhoma_case