コード例 #1
0
    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
        update_case(self.domain, case.case_id,
                    {"prescription_total_days": "169"})
        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()))
コード例 #2
0
ファイル: test_repeaters.py プロジェクト: alemat/commcare-hq
    def test_payload_properties(self, _):
        episode_case = self._create_nikshay_enabled_case()
        update_case(
            self.domain, self.episode_id, {
                TREATMENT_OUTCOME: "treatment_complete",
                TREATMENT_OUTCOME_DATE: "1990-01-01",
                'nikshay_id': self.person_id,
            })
        episode_case = CaseAccessors(self.domain).get_case(self.episode_id)
        payload = (json.loads(
            NikshayTreatmentOutcomePayload(None).get_payload(
                None, episode_case)))
        self.assertEqual(payload['Source'], ENIKSHAY_ID)
        self.assertEqual(payload['IP_From'], "198.1.1.1")
        self.assertEqual(payload['PatientID'], self.person_id)
        self.assertEqual(payload['regBy'], "tbu-dmdmo01")
        self.assertEqual(payload['OutcomeDate'], "1990-01-01")
        self.assertEqual(payload['MO'], "Gandalf The Grey")
        self.assertEqual(payload['MORemark'], 'None Collected in eNikshay')
        self.assertEqual(payload['Outcome'], '2')

        update_case(self.domain, self.episode_id, {
            TREATMENT_OUTCOME: "regimen_changed",
        })
        episode_case = CaseAccessors(self.domain).get_case(self.episode_id)
        payload = (json.loads(
            NikshayTreatmentOutcomePayload(None).get_payload(
                None, episode_case)))
        self.assertEqual(payload['Outcome'], '7')
コード例 #3
0
    def test_trigger(self):
        # episode that does not meet trigger
        cases = self.create_case_structure()
        self.assign_person_to_location(self.pcp.location_id)
        update_case(
            self.domain,
            self.episode_id,
            {
                'prescription_total_days': 20,
                ENROLLED_IN_PRIVATE: "true",
            },
        )
        case = cases[self.episode_id]
        self.assertEqual(0, len(self.repeat_records().all()))

        # meet trigger conditions
        update_case(self.domain, case.case_id, {
            "prescription_total_days": 181,
        })
        self.assertEqual(1, len(self.repeat_records().all()))

        # trigger only once
        payload_generator = BETS180TreatmentPayloadGenerator(None)
        payload_generator.handle_success(
            MockResponse(201, {"success": "hooray"}), case, None)
        update_case(self.domain, case.case_id,
                    {"prescription_total_days": "182"})
        self.assertEqual(1, len(self.repeat_records().all()))
コード例 #4
0
    def test_mandatory_field_interval_id(self):
        update_case(self.domain,
                    self.test_id,
                    {
                        "purpose_of_testing": "testing",
                        "follow_up_test_reason": "unknown_reason"
                    },
                    external_id=DUMMY_NIKSHAY_ID,
                    )
        test_case = CaseAccessors(self.domain).get_case(self.test_id)

        # raises error when purpose_of_testing is not diagnostic and test reason is not known to system
        with self.assertRaisesMessage(NikshayRequiredValueMissing,
                                      "Value missing for intervalID, purpose_of_testing: {testing_purpose}, "
                                      "follow_up_test_reason: {follow_up_test_reason}".format(
                                          testing_purpose="testing",
                                          follow_up_test_reason="unknown_reason"
                                      )):
            NikshayFollowupPayloadGenerator(None).get_payload(self.repeat_record, test_case)

        # does not raise error with purpose_of_testing being diagnostic since test reason is not relevant
        update_case(self.domain,
                    self.test_id,
                    {
                        "purpose_of_testing": "diagnostic",
                        "follow_up_test_reason": "unknown_reason"
                    },
                    external_id=DUMMY_NIKSHAY_ID,
                    )
        test_case = CaseAccessors(self.domain).get_case(self.test_id)
        NikshayFollowupPayloadGenerator(None).get_payload(self.repeat_record, test_case)
コード例 #5
0
 def handle_success(self, response, payload_doc, repeat_record):
     # A successful response returns a Nikshay ID like 00001
     # Failures also return with status code 200 and some message like
     # Dublicate Entry or Invalid data format
     # (Dublicate is not a typo)
     message = parse_SOAP_response(repeat_record.repeater.url,
                                   repeat_record.repeater.operation,
                                   response)
     try:
         if isinstance(message, basestring) and message.isdigit():
             health_facility_id = self._get_person_locations(
                 payload_doc).pcp
             nikshay_id = '-'.join([health_facility_id, message])
             update_case(
                 payload_doc.domain,
                 payload_doc.case_id,
                 {
                     "private_nikshay_registered": "true",
                     "nikshay_id": nikshay_id,
                     "private_nikshay_error": "",
                 },
                 external_id=nikshay_id,
             )
         else:
             self.handle_failure(message, payload_doc, repeat_record)
     except NikshayResponseException as e:
         _save_error_message(payload_doc.domain, payload_doc.case_id,
                             unicode(e.message))
コード例 #6
0
    def test_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,
            {
                'bets_first_prescription_voucher_redeemed': 'false',
                ENROLLED_IN_PRIVATE: "true",
            },
        )
        case = cases[self.episode_id]
        self.assertEqual(0, len(self.repeat_records().all()))

        # Meet trigger
        update_case(self.domain, case.case_id,
                    {"bets_first_prescription_voucher_redeemed": "true"})
        self.assertEqual(1, len(self.repeat_records().all()))

        # Make sure same case doesn't trigger event again
        payload_generator = BETSDiagnosisAndNotificationPayloadGenerator(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()))
コード例 #7
0
 def handle_exception(self, exception, repeat_record):
     if isinstance(exception, RequestConnectionError):
         update_case(
             repeat_record.domain, repeat_record.payload_id, {
                 "dots_99_error":
                 u"RequestConnectionError: {}".format(unicode(exception))
             })
コード例 #8
0
 def handle_exception(self, exception, repeat_record):
     if isinstance(exception, RequestConnectionError):
         update_case(
             repeat_record.domain, repeat_record.payload_id, {
                 "bets_{}_error".format(self.event_id):
                 "RequestConnectionError: {}".format(
                     six.text_type(exception))
             })
コード例 #9
0
def _save_error_message(domain, case_id, error, reg_field="nikshay_registered", error_field="nikshay_error"):
    update_case(
        domain,
        case_id,
        {
            reg_field: "false",
            error_field: unicode(error),
        },
    )
コード例 #10
0
 def handle_exception(self, exception, repeat_record):
     if isinstance(exception, RequestConnectionError):
         update_case(
             repeat_record.domain,
             repeat_record.payload_id,
             {
                 "private_nikshay_error": unicode(exception)
             }
         )
コード例 #11
0
def _save_error_message(domain, case_id, error):
    update_case(
        domain,
        case_id,
        {
            "nikshay_registered": "false",
            "nikshay_error": error,
        },
    )
コード例 #12
0
 def test_update_case(self):
     update_properties = {'age': 99}
     self.factory.create_or_update_cases([self.person])
     case_accessors = CaseAccessors(self.domain)
     person_case = case_accessors.get_case(self.person_id)
     self.assertEqual(person_case.dynamic_case_properties().get('age', None), '20')
     update_case(self.domain, self.person_id, update_properties)
     person_case = case_accessors.get_case(self.person_id)
     self.assertEqual(person_case.dynamic_case_properties()['age'], '99')
コード例 #13
0
 def handle_success(self, response, payload_doc, repeat_record):
     update_case(
         payload_doc.domain,
         payload_doc.case_id,
         {
             "followup_nikshay_registered": "true",
             "followup_nikshay_error": "",
         },
     )
コード例 #14
0
    def handle_success(self, response, episode_or_person, repeat_record):
        try:
            person_case, episode_case = self._get_cases(episode_or_person)
        except ENikshayCaseNotFound as e:
            self.handle_exception(e, repeat_record)

        if response.status_code == 200:
            update_case(episode_case.domain, episode_case.case_id,
                        {"dots_99_error": ""})
コード例 #15
0
 def _create_nikshay_registered_case(self):
     update_case(
         self.domain,
         self.episode_id,
         {
             "nikshay_id": DUMMY_NIKSHAY_ID,
         },
         external_id=DUMMY_NIKSHAY_ID,
     )
コード例 #16
0
 def handle_success(self, response, payload_doc, repeat_record):
     # Simple success message that has {"Nikshay_Message": "Success"...}
     update_case(
         payload_doc.domain,
         payload_doc.case_id,
         {
             "hiv_test_nikshay_registered": "true",
             "hiv_test_nikshay_error": "",
         },
     )
コード例 #17
0
 def handle_success(self, response, episode_case, repeat_record):
     if response.status_code == 200:
         update_case(
             episode_case.domain,
             episode_case.case_id,
             {
                 "dots_99_treatment_outcome_updated": "true",
                 "dots_99_error": ""
             }
         )
コード例 #18
0
 def handle_success(self, response, adherence_case, repeat_record):
     if response.status_code == 200:
         update_case(
             adherence_case.domain,
             adherence_case.case_id,
             {
                 "dots_99_updated": "true",
                 "dots_99_error": ""
             }
         )
コード例 #19
0
    def handle_success(self, response, person_case, repeat_record):
        try:
            episode_case = get_open_episode_case_from_person(
                person_case.domain, person_case.case_id)
        except ENikshayCaseNotFound as e:
            self.handle_exception(e, repeat_record)

        if response.status_code == 200:
            update_case(episode_case.domain, episode_case.case_id,
                        {"dots_99_error": ""})
コード例 #20
0
 def handle_success(self, response, episode_case, repeat_record, force=False):
     if response.status_code == 201 or force:
         update_case(
             episode_case.domain,
             episode_case.case_id,
             {
                 "dots_99_registered": "true",
                 "dots_99_error": ""
             }
         )
コード例 #21
0
 def handle_failure(self, response, episode_case, repeat_record):
     if 400 <= response.status_code <= 500:
         update_case(
             episode_case.domain, episode_case.case_id, {
                 "dots_99_treatment_outcome_updated":
                 ("false" if episode_case.dynamic_case_properties().get(
                     'dots_99_updated') != 'true' else 'true'),
                 "dots_99_error":
                 "{}: {}".format(response.status_code,
                                 response.json().get('error')),
             })
コード例 #22
0
 def handle_failure(self, response, episode_case, repeat_record):
     if 400 <= response.status_code <= 500:
         update_case(
             episode_case.domain,
             episode_case.case_id,
             {
                 "dots_99_error": "{}: {}".format(
                     response.status_code,
                     response.json().get('error')
                 ),
             }
         )
コード例 #23
0
 def handle_failure(self, response, payload_doc, repeat_record):
     if response.status_code == 409:  # Conflict
         update_case(
             payload_doc.domain,
             payload_doc.case_id,
             {
                 "nikshay_registered": "true",
                 "nikshay_error": "duplicate",
             },
         )
     else:
         _save_error_message(payload_doc.domain, payload_doc.case_id, unicode(response.json()))
コード例 #24
0
ファイル: test_repeaters.py プロジェクト: alemat/commcare-hq
    def test_trigger_test_submission(self):
        self.phi.metadata['is_test'] = 'yes'
        self.phi.save()
        self.create_case(self.episode)
        self.assign_person_to_location(self.phi.location_id)
        self._create_nikshay_registered_case()
        self.assertEqual(0, len(self.repeat_records().all()))

        update_case(self.domain, self.episode_id, {
            TREATMENT_OUTCOME: "cured",
        })
        self.assertEqual(0, len(self.repeat_records().all()))
コード例 #25
0
    def handle_failure(self, response, episode_or_person, repeat_record):
        try:
            person_case, episode_case = self._get_cases(episode_or_person)
        except ENikshayCaseNotFound as e:
            self.handle_exception(e, repeat_record)

        if 400 <= response.status_code <= 500:
            update_case(
                episode_case.domain, episode_case.case_id, {
                    "dots_99_error":
                    "{}: {}".format(response.status_code,
                                    response.json().get('error')),
                })
コード例 #26
0
    def test_trigger(self):
        important_case_property = "phone_number"
        frivolous_case_property = "hair_color"

        # Create, then update test person case
        test_person = self.create_person_case(self.test_location.location_id)
        update_case(self.domain, test_person.case_id,
                    {important_case_property: "7"})

        # Do the same for a public sector person case
        public_person = self.create_person_case(self.real_location.location_id,
                                                private=False)
        update_case(self.domain, public_person.case_id,
                    {important_case_property: "7"})

        # None of the above should trigger forwarding
        self.assertEqual(0, len(self.repeat_records().all()))

        # Create real case
        real_person = self.create_person_case(self.real_location.location_id)
        self.assertEqual(1, len(self.repeat_records().all()))
        # Update real case
        update_case(self.domain, real_person.case_id,
                    {important_case_property: "7"})
        self.assertEqual(2, len(self.repeat_records().all()))
        # frivolous update shouldn't trigger another repeat
        update_case(self.domain, real_person.case_id,
                    {frivolous_case_property: "blue"})
        self.assertEqual(2, len(self.repeat_records().all()))
コード例 #27
0
    def test_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,
            {
                FIRST_PRESCRIPTION_VOUCHER_REDEEMED: 'false',
                'created_by_user_type': 'pac',
                ENROLLED_IN_PRIVATE: "true",
            },
        )
        self.assertEqual(0, len(self.repeat_records().all()))

        # Meet trigger
        update_case(self.domain, self.episode_id,
                    {"bets_first_prescription_voucher_redeemed": "true"})
        self.assertEqual(1, len(self.repeat_records().all()))

        # Make sure same case doesn't trigger event again
        payload_generator = BETSAYUSHReferralPayloadGenerator(None)
        payload_generator.handle_success(
            MockResponse(201, {"success": "hooray"}), cases[self.episode_id],
            None)
        update_case(self.domain, self.episode_id,
                    {"bets_first_prescription_voucher_redeemed": "false"})
        update_case(self.domain, self.episode_id,
                    {"bets_first_prescription_voucher_redeemed": "true"})
        self.assertEqual(1, len(self.repeat_records().all()))
コード例 #28
0
 def handle_success(self, response, payload_doc, repeat_record):
     # A success would be getting a nikshay_id for the patient
     # without it this would actually be a failure
     try:
         nikshay_id = _get_nikshay_id_from_response(response)
         update_case(
             payload_doc.domain,
             payload_doc.case_id,
             {
                 "nikshay_registered": "true",
                 "nikshay_id": nikshay_id,
                 "nikshay_error": "",
             },
             external_id=nikshay_id,
         )
     except NikshayResponseException as e:
         _save_error_message(payload_doc.domain, payload_doc.case_id, unicode(e.message))
コード例 #29
0
 def handle_failure(self, response, episode_case, repeat_record):
     if "A patient with this beneficiary_id already exists" in response.json().get('error'):
         self.handle_success(response, episode_case, repeat_record, force=True)
     elif 400 <= response.status_code <= 500:
         update_case(
             episode_case.domain,
             episode_case.case_id,
             {
                 "dots_99_registered": (
                     "false"
                     if episode_case.dynamic_case_properties().get('dots_99_registered') != 'true'
                     else 'true'
                 ),
                 "dots_99_error": "{}: {}".format(
                     response.status_code,
                     response.json().get('error')
                 ),
             }
         )
コード例 #30
0
 def test_trigger(self):
     # nikshay not enabled
     self.create_case(self.episode)
     self.assertEqual(0, len(self.repeat_records().all()))
     person = self.create_case(self.person)[0]
     update_case(self.domain, self.person_id, {ENROLLED_IN_PRIVATE: "true"})
     with self.assertRaisesMessage(
             NikshayLocationNotFound,
             "Location with id {location_id} not found. This is the owner for person with "
             "id: {person_id}".format(location_id=person.owner_id, person_id=self.person_id)
     ):
         self._create_nikshay_enabled_case(set_property=PRIVATE_PATIENT_EPISODE_PENDING_REGISTRATION)
     # nikshay enabled, should register a repeat record
     self.assign_person_to_location(self.pcp.location_id)
     self._create_nikshay_enabled_case(set_property=PRIVATE_PATIENT_EPISODE_PENDING_REGISTRATION)
     self.assertEqual(1, len(self.repeat_records().all()))
     #
     # set as registered, should not register a new repeat record
     self._create_nikshay_registered_case()
     self.assertEqual(1, len(self.repeat_records().all()))