Skip to content

Commit

Permalink
test: finalized snapshot testing implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
chgl committed Nov 8, 2023
1 parent 10fd5ec commit bf30551
Show file tree
Hide file tree
Showing 17 changed files with 2,296 additions and 134 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ bin
# ignored since it isn't automatically refreshed by renovate
# (we're also pinning the dependency versions anyways)
fhirpkg.lock.json

*.received.fhir.json
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,33 @@ This project contains a Kafka Stream processor that creates FHIR resources from

## Used FHIR profiles

See [package.json](package.json) for a list of used profiles and their versions.
See [package.json](package.json) for a list of used packages and their versions.

## Observations

- Histologie (<https://simplifier.net/oncology/histologie>)
- Grading (<https://simplifier.net/oncology/grading>)
- TNMc (<https://simplifier.net/oncology/tnmc>)
- TNMp (<https://simplifier.net/oncology/tnmp>)
- Fernmetastasen (<https://simplifier.net/oncology/fernmetastasen-duplicate-2>)
- Tod Ursache (<https://simplifier.net/oncology/todursache>)

## Condition

- Primärdiagnose (<https://simplifier.net/oncology/primaerdiagnose>)

## Procedure

- Operation (<https://simplifier.net/oncology/operation>)
- Strahlentherapie (<https://simplifier.net/oncology/strahlentherapie>)

## MedicationStatement

- Systemtherapie (<https://simplifier.net/oncology/systemtherapie>)

## Patient

- Patient (<https://simplifier.net/medizininformatikinitiative-modulperson>)

## Dev

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fhir:
observationId: "https://fhir.diz.uk-erlangen.de/identifiers/onkostar-xml-observation-id"
procedureId: "https://fhir.diz.uk-erlangen.de/identifiers/onkostar-xml-procedure-id"
medicationStatementId: "https://fhir.diz.uk-erlangen.de/identifiers/onkostar-xml-medication-statement-id"
observationCategorySystem: "http://terminology.hl7.org/CodeSystem/observation-category"
observationCategorySystem: "http://hl7.org/fhir/observation-category"
loinc: "http://loinc.org"
idco3Morphologie: "urn:oid:2.16.840.1.113883.6.43.1"
gradingDktk: "http://dktk.dkfz.de/fhir/onco/core/CodeSystem/GradingCS"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@

import static org.assertj.core.api.Assertions.assertThat;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.util.BundleUtil;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.*;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.approvaltests.Approvals;
import org.hl7.fhir.r4.model.Condition;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.miracum.streams.ume.obdstofhir.FhirProperties;
import org.miracum.streams.ume.obdstofhir.mapper.*;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.ResourceUtils;

@SpringBootTest(
classes = {
Expand All @@ -48,7 +42,6 @@ public class ObdsConditionProcessorTest extends ObdsProcessorTest {
private final ObdsProcedureMapper onkoProcedureMapper;
private final ObdsPatientMapper onkoPatientMapper;
private final ObdsConditionMapper onkoConditionMapper;
private final FhirContext ctx = FhirContext.forR4();

@Autowired
public ObdsConditionProcessorTest(
Expand Down Expand Up @@ -123,31 +116,7 @@ void mapCondition_withGivenAdtXml(
String expectedOnsetDate)
throws IOException {

MeldungExportList meldungExportList = new MeldungExportList();

int payloadId = 1;

for (var xmlTupel : xmlFileNames) {
File xmlFile = ResourceUtils.getFile("classpath:" + xmlTupel.getFirst());
String xmlContent = new String(Files.readAllBytes(xmlFile.toPath()));

var meldungsId = StringUtils.substringBetween(xmlContent, "Meldung_ID=\"", "\" Melder_ID");
var melderId = StringUtils.substringBetween(xmlContent, "Melder_ID=\"", "\">");
var patId = StringUtils.substringBetween(xmlContent, "Patient_ID=\"", "\">");

Map<String, Object> payloadOnkoRessource = new HashMap<>();
payloadOnkoRessource.put("ID", payloadId);
payloadOnkoRessource.put("REFERENZ_NUMMER", patId);
payloadOnkoRessource.put("LKR_MELDUNG", Integer.parseInt(meldungsId.replace(melderId, "")));
payloadOnkoRessource.put("VERSIONSNUMMER", xmlTupel.getSecond());
payloadOnkoRessource.put("XML_DATEN", xmlContent);

MeldungExport meldungExport = new MeldungExport();
meldungExport.getPayload(payloadOnkoRessource);
meldungExportList.addElement(meldungExport);

payloadId++;
}
var meldungExportList = buildMeldungExportList(xmlFileNames);

ObdsProcessor onkoProcessor =
new ObdsProcessor(
Expand Down Expand Up @@ -192,7 +161,13 @@ void mapCondition_withGivenAdtXml(
assertThat(conditionList.get(0).getOnsetDateTimeType().getValueAsString())
.isEqualTo(expectedOnsetDate);

// assertThat(isValid(resultBundle)).isTrue();
var fhirJson = fhirParser.encodeResourceToString(resultBundle);
Approvals.verify(
fhirJson,
Approvals.NAMES
.withParameters(xmlFileNames.stream().map(t -> t.getFirst()).toArray(String[]::new))
.forFile()
.withExtension(".fhir.json"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.util.BundleUtil;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.*;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.approvaltests.Approvals;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.MedicationStatement;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.miracum.streams.ume.obdstofhir.FhirProperties;
import org.miracum.streams.ume.obdstofhir.mapper.*;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.ResourceUtils;

@SpringBootTest(
classes = {
Expand Down Expand Up @@ -101,31 +96,7 @@ void mapMedicationStatement_withGivenAdtXml(
String expectedIntention)
throws IOException {

MeldungExportList meldungExportList = new MeldungExportList();

int payloadId = 1;

for (var xmlTupel : xmlFileNames) {
File xmlFile = ResourceUtils.getFile("classpath:" + xmlTupel.getFirst());
String xmlContent = new String(Files.readAllBytes(xmlFile.toPath()));

var meldungsId = StringUtils.substringBetween(xmlContent, "Meldung_ID=\"", "\" Melder_ID");
var melderId = StringUtils.substringBetween(xmlContent, "Melder_ID=\"", "\">");
var patId = StringUtils.substringBetween(xmlContent, "Patient_ID=\"", "\">");

Map<String, Object> payloadOnkoRessource = new HashMap<>();
payloadOnkoRessource.put("ID", payloadId);
payloadOnkoRessource.put("REFERENZ_NUMMER", patId);
payloadOnkoRessource.put("LKR_MELDUNG", Integer.parseInt(meldungsId.replace(melderId, "")));
payloadOnkoRessource.put("VERSIONSNUMMER", xmlTupel.getSecond());
payloadOnkoRessource.put("XML_DATEN", xmlContent);

MeldungExport meldungExport = new MeldungExport();
meldungExport.getPayload(payloadOnkoRessource);
meldungExportList.addElement(meldungExport);

payloadId++;
}
var meldungExportList = buildMeldungExportList(xmlFileNames);

ObdsProcessor medicationStatementProcessor =
new ObdsProcessor(
Expand Down Expand Up @@ -186,7 +157,13 @@ void mapMedicationStatement_withGivenAdtXml(
String finalPartOfId = partOfId;
assertThat(partOfReferences).allSatisfy(ref -> ref.equals(finalPartOfId));

// assertThat(isValid(resultBundle)).isTrue();
var fhirJson = fhirParser.encodeResourceToString(resultBundle);
Approvals.verify(
fhirJson,
Approvals.NAMES
.withParameters(xmlFileNames.stream().map(t -> t.getFirst()).toArray(String[]::new))
.forFile()
.withExtension(".fhir.json"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,24 @@

import static org.assertj.core.api.Assertions.assertThat;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.util.BundleUtil;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.*;
import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.approvaltests.Approvals;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Observation;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.miracum.streams.ume.obdstofhir.FhirProperties;
import org.miracum.streams.ume.obdstofhir.mapper.*;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.ResourceUtils;

@SpringBootTest(
classes = {
Expand All @@ -48,7 +42,6 @@ public class ObdsObservationProcessorTest extends ObdsProcessorTest {
private final ObdsProcedureMapper onkoProcedureMapper;
private final ObdsPatientMapper onkoPatientMapper;
private final ObdsConditionMapper onkoConditionMapper;
private final FhirContext ctx = FhirContext.forR4();

@Autowired
public ObdsObservationProcessorTest(
Expand Down Expand Up @@ -110,31 +103,7 @@ void mapObservation_withGivenAdtXml(
String expectedDeathDate)
throws IOException {

MeldungExportList meldungExportList = new MeldungExportList();

int payloadId = 1;

for (var xmlTupel : xmlFileNames) {
File xmlFile = ResourceUtils.getFile("classpath:" + xmlTupel.getFirst());
String xmlContent = new String(Files.readAllBytes(xmlFile.toPath()));

var meldungsId = StringUtils.substringBetween(xmlContent, "Meldung_ID=\"", "\" Melder_ID");
var melderId = StringUtils.substringBetween(xmlContent, "Melder_ID=\"", "\">");
var patId = StringUtils.substringBetween(xmlContent, "Patient_ID=\"", "\">");

Map<String, Object> payloadOnkoRessource = new HashMap<>();
payloadOnkoRessource.put("ID", payloadId);
payloadOnkoRessource.put("REFERENZ_NUMMER", patId);
payloadOnkoRessource.put("LKR_MELDUNG", Integer.parseInt(meldungsId.replace(melderId, "")));
payloadOnkoRessource.put("VERSIONSNUMMER", xmlTupel.getSecond());
payloadOnkoRessource.put("XML_DATEN", xmlContent);

MeldungExport meldungExport = new MeldungExport();
meldungExport.getPayload(payloadOnkoRessource);
meldungExportList.addElement(meldungExport);

payloadId++;
}
var meldungExportList = buildMeldungExportList(xmlFileNames);

ObdsProcessor observationProcessor =
new ObdsProcessor(
Expand Down Expand Up @@ -226,7 +195,13 @@ void mapObservation_withGivenAdtXml(
}
assertThat(fenMetaCount).isEqualTo(expectedFernMetaCount);

// assertThat(isValid(resultBundle)).isTrue();
var fhirJson = fhirParser.encodeResourceToString(resultBundle);
Approvals.verify(
fhirJson,
Approvals.NAMES
.withParameters(xmlFileNames.stream().map(t -> t.getFirst()).toArray(String[]::new))
.forFile()
.withExtension(".fhir.json"));
}
}
}
Loading

0 comments on commit bf30551

Please sign in to comment.