From 3de8aa69fe8642395864d60ce3e7d8a047e068b0 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 29 Sep 2023 13:42:25 +1000 Subject: [PATCH] handle additional bindings when generating snapshots for R5 profiles --- .../conformance/profile/ProfileUtilities.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java index bc3deedf1..e4d8342c7 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java @@ -92,6 +92,7 @@ import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingCompo import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionSnapshotComponent; import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule; import org.hl7.fhir.r5.model.UriType; +import org.hl7.fhir.r5.model.UsageContext; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent; import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent; @@ -2691,6 +2692,14 @@ public class ProfileUtilities extends TranslatingUtilities { if (d.hasValueSet()) { nb.setValueSet(d.getValueSet()); } + for (ElementDefinitionBindingAdditionalComponent ab : d.getAdditional()) { + ElementDefinitionBindingAdditionalComponent eab = getMatchingAdditionalBinding(nb, ab); + if (eab != null) { + mergeAdditionalBinding(eab, ab); + } else { + nb.getAdditional().add(ab); + } + } base.setBinding(nb); } else if (trimDifferential) derived.setBinding(null); @@ -2790,6 +2799,42 @@ public class ProfileUtilities extends TranslatingUtilities { //updateURLs(url, webUrl, dest); } + private void mergeAdditionalBinding(ElementDefinitionBindingAdditionalComponent dest, ElementDefinitionBindingAdditionalComponent source) { + for (UsageContext t : source.getUsage()) { + if (!hasUsage(dest, t)) { + dest.addUsage(t); + } + } + if (source.getAny()) { + source.setAny(true); + } + if (source.hasShortDoco()) { + dest.setShortDoco(source.getShortDoco()); + } + if (source.hasDocumentation()) { + dest.setDocumentation(source.getDocumentation()); + } + + } + + private boolean hasUsage(ElementDefinitionBindingAdditionalComponent dest, UsageContext tgt) { + for (UsageContext t : dest.getUsage()) { + if (t.getCode() != null && t.getCode().matches(tgt.getCode()) && t.getValue() != null && t.getValue().equals(tgt.getValue())) { + return true; + } + } + return false; + } + + private ElementDefinitionBindingAdditionalComponent getMatchingAdditionalBinding(ElementDefinitionBindingComponent nb,ElementDefinitionBindingAdditionalComponent ab) { + for (ElementDefinitionBindingAdditionalComponent t : nb.getAdditional()) { + if (t.getValueSet() != null && t.getValueSet().equals(ab.getValueSet()) && t.getPurpose() == ab.getPurpose()) { + return t; + } + } + return null; + } + private void mergeExtensions(Element tgt, Element src) { tgt.getExtension().addAll(src.getExtension()); }