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 2 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 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 @@
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 @@
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.");
Fixed Show fixed Hide fixed
break;
}
return Optional.of(date);
return date;
}

public static Optional<DateTimeType> convertObdsDatumToDateTimeType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import de.basisdatensatz.obds.v3.OBDS;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
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,12 +22,19 @@ 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) {
Objects.requireNonNull(meldung);
Objects.requireNonNull(meldung.getTumorzuordnung());
Objects.requireNonNull(patient);
Validate.isTrue(
Objects.equals(
patient.getReferenceElement().getResourceType(), ResourceType.PATIENT.toCode()),
"The subject reference should point to a Patient resource");

var condition = new Condition();

if (meldung.getDiagnose().getDiagnosesicherung() != null) {
Expand All @@ -46,9 +55,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 +111,11 @@ 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.setRecordedDateElement(diagnoseDatum);
chgl marked this conversation as resolved.
Show resolved Hide resolved
condition.addExtension(
fhirProperties.getExtensions().getConditionAssertedDate(), diagnoseDatum);

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 @@ -12,6 +12,9 @@
"code": "8010/3"
} ]
}
}, {
"url": "http://hl7.org/fhir/StructureDefinition/condition-assertedDate",
"valueDateTime": "2020-03-01"
} ],
"verificationStatus": {
"coding": [ {
Expand Down Expand Up @@ -44,5 +47,5 @@
"subject": {
"reference": "Patient/1"
},
"recordedDate": "2020-03-01T00:00:00+01:00"
}
"recordedDate": "2020-03-01"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"code": "8140/3"
} ]
}
}, {
"url": "http://hl7.org/fhir/StructureDefinition/condition-assertedDate",
"valueDateTime": "2021-07-08"
} ],
"verificationStatus": {
"coding": [ {
Expand Down Expand Up @@ -44,5 +47,5 @@
"subject": {
"reference": "Patient/1"
},
"recordedDate": "2021-07-08T00:00:00+02:00"
}
"recordedDate": "2021-07-08"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"code": "8461/3"
} ]
}
}, {
"url": "http://hl7.org/fhir/StructureDefinition/condition-assertedDate",
"valueDateTime": "2017-07-02"
} ],
"verificationStatus": {
"coding": [ {
Expand Down Expand Up @@ -44,5 +47,5 @@
"subject": {
"reference": "Patient/1"
},
"recordedDate": "2017-07-02T00:00:00+02:00"
}
"recordedDate": "2017-07-02"
}