Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use day-precision for condition dates and asserted-extension for v2025 compatibility #171

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static class FhirExtensions {
private String miiExOnkoStrahlentherapieBestrahlung;
private String miiExOnkoHistologyMorphologyBehaviorIcdo3;
private String miiExOnkoSystemischeTherapieIntention;
private String conditionAssertedDate;
}

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,19 @@ public static boolean isIcd10GmCode(String value) {

public static DateType convertObdsDatumToDateType(
DatumTagOderMonatOderJahrOderNichtGenauTyp obdsDatum) {
var date = new DateType(obdsDatum.getValue().toGregorianCalendar().getTime());
var dateTimeType = convertObdsDatumToDateTimeType(obdsDatum);
var dateType = new DateType(dateTimeType.getValue());
dateType.setPrecision(dateTimeType.getPrecision());
return dateType;
}

public static Optional<DateTimeType> convertObdsDatumToDateTimeType(
DatumTagOderMonatGenauTyp obdsDatum) {
if (null == obdsDatum) {
return Optional.empty();
}

var date = new DateTimeType(obdsDatum.getValue().toGregorianCalendar().getTime());
switch (obdsDatum.getDatumsgenauigkeit()) {
// exakt (entspricht taggenau)
case E:
Expand All @@ -265,23 +277,12 @@ public static DateType convertObdsDatumToDateType(
case T:
date.setPrecision(TemporalPrecisionEnum.MONTH);
break;
// Monat geschätzt (entspricht jahrgenau)
case M:
date.setPrecision(TemporalPrecisionEnum.YEAR);
break;
// vollständig geschätzt (genaue Angabe zum Jahr nicht möglich)
case V:
log.warn("Date precision is completely estimated. Likely not a correct value.");
}
return date;
return Optional.of(date);
}

public static Optional<DateTimeType> convertObdsDatumToDateTimeType(
DatumTagOderMonatGenauTyp obdsDatum) {
if (null == obdsDatum) {
return Optional.empty();
}

public static DateTimeType convertObdsDatumToDateTimeType(
DatumTagOderMonatOderJahrOderNichtGenauTyp obdsDatum) {
var date = new DateTimeType(obdsDatum.getValue().toGregorianCalendar().getTime());
switch (obdsDatum.getDatumsgenauigkeit()) {
// exakt (entspricht taggenau)
Expand All @@ -292,8 +293,19 @@ public static Optional<DateTimeType> convertObdsDatumToDateTimeType(
case T:
date.setPrecision(TemporalPrecisionEnum.MONTH);
break;
// Monat geschätzt (entspricht jahrgenau)
case M:
date.setPrecision(TemporalPrecisionEnum.YEAR);
break;
// vollständig geschätzt (genaue Angabe zum Jahr nicht möglich)
case V:
date.setPrecision(TemporalPrecisionEnum.YEAR);
log.warn(
"Date precision is completely estimated. Likely not a correct value. "
+ "Defaulting to most granular 'year' precision.");
break;
}
return Optional.of(date);
return date;
}

public static Optional<DateTimeType> convertObdsDatumToDateTimeType(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package org.miracum.streams.ume.obdstofhir.mapper.mii;

import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import de.basisdatensatz.obds.v3.OBDS;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
import javax.xml.datatype.XMLGregorianCalendar;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r4.model.Enumerations.ResourceType;
import org.miracum.streams.ume.obdstofhir.FhirProperties;
import org.miracum.streams.ume.obdstofhir.mapper.ObdsToFhirMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

Expand All @@ -20,14 +24,34 @@ public class ConditionMapper extends ObdsToFhirMapper {
private static final Pattern icdVersionPattern =
Pattern.compile("^(10 (?<versionYear>20\\d{2}) ((GM)|(WHO))|Sonstige)$");

@Autowired
public ConditionMapper(FhirProperties fhirProperties) {
super(fhirProperties);
}

public Condition map(OBDS.MengePatient.Patient.MengeMeldung.Meldung meldung, Reference patient) {
public Condition map(
OBDS.MengePatient.Patient.MengeMeldung.Meldung meldung,
Reference patient,
XMLGregorianCalendar meldeDatum) {
Objects.requireNonNull(meldung);
Objects.requireNonNull(meldung.getTumorzuordnung());
Objects.requireNonNull(meldung.getDiagnose());
Objects.requireNonNull(meldung.getMeldungID());
Objects.requireNonNull(patient);
Objects.requireNonNull(meldeDatum);
Validate.isTrue(
Objects.equals(
patient.getReferenceElement().getResourceType(), ResourceType.PATIENT.toCode()),
"The subject reference should point to a Patient resource");

var condition = new Condition();

var identifier =
new Identifier()
.setSystem(fhirProperties.getSystems().getConditionId())
.setValue(meldung.getTumorzuordnung().getTumorID());
condition.addIdentifier(identifier);
condition.setId(computeResourceIdFromIdentifier(identifier));

if (meldung.getDiagnose().getDiagnosesicherung() != null) {
Coding verStatus =
new Coding(fhirProperties.getSystems().getConditionVerStatus(), "confirmed", "");
Expand All @@ -46,9 +70,6 @@ public Condition map(OBDS.MengePatient.Patient.MengeMeldung.Meldung meldung, Ref
condition.getMeta().addProfile(fhirProperties.getProfiles().getMiiPrOnkoDiagnosePrimaertumor());

var tumorzuordnung = meldung.getTumorzuordnung();
if (tumorzuordnung == null) {
throw new RuntimeException("Tumorzuordnung ist null");
}

Coding icd =
new Coding(
Expand Down Expand Up @@ -105,8 +126,14 @@ public Condition map(OBDS.MengePatient.Patient.MengeMeldung.Meldung meldung, Ref
}
condition.setBodySite(bodySite);

condition.setRecordedDate(
tumorzuordnung.getDiagnosedatum().getValue().toGregorianCalendar().getTime());
var diagnoseDatum = convertObdsDatumToDateTimeType(tumorzuordnung.getDiagnosedatum());
condition.addExtension(
fhirProperties.getExtensions().getConditionAssertedDate(), diagnoseDatum);

var recorded = new DateTimeType(meldeDatum.toGregorianCalendar().getTime());
recorded.setPrecision(TemporalPrecisionEnum.DAY);
condition.setRecordedDateElement(recorded);

return condition;
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fhir:
mii-ex-onko-strahlentherapie-bestrahlung: "https://www.medizininformatik-initiative.de/fhir/ext/modul-onko/StructureDefinition/mii-ex-onko-strahlentherapie-bestrahlung"
mii-ex-onko-histology-morphology-behavior-icdo3: "https://www.medizininformatik-initiative.de/fhir/ext/modul-onko/StructureDefinition/mii-ex-onko-histology-morphology-behavior-icdo3"
mii-ex-onko-systemische-therapie-intention: "https://www.medizininformatik-initiative.de/fhir/ext/modul-onko/StructureDefinition/mii-ex-onko-systemische-therapie-intention"
condition-asserted-date: "http://hl7.org/fhir/StructureDefinition/condition-assertedDate"
systems:
patientId: "${fhir.default.baseSystemUrl}/obds-to-fhir/identifiers/patient-id"
identifier-type: "http://terminology.hl7.org/CodeSystem/v2-0203"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import de.basisdatensatz.obds.v3.DatumTagOderMonatGenauTyp;
import de.basisdatensatz.obds.v3.DatumTagOderMonatGenauTyp.DatumsgenauigkeitTagOderMonatGenau;
import de.basisdatensatz.obds.v3.DatumTagOderMonatOderJahrOderNichtGenauTyp;
import de.basisdatensatz.obds.v3.DatumTagOderMonatOderJahrOderNichtGenauTyp.DatumsgenauigkeitTagOderMonatOderJahrOderNichtGenau;
import java.time.DateTimeException;
import java.util.Arrays;
import java.util.stream.Stream;
Expand Down Expand Up @@ -199,4 +201,27 @@ void shouldNotConvertDatumTagOderMonatGenauTypToDateTimeTypeFromNull() {

assertThat(actual).isEmpty();
}

@ParameterizedTest
@CsvSource({
"2017-07-02,E,2017-07-02",
"1999-12-31,E,1999-12-31",
"2017-07-02,T,2017-07",
"2017-07-02,M,2017",
"1999-12-31,M,1999",
"2000-01-01,V,2000",
})
void shouldConvertDatumTagOderMonatOderJahrOderNichtGenauTypToDateType(
String input,
DatumsgenauigkeitTagOderMonatOderJahrOderNichtGenau genauigkeit,
String expected) {
var calendar = DatatypeFactory.newDefaultInstance().newXMLGregorianCalendar(input);
var datum = new DatumTagOderMonatOderJahrOderNichtGenauTyp();
datum.setValue(calendar);
datum.setDatumsgenauigkeit(genauigkeit);

var actual = ObdsToFhirMapper.convertObdsDatumToDateType(datum);

assertThat(actual.asStringValue()).isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void map_withGivenObds_shouldCreateValidConditionResource(String sourceFile) thr
.findFirst()
.get();

final var condition = sut.map(conMeldung, new Reference("Patient/1"));
final var condition = sut.map(conMeldung, new Reference("Patient/1"), obds.getMeldedatum());

var fhirParser = FhirContext.forR4().newJsonParser().setPrettyPrint(true);
var fhirJson = fhirParser.encodeResourceToString(condition);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"resourceType": "Condition",
"id": "9896edd80f6833ea17fbb2c5ad5ca42caa1d02f41baea875f4a390be3b372356",
"meta": {
"profile": [ "https://www.medizininformatik-initiative.de/fhir/ext/modul-onko/StructureDefinition/mii-pr-onko-diagnose-primaertumor" ]
},
Expand All @@ -12,6 +13,13 @@
"code": "8010/3"
} ]
}
}, {
"url": "http://hl7.org/fhir/StructureDefinition/condition-assertedDate",
"valueDateTime": "2020-03-01"
} ],
"identifier": [ {
"system": "https://bzkf.github.io/obds-to-fhir/identifiers/primaerdiagnose-id",
"value": "101"
} ],
"verificationStatus": {
"coding": [ {
Expand Down Expand Up @@ -44,5 +52,5 @@
"subject": {
"reference": "Patient/1"
},
"recordedDate": "2020-03-01T00:00:00+01:00"
}
"recordedDate": "2024-09-19"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"resourceType": "Condition",
"id": "a31f38c3b6c0d35e6f228a50ba288b814250c774b8dc89cf5ae36455eb6d1ea8",
"meta": {
"profile": [ "https://www.medizininformatik-initiative.de/fhir/ext/modul-onko/StructureDefinition/mii-pr-onko-diagnose-primaertumor" ]
},
Expand All @@ -12,6 +13,13 @@
"code": "8140/3"
} ]
}
}, {
"url": "http://hl7.org/fhir/StructureDefinition/condition-assertedDate",
"valueDateTime": "2021-07-08"
} ],
"identifier": [ {
"system": "https://bzkf.github.io/obds-to-fhir/identifiers/primaerdiagnose-id",
"value": "111"
} ],
"verificationStatus": {
"coding": [ {
Expand Down Expand Up @@ -44,5 +52,5 @@
"subject": {
"reference": "Patient/1"
},
"recordedDate": "2021-07-08T00:00:00+02:00"
}
"recordedDate": "2024-02-16"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"resourceType": "Condition",
"id": "ada766c1f2eea7625dc4d9bac33d99d0f2a3606376cfa0798fa7c839be6f1e16",
"meta": {
"profile": [ "https://www.medizininformatik-initiative.de/fhir/ext/modul-onko/StructureDefinition/mii-pr-onko-diagnose-primaertumor" ]
},
Expand All @@ -12,6 +13,13 @@
"code": "8461/3"
} ]
}
}, {
"url": "http://hl7.org/fhir/StructureDefinition/condition-assertedDate",
"valueDateTime": "2017-07-02"
} ],
"identifier": [ {
"system": "https://bzkf.github.io/obds-to-fhir/identifiers/primaerdiagnose-id",
"value": "121"
} ],
"verificationStatus": {
"coding": [ {
Expand Down Expand Up @@ -44,5 +52,5 @@
"subject": {
"reference": "Patient/1"
},
"recordedDate": "2017-07-02T00:00:00+02:00"
}
"recordedDate": "2024-02-16"
}