diff --git a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsConditionMapper.java b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsConditionMapper.java index 3f284e75..4b67a61c 100644 --- a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsConditionMapper.java +++ b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsConditionMapper.java @@ -157,7 +157,7 @@ public Bundle mapOnkoResourcesToCondition( onkoCondition.setSubject( new Reference() - .setReference(ResourceType.Patient + "/" + this.getHash(ResourceType.Patient, pid)) + .setReference(this.getReference(ResourceType.Patient, pid)) .setIdentifier( new Identifier() .setSystem(fhirProperties.getSystems().getPatientId()) diff --git a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsMedicationStatementMapper.java b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsMedicationStatementMapper.java index ffa05536..ae1320be 100644 --- a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsMedicationStatementMapper.java +++ b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsMedicationStatementMapper.java @@ -149,10 +149,7 @@ public MedicationStatement createSystemtherapyMedicationStatement( stMedicationStatement.setPartOf( List.of( new Reference() - .setReference( - ResourceType.MedicationStatement - + "/" - + this.getHash(ResourceType.MedicationStatement, partOfId)))); + .setReference(this.getReference(ResourceType.MedicationStatement, partOfId)))); } } else { diff --git a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsObservationMapper.java b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsObservationMapper.java index efc250cd..b1965b48 100644 --- a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsObservationMapper.java +++ b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsObservationMapper.java @@ -318,7 +318,7 @@ public Bundle mapOnkoResourcesToObservationsBundle( var patientReference = new Reference() - .setReference(ResourceType.Patient + "/" + this.getHash(ResourceType.Patient, patId)) + .setReference(this.getReference(ResourceType.Patient, patId)) .setIdentifier( new Identifier() .setSystem(fhirProperties.getSystems().getPatientId()) @@ -556,10 +556,7 @@ public Bundle createHistologieAndGradingObservation( if (grading != null) { histObs.addHasMember( new Reference() - .setReference( - ResourceType.Observation - + "/" - + this.getHash(ResourceType.Observation, gradingObsIdentifier))); + .setReference(this.getReference(ResourceType.Observation, gradingObsIdentifier))); } bundle = addResourceAsEntryInBundle(bundle, histObs); diff --git a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsProcedureMapper.java b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsProcedureMapper.java index d8053b33..54b5084c 100644 --- a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsProcedureMapper.java +++ b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsProcedureMapper.java @@ -167,11 +167,7 @@ public Procedure createOpProcedure( if (distinctOpsSet.size() > 1) { opProcedure.setPartOf( List.of( - new Reference() - .setReference( - ResourceType.Procedure - + "/" - + this.getHash(ResourceType.Procedure, partOfId)))); + new Reference().setReference(this.getReference(ResourceType.Procedure, partOfId)))); } // Code diff --git a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java index a888543e..6e243e3a 100644 --- a/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java +++ b/src/main/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirMapper.java @@ -67,6 +67,10 @@ protected String getHash(ResourceType type, String id) { return Hashing.sha256().hashString(idToHash + "|" + id, StandardCharsets.UTF_8).toString(); } + protected String getReference(ResourceType type, String id) { + return type + "/" + this.getHash(type, id); + } + protected String computeResourceIdFromIdentifier(Identifier identifier) { return Hashing.sha256() .hashString(identifier.getSystem() + "|" + identifier.getValue(), StandardCharsets.UTF_8) diff --git a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java index 0ec81312..4c9e82bc 100644 --- a/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java +++ b/src/test/java/org/miracum/streams/ume/obdstofhir/mapper/ObdsToFhirIntegrationTest.java @@ -1,9 +1,12 @@ package org.miracum.streams.ume.obdstofhir.mapper; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.doAnswer; +import org.hl7.fhir.r4.model.ResourceType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -17,9 +20,10 @@ @ExtendWith(SpringExtension.class) @Import({ObdsTestMapper.class}) -@MockBean(FhirProperties.class) public class ObdsToFhirIntegrationTest { + @MockBean FhirProperties fhirProperties; + ObdsTestMapper mapper; @BeforeEach @@ -96,6 +100,26 @@ void applyPatientIdPattern(String input, String output) { assertThat(actual).isEqualTo(output); } } + + @Nested + class References { + + @Test + void shouldCreateReferenceString() { + doAnswer( + invocationOnMock -> { + final var fhirSystems = new FhirProperties.FhirSystems(); + fhirSystems.setPatientId("https://fhir.diz.uk-erlangen.de/identifiers/patient-id"); + return fhirSystems; + }) + .when(fhirProperties) + .getSystems(); + + final var actual = mapper.getReference(ResourceType.Patient, "1"); + assertThat(actual) + .isEqualTo("Patient/82a86769573e519a1fa2d79911fb19fbdceabe2416a5c9230b503618a23a31c1"); + } + } } @Component