Skip to content

Commit

Permalink
Merge branch 'master' into refactor_convert_patid
Browse files Browse the repository at this point in the history
  • Loading branch information
chgl authored Sep 15, 2024
2 parents 905d125 + 5e85d93 commit 748d572
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,39 +115,9 @@ public Bundle mapOnkoResourcesToCondition(
var conditionCode = new CodeableConcept().addCoding(coding);
onkoCondition.setCode(conditionCode);

var bodySiteADTCoding = new Coding();
var bodySiteSNOMEDCoding = new Coding();

var adtBodySite = primDia.getSeitenlokalisation();

if (adtBodySite != null) {
var adtSeitenlokalisationDisplay =
DisplayAdtSeitenlokalisationLookup.lookupDisplay(adtBodySite);
var snomedCtSeitenlokalisationCode = SnomedCtSeitenlokalisationLookup.lookupCode(adtBodySite);
var snomedCtSeitenlokalisationDisplay =
SnomedCtSeitenlokalisationLookup.lookupDisplay(adtBodySite);

if (adtSeitenlokalisationDisplay != null) {
bodySiteADTCoding
.setSystem(fhirProperties.getSystems().getAdtSeitenlokalisation())
.setCode(adtBodySite)
.setDisplay(adtSeitenlokalisationDisplay);
} else {
LOG.warn("Unmappable body site in oBDS data: {}", adtBodySite);
}

if (snomedCtSeitenlokalisationDisplay != null) {
bodySiteSNOMEDCoding
.setSystem(fhirProperties.getSystems().getSnomed())
.setCode(snomedCtSeitenlokalisationCode)
.setDisplay(snomedCtSeitenlokalisationDisplay);
} else {
LOG.warn("Unmappable snomed body site in oBDS data: {}", adtBodySite);
}

var bodySiteConcept = new CodeableConcept();
bodySiteConcept.addCoding(bodySiteADTCoding).addCoding(bodySiteSNOMEDCoding);
onkoCondition.addBodySite(bodySiteConcept);
onkoCondition.addBodySite(getBodySiteConcept(adtBodySite));
}

onkoCondition.setSubject(
Expand Down Expand Up @@ -224,4 +194,38 @@ public Bundle mapOnkoResourcesToCondition(

return bundle;
}

private CodeableConcept getBodySiteConcept(String adtBodySite) {
var bodySiteADTCoding = new Coding();
var bodySiteSNOMEDCoding = new Coding();

var adtSeitenlokalisationDisplay =
DisplayAdtSeitenlokalisationLookup.lookupDisplay(adtBodySite);
var snomedCtSeitenlokalisationCode = SnomedCtSeitenlokalisationLookup.lookupCode(adtBodySite);
var snomedCtSeitenlokalisationDisplay =
SnomedCtSeitenlokalisationLookup.lookupDisplay(adtBodySite);

if (adtSeitenlokalisationDisplay != null) {
bodySiteADTCoding
.setSystem(fhirProperties.getSystems().getAdtSeitenlokalisation())
.setCode(adtBodySite)
.setDisplay(adtSeitenlokalisationDisplay);
} else {
LOG.warn("Unmappable body site in oBDS data: {}", adtBodySite);
}

if (snomedCtSeitenlokalisationDisplay != null) {
bodySiteSNOMEDCoding
.setSystem(fhirProperties.getSystems().getSnomed())
.setCode(snomedCtSeitenlokalisationCode)
.setDisplay(snomedCtSeitenlokalisationDisplay);
} else {
LOG.warn("Unmappable snomed body site in oBDS data: {}", adtBodySite);
}

var bodySiteConcept = new CodeableConcept();
bodySiteConcept.addCoding(bodySiteADTCoding).addCoding(bodySiteSNOMEDCoding);

return bodySiteConcept;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.*;
import org.hl7.fhir.r4.model.*;
import org.miracum.streams.ume.obdstofhir.FhirProperties;
import org.miracum.streams.ume.obdstofhir.model.ADT_GEKID.Menge_Patient.Patient.Patienten_Stammdaten.Menge_Adresse.Adresse;
import org.miracum.streams.ume.obdstofhir.model.Meldeanlass;
import org.miracum.streams.ume.obdstofhir.model.MeldungExport;
import org.slf4j.Logger;
Expand Down Expand Up @@ -104,76 +105,13 @@ public Bundle mapOnkoResourcesToPatient(List<MeldungExport> meldungExportList) {

// deceased
if (!deathReports.isEmpty()) {
// start by setting deceased to true. If a more detailed death date is
// available in the data, override it further down this code path.
patient.setDeceased(new BooleanType(true));

// get the first entry with the largest version number where the death date is set
var reportWithSterbeDatum =
deathReports.stream()
.sorted(Comparator.comparingInt(MeldungExport::getVersionsnummer).reversed())
.filter(
m -> {
var mengeVerlauf =
m.getXml_daten()
.getMenge_Patient()
.getPatient()
.getMenge_Meldung()
.getMeldung()
.getMenge_Verlauf();

if (mengeVerlauf == null) {
return false;
}

if (mengeVerlauf.getVerlauf() == null) {
return false;
}

if (mengeVerlauf.getVerlauf().getTod() == null) {
return false;
}

return StringUtils.hasLength(
mengeVerlauf.getVerlauf().getTod().getSterbedatum());
})
.findFirst();

if (reportWithSterbeDatum.isPresent()) {
var deathDate =
reportWithSterbeDatum
.get()
.getXml_daten()
.getMenge_Patient()
.getPatient()
.getMenge_Meldung()
.getMeldung()
.getMenge_Verlauf()
.getVerlauf()
.getTod()
.getSterbedatum();

patient.setDeceased(convertObdsDateToDateTimeType(deathDate));
} else {
LOG.warn("Sterbedatum not set on any of the Tod Meldungen.");
}
patient.setDeceased(getDeceased(deathReports));
}

// address
var patAddess = patData.getMenge_Adresse().getAdresse().getFirst();
if (StringUtils.hasLength(patAddess.getPatienten_PLZ())) {
var address = new Address();
address.setPostalCode(patAddess.getPatienten_PLZ()).setType(Address.AddressType.BOTH);
if (patAddess.getPatienten_Land() != null
&& patAddess.getPatienten_Land().matches("[a-zA-Z]{2,3}")) {
address.setCountry(patAddess.getPatienten_Land().toUpperCase());
} else {
address
.addExtension()
.setUrl(fhirProperties.getExtensions().getDataAbsentReason())
.setValue(new CodeType("unknown"));
}
patient.addAddress(address);
var patAddress = patData.getMenge_Adresse().getAdresse().getFirst();
if (StringUtils.hasLength(patAddress.getPatienten_PLZ())) {
patient.addAddress(getAddress(patAddress));
}

var bundle = new Bundle();
Expand All @@ -193,4 +131,66 @@ private static String getBirthDateYearMonthString(String gebdatum) {

return YearMonth.of(localBirthDate.getYear(), quarterMonth).toString();
}

private Type getDeceased(List<MeldungExport> deathReports) {
// get the first entry with the largest version number where the death date is set
var reportWithSterbeDatum =
deathReports.stream()
.sorted(Comparator.comparingInt(MeldungExport::getVersionsnummer).reversed())
.filter(
m -> {
var mengeVerlauf =
m.getXml_daten()
.getMenge_Patient()
.getPatient()
.getMenge_Meldung()
.getMeldung()
.getMenge_Verlauf();

try {
return StringUtils.hasLength(
mengeVerlauf.getVerlauf().getTod().getSterbedatum());
} catch (NullPointerException e) {
return false;
}
})
.findFirst();

if (reportWithSterbeDatum.isPresent()) {
var deathDate =
reportWithSterbeDatum
.get()
.getXml_daten()
.getMenge_Patient()
.getPatient()
.getMenge_Meldung()
.getMeldung()
.getMenge_Verlauf()
.getVerlauf()
.getTod()
.getSterbedatum();

return convertObdsDateToDateTimeType(deathDate);
} else {
LOG.warn("Sterbedatum not set on any of the Tod Meldungen.");
}

// If a more detailed death date is not available in the data, return true.
return new BooleanType(true);
}

private Address getAddress(Adresse patAddress) {
var address = new Address();
address.setPostalCode(patAddress.getPatienten_PLZ()).setType(Address.AddressType.BOTH);
if (patAddress.getPatienten_Land() != null
&& patAddress.getPatienten_Land().matches("[a-zA-Z]{2,3}")) {
address.setCountry(patAddress.getPatienten_Land().toUpperCase());
} else {
address
.addExtension()
.setUrl(fhirProperties.getExtensions().getDataAbsentReason())
.setValue(new CodeType("unknown"));
}
return address;
}
}

0 comments on commit 748d572

Please sign in to comment.