def test_filters(self):
        from fhirtordf.rdfsupport.fhirgraphutils import codeable_concept_code
        from fhirtordf.rdfsupport.fhirgraphutils import CodeableConcept

        g = Graph()
        g.load(os.path.join(self.base_dir, "patient-example-f201-roel.ttl"), format="turtle")
        codes = sorted(codeable_concept_code(g, URIRef(FHIR['Patient/f201']), FHIR.Patient.maritalStatus,
                                             "http://snomed.info/sct"))
        self.assertEqual([CodeableConcept("http://snomed.info/sct", "36629006",
                                          URIRef("http://snomed.info/id/36629006"))], codes)
        codes = sorted(codeable_concept_code(g, URIRef(FHIR['Patient/f201']), FHIR.Patient.maritalStatus,
                                             "http://loinc.org"))
        self.assertEqual([], codes)
    def test_empty(self):
        from fhirtordf.rdfsupport.fhirgraphutils import codeable_concept_code

        g = Graph()
        g.load(os.path.join(self.base_dir, "patient-example-f201-roel-edited.ttl"), format="turtle")
        codes = sorted(codeable_concept_code(g, URIRef(FHIR['Patient/f201']), FHIR.Patient.maritalStatus))
        self.assertEqual([], codes)
Esempio n. 3
0
    def add_patient_information(self, g: Graph, patient: URIRef) -> None:
        """
        Add additional information to the patient
        :param g: Graph carrying additional facts about the patient
        :param patient: URI of the actual patient
        """
        if not g.value(patient,
                       FHIR.Patient.animal):  # i2b2 doesn't do animals
            # gender
            gender = value(g, patient, FHIR.Patient.gender)
            if gender == "male":
                self.patient_dimension_entry._sex_cd = 'M'
            elif gender == "female":
                self.patient_dimension_entry._sex_cd = 'F'
            elif gender == "other":
                self.patient_dimension_entry._sex_cd = 'U'

            # deceased.deceasedBoolean --> vital_status_code.deathInd
            isdeceased = value(g, patient, FHIR.Patient.deceasedBoolean)
            if isdeceased is not None:
                self.patient_dimension_entry._vital_status_cd = VitalStatusCd.dd_deceased if isdeceased \
                    else VitalStatusCd.dd_living

            # deceased.deceasedDateTime --> deathcode / death_date
            self.deathdate = value(g, patient, FHIR.Patient.deceasedDateTime,
                                   True)

            # birthdate - must be processed after deceased, as deceased goes into age calculation
            bd = g.value(patient, FHIR.Patient.birthDate)
            birthdate = None
            if bd:
                birthdate = extension(
                    g,
                    bd,
                    "http://hl7.org/fhir/StructureDefinition/patient-birthTime",
                    asLiteral=True)
                if not birthdate:
                    birthdate = value(g,
                                      patient,
                                      FHIR.Patient.birthDate,
                                      asLiteral=True)
            self.birthdate = birthdate

            # address -- use == home / period.end is empty or past deathcode date
            addresses = g.objects(patient, FHIR.Patient.address)
            for address in addresses:
                address_use = value(g, address, FHIR.Address.use)
                if address_use is None or address_use == "home":
                    period = g.value(address, FHIR.Address.period)
                    if not period or (period and value(
                            g, period, FHIR.Period.end) is None):
                        city = value(g, address, FHIR.Address.city)
                        state = value(g, address, FHIR.Address.state)
                        zipcode = value(g, address, FHIR.Address.postalCode)
                        if zipcode:
                            self.patient_dimension_entry._zip_cd = zipcode
                            if city and state:
                                self.patient_dimension_entry._statecityzip_path = \
                                    'Zip codes\\' + state + '\\' + city + '\\' + zipcode + '\\'

            # maritalStatus --> map to 'single', 'married', 'divorced', 'widow', other?
            marital_stati = codeable_concept_code(g, patient,
                                                  FHIR.Patient.maritalStatus)
            for ms in marital_stati:
                if ms.system == str(V3.MaritalStatus):
                    self._marital_status = marital_stati[0]
                    msc = self._marital_status.code
                    if msc != 'UNK':
                        self.patient_dimension_entry._marital_status_cd = \
                            'divorced' if msc in ['A', 'D'] else \
                            'married' if msc in ['L', 'M', 'P'] else \
                            'widow' if msc in ['W'] else \
                            'single'
                    break
            else:
                msuri = concept_uri(g, patient, FHIR.Patient.maritalStatus,
                                    SNOMEDCT)
                if msuri:
                    # TODO: figure out what to do with SNOMED id's (terminology service, anyone?)
                    pass

            # language
            communications = list(
                g.objects(patient, FHIR.Patient.communication))
            language = None
            for communication in communications:
                pref = value(g, communication,
                             FHIR.Patient.communication.preferred)
                if pref or (pref is None and len(communications) == 1):
                    languages = codeable_concept_code(
                        g, communication, FHIR.Patient.communication.language)
                    if languages:
                        language = languages[0]
                        break

            if language is not None:
                self._language = language.code