Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit a53d202

Browse files
committed
better resource and unresolved references cleanup
This fix is related to #37 as it removes all references that can not be resolved. It is not a fix for the more general problem of references between GECCO resources such as Observation with the profile https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/blood-gas-panel With this commit blood-gas-panel is still broken.
1 parent 769f690 commit a53d202

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

  • codex-process-data-transfer/src/main/java/de/netzwerk_universitaetsmedizin/codex/processes/data_transfer/service/send

codex-process-data-transfer/src/main/java/de/netzwerk_universitaetsmedizin/codex/processes/data_transfer/service/send/ReadData.java

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.hl7.fhir.r4.model.Coding;
3535
import org.hl7.fhir.r4.model.Condition;
3636
import org.hl7.fhir.r4.model.Consent;
37+
import org.hl7.fhir.r4.model.Consent.provisionComponent;
3738
import org.hl7.fhir.r4.model.DateTimeType;
3839
import org.hl7.fhir.r4.model.DiagnosticReport;
3940
import org.hl7.fhir.r4.model.DomainResource;
@@ -190,10 +191,134 @@ private DomainResource clean(DomainResource r)
190191
|| MII_LAB_STRUCTURED_DEFINITION.equals(p.getValue()))
191192
.collect(Collectors.toList());
192193
r.setMeta(new Meta().setProfile(profiles));
194+
r.setText(null);
195+
196+
cleanUnsupportedReferences(r);
193197

194198
return r;
195199
}
196200

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+
197322
private Resource setSubjectOrIdentifier(Resource resource, String pseudonym)
198323
{
199324
Identifier identifier = new Identifier().setSystem(NAMING_SYSTEM_NUM_CODEX_DIC_PSEUDONYM).setValue(pseudonym);

0 commit comments

Comments
 (0)