def create_test_fhir_instance(self): fhir_claim_response = ClaimResponse() fhir_claim_response.id = self._TEST_CODE pk_id = ClaimResponseConverter.build_fhir_identifier( self._TEST_ID, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_id_type_code()) claim_code = ClaimResponseConverter.build_fhir_identifier( self._TEST_CODE, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_claim_code_type()) fhir_claim_response.identifier = [pk_id, claim_code] display = Stu3ClaimConfig.get_fhir_claim_status_rejected_code() fhir_claim_response.outcome = ClaimResponseConverter.build_codeable_concept( self._TEST_STATUS, system=None, text=display) fhir_payment = ClaimResponsePayment() fhir_payment.adjustmentReason = ClaimResponseConverter.build_simple_codeable_concept( self._TEST_ADJUSTMENT) fhir_payment.date = self._TEST_DATE_PROCESSED fhir_claim_response.payment = fhir_payment total_approved = Money() total_approved.value = self._TEST_APPROVED fhir_claim_response.totalBenefit = total_approved fhir_error = ClaimResponseError() fhir_error.code = ClaimResponseConverter.build_codeable_concept( self._TEST_REJECTION_REASON) fhir_claim_response.error = [fhir_error] feedback = Feedback() feedback.id = self._TEST_FEEDBACK_ID fhir_claim_response.communicationRequest = \ [CommunicationRequestConverter.build_fhir_resource_reference(feedback)] self.build_response_item(fhir_claim_response) self.build_response_service(fhir_claim_response) return fhir_claim_response
def verify_fhir_instance(self, fhir_obj): self.assertEqual(self._TEST_UUID, fhir_obj.id) main_id_check = False for identifier in fhir_obj.identifier: if identifier.value == fhir_obj.id: main_id_check = True if identifier.type.coding[0].code == Stu3IdentifierConfig.get_fhir_uuid_type_code(): self.assertEqual(str(self._TEST_UUID), identifier.value) elif identifier.type.coding[0].code == Stu3IdentifierConfig.get_fhir_claim_code_type(): self.assertEqual(self._TEST_CODE, identifier.value) self.assertTrue(main_id_check, "One of the identifiers should match the main ID") self.assertEqual(self._TEST_STATUS, fhir_obj.outcome.coding[0].code) self.assertEqual(self._TEST_ADJUSTMENT, fhir_obj.payment.adjustmentReason.text) self.assertEqual(self._TEST_DATE_PROCESSED, fhir_obj.payment.date) self.assertEqual(self._TEST_APPROVED, fhir_obj.totalBenefit.value) self.assertEqual(self._TEST_REJECTION_REASON, fhir_obj.error[0].code.coding[0].code) self.assertEqual(str(self._TEST_FEEDBACK_UUID), CommunicationRequestConverter.get_resource_id_from_reference( fhir_obj.communicationRequest[0])) self.assertEqual(str(self._TEST_ITEM_STATUS), fhir_obj.item[0].adjudication[0].reason.coding[0].code) self.assertEqual(self._TEST_ITEM_QUANTITY_APPROVED, fhir_obj.item[0].adjudication[0].value) self.assertEqual(self._TEST_ITEM_JUSTIFICATION, fhir_obj.processNote[0].text) self.assertEqual(str(self._TEST_ITEM_REJECTED_REASON), fhir_obj.item[0].adjudication[1].reason.coding[0].code) self.assertEqual(self._TEST_ITEM_LIMITATION_VALUE, fhir_obj.item[0].adjudication[0].amount.value) self.assertEqual(str(self._TEST_SERVICE_STATUS), fhir_obj.item[1].adjudication[0].reason.coding[0].code) self.assertEqual(self._TEST_SERVICE_QUANTITY_APPROVED, fhir_obj.item[1].adjudication[0].value) self.assertEqual(self._TEST_SERVICE_JUSTIFICATION, fhir_obj.processNote[1].text) self.assertEqual(str(self._TEST_SERVICE_REJECTED_REASON), fhir_obj.item[1].adjudication[1].reason.coding[0].code) self.assertEqual(self._TEST_SERVICE_LIMITATION_VALUE, fhir_obj.item[1].adjudication[0].amount.value)
def build_fhir_code_identifier(cls, identifiers, imis_claim_admin): if imis_claim_admin.code: identifier = cls.build_fhir_identifier( imis_claim_admin.code, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_claim_admin_code_type()) identifiers.append(identifier)
def build_fhir_id_identifier(cls, identifiers, imis_object): if imis_object.id is not None: identifier = cls.build_fhir_identifier( str(imis_object.id), Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_id_type_code()) identifiers.append(identifier)
def create_test_fhir_instance(self): location = Location() identifier = LocationConverter.build_fhir_identifier( self._TEST_HF_CODE, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_facility_id_type()) location.identifier = [identifier] location.name = self._TEST_HF_NAME location.type = LocationConverter.build_codeable_concept( Stu3LocationConfig.get_fhir_code_for_hospital(), Stu3LocationConfig.get_fhir_location_role_type_system()) location.address = LocationConverter.build_fhir_address( self._TEST_ADDRESS, AddressUse.HOME.value, AddressType.PHYSICAL.value) telecom = [] phone = LocationConverter.build_fhir_contact_point( self._TEST_PHONE, ContactPointSystem.PHONE.value, ContactPointUse.HOME.value) telecom.append(phone) fax = LocationConverter.build_fhir_contact_point( self._TEST_FAX, ContactPointSystem.FAX.value, ContactPointUse.HOME.value) telecom.append(fax) email = LocationConverter.build_fhir_contact_point( self._TEST_EMAIL, ContactPointSystem.EMAIL.value, ContactPointUse.HOME.value) telecom.append(email) location.telecom = telecom return location
def build_fhir_hf_code_identifier(cls, identifiers, imis_hf): if imis_hf is not None: identifier = cls.build_fhir_identifier( imis_hf.code, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_facility_id_type()) identifiers.append(identifier)
def verify_fhir_instance(self, fhir_obj): self.assertEqual(1, len(fhir_obj.name)) human_name = fhir_obj.name[0] self.assertTrue(isinstance(human_name, HumanName)) self.assertEqual(self._TEST_OTHER_NAME, human_name.given[0]) self.assertEqual(self._TEST_LAST_NAME, human_name.family) self.assertEqual(NameUse.USUAL.value, human_name.use) for identifier in fhir_obj.identifier: self.assertTrue(isinstance(identifier, Identifier)) code = PatientConverter.get_first_coding_from_codeable_concept(identifier.type).code if code == Stu3IdentifierConfig.get_fhir_chfid_type_code(): self.assertEqual(self._TEST_CHF_ID, identifier.value) elif code == Stu3IdentifierConfig.get_fhir_uuid_type_code() and not isinstance(identifier.value, UUID): self.assertEqual(self._TEST_UUID, identifier.value) elif code == Stu3IdentifierConfig.get_fhir_passport_type_code(): self.assertEqual(self._TEST_PASSPORT, identifier.value) self.assertEqual(self._TEST_DOB, fhir_obj.birthDate) self.assertEqual(AdministrativeGender.MALE.value, fhir_obj.gender) marital_code = PatientConverter.get_first_coding_from_codeable_concept(fhir_obj.maritalStatus).code self.assertEqual(Stu3MaritalConfig.get_fhir_divorced_code(), marital_code) self.assertEqual(2, len(fhir_obj.telecom)) for telecom in fhir_obj.telecom: self.assertTrue(isinstance(telecom, ContactPoint)) if telecom.system == ContactPointSystem.PHONE.value: self.assertEqual(self._TEST_PHONE, telecom.value) elif telecom.system == ContactPointSystem.EMAIL.value: self.assertEqual(self._TEST_EMAIL, telecom.value) self.assertEqual(2, len(fhir_obj.address)) for adddress in fhir_obj.address: self.assertTrue(isinstance(adddress, Address)) if adddress.type == AddressType.PHYSICAL.value: self.assertEqual(self._TEST_ADDRESS, adddress.text) elif adddress.type == AddressType.BOTH.value: self.assertEqual(self._TEST_GEOLOCATION, adddress.text)
def create_test_fhir_instance(self): fhir_practitioner = Practitioner() name = HumanName() name.family = self._TEST_LAST_NAME name.given = [self._TEST_OTHER_NAME] name.use = NameUse.USUAL.value fhir_practitioner.name = [name] identifiers = [] chf_id = PractitionerConverter.build_fhir_identifier( self._TEST_CODE, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_claim_admin_code_type()) identifiers.append(chf_id) fhir_practitioner.identifier = identifiers fhir_practitioner.birthDate = self._TEST_DOB telecom = [] phone = PractitionerConverter.build_fhir_contact_point( self._TEST_PHONE, ContactPointSystem.PHONE.value, ContactPointUse.HOME.value) telecom.append(phone) email = PractitionerConverter.build_fhir_contact_point( self._TEST_EMAIL, ContactPointSystem.EMAIL.value, ContactPointUse.HOME.value) telecom.append(email) fhir_practitioner.telecom = telecom return fhir_practitioner
def create_test_fhir_instance(self): fhir_communication_request = CommunicationRequest() fhir_communication_request.id = self._TEST_FEEDBACK_ID fhir_communication_request.occurrenceDateTime = self._TEST_FEEDBACK_DATE identifiers = [] identifier = Converter.build_fhir_identifier( self._TEST_FEEDBACK_ID, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_id_type_code()) identifiers.append(identifier) fhir_communication_request.identifier = identifiers reasons = [ Converter.build_codeable_concept( Config.get_fhir_care_rendered_code(), text=str(self._TEST_CARE_RENDERED)), Converter.build_codeable_concept( Config.get_fhir_payment_asked_code(), text=str(self._TEST_PAYMENT_ASKED)), Converter.build_codeable_concept( Config.get_fhir_drug_prescribed_code(), text=str(self._TEST_DRUG_PRESCRIBED)), Converter.build_codeable_concept( Config.get_fhir_drug_received_code(), text=str(self._TEST_DRUG_RECEIVED)), Converter.build_codeable_concept(Config.get_fhir_asessment_code(), text=str(self._TEST_ASESSMENT)) ] fhir_communication_request.reasonCode = reasons return fhir_communication_request
def build_fhir_passport_identifier(cls, identifiers, imis_insuree): if hasattr(imis_insuree, "typeofid") and imis_insuree.typeofid is not None: pass # TODO typeofid isn't provided, this section should contain logic used to create passport field based on typeofid elif imis_insuree.passport is not None: identifier = cls.build_fhir_identifier(imis_insuree.passport, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_passport_type_code()) identifiers.append(identifier)
def build_imis_identifiers(cls, imis_insuree, fhir_patient): value = cls.get_fhir_identifier_by_code(fhir_patient.identifier, Stu3IdentifierConfig.get_fhir_chfid_type_code()) if value: imis_insuree.chf_id = value value = cls.get_fhir_identifier_by_code(fhir_patient.identifier, Stu3IdentifierConfig.get_fhir_passport_type_code()) if value: imis_insuree.passport = value
def build_fhir_identifiers(cls, fhir_claim, imis_claim): identifiers = [] cls.build_fhir_id_identifier(identifiers, imis_claim) claim_code = cls.build_fhir_identifier( imis_claim.code, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_claim_code_type()) identifiers.append(claim_code) fhir_claim.identifier = identifiers
def verify_fhir_instance(self, fhir_obj): self.assertIsNotNone(fhir_obj.patient.reference) self.assertEqual(str(self._TEST_UUID), fhir_obj.id) for identifier in fhir_obj.identifier: if identifier.type.coding[ 0].code == Stu3IdentifierConfig.get_fhir_uuid_type_code(): self.assertEqual(fhir_obj.id, identifier.value) elif identifier.type.coding[ 0].code == Stu3IdentifierConfig.get_fhir_claim_code_type(): self.assertEqual(self._TEST_CODE, identifier.value) self.assertEqual(self._TEST_DATE_FROM, fhir_obj.billablePeriod.start) self.assertEqual(self._TEST_DATE_TO, fhir_obj.billablePeriod.end) for diagnosis in fhir_obj.diagnosis: type = diagnosis.type[0].text code = diagnosis.diagnosisCodeableConcept.coding[0].code if type == ImisClaimIcdTypes.ICD_0.value: self.assertEqual(self._TEST_MAIN_ICD_CODE, code) self.assertEqual(self._TEST_CLAIMED, fhir_obj.total.value) self.assertEqual(self._TEST_DATE_CLAIMED, fhir_obj.created) self.assertIsNotNone(fhir_obj.facility.reference) for information in fhir_obj.information: if information.category.text == Stu3ClaimConfig.get_fhir_claim_information_explanation_code( ): self.assertEqual(self._TEST_EXPLANATION, information.valueString) elif information.category.text == Stu3ClaimConfig.get_fhir_claim_information_guarantee_id_code( ): self.assertEqual(self._TEST_GUARANTEE_ID, information.valueString) self.assertIsNotNone(fhir_obj.enterer.reference) self.assertEqual(self._TEST_VISIT_TYPE, fhir_obj.type.text) for item in fhir_obj.item: if item.category.text == Stu3ClaimConfig.get_fhir_claim_item_code( ): self.assertEqual(self._TEST_ITEM_CODE, item.service.text) self.assertEqual(self._TEST_ITEM_QUANTITY_PROVIDED, item.quantity.value) self.assertEqual(self._TEST_ITEM_PRICE_ASKED, item.unitPrice.value) self.assertEqual( self._TEST_ITEM_EXPLANATION, fhir_obj.information[item.informationLinkId[0] - 1].valueString) elif item.category.text == Stu3ClaimConfig.get_fhir_claim_service_code( ): self.assertEqual(self._TEST_SERVICE_CODE, item.service.text) self.assertEqual(self._TEST_SERVICE_QUANTITY_PROVIDED, item.quantity.value) self.assertEqual(self._TEST_SERVICE_PRICE_ASKED, item.unitPrice.value) self.assertEqual( self._TEST_SERVICE_EXPLANATION, fhir_obj.information[item.informationLinkId[0] - 1].valueString)
def create_test_fhir_instance(self): fhir_claim = FHIRClaim() fhir_claim.id = self._TEST_CODE fhir_claim.patient = PatientConverter.build_fhir_resource_reference( self._TEST_INSUREE) claim_code = ClaimConverter.build_fhir_identifier( self._TEST_CODE, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_claim_code_type()) fhir_claim.identifier = [claim_code] billable_period = Period() billable_period.start = self._TEST_DATE_FROM billable_period.end = self._TEST_DATE_TO fhir_claim.billablePeriod = billable_period diagnoses = [] ClaimConverter.build_fhir_diagnosis(diagnoses, self._TEST_DIAGNOSIS_CODE.code, ImisClaimIcdTypes.ICD_0.value) fhir_claim.diagnosis = diagnoses total = Money() total.value = self._TEST_CLAIMED fhir_claim.total = total fhir_claim.created = self._TEST_DATE_CLAIMED fhir_claim.facility = LocationConverter.build_fhir_resource_reference( self._TEST_HF) information = [] guarantee_id_code = Stu3ClaimConfig.get_fhir_claim_information_guarantee_id_code( ) ClaimConverter.build_fhir_string_information(information, guarantee_id_code, self._TEST_GUARANTEE_ID) explanation_code = Stu3ClaimConfig.get_fhir_claim_information_explanation_code( ) ClaimConverter.build_fhir_string_information(information, explanation_code, self._TEST_EXPLANATION) fhir_claim.information = information fhir_claim.enterer = PractitionerConverter.build_fhir_resource_reference( self._TEST_CLAIM_ADMIN) fhir_claim.type = ClaimConverter.build_simple_codeable_concept( self._TEST_VISIT_TYPE) type = Stu3ClaimConfig.get_fhir_claim_item_code() ClaimConverter.build_fhir_item(fhir_claim, self._TEST_ITEM_CODE, type, self._TEST_ITEM) type = Stu3ClaimConfig.get_fhir_claim_service_code() ClaimConverter.build_fhir_item(fhir_claim, self._TEST_SERVICE_CODE, type, self._TEST_SERVICE) return fhir_claim
def get_id_for_created_resource(self, response): result = None fhir_obj = FHIRBaseObject.loads(response.content, 'json') if hasattr(fhir_obj, 'identifier'): result = BaseFHIRConverter.get_fhir_identifier_by_code(fhir_obj.identifier, Stu3IdentifierConfig.get_fhir_id_type_code()) return result
def build_imis_identifier(cls, imis_claim, fhir_claim, errors): value = cls.get_fhir_identifier_by_code( fhir_claim.identifier, Stu3IdentifierConfig.get_fhir_claim_code_type()) if value: imis_claim.code = value cls.valid_condition(imis_claim.code is None, gettext('Missing the claim code'), errors)
def build_imis_hf_identiftier(cls, imis_hf, fhir_location, errors): value = cls.get_fhir_identifier_by_code( fhir_location.identifier, Stu3IdentifierConfig.get_fhir_facility_id_type()) if value: imis_hf.code = value cls.valid_condition(imis_hf.code is None, gettext('Missing hf code'), errors)
def create_test_fhir_instance(self): fhir_patient = Patient() name = HumanName() name.family = self._TEST_LAST_NAME name.given = [self._TEST_OTHER_NAME] name.use = NameUse.USUAL.value fhir_patient.name = [name] identifiers = [] chf_id = PatientConverter.build_fhir_identifier( self._TEST_CHF_ID, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_chfid_type_code()) identifiers.append(chf_id) passport = PatientConverter.build_fhir_identifier( self._TEST_PASSPORT, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_passport_type_code()) identifiers.append(passport) fhir_patient.identifier = identifiers fhir_patient.birthDate = self._TEST_DOB fhir_patient.gender = AdministrativeGender.MALE.value fhir_patient.maritalStatus = PatientConverter.build_codeable_concept( Stu3MaritalConfig.get_fhir_divorced_code(), Stu3MaritalConfig.get_fhir_marital_status_system()) telecom = [] phone = PatientConverter.build_fhir_contact_point( self._TEST_PHONE, ContactPointSystem.PHONE.value, ContactPointUse.HOME.value) telecom.append(phone) email = PatientConverter.build_fhir_contact_point( self._TEST_EMAIL, ContactPointSystem.EMAIL.value, ContactPointUse.HOME.value) telecom.append(email) fhir_patient.telecom = telecom addresses = [] current_address = PatientConverter.build_fhir_address( self._TEST_ADDRESS, AddressUse.HOME.value, AddressType.PHYSICAL.value) addresses.append(current_address) geolocation = PatientConverter.build_fhir_address( self._TEST_GEOLOCATION, AddressUse.HOME.value, AddressType.BOTH.value) addresses.append(geolocation) fhir_patient.address = addresses return fhir_patient
def build_imis_identifiers(cls, imis_claim_admin, fhir_practitioner, errors): value = cls.get_fhir_identifier_by_code( fhir_practitioner.identifier, Stu3IdentifierConfig.get_fhir_claim_admin_code_type()) if value: imis_claim_admin.code = value cls.valid_condition(imis_claim_admin.code is None, gettext('Missing the claim admin code'), errors)
def get_fhir_identifier_by_code(cls, identifiers, lookup_code): value = None for identifier in identifiers or []: first_coding = cls.get_first_coding_from_codeable_concept(identifier.type) if first_coding.system == Stu3IdentifierConfig.get_fhir_identifier_type_system() \ and first_coding.code == lookup_code: value = identifier.value break return value
def verify_fhir_instance(self, fhir_obj): for identifier in fhir_obj.identifier: code = LocationConverter.get_first_coding_from_codeable_concept(identifier.type).code if code == Stu3IdentifierConfig.get_fhir_uuid_type_code(): self.assertEqual(fhir_obj.id, identifier.value) elif code == Stu3IdentifierConfig.get_fhir_facility_id_type(): self.assertEqual(self._TEST_HF_CODE, identifier.value) self.assertEqual(self._TEST_HF_NAME, fhir_obj.name) type_code = LocationConverter.get_first_coding_from_codeable_concept(fhir_obj.type).code self.assertEqual(Stu3LocationConfig.get_fhir_code_for_hospital(), type_code) self.assertEqual(self._TEST_ADDRESS, fhir_obj.address.text) self.assertEqual(3, len(fhir_obj.telecom)) for telecom in fhir_obj.telecom: if telecom.system == ContactPointSystem.PHONE.value: self.assertEqual(self._TEST_PHONE, telecom.value) elif telecom.system == ContactPointSystem.EMAIL.value: self.assertEqual(self._TEST_EMAIL, telecom.value) elif telecom.system == ContactPointSystem.FAX.value: self.assertEqual(self._TEST_FAX, telecom.value)
def verify_fhir_instance(self, fhir_obj): self.assertEqual(1, len(fhir_obj.name)) human_name = fhir_obj.name[0] self.assertTrue(isinstance(human_name, HumanName)) self.assertEqual(self._TEST_OTHER_NAME, human_name.given[0]) self.assertEqual(self._TEST_LAST_NAME, human_name.family) self.assertEqual(NameUse.USUAL.value, human_name.use) for identifier in fhir_obj.identifier: self.assertTrue(isinstance(identifier, Identifier)) code = PractitionerConverter.get_first_coding_from_codeable_concept( identifier.type).code if code == Stu3IdentifierConfig.get_fhir_claim_admin_code_type(): self.assertEqual(self._TEST_CODE, identifier.value) elif code == Stu3IdentifierConfig.get_fhir_id_type_code(): self.assertEqual(str(self._TEST_ID), identifier.value) self.assertEqual(self._TEST_DOB, fhir_obj.birthDate) self.assertEqual(2, len(fhir_obj.telecom)) for telecom in fhir_obj.telecom: self.assertTrue(isinstance(telecom, ContactPoint)) if telecom.system == ContactPointSystem.PHONE.value: self.assertEqual(self._TEST_PHONE, telecom.value) elif telecom.system == ContactPointSystem.EMAIL.value: self.assertEqual(self._TEST_EMAIL, telecom.value)
def build_fhir_chfid_identifier(cls, identifiers, imis_insuree): if imis_insuree.chf_id is not None: identifier = cls.build_fhir_identifier(imis_insuree.chf_id, Stu3IdentifierConfig.get_fhir_identifier_type_system(), Stu3IdentifierConfig.get_fhir_chfid_type_code()) identifiers.append(identifier)