예제 #1
0
 def test_get_patient_total_should_handle_strings(self):
     records = [
         PatientRecord(
             formulation=u"TDF/3TC/EFV (PMTCT)",
             location=Location(
                 facility=u"Bugongi HC III",
                 district=u"Sheema District",
                 partner=u"RHITES SW",
                 warehouse=u"NMS",
                 multiple="",
                 status="",
             ),
             regimen_location=RegimenLocationCombination(
                 location=Location(
                     facility=u"Bugongi HC III",
                     district=u"Sheema District",
                     partner=u"RHITES SW",
                     warehouse=u"NMS",
                     multiple="",
                     status="",
                 ),
                 formulation=u"TDF/3TC/EFV (PMTCT)",
             ),
             existing=u"",
             new=8,
         )
     ]
     total = get_patient_total(records)
     assert_that(total, equal_to(8))
예제 #2
0
    def test_location_works_as_key(self):
        facility = "Home"
        district = "dis"
        partner = "p"
        warehouse = "JMS"

        location = Location(
            facility=facility, district=district, partner=partner, warehouse=warehouse
        )

        data = {location: 1}
        other_location = Location(
            district=district, facility=facility, partner=partner, warehouse="JMS"
        )
        self.assertEqual(data.get(other_location), 1)
예제 #3
0
 def test_should_record_consumption_for_each_facility(self):
     report = FakeReport()
     report.ads = defaultdict(list)
     report.pds = defaultdict(list)
     report.cycle = "May - Jun 2015"
     location = Location.migrate_from_dict(
         {
             "name": "location_one",
             "IP": "ip_one",
             "District": "district_one",
             "Warehouse": "warehouse_one",
             "Multiple": "",
             "status": "",
             "Web/Paper": "",
             "scores": defaultdict(dict),
         }
     )
     report.locs = [location]
     report.cs = {
         location: [
             ConsumptionRecord.migrate_from_dict(
                 {"opening_balance": 20, "closing_balance": 12}
             )
         ]
     }
     self.assertEqual(Consumption.objects.count(), 0)
     persist_consumption(report)
     self.assertEqual(Consumption.objects.count(), 1)
     first_record = Consumption.objects.all()[0]
     self.assertEqual(first_record.name, "location_one")
     self.assertEqual(first_record.ip, "ip_one")
     self.assertEqual(first_record.district, "district_one")
     self.assertEqual(first_record.warehouse, "warehouse_one")
     self.assertEqual(first_record.opening_balance, 20)
     self.assertEqual(first_record.closing_balance, 12)
예제 #4
0
 def test_should_record_paed_records_for_each_facility(self):
     report = FakeReport()
     report.ads = defaultdict(list)
     report.pds = defaultdict(list)
     report.cycle = "May - Jun 2015"
     location_one = Location.migrate_from_dict(
         {
             "name": "location_one",
             "IP": "ip_one",
             "District": "district_one",
             "Warehouse": "warehouse_one",
             "Multiple": "",
             "status": "",
             "Web/Paper": "",
             "scores": defaultdict(dict),
         }
     )
     report.locs = [location_one]
     report.pds = {
         location_one: [PatientRecord.migrate_from_dict({"new": 20, "existing": 12})]
     }
     self.assertEqual(PAEDPatientsRecord.objects.count(), 0)
     persist_paed_records(report)
     self.assertEqual(PAEDPatientsRecord.objects.count(), 1)
     first_record = PAEDPatientsRecord.objects.all()[0]
     self.assertEqual(first_record.name, "location_one")
     self.assertEqual(first_record.ip, "ip_one")
     self.assertEqual(first_record.district, "district_one")
     self.assertEqual(first_record.warehouse, "warehouse_one")
     self.assertEqual(first_record.new, 20)
     self.assertEqual(first_record.existing, 12)
 def test_check_runs(self):
     scores = defaultdict(lambda: defaultdict(dict))
     test_location = Location(
         facility=u"St. Michael Kanyike HC III",
         district=u"Mpigi District",
         partner="Unknown",
         warehouse=u"MAUL",
         multiple="not",
         status="Not Reporting",
     )
     locations = [test_location]
     consumption_records = {test_location: []}
     adult_records = {test_location: []}
     paed_records = {test_location: []}
     fake_import = FakeImport(locations, consumption_records, adult_records,
                              paed_records)
     run_facility_test(
         FacilityTest.objects.get(slug="stable-patients"),
         fake_import,
         fake_import,
         scores,
     )
     self.assertEqual(
         scores[test_location]["STABLE PATIENTS"],
         {
             u"abc3tc-paed": "NOT_REPORTING",
             u"efv200-paed": "NOT_REPORTING",
             u"tdf3tcefv-adult": "NOT_REPORTING",
         },
     )
예제 #6
0
    def f(facility_dict):
        name = facility_dict.get("name", "")
        new_location = Location(
            facility=name,
            district=py_(facility_dict.get("ancestors", [])).find({
                "level": 3
            }).value().get("name"),
            partner=partner_mapping.get(name, "Unknown"),
            warehouse=facility_dict.get("warehouse"),
        )
        reference_location = locations_that_are_reporting.get(
            new_location, None)
        location_has_multiple = locations_reporting_multiple_times.get(
            new_location, None)
        if reference_location:
            new_location = attr.evolve(new_location, status="Reporting")
            if location_has_multiple:
                new_location = attr.evolve(new_location,
                                           multiple="multiple orders")
        else:
            new_location = attr.evolve(new_location,
                                       status="Not Reporting",
                                       multiple="not")

        return new_location
예제 #7
0
 def test_should_record_facilities_with_multiple_orders(self):
     report = FakeReport()
     report.ads = defaultdict(list)
     report.pds = defaultdict(list)
     report.cycle = "May - Jun 2015"
     two = Location(
         facility="location_two",
         district="district_one",
         warehouse="warehouse_one",
         partner="ip_one",
         multiple="Multiple orders",
     )
     one = Location(
         facility="location_one",
         district="district_one",
         warehouse="warehouse_one",
         partner="ip_one",
     )
     report.locs = [one, two]
     self.assertEqual(MultipleOrderFacility.objects.count(), 0)
     persist_multiple_order_records(report)
     self.assertEqual(MultipleOrderFacility.objects.count(), 1)
예제 #8
0
    def test_should_record_scores_for_each_facility(self):
        report = FakeReport()
        report.cycle = "May - Jun 2015"
        location_one = Location.migrate_from_dict(
            {
                "name": "location_one",
                "IP": "ip_one",
                "District": "district_one",
                "Warehouse": "warehouse_one",
            }
        )
        location_two = Location.migrate_from_dict(
            {
                "name": "location_two",
                "District": "district_one",
                "IP": "ip_one",
                "Warehouse": "warehouse_one",
            }
        )
        report.locs = [location_one, location_two]
        scores_cache = {
            location_one: {
                "WEB_BASED": {"DEFAULT": "YES"}, "REPORTING": {"DEFAULT": "NO"}
            },
            location_two: {
                "WEB_BASED": {"DEFAULT": "YES"}, "REPORTING": {"DEFAULT": "NO"}
            },
        }

        self.assertEqual(Score.objects.count(), 0)
        persist_scores(scores_cache, report.cycle)
        persist_scores(scores_cache, report.cycle)
        self.assertEqual(Score.objects.count(), 2)
        first_score = Score.objects.all()[0]
        self.assertEqual(first_score.default_pass_count, 1)
        self.assertEqual(first_score.default_fail_count, 1)
    def setUp(self):
        self.test_location = Location(
            facility="AAR Acacia Clinic HC II",
            district="Kampala District",
            partner="TASO",
            status="reporting",
            warehouse=MAUL,
        )

        self.data_import = HtmlDataImport(
            get_test_output_from_fixture(
                "arv-2-paediatric-art-patient-report-maul.html"
            ),
            None,
        ).load(
            LocationToPartnerMapping.get_mapping()
        )
    def setUp(self):
        self.test_location = Location(
            facility="AAR Acacia Clinic HC II",
            district="Kampala District",
            partner="UHMG",
            status="reporting",
            warehouse=JMS,
        )

        fixture = get_test_output_from_fixture(
            "arv-2-adult-pmtct-art-patient-report-all-regimen-jms.html",
            report_type=ADULT_PATIENT_REPORT,
            warehouse=JMS,
        )
        self.data_import = HtmlDataImport(fixture, None).load(
            LocationToPartnerMapping.get_mapping()
        )
    def setUp(self):
        self.test_location = Location(
            facility="Health Initiative Association Uganda",
            district="Buikwe District",
            status="reporting",
            partner="PHS",
            warehouse=MAUL,
        )

        self.data_import = HtmlDataImport(
            get_test_output_from_fixture(
                "arv-0-consumption-data-report-maul.html",
                report_type=CONSUMPTION_REPORT,
            ),
            None,
        ).load(
            LocationToPartnerMapping.get_mapping()
        )
    def test_that_check_has_same_result_as_preview(self, name, scenario,
                                                   combination, expected):
        f1_combination = StableConsumptionCheck().combinations[0]
        f2_combination = StableConsumptionCheck().combinations[1]
        combinations = {"f1": f1_combination, "f2": f2_combination}
        combination = combinations[combination]
        new_check = get_check_from_dict(stable_consumption_check())
        new_check_result = new_check.for_each_facility(scenario["Current"],
                                                       Tracer.F1(),
                                                       scenario["Previous"])
        self.assertEqual(expected, new_check_result)
        current_cycle = "Nov - Dec 2017"
        previous_cycle = "Sep - Oct 2017"
        location = Location(facility="loc1",
                            district="dis1",
                            partner="",
                            warehouse="")
        for record in scenario.get("Current").c_records:
            create_consumption_record(
                location,
                record.formulation,
                current_cycle,
                consumption=record.consumption,
            )

        for record in scenario.get("Previous").c_records:
            create_consumption_record(
                location,
                record.formulation,
                previous_cycle,
                consumption=record.consumption,
            )

        data = new_check.get_preview_data(
            {
                "name": location.facility,
                "district": location.district
            },
            current_cycle,
            combination,
        )
        self.assertEqual(data["result"][combination.key], expected)
예제 #13
0
 def test_dhis2_facility_as_location(self):
     data = {
         "level":
         5,
         "name":
         "01 Commando HC II",
         "id":
         "Ugl9pT2K5B0",
         "ancestors": [
             {
                 "name": "MOH - Uganda",
                 "level": 1
             },
             {
                 "name": "Northern Region",
                 "level": 2
             },
             {
                 "name": "Otuke District",
                 "level": 3
             },
             {
                 "name": "Okwang Subcounty",
                 "level": 4
             },
         ],
     }
     loc = Location.migrate_from_dict({
         "name": "01 Commando HC II",
         "District": "Otuke District"
     })
     location = dhis2_facility_as_location({"01 Commando HC II": "PT"},
                                           {loc: loc}, {})(data)
     self.assertEqual(location.facility, "01 Commando HC II")
     self.assertEqual(location.district, "Otuke District")
     self.assertEqual(location.status, "Reporting")
     self.assertEqual(location.partner, "PT")