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

fix: keep PLZ as-is when mapping to Patient.address.postalCode #29

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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 {
Expand Down Expand Up @@ -128,12 +129,10 @@ public Bundle mapOnkoResourcesToPatient(List<MeldungExport> 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());
Expand All @@ -143,8 +142,8 @@ public Bundle mapOnkoResourcesToPatient(List<MeldungExport> meldungExportList) {
.setUrl(fhirProperties.getExtensions().getDataAbsentReason())
.setValue(new CodeType("unknown"));
}
patient.addAddress(address);
}
patient.addAddress(address);

var bundle = new Bundle();
bundle.setType(Bundle.BundleType.TRANSACTION);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<Arguments> generateTestData() {
return Stream.of(
Arguments.of(List.of(new Tupel<>("003_Pat1_Tumor1_Therapie1_Behandlungsende_OP.xml", 1))),
Expand All @@ -44,4 +92,38 @@ void mapOnkoResourcesToPatient_withGivenAdtXml(List<Tupel<String, Integer>> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"birthDate": "1900-07",
"address": [ {
"type": "both",
"postalCode": "91",
"postalCode": "91000",
"country": "DE"
} ]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"birthDate": "1900-07",
"address": [ {
"type": "both",
"postalCode": "91",
"postalCode": "91000",
"country": "DE"
} ]
},
Expand Down
Loading