6
6
import org .hl7 .fhir .r4 .model .CanonicalType ;
7
7
import org .hl7 .fhir .r4 .model .CodeableConcept ;
8
8
import org .hl7 .fhir .r4 .model .Coding ;
9
+ import org .hl7 .fhir .r4 .model .Condition ;
9
10
import org .hl7 .fhir .r4 .model .DomainResource ;
10
11
import org .hl7 .fhir .r4 .model .Identifier ;
11
12
import org .hl7 .fhir .r4 .model .Medication ;
23
24
24
25
import static de .medizininformatikinitiative .torch .util .FhirUtil .createAbsentReasonExtension ;
25
26
import static org .assertj .core .api .Assertions .assertThat ;
27
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
26
28
27
29
public class RedactionTest {
28
30
@@ -82,6 +84,38 @@ void testReferenceComplexType(String resource) throws IOException {
82
84
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
83
85
}
84
86
87
+ @ Test
88
+ public void mismatchProfileWithAssignedProfile () {
89
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
90
+ Meta meta = new Meta ();
91
+ meta .setProfile (List .of (new CanonicalType (MEDICATION )));
92
+ src .setMeta (meta );
93
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of (), Set .of ());
94
+
95
+ assertThatThrownBy (() -> integrationTestSetup .redaction ().redact (wrapper )).isInstanceOf (RuntimeException .class )
96
+ .hasMessage ("Resource is missing required profiles: [" + DIAGNOSIS + "]" );
97
+ }
98
+
99
+ @ Test
100
+ public void unknownProfile () {
101
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
102
+ Meta meta = new Meta ();
103
+ meta .setProfile (List .of (new CanonicalType ("UnknownProfile" )));
104
+ src .setMeta (meta );
105
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of ("UnknownProfile" ), Map .of (), Set .of ());
106
+
107
+ assertThatThrownBy (() -> integrationTestSetup .redaction ().redact (wrapper )).isInstanceOf (RuntimeException .class )
108
+ .hasMessage ("Trying to handle unknown profiles: [UnknownProfile]" );
109
+ }
110
+
111
+ @ Test
112
+ public void metaMissing () {
113
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
114
+
115
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of (), Set .of ());
116
+ assertThatThrownBy (() -> integrationTestSetup .redaction ().redact (wrapper )).isInstanceOf (RuntimeException .class );
117
+ }
118
+
85
119
@ Test
86
120
public void unknownSlice () throws IOException {
87
121
DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + "unknownSlice.json" );
@@ -100,6 +134,35 @@ public void unknownSlice() throws IOException {
100
134
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
101
135
}
102
136
137
+ @ ParameterizedTest
138
+ @ ValueSource (strings = {"DiagnosisWithExtensionAtCodeWithUnknownField.json" })
139
+ void notHandlingUnknownElementID (String resource ) throws IOException {
140
+
141
+ DomainResource src = integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
142
+ DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
143
+
144
+ 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 ());
145
+ DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
146
+
147
+ assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
148
+
149
+
150
+ }
151
+
152
+ @ Test
153
+ public void emptyValues () throws IOException {
154
+ DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + "EmptyValues.json" );
155
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
156
+ Meta meta = new Meta ();
157
+ meta .setProfile (List .of (new CanonicalType (DIAGNOSIS )));
158
+ src .setMeta (meta );
159
+
160
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of (), Set .of ());
161
+ DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
162
+
163
+ assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
164
+ }
165
+
103
166
@ ParameterizedTest
104
167
@ ValueSource (strings = {"DiagnosisUnknownPrimitiveExtension.json" , "DiagnosisWithExtensionAtCode.json" , "DiagnosisUnknownComplexExtension.json" })
105
168
void removeUnknownPrimitiveAndComplexExtension (String resource ) throws IOException {
@@ -159,13 +222,13 @@ public void patient() {
159
222
}
160
223
161
224
@ Nested
162
- class Condition {
225
+ class ConditionTest {
163
226
164
227
@ ParameterizedTest
165
228
@ 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" })
166
229
void diagnosisAllValid (String resource ) throws IOException {
167
- DomainResource src = integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
168
- DomainResource expected = integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
230
+ Condition src = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
231
+ Condition expected = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
169
232
170
233
ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of ("Condition.subject" , Set .of ("Patient/12345" , "Patient/mii-exa-test-data-patient-1" , "Patient/mii-exa-test-data-patient-3" ), "Condition.encounter" , Set .of ("Encounter/12345" )), Set .of ());
171
234
DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
@@ -176,8 +239,8 @@ void diagnosisAllValid(String resource) throws IOException {
176
239
@ ParameterizedTest
177
240
@ ValueSource (strings = {"Condition-mii-exa-diagnose-condition-minimal.json" , "Condition-mii-exa-diagnose-mehrfachkodierung-primaercode.json" })
178
241
void invalidReferences (String resource ) throws IOException {
179
- DomainResource src = integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
180
- DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
242
+ Condition src = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
243
+ Condition expected = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
181
244
182
245
ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of ("Condition.subject" , Set .of (), "Condition.encounter" , Set .of ("Encounter/12345" )), Set .of ());
183
246
DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
@@ -188,8 +251,8 @@ void invalidReferences(String resource) throws IOException {
188
251
@ ParameterizedTest
189
252
@ ValueSource (strings = {"DiagnosisWithInvalidSliceCode.json" })
190
253
void diagnosisInvalidElements (String resource ) throws IOException {
191
- DomainResource src = integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
192
- DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
254
+ Condition src = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
255
+ Condition expected = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
193
256
194
257
ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of ("Condition.subject" , Set .of ("Patient/12345" ), "Condition.encounter" , Set .of ("Encounter/12345" )), Set .of ());
195
258
DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
@@ -200,8 +263,8 @@ void diagnosisInvalidElements(String resource) throws IOException {
200
263
@ ParameterizedTest
201
264
@ ValueSource (strings = {"Diagnosis1.json" , "Diagnosis2.json" })
202
265
void diagnosisMissingElements (String resource ) throws IOException {
203
- DomainResource src = integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
204
- DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
266
+ Condition src = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
267
+ Condition expected = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
205
268
206
269
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 ());
207
270
DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
0 commit comments