|
34 | 34 | import org.hl7.fhir.r4.model.Coding; |
35 | 35 | import org.hl7.fhir.r4.model.Condition; |
36 | 36 | import org.hl7.fhir.r4.model.Consent; |
| 37 | +import org.hl7.fhir.r4.model.Consent.provisionComponent; |
37 | 38 | import org.hl7.fhir.r4.model.DateTimeType; |
38 | 39 | import org.hl7.fhir.r4.model.DiagnosticReport; |
39 | 40 | import org.hl7.fhir.r4.model.DomainResource; |
@@ -190,10 +191,134 @@ private DomainResource clean(DomainResource r) |
190 | 191 | || MII_LAB_STRUCTURED_DEFINITION.equals(p.getValue())) |
191 | 192 | .collect(Collectors.toList()); |
192 | 193 | r.setMeta(new Meta().setProfile(profiles)); |
| 194 | + r.setText(null); |
| 195 | + |
| 196 | + cleanUnsupportedReferences(r); |
193 | 197 |
|
194 | 198 | return r; |
195 | 199 | } |
196 | 200 |
|
| 201 | + private void cleanUnsupportedReferences(DomainResource resource) |
| 202 | + { |
| 203 | + if (resource == null) |
| 204 | + { |
| 205 | + return; |
| 206 | + } |
| 207 | + else if (resource instanceof Condition) |
| 208 | + { |
| 209 | + Condition condition = (Condition) resource; |
| 210 | + condition.setEncounter(null); |
| 211 | + condition.setRecorder(null); |
| 212 | + condition.setAsserter(null); |
| 213 | + if (condition.hasStage()) |
| 214 | + condition.getStage().forEach(s -> s.setAssessment(null)); |
| 215 | + if (condition.hasEvidence()) |
| 216 | + condition.getEvidence().forEach(e -> e.setDetail(null)); |
| 217 | + } |
| 218 | + else if (resource instanceof Consent) |
| 219 | + { |
| 220 | + Consent consent = (Consent) resource; |
| 221 | + consent.setPerformer(null); |
| 222 | + consent.setOrganization(null); |
| 223 | + if (consent.hasVerification()) |
| 224 | + consent.getVerification().forEach(v -> v.setVerifiedWith(null)); |
| 225 | + if (consent.hasProvision()) |
| 226 | + { |
| 227 | + // class name starts with lower case p |
| 228 | + provisionComponent provision = consent.getProvision(); |
| 229 | + if (provision.hasActor()) |
| 230 | + provision.getActor().forEach(a -> a.setReference(null)); |
| 231 | + if (provision.hasData()) |
| 232 | + provision.getData().forEach(d -> d.setReference(null)); |
| 233 | + } |
| 234 | + } |
| 235 | + else if (resource instanceof DiagnosticReport) |
| 236 | + { |
| 237 | + DiagnosticReport report = (DiagnosticReport) resource; |
| 238 | + report.setBasedOn(null); |
| 239 | + report.setEncounter(null); |
| 240 | + report.setPerformer(null); |
| 241 | + report.setResultsInterpreter(null); |
| 242 | + report.setSpecimen(null); |
| 243 | + report.setImagingStudy(null); |
| 244 | + if (report.hasMedia()) |
| 245 | + report.getMedia().forEach(m -> m.setLink(null)); |
| 246 | + } |
| 247 | + else if (resource instanceof Immunization) |
| 248 | + { |
| 249 | + Immunization immunization = (Immunization) resource; |
| 250 | + immunization.setEncounter(null); |
| 251 | + immunization.setLocation(null); |
| 252 | + immunization.setManufacturer(null); |
| 253 | + if (immunization.hasPerformer()) |
| 254 | + immunization.getPerformer().forEach(p -> p.setActor(null)); |
| 255 | + immunization.setReasonReference(null); |
| 256 | + if (immunization.hasReaction()) |
| 257 | + immunization.getReaction().forEach(r -> r.setDetail(null)); |
| 258 | + if (immunization.hasProtocolApplied()) |
| 259 | + immunization.getProtocolApplied().forEach(p -> p.setAuthority(null)); |
| 260 | + } |
| 261 | + else if (resource instanceof MedicationStatement) |
| 262 | + { |
| 263 | + MedicationStatement medication = (MedicationStatement) resource; |
| 264 | + medication.setBasedOn(null); |
| 265 | + medication.setPartOf(null); |
| 266 | + if (medication.hasMedicationReference()) |
| 267 | + medication.setMedication(null); |
| 268 | + medication.setContext(null); |
| 269 | + medication.setInformationSource(null); |
| 270 | + medication.setDerivedFrom(null); |
| 271 | + medication.setReasonReference(null); |
| 272 | + } |
| 273 | + else if (resource instanceof Observation) |
| 274 | + { |
| 275 | + Observation observation = (Observation) resource; |
| 276 | + observation.setBasedOn(null); |
| 277 | + observation.setPartOf(null); |
| 278 | + observation.setFocus(null); |
| 279 | + observation.setEncounter(null); |
| 280 | + observation.setPerformer(null); |
| 281 | + observation.setSpecimen(null); |
| 282 | + observation.setDevice(null); |
| 283 | + |
| 284 | + // Do not remove blood-gas-panel member references |
| 285 | + // TODO fix blood-gas-panel member references, to bundle internal temporary urn:uuid:... IDs |
| 286 | + if (!resource.getMeta().getProfile().stream().map(CanonicalType::getValue).anyMatch( |
| 287 | + url -> "https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/blood-gas-panel" |
| 288 | + .equals(url))) |
| 289 | + { |
| 290 | + observation.setHasMember(null); |
| 291 | + } |
| 292 | + |
| 293 | + observation.setDerivedFrom(null); |
| 294 | + } |
| 295 | + else if (resource instanceof Procedure) |
| 296 | + { |
| 297 | + Procedure procedure = (Procedure) resource; |
| 298 | + procedure.setInstantiatesCanonical(null); |
| 299 | + procedure.setBasedOn(null); |
| 300 | + procedure.setPartOf(null); |
| 301 | + procedure.setEncounter(null); |
| 302 | + procedure.setRecorder(null); |
| 303 | + procedure.setAsserter(null); |
| 304 | + if (procedure.hasPerformer()) |
| 305 | + procedure.getPerformer().forEach(p -> |
| 306 | + { |
| 307 | + p.setActor(null); |
| 308 | + p.setOnBehalfOf(null); |
| 309 | + }); |
| 310 | + procedure.setLocation(null); |
| 311 | + procedure.setReasonReference(null); |
| 312 | + procedure.setReport(null); |
| 313 | + procedure.setComplicationDetail(null); |
| 314 | + if (procedure.hasFocalDevice()) |
| 315 | + procedure.getFocalDevice().forEach(d -> d.setManipulated(null)); |
| 316 | + procedure.setUsedReference(null); |
| 317 | + } |
| 318 | + else |
| 319 | + throw new RuntimeException("Resource of type " + resource.getResourceType().name() + " not supported"); |
| 320 | + } |
| 321 | + |
197 | 322 | private Resource setSubjectOrIdentifier(Resource resource, String pseudonym) |
198 | 323 | { |
199 | 324 | Identifier identifier = new Identifier().setSystem(NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM).setValue(pseudonym); |
|
0 commit comments