Skip to content

Commit

Permalink
improved redacttest
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas0T committed Dec 12, 2024
1 parent 1cae54f commit 42cd4d5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
59 changes: 39 additions & 20 deletions src/test/java/de/medizininformatikinitiative/torch/RedactTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"code": {
"coding": [
{
"system": "error",
"system": "invalid",
"extension": [
{
"url": "http://fhir.de/StructureDefinition/icd-10-gm-diagnosesicherheit",
Expand Down

0 comments on commit 42cd4d5

Please sign in to comment.