Esempio n. 1
0
 def test_that_aar_passes(self):
     aar = {
         "Current": LocationData.migrate_from_dict(
             {
                 "status": "reporting",
                 A_RECORDS: [
                     {FORMULATION: "TDF/3TC/EFV (PMTCT)", "new": 0.0},
                     {FORMULATION: "TDF/3TC/EFV (PMTCT)", "existing": 7.0},
                     {FORMULATION: "TDF/3TC/EFV (ADULT)", "new": 2.0},
                     {FORMULATION: "TDF/3TC/EFV (ADULT)", "existing": 68.0},
                 ],
             }
         ),
         "Previous": LocationData.migrate_from_dict(
             {
                 "status": "reporting",
                 A_RECORDS: [
                     {FORMULATION: "TDF/3TC/EFV (PMTCT)", "new": 0.0},
                     {FORMULATION: "TDF/3TC/EFV (PMTCT)", "existing": 7.0},
                     {FORMULATION: "TDF/3TC/EFV (ADULT)", "new": 2.0},
                     {FORMULATION: "TDF/3TC/EFV (ADULT)", "existing": 68.0},
                 ],
             }
         ),
     }
     new_check = get_check_from_dict(stable_patients_check())
     new_check_result = new_check.for_each_facility(
         aar["Current"], Tracer.F1(), aar["Previous"]
     )
     self.assertEqual("YES", new_check_result)
 def test_check(self, name, data1, data2, expected):
     new_check = get_check_from_dict(non_repeating_check())
     new_check_result = new_check.for_each_facility(data1, Tracer.F1(),
                                                    data2)
     self.assertEqual(expected, new_check_result)
     check = OrdersOverTimeCheck()
     result = check.for_each_facility(data1, check.combinations[0], data2)
     self.assertEqual(expected, result)
 def test_check_has_correct_combinations(self):
     new_check = get_check_from_dict(stable_patients_check())
     combinations = new_check.get_combinations()
     self.assertEqual(len(combinations), 3)
     self.assertEqual(
         [tracer.key for tracer in combinations],
         [u"tdf3tcefv-adult", u"abc3tc-paed", u"efv200-paed"],
     )
Esempio n. 4
0
 def test_f2(self, name, data, expected):
     new_check = get_check_from_dict(volume_tally_check())
     new_check_result = new_check.for_each_facility(data, Tracer.F2())
     self.assertEqual(expected, new_check_result)
     legacy_check = VolumeTallyCheck()
     legacy_check_result = legacy_check.for_each_facility(
         data, legacy_check.combinations[1])
     self.assertEqual(expected, legacy_check_result)
     self.assertEqual(legacy_check_result, new_check_result)
Esempio n. 5
0
 def get_context_data(self, request, id, column):
     scores = {YES: "Pass", NO: "Fail", NOT_REPORTING: "N/A"}
     combination = request.GET.get("combination", DEFAULT)
     combination_name = combination
     if combination != DEFAULT:
         tracers = TracingFormulations.objects.filter(slug=combination)
         if len(tracers) > 0:
             combination_name = tracers[0].name
     column = int(column)
     score = Score.objects.get(id=id)
     score_data = {
         "ip": score.ip,
         "district": score.district,
         "warehouse": score.warehouse,
         "name": score.name,
         "cycle": score.cycle,
         "combination": combination_name,
     }
     has_result = column > 3
     response_data = {"score": score_data, "has_result": has_result}
     template_name = "check/base.html"
     if has_result:
         check_obj = self.get_test_by_column(column)
         check = get_check_from_dict(json.loads(check_obj.definition))
         response_data["data"] = check.get_preview_data(
             {
                 "name": score.name,
                 "district": score.district
             },
             score.cycle,
             Tracer(key=combination),
         )
         if score.data and type(score.data) is dict:
             result = score.data.get(check_obj.name)
         else:
             result = None
         # actual_result = get_actual_result(result, combination)
         result_data = {
             "name": check_obj.name,
             "test": check_obj.short_description,
             "result":
             scores.get(response_data["data"]["result"][combination]),
             "has_combination": len(maybe(result).or_else([])) > 1,
         }
         response_data["result"] = result_data
     response_data["detail"] = {
         "id": id,
         "column": column,
         "test": score.name
     }
     return response_data, template_name, score, combination_name
    def test_that_legacy_gets_same_result_as_new(self, name, scenario,
                                                 expected):
        legacy_check = StableConsumptionCheck()
        f1_combination = legacy_check.combinations[0]

        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)

        legacy_check_result = legacy_check.for_each_facility(
            scenario["Current"], f1_combination, scenario["Previous"])
        self.assertEqual(expected, legacy_check_result)
        self.assertEqual(legacy_check_result, new_check_result)
Esempio n. 7
0
 def test_get_combinations(self):
     new_check = get_check_from_dict(volume_tally_check())
     combinations = new_check.get_combinations()
     self.assertListEqual(
         ["tdf3tcefv-adult", "abc3tc-paed", "efv200-paed"],
         [tr.key for tr in combinations],
     )
     f1_formulations = new_check.get_formulations(
         new_check.definition.groups[0], combinations[0]
     )
     f2_formulations = new_check.get_formulations(
         new_check.definition.groups[0], combinations[1]
     )
     f3_formulations = new_check.get_formulations(
         new_check.definition.groups[0], combinations[2]
     )
     self.assertNotEqual(f1_formulations, f2_formulations)
     self.assertNotEqual(f1_formulations, f3_formulations)
    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)