def map(self):
    try:
      id_value = sha256(self.data['concat_elements'].encode('utf-8')).hexdigest()

      lufu_diagnostic_report = diagnosticreport.DiagnosticReport();
      lufu_diagnostic_report.id = id_value
      lufu_diagnostic_report_identifier = self.data['untersuchung_id']
      lufu_diagnostic_report.identifier = [identifier.Identifier({"use": "official",
                                                                  "system": self.systems['lufu_obs_id'],
                                                                  "value": str(lufu_diagnostic_report_identifier)})]
      dt_string = self.data['untersuchungsdatum']+" "+self.data['untersuchungsuhrzeit']
      lufu_report_dt = datetime.strftime(datetime.strptime(dt_string, "%Y-%m-%d %H:%M:%S"), '%Y-%m-%dT%H:%M:%S')
      lufu_diagnostic_report_date = fhirdate.FHIRDate(lufu_report_dt)

      lufu_diagnostic_report.effectiveDateTime = lufu_diagnostic_report_date

      ref = {"reference": f"Patient/{self.data['patient_psn']}"}
      lufu_diagnostic_report.subject = fhirreference.FHIRReference(jsondict=ref)
      ref = {"reference": f"Encounter/{self.data['encounter_psn']}"}
      lufu_diagnostic_report.encounter = fhirreference.FHIRReference(jsondict=ref)

      rep_code_system_cc = codeableconcept.CodeableConcept()
      rep_code_system_cc.coding = [coding.Coding({"system": "https://www.dimdi.de/static/de/klassifikationen/ops",
                     "code": "1-71",
                     "display": "Pneumologische Funktionsuntersuchunge"})]

      rep_status = 'final'
      lufu_diagnostic_report.code = rep_code_system_cc
      lufu_diagnostic_report.status = rep_status
      conclusion_str = ""
      if self.data['beurteilung'] is not None and self.data['beurteilung'] != "":
        conclusion_str = conclusion_str + "Beurteilung: "+self.data['beurteilung']
      if self.data['anmerkung'] is not None and self.data['anmerkung'] != "":
        conclusion_str = conclusion_str + "|\n Anmerkung: "+self.data['anmerkung']
      if self.data['empfehlung'] is not None and self.data['empfehlung'] != "":
        conclusion_str = conclusion_str + " |\n Empfehlung: "+self.data['empfehlung']

      lufu_diagnostic_report.conclusion = conclusion_str

      return lufu_diagnostic_report
    except KeyError as exc:
      self.logger.error(f"In {__name__}: Key {exc} not found in dictionary")
      raise
    except Exception as exc:
      self.logger.error(f"In {__name__}: Error occurred in mapping ({exc})")
      raise
def mapLufuItems2Obs(self, param, items):

    sct_code = self.snomed_mapper.codeLookup(str(param))
    sct_display = self.snomed_mapper.displayLookup(str(sct_code))

    lufu_observation = observation.Observation()
    observation_unit = ''
    concat_string = self.data['concat_elements'] + param
    id_value = sha256(concat_string.encode('utf-8')).hexdigest()
    lufu_observation.id = id_value
    lufu_observation.identifier = [
        identifier.Identifier({
            "system": self.systems['lufu_obs_id'],
            "value": id_value
        })
    ]
    obs_actual_code = codeableconcept.CodeableConcept()
    obs_actual_code.coding = [
        coding.Coding({
            "system": "http://snomed.info/sct",
            "code": sct_code,
            "display": sct_display,
            "version": "0.1"
        })
    ]
    # obs category
    obs_type_sys = "http://terminology.hl7.org/CodeSystem/observation-category"
    code = 'exam'
    observation_cat = codeableconcept.CodeableConcept()
    observation_cat.coding = [
        coding.Coding({
            "system": obs_type_sys,
            "code": code
        })
    ]
    lufu_observation.category = [observation_cat]
    lufu_observation.code = obs_actual_code

    ref = {"reference": f"Encounter/{self.data['encounter_psn']}"}
    lufu_observation.encounter = fhirreference.FHIRReference(jsondict=ref)
    ref = {"reference": f"Patient/{self.data['patient_psn']}"}
    lufu_observation.subject = fhirreference.FHIRReference(jsondict=ref)

    if not pd.isna(self.data['untersuchungsdatum']) and not pd.isna(
            self.data['untersuchungsuhrzeit']):
        dt_string = self.data['untersuchungsdatum'] + " " + self.data[
            'untersuchungsuhrzeit']
        obs_datetime = datetime.strptime(dt_string, "%Y-%m-%d %H:%M:%S")
        obs_datetime.replace(tzinfo=timezone.utc)
        # collect_ts_fhir = datetime.strftime(obs_datetime.astimezone().isoformat(), '%Y-%m-%dT%H:%M:%S')
        lufu_observation.effectiveDateTime = fhirdate.FHIRDate(
            obs_datetime.astimezone().isoformat())

    components = []

    for item in items:
        if 'actual' in str(item):
            obs_component = observation.ObservationComponent()
            lufu_value = self.data[item]
            lookupParam = item
            if ("PRE" not in param) and ("POST" not in param):
                lookupParam = str(item).replace("PRE_", "")
            loinc_code = self.loinc_mapper.codeLookup(lookupParam)
            loinc_display = self.loinc_mapper.displayLookup(loinc_code)
            i2b2_code = self.i2b2_mapper.codeLookup(lookupParam)

            codings = []

            if loinc_code != 'No Code':
                codings.append(
                    coding.Coding({
                        "system": "http://loinc.org",
                        "code": loinc_code,
                        "display": loinc_display,
                        "version": "2.46"
                    }))
                mask = self.map_table[self.map_table['RELMA'] == loinc_code]
                observation_unit = mask['Unit'].values[0]
            if i2b2_code != 'No Code':
                codings.append(
                    coding.Coding({
                        "system": "http://mdr.miracum.org",
                        "code": i2b2_code,
                        "version": "0.01"
                    }))
                mask = self.map_table[self.map_table['I2B2 Basecode'] ==
                                      i2b2_code]
                observation_unit = mask['Unit'].values[0]

            if len(codings) > 0:
                obs_component_code = codeableconcept.CodeableConcept()
                obs_component_code.coding = codings
                obs_component.code = obs_component_code
                #obs_component.valueDateTime = fhirdate.FHIRDate(collect_ts_fhir)
                obs_component.valueQuantity = quantity.Quantity({
                    "value":
                    lufu_value,
                    "unit":
                    observation_unit,
                    "system":
                    "http://unitsofmeasure.org",
                    "code":
                    observation_unit
                })
                lufu_ref_value = self.data[str(item).replace(
                    'actual', 'target')]
                low_ref_value = quantity.Quantity({
                    "value": lufu_ref_value,
                    "unit": observation_unit,
                    "system": "http://unitsofmeasure.org",
                    "code": observation_unit
                })
                ref_range = ObservationReferenceRange()
                ref_range.low = low_ref_value
                ref_range.high = low_ref_value
                obs_component.referenceRange = [ref_range]

                components.append(obs_component)

    lufu_observation.component = components
    lufu_observation.status = "final"

    lufu_actual_meta = meta.Meta()
    lufu_actual_meta.source = "#lufu-cwd"
    lufu_observation.meta = lufu_actual_meta
    if len(lufu_observation.component) > 0:
        return lufu_observation
    else:
        return []
    def _map_dmpro2medi(self, encounter_ref, patient_ref):
        new_medication = []
        medication_stm = []
        mapping_row = self.ops_drug_mapping[self.ops_drug_mapping['ops_code']
                                            == self.data['ops_kode']]
        if not mapping_row.empty:
            drug_name = mapping_row['medication'].to_string(index=False)[1:]
            drug_atc = mapping_row['atc_code1'].to_string(index=False)[1:]
            dosage_text = mapping_row['text'].to_string(index=False)[1:]
            ucum_short = mapping_row['ucum_short'].to_string(index=False)[1:]
            ucum_full = mapping_row['ucum_full'].to_string(index=False)[1:]
            dosage_min = mapping_row['dosage_min'].to_string(index=False)[1:]
            dosage_max = mapping_row['dosage_max'].to_string(index=False)[1:]
            combi_product = mapping_row['medication_combi'].to_string(
                index=False)

            # generate medication statement resources
            new_medication = medication.Medication()
            id_value = str(self.data['encounter_psn']) + '_' + str(
                self.data['procedure_nr']) + '_med'
            #id_value = f"{drug_name}"
            #id_value = sha256(id_value.encode('utf-8')).hexdigest()
            new_medication.id = id_value
            new_medication.identifier = [
                identifier.Identifier({
                    "system": self.systems['med_id'],
                    "value": id_value
                })
            ]

            atc_cc = codeableconcept.CodeableConcept()
            atc_cc.coding = [
                coding.Coding({
                    "system": "http://fhir.de/CodeSystem/dimdi/atc",
                    "code": drug_atc,
                    "version": "ATC/DDD Version 2020",
                    "display": drug_name
                })
            ]
            new_medication.code = atc_cc
            new_medication.status = "active"
            med_meta = meta.Meta()
            med_meta.source = "#sap-ish"
            new_medication.meta = med_meta

            substances = [drug_name]
            if combi_product:
                substances = drug_name.split('-')

            ingredients = []
            if substances != ["UNKLAR"]:
                for substance in substances:
                    mapping_row2 = self.drug_unii_mapping[
                        self.drug_unii_mapping['Substanzangabe_aus_OPS-Code']
                        == substance]
                    substance_unii = mapping_row2[
                        'Substanz_fuer_Dosisberechnung_UNII-number'].to_string(
                            index=False)[1:]
                    substance_ask = mapping_row2[
                        'Substanz_fuer_Dosisberechnung_ASK-Nr'].to_string(
                            index=False)[1:]
                    substance_cas = mapping_row2[
                        'Substanz_fuer_Dosisberechnung_CAS-Nummer'].to_string(
                            index=False)[1:]

                    ingredient = medication.MedicationIngredient()
                    ingredient_cc = codeableconcept.CodeableConcept()
                    ingredient_cc.coding = [
                        coding.Coding({
                            "system": "http://fdasis.nlm.nih.gov",
                            "code": substance_unii,
                            "display": substance
                        })
                    ]
                    ingredient_cc.coding += [
                        coding.Coding({
                            "system": "http://fhir.de/CodeSystem/ask",
                            "code": substance_ask,
                            "display": substance
                        })
                    ]
                    ingredient_cc.coding += [
                        coding.Coding({
                            "system": "urn:oid:2.16.840.1.113883.6.61",
                            "code": substance_cas,
                            "display": substance
                        })
                    ]
                    ingredient.itemCodeableConcept = ingredient_cc
                    ingredients.append(ingredient)
            new_medication.ingredient = ingredients

            # generate medication statement resources
            id_value = str(self.data['encounter_psn']) + '_' + str(
                self.data['procedure_nr']) + '_med_stat'
            #id_value = f"{self.data['concat_elements']}-medication"
            #id_value = sha256(id_value.encode('utf-8')).hexdigest()

            medication_stm = medicationstatement.MedicationStatement()
            medication_stm.id = id_value
            medication_stm.identifier = [
                identifier.Identifier({
                    "system": self.systems['med_stm_id'],
                    "value": id_value
                })
            ]
            med_meta = meta.Meta()
            med_meta.source = "#sap-ish"
            medication_stm.meta = med_meta

            ref = {"reference": f"Medication/{new_medication.id}"}
            medication_ref = fhirreference.FHIRReference(jsondict=ref)
            medication_stm.medicationReference = medication_ref
            medication_stm.context = encounter_ref
            medication_stm.subject = patient_ref
            #medication_stm.partOf =

            medication_stm.status = "active"

            if not pd.isna(self.data['admission_dt']):
                med_period = period.Period()
                med_period.start = fhirdate.FHIRDate(
                    datetime.strftime(self.data['admission_dt'],
                                      '%Y-%m-%dT%H:%M:%S'))
                if not pd.isna(self.data['discharge_dt']):
                    med_period.end = fhirdate.FHIRDate(
                        datetime.strftime(self.data['discharge_dt'],
                                          '%Y-%m-%dT%H:%M:%S'))
                    medication_stm.status = "completed"
                medication_stm.effectivePeriod = med_period

            new_dosage = dosage.Dosage()
            new_dosage.text = dosage_text

            dose_range = range.Range()
            if dosage_min != "NaN":
                dose_range.low = quantity.Quantity({
                    "value":
                    float(dosage_min.replace(',', '.')),
                    "unit":
                    ucum_full,
                    "system":
                    "http://unitsofmeasure.org",
                    "code":
                    ucum_short
                })
            if dosage_max != "NaN":
                dose_range.high = quantity.Quantity({
                    "value":
                    float(dosage_max.replace(',', '.')),
                    "unit":
                    ucum_full,
                    "system":
                    "http://unitsofmeasure.org",
                    "code":
                    ucum_short
                })
            dose_rate = dosage.DosageDoseAndRate()
            dose_rate.doseRange = dose_range
            new_dosage.doseAndRate = [dose_rate]

            #method, route, site

            medication_stm.dosage = [new_dosage]
        return [new_medication, medication_stm]
    def map(self, lufu_section):
        try:
            ops_code = 'No OPS Code'
            ops_text = 'No OPS Code Text'

            if lufu_section == 'B':
                ops_code = '1-710'
                ops_text = self.procedure_mapper.codeLookup(ops_code)
            else:
                ops_code = '1-71'
                ops_text = self.procedure_mapper.codeLookup(ops_code)

            id_value = sha256(
                (str(lufu_section) +
                 self.data['concat_elements']).encode('utf-8')).hexdigest()

            lufu_procedure = procedure.Procedure()

            #lufu_procedure_system = ''
            lufu_procedure_identifier = id_value
            lufu_procedure.identifier = [
                identifier.Identifier({
                    "use": "official",
                    "system": self.systems['prod_id'],
                    "value": lufu_procedure_identifier
                })
            ]
            lufu_procedure.id = id_value

            lufu_procedure_identifier_perf_date = fhirdate.FHIRDate(
                datetime.strftime(
                    datetime.strptime(self.data['untersuchungsdatum'],
                                      '%d.%m.%Y %H:%M:%S'),
                    '%Y-%m-%dT%H:%M:%S'))

            lufu_procedure.performedDateTime = lufu_procedure_identifier_perf_date

            ref = {"reference": f"Patient/{self.data['patient_psn']}"}
            lufu_procedure.subject = fhirreference.FHIRReference(jsondict=ref)
            ref = {"reference": f"Encounter/{self.data['encounter_psn']}"}
            lufu_procedure.encounter = fhirreference.FHIRReference(
                jsondict=ref)

            rep_code_system_cc = codeableconcept.CodeableConcept()
            rep_code_system_cc.coding = [
                coding.Coding({
                    "system":
                    "https://www.dimdi.de/static/de/klassifikationen/ops",
                    "code": ops_code,
                    "display": ops_text
                })
            ]

            rep_status = 'completed'

            lufu_procedure.code = rep_code_system_cc
            lufu_procedure.status = rep_status

            return lufu_procedure
        except KeyError as exc:
            self.logger.error(
                f"In {__name__}: Key {exc} not found in dictionary")
            raise
        except Exception as exc:
            self.logger.error(
                f"In {__name__}: Error occurred in mapping ({exc})")
            raise
Ejemplo n.º 5
0
    def map(self):
        try:
            id_value = str(
                self.data['result_id']
            )  #2sha256(self.data['concat_elements'].encode('utf-8')).hexdigest()

            lab_observation = mii_observation.Observation()
            lab_observation.id = id_value
            identifier_type = mii_codeableconcept.CodeableConcept()
            identifier_type.coding = [
                mii_coding.Coding({
                    "system": "http://terminology.hl7.org/CodeSystem/v2-0203",
                    "code": "MR"
                })
            ]
            lab_observation.identifier = [
                mii_identifier.Identifier({
                    "system": self.systems['lab_id'],
                    "value": id_value,
                    "assigner": {
                        "reference": "Organization/1111"
                    },
                    "type": identifier_type.as_json()
                })
            ]
            ref = {"reference": f"Encounter/{self.data['encounter_psn']}"}
            lab_observation.encounter = fhirreference.FHIRReference(
                jsondict=ref)
            ref = {"reference": f"Patient/{self.data['patient_psn']}"}
            lab_observation.subject = fhirreference.FHIRReference(jsondict=ref)
            lab_observation.status = "final"

            if not pd.isna(self.data['collect_ts']):
                collect_ts_fhir = datetime.strftime(self.data['collect_ts'],
                                                    '%Y-%m-%dT%H:%M:%S')
                lab_observation.effectiveDateTime = fhirdate.FHIRDate(
                    collect_ts_fhir)

            if not pd.isna(self.data['value_num']):
                if (self.data['loinc_code']
                        and self.data['loinc_code'] != 'noLoinc'
                        and self.data['value_unit']):
                    if self.data['value_unit'] == '10E12/L':
                        self.data['value_unit'] = '10*6/uL'
                    elif self.data['value_unit'] == '10E9/L':
                        self.data['value_unit'] = '10*3/uL'
                    elif self.data['value_unit'] == 'mE/l':
                        self.data['value_unit'] = 'm[IU]/L'
                    elif (self.data['value_unit'] == 'ug/l'
                          or self.data['value_unit'] == 'µg/l'):
                        self.data['value_unit'] = 'ng/mL'

                    if self.loinc_url:
                        result = self._convert_loinc()
                        #print(f"{self.data['loinc_code']} {self.data['value_num']} {self.data['value_unit']}")
                        #print(result)

                        if result and isinstance(
                                result, list) and not 'error' in result[0]:
                            if result[0]['loinc'] and result[0][
                                    'value'] and result[0]['unit']:
                                self.data['loinc_code'] = result[0]['loinc']
                                self.data['value_num'] = result[0]['value']
                                self.data['value_unit'] = result[0]['unit']
                                self.data['value_unit'] = self.data[
                                    'value_unit'].replace("'", "''")
                    #else:
                    #  print(f"{self.data['loinc_code']} {self.data['value_num']} {self.data['value_unit']}")
                    #  print(result)

                if (self.data['value_comp'] == '!='
                        or self.data['value_comp'] == '='
                        or self.data['value_comp'] == '=='):
                    self.data['value_comp'] = None

                lab_quantity = mii_quantity.Quantity({
                    "value":
                    self.data['value_num'],
                    "unit":
                    self.data['value_unit'],
                    "comparator":
                    self.data['value_comp'],
                    "system":
                    "http://unitsofmeasure.org",
                    "code":
                    self.data['value_unit']
                })
                lab_observation.valueQuantity = lab_quantity
            elif self.data['value_text']:
                lab_observation.valueString = self.data['value_text']

            lab_code = codeableconcept.CodeableConcept()
            lab_code.coding = [
                coding.Coding({
                    "system": "http://loinc.org",
                    "code": self.data['loinc_code']
                })
            ]
            lab_observation.code = lab_code

            if not pd.isna(self.data['ref_high_num']) and not pd.isna(
                    self.data['ref_low_num']):
                reference_range = mii_observation.ObservationReferenceRange()
                reference_range.high = quantity.Quantity({
                    "value":
                    self.data['ref_high_num'],
                    "unit":
                    self.data['value_unit'],
                    "system":
                    "http://unitsofmeasure.org",
                    "code":
                    self.data['value_unit']
                })
                reference_range.low = quantity.Quantity({
                    "value":
                    self.data['ref_low_num'],
                    "unit":
                    self.data['value_unit'],
                    "system":
                    "http://unitsofmeasure.org",
                    "code":
                    self.data['value_unit']
                })
                lab_observation.referenceRange = [reference_range]

            lab_method = codeableconcept.CodeableConcept()
            lab_method.coding = [
                coding.Coding({
                    "system": "http://methodConcept",
                    "display": self.data['method']
                })
            ]
            lab_observation.method = lab_method

            lab_meta = meta.Meta()
            lab_meta.source = "#laboratory"
            lab_observation.meta = lab_meta

            lab_cat = mii_codeableconcept.CodeableConcept()
            lab_cat_sys = "http://terminology.hl7.org/CodeSystem/observation-category"
            lab_cat.coding = [
                mii_coding.Coding({
                    "system": lab_cat_sys,
                    "display": "Laboratory",
                    "code": "laboratory"
                })
            ]
            lab_observation.category = lab_cat

            #lab_annotation = annotation_model.Annotation({"text": note})
            #lab_observation.note = [lab_annotation]

            if self.data['int_flag']:
                if self.data['int_flag'] == "N":
                    int_flag_long = "Normal"
                elif self.data['int_flag'] == "L":
                    int_flag_long = "Low"
                elif self.data['int_flag'] == "H":
                    int_flag_long = "High"
                else:
                    int_flag_long = "Unknown"

                lab_interpretation = codeableconcept.CodeableConcept()
                lab_int_sys = "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation"
                lab_interpretation.coding = [
                    coding.Coding({
                        "system": lab_int_sys,
                        "code": self.data['int_flag'],
                        "display": int_flag_long
                    })
                ]
                lab_observation.interpretation = [lab_interpretation]

            return lab_observation
        except KeyError as exc:
            self.logger.error(
                f"In {__name__}: Key {exc} not found in dictionary")
            raise
        except FHIRValidationError:
            raise
    def map(self):
        try:
            id_value = str(self.data['encounter_psn']) + '_' + str(
                self.data['diagnosis_nr'])
            #sha256(self.data['concat_elements'].encode('utf-8')).hexdigest()

            icd_condition = mii_condition.Condition()
            icd_condition.id = id_value
            icd_condition.identifier = [
                identifier.Identifier({
                    "system": self.systems['condition_id'],
                    "value": id_value
                })
            ]

            clinic_status = codeableconcept.CodeableConcept()
            clinic_status.coding = [
                coding.Coding({
                    "system":
                    "http://terminology.hl7.org/CodeSystem/condition-clinical",
                    "code": "active"
                })
            ]
            icd_condition.clinicalStatus = clinic_status

            full_code = self.data['code']
            if self.data['sec_code']:
                full_code = self.data['code'] + " " + self.data['sec_code']
            condition_coding = mii_coding.Coding()
            condition_coding.system = "http://fhir.de/CodeSystem/dimdi/icd-10-gm"
            condition_coding.code = full_code
            condition_coding.version = self.data['code_ver']

            if self.data['sec_code']:
                main_cross_ext = extension.Extension()
                main_cross_ext.url = "http://fhir.de/StructureDefinition/icd-10-gm-haupt-kreuz"
                main_cross_ext.valueCoding = coding.Coding({
                    "system":
                    condition_coding.system,
                    "version":
                    self.data['code_ver'],
                    "code":
                    re.sub(r"[+†]", "", self.data['code'])
                })
                condition_coding.extension = [main_cross_ext]

                if '!' in self.data['sec_code']:
                    excl_ext = extension.Extension()
                    excl_ext.url = "http://fhir.de/StructureDefinition/icd-10-gm-ausrufezeichen"
                    excl_ext.valueCoding = coding.Coding({
                        "system":
                        condition_coding.system,
                        "version":
                        self.data['code_ver'],
                        "code":
                        re.sub(r"!", "", self.data['sec_code'])
                    })
                    condition_coding.extension.append(excl_ext)

                if '*' in self.data['sec_code']:
                    star_ext = extension.Extension()
                    star_ext.url = "http://fhir.de/StructureDefinition/icd-10-gm-stern"
                    star_ext.valueCoding = coding.Coding({
                        "system":
                        condition_coding.system,
                        "version":
                        self.data['code_ver'],
                        "code":
                        re.sub(r"\*", "", self.data['sec_code'])
                    })
                    condition_coding.extension.append(star_ext)

            condition_code = mii_codeableconcept.CodeableConcept()
            condition_code.coding = [condition_coding]
            icd_condition.code = condition_code

            # todo: what value of the data mart should be mapped?
            icd_condition.onsetString = '2002-01-01'

            ref = {"reference": f"Encounter/{self.data['encounter_psn']}"}
            icd_condition.encounter = fhirreference.FHIRReference(jsondict=ref)
            ref = {"reference": f"Patient/{self.data['patient_psn']}"}
            icd_condition.subject = fhirreference.FHIRReference(jsondict=ref)

            if not pd.isna(self.data['admission_dt']):
                icd_condition.recordedDate = fhirdate.FHIRDate(
                    datetime.strftime(self.data['admission_dt'],
                                      '%Y-%m-%dT%H:%M:%S'))

            if self.data['loc']:
                icd_condition.bodySite = []
                if self.data['loc'] == "L" or self.data['loc'] == "B":
                    left_body_part = mii_codeableconcept.CodeableConcept()
                    icd_loc_sys = "http://fhir.de/CodeSystem/kbv/s_icd_seitenlokalisation"
                    left_body_part.coding = [
                        mii_coding.Coding({
                            "system": icd_loc_sys,
                            "code": "L",
                            "display": "links"
                        })
                    ]
                    icd_condition.bodySite.append(left_body_part)

                if self.data['loc'] == "R" or self.data['loc'] == "B":
                    right_body_part = mii_codeableconcept.CodeableConcept()
                    icd_loc_sys = "http://fhir.de/CodeSystem/kbv/s_icd_seitenlokalisation"
                    right_body_part.coding = [
                        mii_coding.Coding({
                            "system": icd_loc_sys,
                            "code": "R",
                            "display": "rechts"
                        })
                    ]
                    icd_condition.bodySite.append(right_body_part)

            rank = 2
            if self.data['diag_type'] == 1:
                rank = 1

            icd_meta = meta.Meta()
            icd_meta.source = "#sap-ish"
            icd_condition.meta = icd_meta

            return [icd_condition, rank]

        except KeyError as exc:
            self.logger.error(
                f"In {__name__}: Key {exc} not found in dictionary")
            raise