Beispiel #1
0
    def testHealthyPregnancyPhoneCaseGeneration(self):
        # Healthy Pregnancy
        #  a. initial visit creates case for N days past EDD
         
        folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "healthy_pregnancy")
        patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
        # forms are loaded one at a time.  If you need to run tests at 
        # intermediate states, put them in between whatever forms you
        # want loaded
        days_offset = -50
        updated_patient, _ = add_form_with_date_offset\
                (patient.get_id, os.path.join(folder_name, "001_pregnancy.xml"),
                 days_from_today=days_offset)

        
        self.assertEqual(1, len(updated_patient.cases))
        case = updated_patient.cases[-1]
        self.assertTrue(case.send_to_phone)
        self.assertEqual("pregnancy_expecting_outcome", case.send_to_phone_reason)
        [ccase] = case.commcare_cases
        self.assertEqual("pregnancy", ccase.followup_type)
        self.assertFalse(ccase.closed)
        today = datetime.utcnow().date()
        visit_date = today + timedelta(days=days_offset)
        start_date = visit_date + timedelta(days=7*42)
        ltfu_date = visit_date + timedelta(days=7*46)
        due_date = start_date + timedelta(days=5)
        #self.assertEqual(visit_date, ccase.visit_date)
        self.assertEqual(start_date, ccase.start_date)
        self.assertEqual(start_date, ccase.activation_date)
        self.assertEqual(due_date, ccase.due_date)
        self.assertEqual(ltfu_date, case.ltfu_date)
        self.assertEqual("pregnancy|pregnancy", ccase.name)
Beispiel #2
0
 def testFirstVisitSick(self):
     # initial visit sick
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "pregnancy_sickvisit")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_sick_pregnancy.xml"))
     self.assertEqual(1, len(updated_patient.pregnancies))
     [preg] = updated_patient.pregnancies
     self.assertEqual(date(2011,1,5), preg.edd)
     self.assertEqual(form_doc1.get_id, preg.anchor_form_id)
     self.assertEqual(0, len(preg.other_form_ids))
     
     # add a healthy visit after, should be part of the same pregnancy
     updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "003_pregnancy.xml"))
     [preg] = updated_patient.pregnancies
     self.assertEqual(date(2011,1,5), preg.edd)
     self.assertEqual(form_doc1.get_id, preg.anchor_form_id)
     self.assertEqual(1, len(preg.other_form_ids))
     self.assertEqual(form_doc2.get_id, preg.other_form_ids[0])
     
     # add a healthy visit before, should be part of the same pregnancy, 
     updated_patient, form_doc3 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_pregnancy.xml"))
     [preg] = updated_patient.pregnancies
     self.assertEqual(date(2011,1,5), preg.edd)
     # should not change anchor
     self.assertEqual(form_doc1.get_id, preg.anchor_form_id)
     self.assertEqual(2, len(preg.other_form_ids))
Beispiel #3
0
 def _run_phone_visit_case_test(self, folder_name, type):
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     
     #  a. Severe symptom
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_%s.xml" % type))
     self.assertEqual(1, len(updated_patient.cases))
     case = updated_patient.cases[-1]
     self.assertTrue(case.send_to_phone)
     self.assertTrue("severe_symptom_checked" in case.send_to_phone_reason)
     
     #  b. Danger sign
     updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_%s.xml" % type))
     self.assertEqual(2, len(updated_patient.cases))
     case = updated_patient.cases[-1]
     self.assertTrue(case.send_to_phone)
     self.assertEqual("danger_sign_present", case.send_to_phone_reason)
     
     #  c. Missed appointment < 5 days
     updated_patient, form_doc3 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "003_%s.xml" % type))
     self.assertEqual(3, len(updated_patient.cases))
     case = updated_patient.cases[-1]
     self.assertTrue(case.send_to_phone)
     self.assertEqual("urgent_clinic_followup", case.send_to_phone_reason)
     
     #  d. None of the above (no case)
     updated_patient, form_doc4 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "004_%s.xml" % type))
     self.assertEqual(4, len(updated_patient.cases))
     case = updated_patient.cases[-1]
     self.assertFalse(case.send_to_phone)
     self.assertEqual("sending_criteria_not_met", case.send_to_phone_reason)
Beispiel #4
0
    def testSickPregnancyPhoneCaseGeneration(self):
        # Sick pregnancy
        
        folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "sick_pregnancy")
        patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
        # forms are loaded one at a time.  If you need to run tests at 
        # intermediate states, put them in between whatever forms you
        # want loaded

        #  a. Severe symptom
        updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_sick_pregnancy.xml"))
        self.assertEqual(1, len(updated_patient.cases))
        case = updated_patient.cases[-1]
        self.assertTrue(case.send_to_phone)
        self.assertTrue("severe_symptom_checked" in case.send_to_phone_reason)
        
        #  b. Missed appointment < 5 days
        updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_sick_pregnancy.xml"))
        self.assertEqual(2, len(updated_patient.cases))
        case = updated_patient.cases[-1]
        self.assertTrue(case.send_to_phone)
        self.assertEqual("urgent_clinic_followup", case.send_to_phone_reason)
        
        #  c. None of the above (no case)
        updated_patient, form_doc3 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "003_sick_pregnancy.xml"))
        self.assertEqual(3, len(updated_patient.cases))
        case = updated_patient.cases[-1]
        self.assertFalse(case.send_to_phone)
        self.assertEqual("sending_criteria_not_met", case.send_to_phone_reason)
Beispiel #5
0
 def testClosedCases(self):
     # run through all four forms, verify that the case closed at the clinic
     # behaves properly
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "closed_cases")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_general.xml"))
     [case] = updated_patient.cases
     self.assertTrue(case.closed)
     self.assertEqual("tb", case.type)
     self.assertEqual(Outcome.CLOSED_AT_CLINIC, case.outcome)
     self.assertEqual(0, len(case.commcare_cases))
     
     updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_sick_pregnancy.xml"))
     [_, case] = updated_patient.cases
     self.assertTrue(case.closed)
     self.assertEqual("malaria", case.type)
     self.assertEqual(Outcome.CLOSED_AT_CLINIC, case.outcome)
     self.assertEqual(0, len(case.commcare_cases))
 
     updated_patient, form_doc3 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "003_underfive.xml"))
     [_, _, case] = updated_patient.cases
     self.assertTrue(case.closed)
     self.assertEqual("meningitis", case.type)
     self.assertEqual(Outcome.CLOSED_AT_CLINIC, case.outcome)
     self.assertEqual(0, len(case.commcare_cases))
Beispiel #6
0
 def testSingleSickVisitOpenClose(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "open_close_preg")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_sick_pregnancy.xml"))
     [preg] = updated_patient.pregnancies
     [case] = updated_patient.cases
     self.assertTrue(case.closed)
     self.assertEqual(Outcome.FETAL_DEATH, case.outcome)
Beispiel #7
0
 def testHugeFollow(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "huge_follow")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     
     # these all have huge follow up dates, so these functions not throwing errors
     # is enough to test.
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_delivery.xml"))
     updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_general.xml"))
     updated_patient, form_doc3 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "003_sick_pregnancy.xml"))
Beispiel #8
0
 def testPostSaveDrugBug(self):
     self.assertEqual(0, len(ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all()))
     folder_name = os.path.join(os.path.dirname(__file__), "testdata", "test_post_save_drug_bug")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_underfive.xml"))
     
     self.assertEqual(0, len(ExceptionRecord.view("couchlog/all_by_date", include_docs=True).all()))
     
Beispiel #9
0
    def testCaseOutcomes(self):
        folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "adult_visit")
        patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))

        # Enter new form, make sure to choose a danger sign, then choose outcome follow up prn
        updated_patient, form_doc1 = add_form_with_date_offset(
            patient.get_id, os.path.join(folder_name, "001_general.xml"), days_from_today=-5
        )

        [case] = updated_patient.cases
        self.assertFalse(patient.is_deceased)
        self.assertEqual(0, len(case.commcare_cases))
        self.assertTrue(case.closed)
        self.assertEqual(Outcome.CLOSED_AT_CLINIC, case.outcome)

        # Enter new form, make sure to choose a danger sign, then choose outcome referred
        updated_patient, form_doc2 = add_form_with_date_offset(
            patient.get_id, os.path.join(folder_name, "002_general.xml"), days_from_today=-4
        )
        self.assertEqual(2, len(updated_patient.cases))
        case = updated_patient.cases[-1]
        self.assertFalse(case.closed)
        [ccase] = case.commcare_cases
        check_commcare_dates(self, case, ccase, 9, 14, 19, 42)

        # Enter new form, make sure to choose a danger sign, then choose outcome follow up facilility
        updated_patient, form_doc3 = add_form_with_date_offset(
            patient.get_id, os.path.join(folder_name, "003_general.xml"), days_from_today=-3
        )

        self.assertEqual(3, len(updated_patient.cases))
        case = updated_patient.cases[-1]
        self.assertFalse(case.closed)
        [ccase] = case.commcare_cases
        check_commcare_dates(self, case, ccase, 10, 10, 20, 42)

        # Enter new form, make sure to choose a danger sign, then choose outcome blank
        updated_patient, form_doc4 = add_form_with_date_offset(
            patient.get_id, os.path.join(folder_name, "004_general.xml"), days_from_today=-2
        )

        self.assertEqual(4, len(updated_patient.cases))
        case = updated_patient.cases[-1]
        self.assertFalse(case.closed)
        [ccase] = case.commcare_cases
        check_commcare_dates(self, case, ccase, 8, 8, 18, 42)

        # Enter new form, make sure to choose a danger sign, then choose outcome death
        updated_patient, form_doc5 = add_form_with_date_offset(
            patient.get_id, os.path.join(folder_name, "005_general.xml"), days_from_today=-1
        )

        self.assertEqual(5, len(updated_patient.cases))
        case = updated_patient.cases[-1]
        self.assertTrue(case.closed)
        self.assertEqual(0, len(case.commcare_cases))
        self.assertTrue(updated_patient.is_deceased)
Beispiel #10
0
 def testNonSevereGoesToPhone(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "random_futest")
     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, "002_general.xml"), days_from_today=0
     )
     [case] = updated_patient.cases
     self.assertEqual(const.AUTO_FU_PROBABILITY, case.random_fu_probability)
     self._checkRandomFollowup(case)
Beispiel #11
0
 def testDeath(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "death_test")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     self.assertFalse(patient.is_deceased)
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_general.xml"))
     self.assertTrue(updated_patient.is_deceased)
     [case] = updated_patient.cases
     self.assertTrue(case.closed)
     self.assertTrue(updated_patient.is_deceased)
     self.assertEqual("cardiac_failure", case.type)
     self.assertEqual(Outcome.PATIENT_DIED, case.outcome)
     self.assertEqual(0, len(case.commcare_cases))
Beispiel #12
0
 def testRegeneratePatient(self):
     folder_name = os.path.join(os.path.dirname(__file__), "data", "chw")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     self.assertEqual(0, len(patient.encounters))
     with open(os.path.join(folder_name, "non_life_threatening_referral.xml"), "r") as f:
         formbody = f.read()
     formdoc = post_xform_to_couch(formbody)
     new_form_workflow(formdoc, SENDER_PHONE, None)
     patient = CPatient.get(patient.get_id)
     self.assertEqual(1, len(patient.encounters))
     self.assertTrue(reprocess(patient.get_id))
     patient = CPatient.get(patient.get_id)
     self.assertEqual(1, len(patient.encounters))
Beispiel #13
0
 def testPregnancyUnchanged(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "random_futest")
     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, "004_pregnancy.xml"), days_from_today=0
     )
     [case] = updated_patient.cases
     self.assertFalse(case.closed)
     self.assertTrue(case.send_to_phone)
     self.assertNotEqual(const.SendToPhoneReasons.RANDOMLY_CHOSEN, case.send_to_phone_reason)
     [ccase] = case.commcare_cases
     # use the pregnancy dates
     check_commcare_dates(self, case, ccase, 7 * 42, 7 * 42, 7 * 42 + 5, 7 * 46)
Beispiel #14
0
 def testLostImmediatelyCloses(self):
     """
     Creates a case that is too long ago and is lost and therefore is 
     closed as such.
     """
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "ltfu_test")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     updated_patient, _ = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_general.xml"))
     [case] = updated_patient.cases
     self.assertTrue(case.closed)
     self.assertTrue(case.outcome.startswith("lost_to_followup"))
     self.assertEqual(case.closed_on.date(), case.ltfu_date)
     [ccase] = case.commcare_cases
     self.assertTrue(ccase.closed)
Beispiel #15
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)
Beispiel #16
0
 def testDeathAfter(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "death_after")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     
     self.assertFalse(patient.is_deceased)
     # enter a form with outcome death
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_general.xml"))
     # enter a form with a different outcome that should create a case
     updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_general.xml"))
     # make sure the second case is closed and the outcome is also death 
     self.assertTrue(updated_patient.is_deceased)
     self.assertEqual(2, len(updated_patient.cases))
     for case in updated_patient.cases:
         self.assertTrue(case.closed)
         self.assertEqual(Outcome.PATIENT_DIED, case.outcome)
Beispiel #17
0
 def testSevereUnchanged(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "random_futest")
     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, "003_general.xml"), days_from_today=0
     )
     [case] = updated_patient.cases
     self.assertFalse(case.closed)
     self.assertTrue(case.send_to_phone)
     self.assertNotEqual(const.SendToPhoneReasons.RANDOMLY_CHOSEN, case.send_to_phone_reason)
     [ccase] = case.commcare_cases
     # these dates are different because it should actually
     # follow the original cases logic, in this case a missed
     # appointment 7 days later
     check_commcare_dates(self, case, ccase, 10, 10, 20, 42)
Beispiel #18
0
 def testXMLEscaping(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "xml_test")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     # add the form that creates a case
     add_form_with_date_offset\
             (patient.get_id, os.path.join(folder_name, "001_general.xml"),
              days_from_today=0)
     
     # grab the case xml and check it against what we expect to get back
     c = Client()
     response = c.get(reverse("patient_case_xml", args=[patient.get_id]))
     # this call fails if it's not good xml
     et = xml.etree.ElementTree.fromstring(response.content)
     # for good measure
     self.assertTrue("&amp;" in response.content)
     self.assertTrue("&lt;" in response.content)
Beispiel #19
0
 def testDeliveryPhoneCaseGeneration(self):
     # Delivery
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "delivery_tester")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     
     #  a. Missed appointment < 5 days
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_delivery.xml"))
     self.assertEqual(1, len(updated_patient.cases))
     case = updated_patient.cases[-1]
     self.assertTrue(case.send_to_phone)
     self.assertEqual("urgent_clinic_followup", case.send_to_phone_reason)
     
     #  b. None of the above (no case)
     updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_delivery.xml"))
     self.assertEqual(2, len(updated_patient.cases))
     case = updated_patient.cases[-1]
     self.assertFalse(case.send_to_phone)
     self.assertEqual("sending_criteria_not_met", case.send_to_phone_reason)
Beispiel #20
0
 def testImportFromFolder(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testdata", "export_test")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     # forms are loaded one at a time.  If you need to run tests at 
     # intermediate states, put them in between whatever forms you
     # want loaded
     self.assertEqual("EXPORT", patient.first_name)
     self.assertEqual("TEST", patient.last_name)
     self.assertEqual("f", patient.gender)
     self.assertEqual(0, len(patient.encounters))
     
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_pregnancy.xml"))
     updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_sick_pregnancy.xml"))
     updated_patient, form_doc3 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "003_general.xml"))
     
     # custom test conditions after all forms are loaded go here 
     self.assertEqual(3, len(updated_patient.encounters))
     
Beispiel #21
0
 def testReturnToClinicSupercedes(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "ltfu_test2")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_general.xml"))
     updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_general.xml"))
     updated_patient, form_doc3 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "003_general.xml"))
     
     reprocess(updated_patient.get_id)
     updated_patient = CPatient.get(updated_patient.get_id)
     self.assertEqual(3, len(updated_patient.cases))
     [c1, c2, c3] = sorted(updated_patient.cases, key=lambda case: case.opened_on)
     
     # after reprocessing the first case should be closed with returned to clinic, 
     # but the second should be ltfu
     self.assertTrue(c1.closed)
     self.assertEqual(const.Outcome.RETURNED_TO_CLINIC, c1.outcome)
     self.assertTrue(c2.closed)
     self.assertEqual(const.Outcome.LOST_TO_FOLLOW_UP, c2.outcome)
Beispiel #22
0
 def testOutOfOrderLoss(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "ltfu_test2")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     
     # make sure we properly handle when the forms come out of order
     updated_patient, form_doc3 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "003_general.xml"))
     updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_general.xml"))
     [c2, c3] = sorted(updated_patient.cases, key=lambda case: case.opened_on)
     self.assertTrue(c2.closed)
     self.assertEqual(const.Outcome.LOST_TO_FOLLOW_UP, c2.outcome)
     
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_general.xml"))
     [c1, c2, c3] = sorted(updated_patient.cases, key=lambda case: case.opened_on)
     self.assertTrue(c1.closed)
     self.assertEqual(const.Outcome.RETURNED_TO_CLINIC, c1.outcome)
     
 
     
 
     
Beispiel #23
0
 def testLifeThreatening(self):
     folder_name = os.path.join(os.path.dirname(__file__), "data", "chw")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     self.assertEqual(0, len(patient.encounters))
     self.assertEqual(0, len(patient.cases))
     add_form_with_date_offset\
             (None, os.path.join(folder_name, "life_threatening_referral.xml"),
              days_from_today=0)
     patient = CPatient.get(patient.get_id)
     self.assertEqual(1, len(patient.encounters))
     [case] = patient.cases
     [ccase] = case.commcare_cases
     self.assertFalse(ccase.closed)
     visit_date = datetime.utcnow().date()
     self.assertEqual("referral_no_show", ccase.followup_type)
     self.assertFalse(ccase.closed)
     self.assertEqual(visit_date + timedelta(days=3), ccase.start_date)
     self.assertEqual(visit_date + timedelta(days=3), ccase.activation_date)
     self.assertEqual(visit_date + timedelta(days=3), ccase.due_date)
     self.assertEqual(visit_date + timedelta(days=42), case.ltfu_date)
     self.assertEqual("new_clinic_referral|fever headache", ccase.name)
Beispiel #24
0
 def testHivPi(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "hiv_pitest")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     
     # first visit has a recent test so it doesn't count to denominator
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_general.xml"))
     [res] = get_db().view(const.get_view_name("adult_pi"), group=True, group_level=4, 
                         key=[2011,4, "9999999", "hiv_test"]).all()
     num, denom = res["value"]
     self.assertEqual(0, num)
     self.assertEqual(0, denom)
     updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_general.xml"))
     
     # second visit has no recent test so it counts
     [res] = get_db().view(const.get_view_name("adult_pi"), group=True, group_level=4, 
                         key=[2011,5, "9999999", "hiv_test"]).all()
     num, denom = res["value"]
     self.assertEqual(0, num)
     self.assertEqual(1, denom)
     
     
Beispiel #25
0
 def testFansidar(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "fansidar")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     
     def _latest_pregnancy():
         return PregnancyReportRecord.view("reports/pregnancies_for_patient", 
                                            key=updated_patient.get_id, 
                                            include_docs=True).one()
     # dose 1
     updated_patient, form_doc1 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "001_pregnancy.xml"))
     pregnancy = _latest_pregnancy()
     self.assertFalse(pregnancy.eligible_three_doses_fansidar)
     self.assertFalse(pregnancy.got_three_doses_fansidar)
     
     # dose 2
     updated_patient, form_doc2 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "002_pregnancy.xml"))
     pregnancy = _latest_pregnancy()
     self.assertFalse(pregnancy.eligible_three_doses_fansidar)
     self.assertFalse(pregnancy.got_three_doses_fansidar)
     
     # sick visit, doesn't count
     updated_patient, form_doc3 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "003_sick_pregnancy.xml"))
     pregnancy = _latest_pregnancy()
     self.assertFalse(pregnancy.eligible_three_doses_fansidar)
     self.assertFalse(pregnancy.got_three_doses_fansidar)
     
     # healthy visit, no fansidar count
     updated_patient, form_doc4 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "004_pregnancy.xml"))
     pregnancy = _latest_pregnancy()
     self.assertTrue(pregnancy.eligible_three_doses_fansidar)
     self.assertFalse(pregnancy.got_three_doses_fansidar)
     
     # healthy visit fansidar 
     updated_patient, form_doc5 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "005_pregnancy.xml"))
     pregnancy = _latest_pregnancy()
     self.assertTrue(pregnancy.eligible_three_doses_fansidar)
     self.assertTrue(pregnancy.got_three_doses_fansidar)
Beispiel #26
0
 def setUp(self):
     self.folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "delivery_case_test")
     patient = export.import_patient_json_file(os.path.join(self.folder_name, "patient.json"))
     self.patient, self.delivery_form = add_form_with_date_offset(
         patient.get_id, os.path.join(self.folder_name, "001_delivery.xml")
     )
Beispiel #27
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)
Beispiel #28
0
 def setUp(self):
     self.patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
Beispiel #29
0
 def testHealthyPregnancyMisingEDD(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "edd_conditions")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     updated_patient, form_doc4 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "004_pregnancy.xml"))
     [preg] = updated_patient.pregnancies
     self.assertEqual(None, preg.edd)
Beispiel #30
0
 def testSickPregnancyGestationalAge(self):
     folder_name = os.path.join(os.path.dirname(__file__), "testpatients", "edd_conditions")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     updated_patient, form_doc5 = export.add_form_file_to_patient(patient.get_id, os.path.join(folder_name, "005_sick_pregnancy.xml"))
     [preg] = updated_patient.pregnancies
     self.assertEqual(date(2011,3,21), preg.edd)