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

refactor: add method to create FHIR references #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,9 +20,10 @@

@ExtendWith(SpringExtension.class)
@Import({ObdsTestMapper.class})
@MockBean(FhirProperties.class)
public class ObdsToFhirIntegrationTest {

@MockBean FhirProperties fhirProperties;

ObdsTestMapper mapper;

@BeforeEach
Expand Down Expand Up @@ -96,6 +100,26 @@ void applyPatientIdPattern(String input, String output) {
assertThat(actual).isEqualTo(output);
}
}

@Nested
class References {

@Test
void shouldCreateReferenceString() {
doAnswer(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@pcvolkmer pcvolkmer Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bei Verwendung von @SpringBootTest wird die komplette Anwendung konfiguriert und es ist z.B. auch eine Kafka-Instanz erforderlich (@ExtendWith(SpringExtension.class)). Mit dem Ansatz, müsste der benötigte Test-Slices explizit konfiguriert werden.

Mit dem hier gewählten Ansatz wird lediglich die Integration der Konfiguration(sparameter) - hier mit Mockitos doAnswer(..) gemockt um einen Wert für fhirSystems.setPatientId zu liefern - und der Methoden getHash(..) der abstrakten Klasse ObdsToFhir in einer konkreten (Test-)Implementierung (hier: ObdsTestMapper) von ObdsToFhir zur Erzeugung eines Resource-Strings getestet, ohne größere Teile der Anwendung konfigurieren zu müssen.

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
Expand Down
Loading