def create_test_fhir_instance(self): location = Location() identifier = LocationConverter.build_fhir_identifier( self._TEST_HF_CODE, R4IdentifierConfig.get_fhir_identifier_type_system(), R4IdentifierConfig.get_fhir_facility_id_type()) location.identifier = [identifier] location.name = self._TEST_HF_NAME location.type = LocationConverter.build_codeable_concept( R4LocationConfig.get_fhir_code_for_hospital(), R4LocationConfig.get_fhir_location_site_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_imis_hf_level(cls, imis_hf, fhir_location, errors): code = fhir_location.code if code == R4LocationConfig.get_fhir_code_for_hospital(): imis_hf.level = ImisHfLevel.HOSPITAL.value elif code == R4LocationConfig.get_fhir_code_for_dispensary(): imis_hf.level = ImisHfLevel.DISPENSARY.value elif code == R4LocationConfig.get_fhir_code_for_health_center(): imis_hf.level = ImisHfLevel.HEALTH_CENTER.value cls.valid_condition(imis_hf.level is None, gettext('Missing location level'), errors)
def build_imis_location_type(cls, imis_location, fhir_location, errors): if code == R4LocationConfig.get_fhir_code_for_region(): imis_location.type = ImisLocationType.REGION.value elif code == R4LocationConfig.get_fhir_code_for_district(): imis_location.type = ImisLocationType.DISTRICT.value elif code == R4LocationConfig.get_fhir_code_for_ward(): imis_location.type = ImisLocationType.WARD.value elif code == R4LocationConfig.get_fhir_code_for_village(): imis_location.type = ImisLocationType.VILLAGE.value cls.valid_condition(imis_location.type is None, gettext('Missing location type'), errors)
def build_fhir_type(cls, fhir_location, imis_hf): code = "" text = "" if imis_hf.level == ImisHfLevel.HEALTH_CENTER.value: code = R4LocationConfig.get_fhir_code_for_health_center() text = "health-center" elif imis_hf.level == ImisHfLevel.DISPENSARY.value: code = R4LocationConfig.get_fhir_code_for_dispensary() text = "dispensary" elif imis_hf.level == ImisHfLevel.HOSPITAL.value: code = R4LocationConfig.get_fhir_code_for_hospital() text = "hospital" fhir_location.type = \ [cls.build_codeable_concept(code, R4LocationConfig.get_fhir_location_site_type_system(), text=text)]
def build_fhir_healthcare_service_type(cls, fhir_hcs, imis_hf): code = "" text = "" if imis_hf.care_type == HealthFacility.CARE_TYPE_IN_PATIENT: code = R4LocationConfig.get_fhir_code_for_in_patient() text = "In-patient" elif imis_hf.care_type == HealthFacility.CARE_TYPE_OUT_PATIENT: code = R4LocationConfig.get_fhir_code_for_out_patient() text = "Out-patient" elif imis_hf.care_type == HealthFacility.CARE_TYPE_BOTH: code = R4LocationConfig.get_fhir_code_for_both() text = "Both" fhir_hcs.type = \ [cls.build_codeable_concept(code, R4LocationConfig.get_fhir_hf_service_type_system(), text=text)]
def build_fhir_healthcare_service_category(cls, fhir_hcs, imis_hf): code = "" text = "" if imis_hf.level == ImisHfLevel.HEALTH_CENTER.value: code = R4LocationConfig.get_fhir_code_for_health_center() text = "Hospital center" elif imis_hf.level == ImisHfLevel.HOSPITAL.value: code = R4LocationConfig.get_fhir_code_for_hospital() text = "Hospital" elif imis_hf.level == ImisHfLevel.DISPENSARY.value: code = R4LocationConfig.get_fhir_code_for_dispensary() text = "Dispensary" fhir_hcs.category = \ [cls.build_codeable_concept(code, R4LocationConfig.get_fhir_location_site_type_system(), text=text)]
def build_fhir_type(cls, fhir_location, imis_location): code = "" text = "" if imis_location.type == ImisLocationType.REGION.value: code = R4LocationConfig.get_fhir_code_for_region() text = "region" elif imis_location.type == ImisLocationType.DISTRICT.value: code = R4LocationConfig.get_fhir_code_for_district() text = "district" elif imis_location.type == ImisLocationType.WARD.value: code = R4LocationConfig.get_fhir_code_for_ward() text = "ward" elif imis_location.type == ImisLocationType.VILLAGE.value: code = R4LocationConfig.get_fhir_code_for_village() text = "village" fhir_location.type = \ [cls.build_codeable_concept(code, R4LocationConfig.get_fhir_location_area_type_system(), text=text)]
def build_imis_care_type(cls, imis_hf, fhir_hcs, errors): care_type = fhir_hcs.type if not cls.valid_condition(care_type is None, gettext('Missing hf `care type` attribute'), errors): for maritalCoding in care_type.coding: if maritalCoding.system == R4LocationConfig.get_fhir_hf_service_type_system( ): code = maritalCoding.code if code == R4LocationConfig.get_fhir_code_for_in_patient(): imis_hf.care_type = HealthFacility.CARE_TYPE_IN_PATIENT elif code == R4LocationConfig.get_fhir_code_for_out_patient( ): imis_hf.care_type = HealthFacility.CARE_TYPE_OUT_PATIENT elif code == R4LocationConfig.get_fhir_code_for_both(): imis_hf.care_type = HealthFacility.CARE_TYPE_BOTH cls.valid_condition(imis_hf.care_type is None, gettext('Missing hf care type'), errors)
def build_imis_hf_level(cls, imis_hf, fhir_hcs, errors): location_type = fhir_hcs.category if not cls.valid_condition(location_type is None, gettext('Missing patient `type` attribute'), errors): for maritalCoding in location_type.coding: if maritalCoding.system == R4LocationConfig.get_fhir_location_site_type_system( ): code = maritalCoding.code if code == R4LocationConfig.get_fhir_code_for_health_center( ): imis_hf.level = ImisHfLevel.HEALTH_CENTER.value elif code == R4LocationConfig.get_fhir_code_for_hospital(): imis_hf.level = ImisHfLevel.HOSPITAL.value elif code == R4LocationConfig.get_fhir_code_for_dispensary( ): imis_hf.level = ImisHfLevel.DISPENSARY.value cls.valid_condition(imis_hf.level is None, gettext('Missing hf level'), errors)
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 == R4IdentifierConfig.get_fhir_uuid_type_code(): self.assertEqual(fhir_obj.id, identifier.value) elif code == R4IdentifierConfig.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(R4LocationConfig.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 build_fhir_physical_type(cls, fhir_location, imis_hf): code = R4LocationConfig.get_fhir_code_for_site() text = "site" fhir_location.physicalType = \ cls.build_codeable_concept(code, R4LocationConfig.get_fhir_location_physical_type_system(), text=text)