From 7643e724797089869199784a37d52a68e090ed1b Mon Sep 17 00:00:00 2001 From: chgl Date: Fri, 8 Mar 2024 17:36:07 +0100 Subject: [PATCH] fix: keep PLZ as-is when mapping to Patient.address.postalCode --- .../obdstofhir/mapper/ObdsPatientMapper.java | 11 ++- .../processor/ObdsPatientMapperTest.java | 82 +++++++++++++++++++ ...t_withGivenAdtXml.003_P.approved.fhir.json | 2 +- ...t_withGivenAdtXml.007_P.approved.fhir.json | 2 +- 4 files changed, 89 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsPatientMapper.java b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsPatientMapper.java index da485d5a..c4e4b7b7 100644 --- a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsPatientMapper.java +++ b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsPatientMapper.java @@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; +import org.springframework.util.StringUtils; @Configuration public class ObdsPatientMapper extends ObdsToFhirMapper { @@ -128,12 +129,10 @@ public Bundle mapOnkoResourcesToPatient(List meldungExportList) { } // address - var address = new Address(); var patAddess = patData.getMenge_Adresse().getAdresse().get(0); - if (patAddess.getPatienten_PLZ() != null && patAddess.getPatienten_PLZ().length() >= 2) { - address - .setPostalCode(patAddess.getPatienten_PLZ().substring(0, 2)) - .setType(Address.AddressType.BOTH); + if (StringUtils.hasLength(patAddess.getPatienten_PLZ())) { + var address = new Address(); + address.setPostalCode(patAddess.getPatienten_PLZ()).setType(Address.AddressType.BOTH); if (patAddess.getPatienten_Land() != null && patAddess.getPatienten_Land().matches("[a-zA-Z]{2,3}")) { address.setCountry(patAddess.getPatienten_Land().toUpperCase()); @@ -143,8 +142,8 @@ public Bundle mapOnkoResourcesToPatient(List meldungExportList) { .setUrl(fhirProperties.getExtensions().getDataAbsentReason()) .setValue(new CodeType("unknown")); } + patient.addAddress(address); } - patient.addAddress(address); var bundle = new Bundle(); bundle.setType(Bundle.BundleType.TRANSACTION); diff --git a/src/test/java/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.java b/src/test/java/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.java index c7ad9d0a..b8419b8b 100644 --- a/src/test/java/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.java +++ b/src/test/java/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.java @@ -1,13 +1,21 @@ package org.miracum.streams.ume.obdstofhir.processor; +import static org.assertj.core.api.Assertions.assertThat; + import java.io.IOException; import java.util.*; import java.util.stream.Stream; import org.approvaltests.Approvals; +import org.hl7.fhir.r4.model.Patient; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.NullSource; +import org.junit.jupiter.params.provider.ValueSource; import org.miracum.streams.ume.obdstofhir.mapper.*; +import org.miracum.streams.ume.obdstofhir.model.ADT_GEKID; +import org.miracum.streams.ume.obdstofhir.model.MeldungExport; +import org.miracum.streams.ume.obdstofhir.model.MeldungExportList; import org.miracum.streams.ume.obdstofhir.model.Tupel; import org.springframework.beans.factory.annotation.Autowired; @@ -20,6 +28,46 @@ public ObdsPatientMapperTest(ObdsPatientMapper onkoPatientMapper) { this.onkoPatientMapper = onkoPatientMapper; } + private static MeldungExportList createMeldungExportListFromPLZ(String plz) { + // TODO: we might want to introduce more concise builder patterns + var meldung = new ADT_GEKID.Menge_Patient.Patient.Menge_Meldung.Meldung(); + meldung.setMeldung_ID("id-" + plz); + + var mengeMeldung = new ADT_GEKID.Menge_Patient.Patient.Menge_Meldung(); + mengeMeldung.setMeldung(meldung); + + var adresse = new ADT_GEKID.Menge_Patient.Patient.Patienten_Stammdaten.Menge_Adresse.Adresse(); + adresse.setPatienten_PLZ(plz); + + var mengeAdresse = new ADT_GEKID.Menge_Patient.Patient.Patienten_Stammdaten.Menge_Adresse(); + mengeAdresse.setAdresse(List.of(adresse)); + + var stammdaten = new ADT_GEKID.Menge_Patient.Patient.Patienten_Stammdaten(); + stammdaten.setMenge_Adresse(mengeAdresse); + + var patient = new ADT_GEKID.Menge_Patient.Patient(); + patient.setPatienten_Stammdaten(stammdaten); + patient.setMenge_Meldung(mengeMeldung); + + var mengePatient = new ADT_GEKID.Menge_Patient(); + mengePatient.setPatient(patient); + + var absender = new ADT_GEKID.Absender(); + absender.setAbsender_ID("id-" + plz); + + var obdsData = new ADT_GEKID(); + obdsData.setMenge_Patient(mengePatient); + obdsData.setAbsender(absender); + + var meldungExport = new MeldungExport(); + meldungExport.setXml_daten(obdsData); + + var meldungExportList = new MeldungExportList(); + meldungExportList.addElement(meldungExport); + + return meldungExportList; + } + private static Stream generateTestData() { return Stream.of( Arguments.of(List.of(new Tupel<>("003_Pat1_Tumor1_Therapie1_Behandlungsende_OP.xml", 1))), @@ -44,4 +92,38 @@ void mapOnkoResourcesToPatient_withGivenAdtXml(List> xmlF .forFile() .withExtension(".fhir.json")); } + + @ParameterizedTest + @ValueSource(strings = {"0", "123", "00000", "12", "12345", "1234567890"}) + void mapOnkoResourcesToPatient_withMeldungExportWithValidPLZ_shouldSetAsPostalCode(String plz) + throws IOException { + + var meldungExportList = createMeldungExportListFromPLZ(plz); + + var resultBundle = onkoPatientMapper.mapOnkoResourcesToPatient(meldungExportList.getElements()); + + assertThat(resultBundle.getEntry()).hasSize(1); + + var patient = (Patient) resultBundle.getEntry().get(0).getResource(); + + assertThat(patient.getAddress()).hasSize(1); + assertThat(patient.getAddress().get(0).getPostalCode()).isEqualTo(plz); + } + + @ParameterizedTest + @NullSource + @ValueSource(strings = {""}) + void mapOnkoResourcesToPatient_withMeldungExportWithInvalidPLZ_shouldCreateNotFillAddress( + String plz) throws IOException { + + var meldungExportList = createMeldungExportListFromPLZ(plz); + + var resultBundle = onkoPatientMapper.mapOnkoResourcesToPatient(meldungExportList.getElements()); + + assertThat(resultBundle.getEntry()).hasSize(1); + + var patient = (Patient) resultBundle.getEntry().get(0).getResource(); + + assertThat(patient.getAddress()).isEmpty(); + } } diff --git a/src/test/java/snapshots/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.mapOnkoResourcesToPatient_withGivenAdtXml.003_P.approved.fhir.json b/src/test/java/snapshots/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.mapOnkoResourcesToPatient_withGivenAdtXml.003_P.approved.fhir.json index f6e017e1..4691a1b7 100644 --- a/src/test/java/snapshots/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.mapOnkoResourcesToPatient_withGivenAdtXml.003_P.approved.fhir.json +++ b/src/test/java/snapshots/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.mapOnkoResourcesToPatient_withGivenAdtXml.003_P.approved.fhir.json @@ -28,7 +28,7 @@ "birthDate": "1900-07", "address": [ { "type": "both", - "postalCode": "91", + "postalCode": "91000", "country": "DE" } ] }, diff --git a/src/test/java/snapshots/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.mapOnkoResourcesToPatient_withGivenAdtXml.007_P.approved.fhir.json b/src/test/java/snapshots/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.mapOnkoResourcesToPatient_withGivenAdtXml.007_P.approved.fhir.json index e60b579a..ad18ce73 100644 --- a/src/test/java/snapshots/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.mapOnkoResourcesToPatient_withGivenAdtXml.007_P.approved.fhir.json +++ b/src/test/java/snapshots/org/miracum/streams/ume/obdstofhir/processor/ObdsPatientMapperTest.mapOnkoResourcesToPatient_withGivenAdtXml.007_P.approved.fhir.json @@ -28,7 +28,7 @@ "birthDate": "1900-07", "address": [ { "type": "both", - "postalCode": "91", + "postalCode": "91000", "country": "DE" } ] },