コード例 #1
0
    def test_trigger(self):
        # voucher not approved
        self.create_case_structure()
        self.assign_person_to_location(self.pcp.location_id)
        prescription = self.create_prescription_case()
        voucher = self.create_voucher_case(prescription.case_id, {
            "voucher_type": "prescription",
            'state': 'not approved'
        })
        self.assertEqual(0, len(self.repeat_records().all()))

        # voucher approved
        update_case(self.domain, voucher.case_id, {"state": "approved"})
        self.assertEqual(1, len(self.repeat_records().all()))

        # Changing state to some other state doesn't create another record
        update_case(self.domain, voucher.case_id, {"state": "foo"})
        self.assertEqual(1, len(self.repeat_records().all()))

        # Approving voucher again doesn't create new record
        payload_generator = ChemistBETSVoucherPayloadGenerator(None)
        payload_generator.handle_success(
            MockResponse(201, {"success": "hooray"}), voucher, None)
        update_case(self.domain, voucher.case_id, {"state": "approved"})
        self.assertEqual(1, len(self.repeat_records().all()))
コード例 #2
0
    def test_investigation_get_payload(self):
        self.create_case_structure()
        self.assign_person_to_location(self.pcp.location_id)
        prescription = self.create_prescription_case()
        voucher = self.create_voucher_case(
            prescription.case_id, {
                "voucher_type": "test",
                "voucher_fulfilled_by_id": self.user.user_id,
                "voucher_fulfilled_by_location_id": self.plc.location_id,
                "date_fulfilled": "2017-08-15",
                "voucher_id": "ABC-DEF-1123",
                "amount_approved": 10.0,
                "investigation_type": "xray",
            })

        expected_payload = {
            "voucher_details": [{
                u"EventID": u"102",
                u"EventOccurDate": u"2017-08-15",
                u"BeneficiaryUUID": self.user.user_id,
                u"BeneficiaryType": u"lab",
                u"Location": self.plc.location_id,
                u"DTOLocation": self.dto.location_id,
                u"VoucherID": voucher.case_id,
                u"Amount": u'10.0',
                u"InvestigationType": u"xray",
            }]
        }

        self.assertDictEqual(
            expected_payload,
            json.loads(
                ChemistBETSVoucherPayloadGenerator(None).get_payload(
                    None, voucher)))
コード例 #3
0
    def test_investigation_get_payload(self):
        self.create_case_structure()
        self.assign_person_to_location(self.pcp.location_id)
        prescription = self.create_prescription_case()
        voucher = self.create_voucher_case(
            prescription.case_id, {
                "voucher_type": "test",
                "voucher_approved_by_id": self.user.user_id,
                "voucher_fulfilled_by_id": self.user.user_id,
                "voucher_fulfilled_by_location_id": self.plc.location_id,
                "date_fulfilled": "2017-08-15",
                "voucher_id": "ABC-DEF-1123",
                "amount_approved": 10.0,
                "investigation_type": "xray",
            })

        expected_payload = {
            "voucher_details": [{
                u"EventID":
                u"102",
                u"EventOccurDate":
                u"2017-08-15",
                u"BeneficiaryUUID":
                self.user.user_id,
                u"BeneficiaryType":
                u"lab",
                u"Location":
                self.plc.location_id,
                u"DTOLocation":
                self.dto.location_id,
                u"VoucherID":
                voucher.case_id,
                u"ReadableVoucherID":
                voucher.get_case_property('voucher_id'),
                u"Amount":
                u'10',
                u"InvestigationType":
                u"xray",
                u"PersonId":
                self.person.attrs['update']['person_id'],
                u"AgencyId":
                self.username.split('@')[0],
                u"EnikshayApprover":
                self.user.name,
                u"EnikshayRole":
                None,
                u"EnikshayApprovalDate":
                None,
            }]
        }

        self.assertDictEqual(
            expected_payload,
            json.loads(
                ChemistBETSVoucherPayloadGenerator(None).get_payload(
                    None, voucher)))
コード例 #4
0
    def test_prescription_get_payload(self):
        self.create_case_structure()
        self.assign_person_to_location(self.pcp.location_id)
        prescription = self.create_prescription_case()
        voucher = self.create_voucher_case(
            prescription.case_id,
            {
                "voucher_type": "prescription",
                "voucher_fulfilled_by_id": self.user.user_id,
                "voucher_approved_by_id": self.user.user_id,
                "voucher_fulfilled_by_location_id": self.pcc.location_id,
                "date_fulfilled": "2017-08-15",
                "voucher_id": "ABC-DEF-1123",
                "amount_approved": '9.2',  # this should be rounded to 9
            })

        expected_payload = {
            "voucher_details": [{
                "EventID":
                "101",
                "EventOccurDate":
                "2017-08-15",
                "BeneficiaryUUID":
                self.user.user_id,
                "BeneficiaryType":
                "chemist",
                "Location":
                self.pcc.location_id,
                "DTOLocation":
                self.dto.location_id,
                "VoucherID":
                voucher.case_id,
                "ReadableVoucherID":
                voucher.get_case_property('voucher_id'),
                "Amount":
                '9',
                "InvestigationType":
                None,
                "PersonId":
                self.person.attrs['update']['person_id'],
                "AgencyId":
                self.username.split('@')[0],
                "EnikshayApprover":
                "Jon Snow",
                "EnikshayRole":
                None,
                "EnikshayApprovalDate":
                None,
            }]
        }

        self.assertDictEqual(
            expected_payload,
            json.loads(
                ChemistBETSVoucherPayloadGenerator(None).get_payload(
                    None, voucher)))
コード例 #5
0
    def test_fallback_to_amount_fulfilled(self):
        self.create_case_structure()
        self.assign_person_to_location(self.pcp.location_id)
        prescription = self.create_prescription_case()
        voucher = self.create_voucher_case(
            prescription.case_id,
            {
                "voucher_type": "test",
                "voucher_approved_by_id": self.user.user_id,
                "voucher_fulfilled_by_id": self.user.user_id,
                "voucher_fulfilled_by_location_id": self.plc.location_id,
                "date_fulfilled": "2017-08-15",
                "voucher_id": "ABC-DEF-1123",
                # If amount_approved is missing, fallback to amount_fulfilled
                # "amount_approved": 10.0,
                "amount_fulfilled": 10.0,
                "investigation_type": "xray",
            })

        payload = json.loads(
            ChemistBETSVoucherPayloadGenerator(None).get_payload(
                None, voucher))
        self.assertEqual(payload['voucher_details'][0]['Amount'], "10")