Esempio n. 1
0
    def testMissedApptBug(self):
        folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "missedappt_bug")
        patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
        
        updated_patient, _ = add_form_with_date_offset\
                (patient.get_id, os.path.join(folder_name, "001_underfive.xml"),
                 days_from_today=0)

        today = datetime.utcnow().date()
        # grab the case xml and check it against what we expect to get back
        c = Client()
        response = c.get(reverse("patient_case_xml", args=[updated_patient.get_id]))
        expected_xml = \
"""<cases>
<case>
    <case_id>ef17b25547da4554842100e3e3eb3fb7</case_id> 
    <date_modified>%(today)s</date_modified>
    <create>
        <case_type_id>bhoma_followup</case_type_id> 
        <user_id>a014b648-9bed-11df-a250-0001c006087d</user_id> 
        <case_name>underfive</case_name> 
        <external_id>9cfaf4cf2abb411ba7ca0593293109fc</external_id>
    </create>
    <update>
        <first_name>MISSEDAPP</first_name>
        <last_name>BUG</last_name>
        <birth_date>2008-07-20</birth_date>
        <birth_date_est>False</birth_date_est>
        <age>%(age)s</age>
        <sex>f</sex>
        <village>FOX</village>
        <contact>8569</contact>
        <bhoma_case_id>9cfaf4cf2abb411ba7ca0593293109fc</bhoma_case_id>
        <bhoma_patient_id>42253e98d9b241fe7b28a2e3da1f0dbd</bhoma_patient_id>
        <followup_type>hospital</followup_type>
        <orig_visit_type>underfive</orig_visit_type>
        <orig_visit_diagnosis></orig_visit_diagnosis>
        <orig_visit_date>%(today)s</orig_visit_date>
        <activation_date>%(active)s</activation_date>
        <due_date>%(due)s</due_date>
        <missed_appt_date></missed_appt_date>
    </update>
</case>
</cases>""" % {"today": date_to_xml_string(datetime.utcnow().date()),
               "age": updated_patient.formatted_age,
               "active": date_to_xml_string(today + timedelta(days=14)),
               "due": date_to_xml_string(today + timedelta(days=19))}
        
        check_xml_line_by_line(self, expected_xml, response.content)
Esempio n. 2
0
    def testMissedAppointmentPhoneCase(self):
        folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "phone_test")
        patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
        updated_patient, _ = add_form_with_date_offset\
                (patient.get_id, os.path.join(folder_name, "001_general.xml"),
                 days_from_today=-1)

        
        self.assertEqual(1, len(updated_patient.cases))
        case = updated_patient.cases[0]
        self.assertFalse(case.closed)
        self.assertTrue(case.send_to_phone)
        self.assertEqual("urgent_clinic_followup", case.send_to_phone_reason)
        self.assertEqual("diarrhea", case.type)
        self.assertEqual("return to clinic", case.status)
        self.assertEqual(None, case.outcome)
        
        ccase = case.commcare_cases[0]
        self.assertFalse(ccase.closed)
        self.assertEqual(case.get_id, ccase.external_id)
        self.assertEqual("missed_appt", ccase.followup_type)
        today = datetime.utcnow().date()
        visit_date = today + timedelta(days=-1)
        start_date = visit_date + timedelta(days=7)
        due_date = start_date + timedelta(days=10)
        self.assertEqual(start_date, ccase.activation_date)
        self.assertEqual(due_date, ccase.due_date)
        self.assertEqual(start_date, ccase.start_date)
        
        # grab the case xml and check it against what we expect to get back
        c = Client()
        response = c.get(reverse("patient_case_xml", args=[updated_patient.get_id]))
        
        expected_casexml = \
"""<cases>
<case>
    <case_id>27e45e6086a8418290f82e1494ca54e7</case_id> 
    <date_modified>%(today)s</date_modified>
    <create>
        <case_type_id>bhoma_followup</case_type_id> 
        <user_id>f4374680-9bea-11df-a4f6-005056c00008</user_id> 
        <case_name>general|diarrhea</case_name> 
        <external_id>61a91e70d246486b99abb6ad752e82a5</external_id>
    </create>
    <update>
        <first_name>PHONE</first_name>
        <last_name>TEST</last_name>
        <birth_date>1987-03-19</birth_date>
        <birth_date_est>False</birth_date_est>
        <age>%(age)s</age>
        <sex>f</sex>
        <village>GSMLAND</village>
        <contact>0128674102</contact>
        <bhoma_case_id>61a91e70d246486b99abb6ad752e82a5</bhoma_case_id>
        <bhoma_patient_id>829684277b127eed27e1d6ef08d6c74a</bhoma_patient_id>
        <followup_type>missed_appt</followup_type>
        <orig_visit_type>general</orig_visit_type>
        <orig_visit_diagnosis>diarrhea</orig_visit_diagnosis>
        <orig_visit_date>%(visit_date)s</orig_visit_date>
        <activation_date>%(start)s</activation_date>
        <due_date>%(due)s</due_date>
        <missed_appt_date>%(missed)s</missed_appt_date>
    </update>
</case>
</cases>""" % {"today": date_to_xml_string(today),
               "visit_date": date_to_xml_string(visit_date),
               "age": updated_patient.formatted_age,
               "start": date_to_xml_string(start_date),
               "due": date_to_xml_string(due_date),
               "missed": date_to_xml_string(start_date - timedelta(days=3))}
        
        check_xml_line_by_line(self, expected_casexml, response.content)
        
        # add the phone followup
        updated_patient, _ = add_form_with_date_offset\
                (patient.get_id, os.path.join(folder_name, "002_chw_fu.xml"),
                 days_from_today=0)
                
        self.assertEqual(1, len(updated_patient.cases))
        [case] = updated_patient.cases
        self.assertTrue(case.closed)
        self.assertTrue(case.send_to_phone)
        self.assertEqual("urgent_clinic_followup", case.send_to_phone_reason)
        self.assertEqual("diarrhea", case.type)
        self.assertEqual("return to clinic", case.status)
        self.assertEqual("lost_to_followup_wont_return_to_clinic", case.outcome)