Skip to content

Commit

Permalink
refactor: add method to create FHIR references
Browse files Browse the repository at this point in the history
  • Loading branch information
pcvolkmer committed Sep 4, 2024
1 parent 819e0e5 commit 94fa5e9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
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(
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

0 comments on commit 94fa5e9

Please sign in to comment.