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 ;
12
13
import org .hl7 .fhir .r4 .model .Meta ;
14
+ import org .hl7 .fhir .r4 .model .Observation ;
13
15
import org .hl7 .fhir .r4 .model .Patient ;
14
16
import org .junit .Test ;
15
17
import org .junit .jupiter .api .Nested ;
23
25
24
26
import static de .medizininformatikinitiative .torch .util .FhirUtil .createAbsentReasonExtension ;
25
27
import static org .assertj .core .api .Assertions .assertThat ;
28
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
26
29
27
30
public class RedactionTest {
28
31
@@ -45,11 +48,11 @@ public RedactionTest() throws IOException {
45
48
@ ParameterizedTest
46
49
@ ValueSource (strings = {"Observation_lab_Missing_Elements_Unknown_Slices.json" })
47
50
void testObservationLab (String resource ) throws IOException {
48
- DomainResource src = integrationTestSetup .readResource ("src/test/resources/InputResources/Observation/" + resource );
49
- DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
51
+ Observation src = ( Observation ) integrationTestSetup .readResource ("src/test/resources/InputResources/Observation/" + resource );
52
+ Observation expected = ( Observation ) integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
50
53
51
54
ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (OBSERVATION_LAB ), Map .of ("Observation.subject" , Set .of ("Patient/VHF-MIXED-TEST-CASE-0001-a" ), "Observation.encounter" , Set .of ("Encounter/VHF-MIXED-TEST-CASE-0001-a-E-1" )), Set .of ());
52
- DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
55
+ DomainResource tgt = (Observation ) integrationTestSetup .redaction ().redact (wrapper );
53
56
54
57
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
55
58
}
@@ -59,11 +62,11 @@ void testObservationLab(String resource) throws IOException {
59
62
"Observation-mii-exa-test-data-patient-1-vitalstatus-1.json"
60
63
})
61
64
void testValueSetBindingPassingThroughAsDiscriminator (String resource ) throws IOException {
62
- DomainResource src = integrationTestSetup .readResource ("src/test/resources/InputResources/Observation/" + resource );
63
- DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
65
+ Observation src = ( Observation ) integrationTestSetup .readResource ("src/test/resources/InputResources/Observation/" + resource );
66
+ Observation expected = ( Observation ) integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
64
67
65
68
ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (VITALSTATUS ), Map .of ("Observation.subject" , Set .of ("Patient/VHF-MIXED-TEST-CASE-0001-a" ), "Observation.encounter" , Set .of ("Encounter/VHF-MIXED-TEST-CASE-0001-a-E-1" )), Set .of ());
66
- DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
69
+ DomainResource tgt = (Observation ) integrationTestSetup .redaction ().redact (wrapper );
67
70
68
71
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
69
72
}
@@ -73,18 +76,50 @@ void testValueSetBindingPassingThroughAsDiscriminator(String resource) throws IO
73
76
"Observation-mii-exa-test-data-patient-1-vitalstatus-1-identifier.json"
74
77
})
75
78
void testReferenceComplexType (String resource ) throws IOException {
76
- DomainResource src = integrationTestSetup .readResource ("src/test/resources/InputResources/Observation/" + resource );
77
- DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
79
+ Observation src = ( Observation ) integrationTestSetup .readResource ("src/test/resources/InputResources/Observation/" + resource );
80
+ Observation expected = ( Observation ) integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
78
81
79
82
ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (VITALSTATUS ), Map .of ("Observation.subject" , Set .of ("Patient/VHF-MIXED-TEST-CASE-0001-a" ), "Observation.encounter" , Set .of ("Encounter/VHF-MIXED-TEST-CASE-0001-a-E-1" )), Set .of ());
80
- DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
83
+ DomainResource tgt = (Observation ) integrationTestSetup .redaction ().redact (wrapper );
81
84
82
85
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
83
86
}
84
87
88
+ @ Test
89
+ public void mismatchProfileWithAssignedProfile () {
90
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
91
+ Meta meta = new Meta ();
92
+ meta .setProfile (List .of (new CanonicalType (MEDICATION )));
93
+ src .setMeta (meta );
94
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of (), Set .of ());
95
+
96
+ assertThatThrownBy (() -> integrationTestSetup .redaction ().redact (wrapper )).isInstanceOf (RuntimeException .class )
97
+ .hasMessage ("Resource is missing required profiles: [" + DIAGNOSIS + "]" );
98
+ }
99
+
100
+ @ Test
101
+ public void unknownProfile () {
102
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
103
+ Meta meta = new Meta ();
104
+ meta .setProfile (List .of (new CanonicalType ("UnknownProfile" )));
105
+ src .setMeta (meta );
106
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of ("UnknownProfile" ), Map .of (), Set .of ());
107
+
108
+ assertThatThrownBy (() -> integrationTestSetup .redaction ().redact (wrapper )).isInstanceOf (RuntimeException .class )
109
+ .hasMessage ("Trying to handle unknown profiles: [UnknownProfile]" );
110
+ }
111
+
112
+ @ Test
113
+ public void metaMissing () {
114
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
115
+
116
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of (), Set .of ());
117
+ assertThatThrownBy (() -> integrationTestSetup .redaction ().redact (wrapper )).isInstanceOf (RuntimeException .class );
118
+ }
119
+
85
120
@ Test
86
121
public void unknownSlice () throws IOException {
87
- DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + "unknownSlice.json" );
122
+ Condition expected = ( Condition ) integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + "unknownSlice.json" );
88
123
org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
89
124
Meta meta = new Meta ();
90
125
meta .setProfile (List .of (new CanonicalType (DIAGNOSIS )));
@@ -94,6 +129,35 @@ public void unknownSlice() throws IOException {
94
129
concept .setCoding (List .of (code ));
95
130
src .setCode (concept );
96
131
132
+ ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of (), Set .of ());
133
+ DomainResource tgt = (Condition ) integrationTestSetup .redaction ().redact (wrapper );
134
+
135
+ assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
136
+ }
137
+
138
+ @ ParameterizedTest
139
+ @ ValueSource (strings = {"DiagnosisWithExtensionAtCodeWithUnknownField.json" })
140
+ void notHandlingUnknownElementID (String resource ) throws IOException {
141
+
142
+ Condition src = (Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
143
+ Condition expected = (Condition ) integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
144
+
145
+ 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 ());
146
+ DomainResource tgt = (Condition ) integrationTestSetup .redaction ().redact (wrapper );
147
+
148
+ assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
149
+
150
+
151
+ }
152
+
153
+ @ Test
154
+ public void emptyValues () throws IOException {
155
+ Condition expected = (Condition ) integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + "EmptyValues.json" );
156
+ org .hl7 .fhir .r4 .model .Condition src = new org .hl7 .fhir .r4 .model .Condition ();
157
+ Meta meta = new Meta ();
158
+ meta .setProfile (List .of (new CanonicalType (DIAGNOSIS )));
159
+ src .setMeta (meta );
160
+
97
161
ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of (), Set .of ());
98
162
DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
99
163
@@ -103,11 +167,11 @@ public void unknownSlice() throws IOException {
103
167
@ ParameterizedTest
104
168
@ ValueSource (strings = {"DiagnosisUnknownPrimitiveExtension.json" , "DiagnosisWithExtensionAtCode.json" , "DiagnosisUnknownComplexExtension.json" })
105
169
void removeUnknownPrimitiveAndComplexExtension (String resource ) throws IOException {
106
- DomainResource src = integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
107
- DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
170
+ Condition src = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
171
+ Condition expected = ( Condition ) integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
108
172
109
173
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 ());
110
- DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
174
+ DomainResource tgt = (Condition ) integrationTestSetup .redaction ().redact (wrapper );
111
175
112
176
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
113
177
}
@@ -130,7 +194,7 @@ public void backboneElementHandling() {
130
194
131
195
132
196
ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (medication , Set .of (MEDICATION ), Map .of (), Set .of ());
133
- DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
197
+ DomainResource tgt = (Medication ) integrationTestSetup .redaction ().redact (wrapper );
134
198
135
199
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expectedMedication ));
136
200
}
@@ -153,58 +217,58 @@ public void patient() {
153
217
expectedPatient .setIdentifier (List .of (identifier ));
154
218
155
219
ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (patient , Set .of (PATIENT ), Map .of (), Set .of ());
156
- DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
220
+ DomainResource tgt = (Patient ) integrationTestSetup .redaction ().redact (wrapper );
157
221
158
222
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expectedPatient ));
159
223
}
160
224
161
225
@ Nested
162
- class Condition {
226
+ class ConditionTest {
163
227
164
228
@ ParameterizedTest
165
229
@ 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
- 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
+ void diagnosisNoChange (String resource ) throws IOException {
231
+ Condition src = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
232
+ Condition expected = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
169
233
170
234
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
- DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
235
+ DomainResource tgt = (Condition ) integrationTestSetup .redaction ().redact (wrapper );
172
236
173
237
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
174
238
}
175
239
176
240
@ ParameterizedTest
177
241
@ ValueSource (strings = {"Condition-mii-exa-diagnose-condition-minimal.json" , "Condition-mii-exa-diagnose-mehrfachkodierung-primaercode.json" })
178
242
void invalidReferences (String resource ) throws IOException {
179
- DomainResource src = integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
180
- DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
243
+ Condition src = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
244
+ Condition expected = ( Condition ) integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
181
245
182
246
ExtractionRedactionWrapper wrapper = new ExtractionRedactionWrapper (src , Set .of (DIAGNOSIS ), Map .of ("Condition.subject" , Set .of (), "Condition.encounter" , Set .of ("Encounter/12345" )), Set .of ());
183
- DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
247
+ DomainResource tgt = (Condition ) integrationTestSetup .redaction ().redact (wrapper );
184
248
185
249
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
186
250
}
187
251
188
252
@ ParameterizedTest
189
253
@ ValueSource (strings = {"DiagnosisWithInvalidSliceCode.json" })
190
254
void diagnosisInvalidElements (String resource ) throws IOException {
191
- DomainResource src = integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
192
- DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
255
+ Condition src = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
256
+ Condition expected = ( Condition ) integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
193
257
194
258
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
- DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
259
+ DomainResource tgt = (Condition ) integrationTestSetup .redaction ().redact (wrapper );
196
260
197
261
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
198
262
}
199
263
200
264
@ ParameterizedTest
201
265
@ ValueSource (strings = {"Diagnosis1.json" , "Diagnosis2.json" })
202
266
void diagnosisMissingElements (String resource ) throws IOException {
203
- DomainResource src = integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
204
- DomainResource expected = integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
267
+ Condition src = ( Condition ) integrationTestSetup .readResource (INPUT_CONDITION_DIR + resource );
268
+ Condition expected = ( Condition ) integrationTestSetup .readResource (EXPECTED_OUTPUT_DIR + resource );
205
269
206
270
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
- DomainResource tgt = (DomainResource ) integrationTestSetup .redaction ().redact (wrapper );
271
+ DomainResource tgt = (Condition ) integrationTestSetup .redaction ().redact (wrapper );
208
272
209
273
assertThat (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (tgt )).isEqualTo (fhirContext .newJsonParser ().setPrettyPrint (true ).encodeResourceToString (expected ));
210
274
}
0 commit comments