Skip to content

Commit

Permalink
fix: switch to one bundle per patient in obds
Browse files Browse the repository at this point in the history
  • Loading branch information
chgl committed Jan 7, 2025
1 parent 7c135d8 commit 6978b37
Show file tree
Hide file tree
Showing 3 changed files with 427 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.miracum.streams.ume.obdstofhir.mapper.mii;

import de.basisdatensatz.obds.v3.OBDS;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleType;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
Expand Down Expand Up @@ -32,20 +34,23 @@ public ObdsToFhirBundleMapper(
this.strahlentherapieMapper = strahlentherapieMapper;
}

public Bundle map(OBDS obds) {
var bundle = new Bundle();
bundle.setType(BundleType.TRANSACTION);
public List<Bundle> map(OBDS obds) {

var bundles = new ArrayList<Bundle>();

// 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 bundle = new Bundle();
bundle.setType(BundleType.TRANSACTION);

var meldungen = obdsPatient.getMengeMeldung().getMeldung();

// Patient
var patient = patientMapper.map(obdsPatient, meldungen);
var patientReference = new Reference("Patient/" + patient.getId());
addEntryToBundle(bundle, patient);

bundle.setId(patient.getId());

for (var meldung : meldungen) {
// Diagnose
if (meldung.getDiagnose() != null) {
Expand Down Expand Up @@ -79,9 +84,11 @@ public Bundle map(OBDS obds) {
addEntryToBundle(bundle, stProcedure);
}
}

bundles.add(bundle);
}

return bundle;
return bundles;
}

private static Bundle addEntryToBundle(Bundle bundle, Resource resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ void map_withGivenObds_shouldCreateBundleMatchingSnapshot(String sourceFile) thr

final var obds = xmlMapper.readValue(resource.openStream(), OBDS.class);

final var bundle = sut.map(obds);
final var bundles = 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"));

for (int i = 0; i < bundles.size(); i++) {
var fhirJson = fhirParser.encodeResourceToString(bundles.get(i));
Approvals.verify(
fhirJson,
Approvals.NAMES
.withParameters(sourceFile, "index_" + i)
.forFile()
.withExtension(".fhir.json"));
}
}
}
Loading

0 comments on commit 6978b37

Please sign in to comment.