-
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: first draft version of ObdsToFhirBundleMapper
- Loading branch information
Showing
4 changed files
with
485 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/main/java/org/miracum/streams/ume/obdstofhir/mapper/mii/ObdsToFhirBundleMapper.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,72 @@ | ||
package org.miracum.streams.ume.obdstofhir.mapper.mii; | ||
|
||
import de.basisdatensatz.obds.v3.OBDS; | ||
import org.hl7.fhir.r4.model.Bundle; | ||
import org.hl7.fhir.r4.model.Bundle.BundleType; | ||
import org.hl7.fhir.r4.model.Bundle.HTTPVerb; | ||
import org.hl7.fhir.r4.model.Reference; | ||
import org.hl7.fhir.r4.model.Resource; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class ObdsToFhirBundleMapper { | ||
|
||
private final PatientMapper patientMapper; | ||
private final ConditionMapper conditionMapper; | ||
private final StrahlentherapieMapper strahlentherapieMapper; | ||
private final SystemischeTherapieProcedureMapper systemischeTherapieProcedureMapper; | ||
|
||
public ObdsToFhirBundleMapper( | ||
PatientMapper patientMapper, | ||
ConditionMapper conditionMapper, | ||
SystemischeTherapieProcedureMapper systemischeTherapieProcedureMapper, | ||
StrahlentherapieMapper strahlentherapieMapper) { | ||
this.patientMapper = patientMapper; | ||
this.conditionMapper = conditionMapper; | ||
this.systemischeTherapieProcedureMapper = systemischeTherapieProcedureMapper; | ||
this.strahlentherapieMapper = strahlentherapieMapper; | ||
} | ||
|
||
public Bundle map(OBDS obds) { | ||
var bundle = new Bundle(); | ||
bundle.setType(BundleType.TRANSACTION); | ||
|
||
// TODO: set bundle id... to the patient id? sum of all ids? | ||
// TODO: or one bundle per Patient instead? | ||
for (var obdsPatient : obds.getMengePatient().getPatient()) { | ||
var meldungen = obdsPatient.getMengeMeldung().getMeldung(); | ||
|
||
// Patient | ||
var patient = patientMapper.map(obdsPatient, meldungen); | ||
var patientReference = new Reference("Patient/" + patient.getId()); | ||
addEntryToBundle(bundle, patient); | ||
|
||
for (var meldung : meldungen) { | ||
// Diagnose | ||
if (meldung.getDiagnose() != null) { | ||
var condition = conditionMapper.map(meldung, patientReference); | ||
addEntryToBundle(bundle, condition); | ||
} | ||
|
||
if (meldung.getSYST() != null) { | ||
var systProcedure = | ||
systemischeTherapieProcedureMapper.map(meldung.getSYST(), patientReference); | ||
addEntryToBundle(bundle, systProcedure); | ||
} | ||
|
||
if (meldung.getST() != null) { | ||
var stProcedure = strahlentherapieMapper.map(meldung.getST(), patientReference); | ||
addEntryToBundle(bundle, stProcedure); | ||
} | ||
} | ||
} | ||
|
||
return bundle; | ||
} | ||
|
||
private static Bundle addEntryToBundle(Bundle bundle, Resource resource) { | ||
var url = String.format("%s/%s", resource.getResourceType(), resource.getIdBase()); | ||
bundle.addEntry().setResource(resource).getRequest().setMethod(HTTPVerb.PUT).setUrl(url); | ||
return bundle; | ||
} | ||
} |
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
66 changes: 66 additions & 0 deletions
66
src/test/java/org/miracum/streams/ume/obdstofhir/mapper/mii/ObdsToFhirBundleMapperTest.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,66 @@ | ||
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.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, | ||
ObdsToFhirBundleMapper.class, | ||
PatientMapper.class, | ||
ConditionMapper.class, | ||
SystemischeTherapieProcedureMapper.class, | ||
StrahlentherapieMapper.class, | ||
}) | ||
@EnableConfigurationProperties | ||
class ObdsToFhirBundleMapperTest { | ||
private static ObdsToFhirBundleMapper sut; | ||
|
||
@BeforeAll | ||
static void beforeAll(@Autowired ObdsToFhirBundleMapper bundleMapper) { | ||
sut = bundleMapper; | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"Testpatient_1.xml", | ||
}) | ||
void map_withGivenObds_shouldCreateBundleMatchingSnapshot(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()) | ||
// added because the Testpatient_*.xml contain the `xsi:schemaLocation` attribute which | ||
// isn't code-generated | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | ||
.build(); | ||
|
||
final var obds = xmlMapper.readValue(resource.openStream(), OBDS.class); | ||
|
||
final var bundle = sut.map(obds); | ||
|
||
var fhirParser = FhirContext.forR4().newJsonParser().setPrettyPrint(true); | ||
var fhirJson = fhirParser.encodeResourceToString(bundle); | ||
Approvals.verify( | ||
fhirJson, Approvals.NAMES.withParameters(sourceFile).forFile().withExtension(".fhir.json")); | ||
} | ||
} |
Oops, something went wrong.