23
23
24
24
import static de .medizininformatikinitiative .torch .util .FhirUtil .createAbsentReasonExtension ;
25
25
import static org .assertj .core .api .Assertions .assertThat ;
26
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
26
27
27
28
public class RedactionTest {
28
29
@@ -82,6 +83,38 @@ void testReferenceComplexType(String resource) throws IOException {
82
83
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
83
84
}
84
85
86
+ @ Test
87
+ public void mismatchProfileWithAssignedProfile () {
88
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
89
+ Meta meta = new Meta ();
90
+ meta .setProfile (List .of (new CanonicalType (MEDICATION )));
91
+ src .setMeta (meta );
92
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of (), Set .of ());
93
+
94
+ assertThatThrownBy (() -> integrationTestSetup .redaction ().redact (wrapper )).isInstanceOf (RuntimeException .class )
95
+ .hasMessage ("Resource is missing required profiles: []" );
96
+ }
97
+
98
+ @ Test
99
+ public void unknownProfile () {
100
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
101
+ Meta meta = new Meta ();
102
+ meta .setProfile (List .of (new CanonicalType ("UnknownProfile" )));
103
+ src .setMeta (meta );
104
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of ("UnknownProfile" ), Map .of (), Set .of ());
105
+
106
+ assertThatThrownBy (() -> integrationTestSetup .redaction ().redact (wrapper )).isInstanceOf (RuntimeException .class )
107
+ .hasMessage ("Trying to handle unknown profiles: [UnknownProfile]" );
108
+ }
109
+
110
+ @ Test
111
+ public void metaMissing () {
112
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
113
+
114
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of (), Set .of ());
115
+ assertThatThrownBy (() -> integrationTestSetup .redaction ().redact (wrapper )).isInstanceOf (RuntimeException .class );
116
+ }
117
+
85
118
@ Test
86
119
public void unknownSlice () throws IOException {
87
120
DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + "unknownSlice.json" );
@@ -100,6 +133,35 @@ public void unknownSlice() throws IOException {
100
133
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
101
134
}
102
135
136
+ @ ParameterizedTest
137
+ @ ValueSource (strings = {"DiagnosisWithExtensionAtCodeWithUnknownField.json" })
138
+ void notHandlingUnknownElementID (String resource ) throws IOException {
139
+
140
+ DomainResource src = integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
141
+ DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
142
+
143
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of ("Condition.subject" , Set .of ("Patient/12345" , "Patient/123" ), "Condition.encounter" , Set .of ("Encounter/12345" )), Set .of ());
144
+ DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
145
+
146
+ assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
147
+
148
+
149
+ }
150
+
151
+ @ Test
152
+ public void emptyValues () throws IOException {
153
+ DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + "EmptyValues.json" );
154
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
155
+ Meta meta = new Meta ();
156
+ meta .setProfile (List .of (new CanonicalType (DIAGNOSIS )));
157
+ src .setMeta (meta );
158
+
159
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of (), Set .of ());
160
+ DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
161
+
162
+ assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
163
+ }
164
+
103
165
@ ParameterizedTest
104
166
@ ValueSource (strings = {"DiagnosisUnknownPrimitiveExtension.json" , "DiagnosisWithExtensionAtCode.json" , "DiagnosisUnknownComplexExtension.json" })
105
167
void removeUnknownPrimitiveAndComplexExtension (String resource ) throws IOException {
0 commit comments