From 42cd4d52fd1e5b261ca09ed5af930e971968cb48 Mon Sep 17 00:00:00 2001 From: Lucas Triefenbach Date: Thu, 12 Dec 2024 10:19:09 +0100 Subject: [PATCH] improved redacttest --- .../torch/RedactTest.java | 59 ++++++++++++------- .../DiagnosisWithInvalidSliceCode.json | 2 +- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/test/java/de/medizininformatikinitiative/torch/RedactTest.java b/src/test/java/de/medizininformatikinitiative/torch/RedactTest.java index 41ab19e..06aa4c6 100644 --- a/src/test/java/de/medizininformatikinitiative/torch/RedactTest.java +++ b/src/test/java/de/medizininformatikinitiative/torch/RedactTest.java @@ -14,27 +14,18 @@ import static org.assertj.core.api.Assertions.assertThat; public class RedactTest { + public static final String INPUT_CONDITION_DIR = "src/test/resources/InputResources/Condition/"; + public static final String EXPECTED_OUTPUT_DIR = "src/test/resources/RedactTest/expectedOutput/"; private final IntegrationTestSetup integrationTestSetup = new IntegrationTestSetup(); private final FhirContext fhirContext = FhirContext.forR4(); - @ParameterizedTest - @ValueSource(strings = {"Diagnosis1.json", "Diagnosis2.json", "DiagnosisWithInvalidSliceCode.json"}) - public void testDiagnosis(String resource) throws IOException { - DomainResource src = integrationTestSetup.readResource("src/test/resources/InputResources/Condition/" + resource); - DomainResource expected = integrationTestSetup.readResource("src/test/resources/RedactTest/expectedOutput/" + resource); - - src = (DomainResource) integrationTestSetup.redaction().redact(src); - - assertThat(fhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(src)). - isEqualTo(fhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(expected)); - } @ParameterizedTest @ValueSource(strings = {"Observation_lab_Missing_Elements_Unknown_Slices.json"}) public void testObservation(String resource) throws IOException { DomainResource src = integrationTestSetup.readResource("src/test/resources/InputResources/Observation/" + resource); - DomainResource expected = integrationTestSetup.readResource("src/test/resources/RedactTest/expectedOutput/" + resource); + DomainResource expected = integrationTestSetup.readResource(EXPECTED_OUTPUT_DIR + resource); src = (DomainResource) integrationTestSetup.redaction().redact(src); @@ -45,8 +36,8 @@ public void testObservation(String resource) throws IOException { @Test public void unknownSlice() throws IOException { - DomainResource expected = integrationTestSetup.readResource("src/test/resources/RedactTest/expectedOutput/unknownSlice.json"); - Condition src = new Condition(); + DomainResource expected = integrationTestSetup.readResource(EXPECTED_OUTPUT_DIR + "unknownSlice.json"); + org.hl7.fhir.r4.model.Condition src = new org.hl7.fhir.r4.model.Condition(); Meta meta = new Meta(); meta.setProfile(List.of(new CanonicalType("https://www.medizininformatik-initiative.de/fhir/core/modul-diagnose/StructureDefinition/Diagnose"))); src.setMeta(meta); @@ -62,20 +53,48 @@ public void unknownSlice() throws IOException { } @Nested - class KDS { + class Condition { @ParameterizedTest - @ValueSource(strings = {"Condition-mii-exa-diagnose-condition-minimal.json", + @ValueSource(strings = { + "Condition-mii-exa-diagnose-condition-minimal.json", "Condition-mii-exa-diagnose-mehrfachkodierung-primaercode.json", "Condition-mii-exa-diagnose-mehrfachkodierung-primaercode.json", "Condition-mii-exa-diagnose-multiple-kodierungen.json", "Condition-mii-exa-test-data-patient-1-diagnose-1.json", - + "Condition-mii-exa-test-data-patient-1-diagnose-2.json", + "Condition-mii-exa-test-data-patient-3-diagnose-1.json", "Condition-mii-exa-test-data-patient-4-diagnose-1.json"}) - public void diagnosis(String resource) throws IOException { - DomainResource src = integrationTestSetup.readResource("src/test/resources/InputResources/Condition/" + resource); - DomainResource expected = integrationTestSetup.readResource("src/test/resources/InputResources/Condition/" + resource); + public void diagnosisAllValid(String resource) throws IOException { + DomainResource src = integrationTestSetup.readResource(INPUT_CONDITION_DIR + resource); + DomainResource expected = integrationTestSetup.readResource(INPUT_CONDITION_DIR + resource); + + DomainResource tgt = (DomainResource) integrationTestSetup.redaction().redact(src); + + assertThat(fhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(tgt)). + isEqualTo(fhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(expected)); + } + + + @ParameterizedTest + @ValueSource(strings = {"DiagnosisWithInvalidSliceCode.json"}) + public void diagnosisInvalidElements(String resource) throws IOException { + DomainResource src = integrationTestSetup.readResource(INPUT_CONDITION_DIR + resource); + DomainResource expected = integrationTestSetup.readResource(EXPECTED_OUTPUT_DIR + resource); + + DomainResource tgt = (DomainResource) integrationTestSetup.redaction().redact(src); + + assertThat(fhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(tgt)). + isEqualTo(fhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(expected)); + } + + + @ParameterizedTest + @ValueSource(strings = {"Diagnosis1.json", "Diagnosis2.json"}) + public void diagnosisMissingElements(String resource) throws IOException { + DomainResource src = integrationTestSetup.readResource(INPUT_CONDITION_DIR + resource); + DomainResource expected = integrationTestSetup.readResource(EXPECTED_OUTPUT_DIR + resource); DomainResource tgt = (DomainResource) integrationTestSetup.redaction().redact(src); diff --git a/src/test/resources/InputResources/Condition/DiagnosisWithInvalidSliceCode.json b/src/test/resources/InputResources/Condition/DiagnosisWithInvalidSliceCode.json index 4cb737c..0b22ee6 100644 --- a/src/test/resources/InputResources/Condition/DiagnosisWithInvalidSliceCode.json +++ b/src/test/resources/InputResources/Condition/DiagnosisWithInvalidSliceCode.json @@ -9,7 +9,7 @@ "code": { "coding": [ { - "system": "error", + "system": "invalid", "extension": [ { "url": "http://fhir.de/StructureDefinition/icd-10-gm-diagnosesicherheit",