def test_prescription_total_days_trigger(self):
        # Create case that doesn't meet trigger
        cases = self.create_case_structure()
        self.assign_person_to_location(self.pcp.location_id)
        update_case(
            self.domain,
            self.episode_id,
            {
                'treatment_outcome': 'not_evaluated',
                'prescription_total_days': 100,
                'treatment_options': 'fdc',
                ENROLLED_IN_PRIVATE: "true",
            },
        )
        case = cases[self.episode_id]
        self.assertEqual(0, len(self.repeat_records().all()))

        # Meet trigger
        # This property is normally set by the episode task
        update_case(self.domain, case.case_id,
                    {'bets_date_prescription_threshold_met': '2017-08-08'})
        self.assertEqual(1, len(self.repeat_records().all()))

        # Make sure same case doesn't trigger event again
        payload_generator = BETSSuccessfulTreatmentPayloadGenerator(None)
        payload_generator.handle_success(
            MockResponse(201, {"success": "hooray"}), case, None)
        update_case(self.domain, case.case_id, {"foo": "bar"})
        self.assertEqual(1, len(self.repeat_records().all()))
    def test_successful_treatment_payload_non_closed_case(self):
        self.episode.attrs['update']["prescription_total_days"] = 180
        self.episode.attrs['update'][TREATMENT_OUTCOME_DATE] = "2017-08-15"
        self.episode.attrs['update'][TREATMENT_OUTCOME] = "cured"
        self.person.attrs['owner_id'] = self.pcp.location_id
        cases = self.create_case_structure()
        episode = cases[self.episode_id]

        expected_payload = {
            "incentive_details": [{
                u"EventID":
                unicode(SUCCESSFUL_TREATMENT_EVENT),
                u"EventOccurDate":
                u"2017-08-15",
                u"BeneficiaryUUID":
                self.person_id,
                u"BeneficiaryType":
                u"patient",
                u"Location":
                self.pcp.location_id,
                u"DTOLocation":
                self.dto.location_id,
                u"EpisodeID":
                self.episode_id,
                u"PersonId":
                self.person.attrs['update']['person_id'],
                u"AgencyId":
                self.username.split('@')[0],
                u"EnikshayApprover":
                None,
                u"EnikshayRole":
                None,
                u"EnikshayApprovalDate":
                None,
            }]
        }
        self.assertDictEqual(
            expected_payload,
            json.loads(
                BETSSuccessfulTreatmentPayloadGenerator(None).get_payload(
                    None, episode)))
Esempio n. 3
0
    def test_successful_treatment_payload(self):
        self.person.attrs['update']['last_owner'] = self.pcp.location_id
        self.person.attrs['owner_id'] = "_archive_"
        self.episode.attrs['update'][TREATMENT_OUTCOME_DATE] = "2017-08-15"
        self.episode.attrs['update'][TREATMENT_OUTCOME] = "cured"
        cases = self.create_case_structure()
        episode = cases[self.episode_id]

        expected_payload = {
            "incentive_details": [{
                "EventID":
                six.text_type(SUCCESSFUL_TREATMENT_EVENT),
                "EventOccurDate":
                "2017-08-15",
                "BeneficiaryUUID":
                self.person_id,
                "BeneficiaryType":
                "patient",
                "Location":
                self.pcp.location_id,
                "DTOLocation":
                self.dto.location_id,
                "EpisodeID":
                self.episode_id,
                "PersonId":
                self.person.attrs['update']['person_id'],
                "AgencyId":
                self.username.split('@')[0],
                "EnikshayApprover":
                None,
                "EnikshayRole":
                None,
                "EnikshayApprovalDate":
                None,
            }]
        }
        self.assertDictEqual(
            expected_payload,
            json.loads(
                BETSSuccessfulTreatmentPayloadGenerator(None).get_payload(
                    None, episode)))