Exemplo n.º 1
0
 def testIsCurrent(self):
     patient = random_person()
     patient.app_version = MIN_VERSION
     patient.save()
     self.assertEqual(MIN_VERSION, patient.app_version)
     self.assertFalse(patient.is_current())
     patient = random_person()
     patient.app_version = settings.APP_VERSION
     patient.save()
     self.assertTrue(patient.is_current())
     patient = random_person()
     patient.app_version = MAX_VERSION
     patient.save()
     # even though it's from the future, it's still not current.
     self.assertFalse(patient.is_current())
Exemplo n.º 2
0
    def testNVP(self):

        # Not testing positive
        p = random_person()
        p.save()
        post_and_process_xform("preg_no_hiv_test_1.xml", p)
        pregnancy = PregnancyReportRecord.view("reports/pregnancies_for_patient", key=p.get_id, include_docs=True).one()
        self.assertEqual(False, pregnancy.got_nvp_when_tested_positive)
        
        # Test positive subsequent visit
        post_and_process_xform("preg_hiv_pos_2.xml", p)
        pregnancy = PregnancyReportRecord.view("reports/pregnancies_for_patient", key=p.get_id, include_docs=True).one()
        self.assertEqual(True, pregnancy.got_nvp_when_tested_positive)
        
        p2 = random_person()
        p2.save()
        # Testing positive but already on Haart
        post_and_process_xform("preg_hiv_pos_1.xml", p2)
        pregnancy = PregnancyReportRecord.view("reports/pregnancies_for_patient", key=p2.get_id, include_docs=True).one()
        self.assertEqual(False, pregnancy.got_nvp_when_tested_positive)
Exemplo n.º 3
0
 def testReprocessUpgradesVersion(self):
     patient = random_person()
     patient.app_version = MIN_VERSION
     patient.save()
     self.assertEqual(MIN_VERSION, patient.app_version)
     self.assertEqual(MIN_VERSION, patient.original_app_version)
     reprocess(patient.get_id)
     patback = CPatient.get(patient.get_id)
     self.assertEqual(settings.APP_VERSION, patback.app_version)
     # shouldn't upgrade the original version
     self.assertEqual(MIN_VERSION, patient.original_app_version)
Exemplo n.º 4
0
def create_patients(count, clinic_id):
    from bhoma.utils.data import random_person, random_clinic_id
    from bhoma.apps.patient.models import CPatient
    if clinic_id is None:  
        print "no clinic specified, will randomly assign ids"
    CPatient.get_db()
    for i in range(count):
        p = random_person()
        this_clinic_id = clinic_id if clinic_id else random_clinic_id()
        p.clinic_ids = [this_clinic_id,]
        p.save()
    print "successfully generated %s new patients" % count
Exemplo n.º 5
0
 def _add_patients(self, database, count, clinic_id=None):
     """Adds <count> random patients to <database>"""
     # if we don't specify a clinic, use the database name
     if clinic_id is None:  clinic_id = database.dbname
     orig_db = CPatient.get_db()
     CPatient.set_db(database)
     for i in range(count):
         p = random_person()
         p.clinic_ids = [clinic_id,]
         p.save()
     CPatient.set_db(orig_db)
     
Exemplo n.º 6
0
 def testCreate(self):
     patient = random_person()
     case = bootstrap_case_from_xml(self, "create.xml")
     patient.cases=[case,]
     patient.save()
     # make sure we can get it back from our shared view
     case_back = CommCareCase.get_with_patient("case/all_and_patient", case.case_id)
     self.assertEqual(case.case_id, case_back.case_id)
     self.assertEqual(patient.first_name, case_back.patient.first_name)
     self.assertEqual(patient.last_name, case_back.patient.last_name)
     self.assertEqual(patient.get_id, case_back.patient.get_id)
     self.assertEqual(1, len(patient.cases))
     self.assertEqual(case._id, patient.cases[0]._id)
Exemplo n.º 7
0
 def testUpdate(self):
     patient = random_person()
     case = bootstrap_case_from_xml(self, "create_update.xml")
     patient.cases=[case,]
     patient.save()
     # make sure we can get it back from our shared view
     case_back = CommCareCase.get_with_patient("case/all_and_patient", case.case_id)
     self.assertEqual(case.case_id, case_back.case_id)
     self.assertEqual(patient.first_name, case_back.patient.first_name)
     self.assertEqual(patient.last_name, case_back.patient.last_name)
     self.assertEqual(patient.get_id, case_back.patient.get_id)
     self.assertEqual(1, len(patient.cases))
     self.assertEqual(case._id, patient.cases[0]._id)
     
     # update
     case = bootstrap_case_from_xml(self, "update.xml", case.case_id)
     self.assertEqual(patient.get_id, case.patient.get_id)
     case.save()
     
     patient = CPatient.get(patient.get_id)
     self.assertEqual(1, len(patient.cases))
     case_in_patient = patient.cases[0]
     self.assertEqual(case._id, case_in_patient._id)
     
     self.assertEqual(False, case_in_patient.closed)
     self.assertEqual(3, len(case_in_patient.actions))
     new_update_action = case_in_patient.actions[2]
     self.assertEqual(const.CASE_ACTION_UPDATE, new_update_action["action_type"])
     
     # some properties didn't change
     self.assertEqual("123", str(case["someotherprop"]))
     
     # but some should have
     self.assertEqual("abcd", case_in_patient["someprop"])
     self.assertEqual("abcd", new_update_action["someprop"])
     
     # and there are new ones
     self.assertEqual("efgh", case_in_patient["somenewprop"])
     self.assertEqual("efgh", new_update_action["somenewprop"])
     
     # we also changed everything originally in the case
     self.assertEqual("a_new_type", case_in_patient.type)
     self.assertEqual("a_new_type", new_update_action["type"])
     self.assertEqual("a new name", case_in_patient.name)
     self.assertEqual("a new name", new_update_action["name"])        
     self.assertEqual(UPDATE_DATE, case_in_patient.opened_on)
     self.assertEqual(UPDATE_DATE, new_update_action["opened_on"])
     
     # case should have a new modified date
     self.assertEqual(MODIFY_DATE, case.modified_on)
Exemplo n.º 8
0
 def testVersionUpgradeOnlyDependsOnFirstTwoDigits(self):
     old_ver = config.APP_VERSION 
     config.APP_VERSION = "0.1.5"
     patient = random_person()
     patient.app_version = "0.1.0"
     self.assertFalse(patient.requires_upgrade())
     patient.app_version = "0.1.5"
     self.assertFalse(patient.requires_upgrade())
     patient.app_version = "0.1.9"
     self.assertFalse(patient.requires_upgrade())
     patient.app_version = "0.1.4.2"
     self.assertFalse(patient.requires_upgrade())
     patient.app_version = "0.0.9"
     self.assertTrue(patient.requires_upgrade())
     patient.app_version = "0.2.0"
     self.assertFalse(patient.requires_upgrade())
     config.APP_VERSION = old_ver
Exemplo n.º 9
0
 def testEmptyVersionRequiresUpgrade(self):
     patient = random_person()
     patient.app_version = None
     self.assertTrue(patient.requires_upgrade())
Exemplo n.º 10
0
 def testVersionNumberSet(self):
     patient = random_person()
     patient.save()
     self.assertEqual(settings.APP_VERSION, patient.app_version)
     self.assertEqual(settings.APP_VERSION, patient.original_app_version)