-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add initial SystemischeTherapieProcedureMapper (#165)
* feat: add initial SystemischeTherapieMapper * feat: set code.systemische_therapie_art if available * fix: handle oBDS DatumTagOderMonatGenauTyp * fix: use absent category * test: add tests for conversion to DateTimeType * refactor: rename mapper class to reflect destination type * refactor: rename init method * feat: add outcome if available in oBDS
- Loading branch information
Showing
10 changed files
with
457 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...ava/org/miracum/streams/ume/obdstofhir/mapper/mii/SystemischeTherapieProcedureMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package org.miracum.streams.ume.obdstofhir.mapper.mii; | ||
|
||
import de.basisdatensatz.obds.v3.SYSTTyp; | ||
import java.util.Objects; | ||
import org.apache.commons.lang3.Validate; | ||
import org.hl7.fhir.r4.model.CodeType; | ||
import org.hl7.fhir.r4.model.CodeableConcept; | ||
import org.hl7.fhir.r4.model.DateTimeType; | ||
import org.hl7.fhir.r4.model.Enumerations.ResourceType; | ||
import org.hl7.fhir.r4.model.Extension; | ||
import org.hl7.fhir.r4.model.Identifier; | ||
import org.hl7.fhir.r4.model.Period; | ||
import org.hl7.fhir.r4.model.Procedure; | ||
import org.hl7.fhir.r4.model.Reference; | ||
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.stereotype.Service; | ||
|
||
@Service | ||
public class SystemischeTherapieProcedureMapper extends ObdsToFhirMapper { | ||
|
||
private static final Logger LOG = | ||
LoggerFactory.getLogger(SystemischeTherapieProcedureMapper.class); | ||
|
||
public SystemischeTherapieProcedureMapper(FhirProperties fhirProperties) { | ||
super(fhirProperties); | ||
} | ||
|
||
public Procedure map(SYSTTyp syst, Reference subject) { | ||
Objects.requireNonNull(syst, "Systemtherapie must not be null"); | ||
Objects.requireNonNull(subject, "Reference must not be null"); | ||
|
||
Validate.notBlank(syst.getSYSTID(), "Required SYST_ID is unset"); | ||
Validate.isTrue( | ||
Objects.equals( | ||
subject.getReferenceElement().getResourceType(), ResourceType.PATIENT.toCode()), | ||
"The subject reference should point to a Patient resource"); | ||
|
||
var procedure = new Procedure(); | ||
procedure.getMeta().addProfile(fhirProperties.getProfiles().getMiiPrOnkoSystemischeTherapie()); | ||
|
||
// TODO: can we be sure that this SYST-ID is globally unqiue across all SYSTs? - | ||
// if not we may instead need to construct the ID from the patient-id + others. | ||
var identifier = | ||
new Identifier() | ||
.setSystem(fhirProperties.getSystems().getSystemischeTherapieProcedureId()) | ||
.setValue(syst.getSYSTID()); | ||
procedure.addIdentifier(identifier); | ||
procedure.setId(computeResourceIdFromIdentifier(identifier)); | ||
|
||
// Status | ||
if (syst.getMeldeanlass() == SYSTTyp.Meldeanlass.BEHANDLUNGSENDE) { | ||
procedure.setStatus(Procedure.ProcedureStatus.COMPLETED); | ||
} else { | ||
procedure.setStatus(Procedure.ProcedureStatus.INPROGRESS); | ||
} | ||
|
||
procedure.setSubject(subject); | ||
|
||
var dataAbsentExtension = | ||
new Extension( | ||
fhirProperties.getExtensions().getDataAbsentReason(), new CodeType("unknown")); | ||
var dataAbsentCode = new CodeType(); | ||
dataAbsentCode.addExtension(dataAbsentExtension); | ||
|
||
if (syst.getBeginn() == null && syst.getEnde() == null) { | ||
var performedStart = new DateTimeType(); | ||
performedStart.addExtension(dataAbsentExtension); | ||
var performed = new Period().setStartElement(performedStart); | ||
procedure.setPerformed(performed); | ||
} else { | ||
var performed = new Period(); | ||
convertObdsDatumToDateTimeType(syst.getBeginn()).ifPresent(performed::setStartElement); | ||
convertObdsDatumToDateTimeType(syst.getEnde()).ifPresent(performed::setEndElement); | ||
procedure.setPerformed(performed); | ||
} | ||
|
||
var code = new CodeableConcept(); | ||
// Always add absent OPS | ||
code.addCoding().setSystem(fhirProperties.getSystems().getOps()).setCodeElement(dataAbsentCode); | ||
if (null != syst.getTherapieart()) { | ||
code.addCoding() | ||
.setSystem(fhirProperties.getSystems().getMiiCsOnkoSystemischeTherapieArt()) | ||
.setCode(syst.getTherapieart().value()); | ||
} | ||
|
||
procedure.setCode(code); | ||
|
||
var category = new CodeableConcept(); | ||
category | ||
.addCoding() | ||
.setSystem(fhirProperties.getSystems().getSnomed()) | ||
.setCodeElement(dataAbsentCode); | ||
procedure.setCategory(category); | ||
|
||
var intention = new CodeableConcept(); | ||
intention | ||
.addCoding() | ||
.setSystem(fhirProperties.getSystems().getMiiCsOnkoIntention()) | ||
.setCode(syst.getIntention()); // Direct mapping from oBDS value | ||
procedure.addExtension( | ||
fhirProperties.getExtensions().getMiiExOnkoSystemischeTherapieIntention(), intention); | ||
|
||
if (null != syst.getEndeGrund()) { | ||
var outcome = new CodeableConcept(); | ||
outcome | ||
.addCoding() | ||
.setSystem(fhirProperties.getSystems().getMiiCsTherapieGrundEnde()) | ||
.setCode(syst.getEndeGrund().value()); | ||
procedure.setOutcome(outcome); | ||
} | ||
|
||
return procedure; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...org/miracum/streams/ume/obdstofhir/mapper/mii/SystemischeTherapieProcedureMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.miracum.streams.ume.obdstofhir.mapper.mii; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; | ||
import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule; | ||
import de.basisdatensatz.obds.v3.OBDS; | ||
import java.io.IOException; | ||
import org.approvaltests.Approvals; | ||
import org.hl7.fhir.r4.model.Reference; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.miracum.streams.ume.obdstofhir.FhirProperties; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest(classes = {FhirProperties.class}) | ||
@EnableConfigurationProperties | ||
class SystemischeTherapieProcedureMapperTest { | ||
private static SystemischeTherapieProcedureMapper sut; | ||
|
||
@BeforeAll | ||
static void beforeAll(@Autowired FhirProperties fhirProps) { | ||
sut = new SystemischeTherapieProcedureMapper(fhirProps); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({"Testpatient_1.xml", "Testpatient_2.xml", "Testpatient_3.xml"}) | ||
void map_withGivenObds_shouldCreateValidProcedure(String sourceFile) throws IOException { | ||
final var resource = this.getClass().getClassLoader().getResource("obds3/" + sourceFile); | ||
assertThat(resource).isNotNull(); | ||
|
||
final var xmlMapper = | ||
XmlMapper.builder() | ||
.defaultUseWrapper(false) | ||
.addModule(new JakartaXmlBindAnnotationModule()) | ||
.addModule(new Jdk8Module()) | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
.build(); | ||
|
||
final var obds = xmlMapper.readValue(resource.openStream(), OBDS.class); | ||
|
||
var obdsPatient = obds.getMengePatient().getPatient().getFirst(); | ||
|
||
var subject = new Reference("Patient/any"); | ||
var systMeldung = | ||
obdsPatient.getMengeMeldung().getMeldung().stream() | ||
.filter(m -> m.getSYST() != null) | ||
.findFirst() | ||
.get(); | ||
var procedure = sut.map(systMeldung.getSYST(), subject); | ||
|
||
var fhirParser = FhirContext.forR4().newJsonParser().setPrettyPrint(true); | ||
var fhirJson = fhirParser.encodeResourceToString(procedure); | ||
Approvals.verify( | ||
fhirJson, Approvals.NAMES.withParameters(sourceFile).forFile().withExtension(".fhir.json")); | ||
} | ||
} |
Oops, something went wrong.