From b9433f0e8c5a51c471bdc02a9ee8ece69dedf1c5 Mon Sep 17 00:00:00 2001 From: dotasek Date: Mon, 8 May 2023 11:21:50 -0400 Subject: [PATCH] Move ignore extension logic in 14_50 convertors --- .../advisors/impl/BaseAdvisor_14_50.java | 7 ++----- .../conv14_50/VersionConvertor_14_50.java | 16 ++++++++++------ .../resources14_50/Conformance14_50.java | 14 ++++++++++---- .../resources14_50/Resource14_50.java | 18 ++++++++++++------ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/advisors/impl/BaseAdvisor_14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/advisors/impl/BaseAdvisor_14_50.java index c0a0d2886..811902a54 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/advisors/impl/BaseAdvisor_14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/advisors/impl/BaseAdvisor_14_50.java @@ -11,8 +11,6 @@ import org.hl7.fhir.exceptions.FHIRException; public class BaseAdvisor_14_50 extends BaseAdvisor50 { - final List capabilityStatementIgnoredUrls = Collections.singletonList("http://hl7.org/fhir/3.0/StructureDefinition/extension-CapabilityStatement.acceptUnknown"); - public BaseAdvisor_14_50() { } @@ -23,8 +21,7 @@ public class BaseAdvisor_14_50 extends BaseAdvisor50 paths = Arrays.asList(path.split(",")); - final String lastPath = paths.get(paths.size() - 1); - return (lastPath.equals("CapabilityStatement")) && (capabilityStatementIgnoredUrls.contains(url)); + // no globally ignored extensions here. + return false; } } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/VersionConvertor_14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/VersionConvertor_14_50.java index 0718ec831..444666cf6 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/VersionConvertor_14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/VersionConvertor_14_50.java @@ -129,14 +129,18 @@ public class VersionConvertor_14_50 { } } - public void copyDomainResource(@Nonnull org.hl7.fhir.dstu2016may.model.DomainResource src, - @Nonnull org.hl7.fhir.r5.model.DomainResource tgt) throws FHIRException { - resourceConvertor.copyDomainResource(src, tgt); + public void copyDomainResource( + @Nonnull org.hl7.fhir.dstu2016may.model.DomainResource src, + @Nonnull org.hl7.fhir.r5.model.DomainResource tgt, + String... extensionUrlsToIgnore) throws FHIRException { + resourceConvertor.copyDomainResource(src, tgt, extensionUrlsToIgnore); } - public void copyDomainResource(@Nonnull org.hl7.fhir.r5.model.DomainResource src, - @Nonnull org.hl7.fhir.dstu2016may.model.DomainResource tgt) throws FHIRException { - resourceConvertor.copyDomainResource(src, tgt); + public void copyDomainResource( + @Nonnull org.hl7.fhir.r5.model.DomainResource src, + @Nonnull org.hl7.fhir.dstu2016may.model.DomainResource tgt, + String... extensionUrlsToIgnore) throws FHIRException { + resourceConvertor.copyDomainResource(src, tgt, extensionUrlsToIgnore); } public void copyElement(@Nonnull org.hl7.fhir.dstu2016may.model.Element src, diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/Conformance14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/Conformance14_50.java index c98e72650..afe87693e 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/Conformance14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/Conformance14_50.java @@ -18,6 +18,12 @@ import org.hl7.fhir.r5.model.CapabilityStatement.CapabilityStatementRestResource public class Conformance14_50 { + public static final String ACCEPT_UNKNOWN_EXTENSION_URL = "http://hl7.org/fhir/3.0/StructureDefinition/extension-CapabilityStatement.acceptUnknown"; + + private static final String[] IGNORED_EXTENSION_URLS = new String[]{ + ACCEPT_UNKNOWN_EXTENSION_URL + }; + static public org.hl7.fhir.dstu2016may.model.Enumeration convertConditionalDeleteStatus(org.hl7.fhir.r5.model.Enumeration src) throws FHIRException { if (src == null || src.isEmpty()) return null; @@ -103,7 +109,7 @@ public class Conformance14_50 { if (src.hasFhirVersion()) tgt.setFhirVersion(org.hl7.fhir.r5.model.Enumerations.FHIRVersion.fromCode(src.getFhirVersion())); if (src.hasAcceptUnknown()) - tgt.addExtension().setUrl("http://hl7.org/fhir/3.0/StructureDefinition/extension-CapabilityStatement.acceptUnknown").setValue(new org.hl7.fhir.r5.model.CodeType(src.getAcceptUnknownElement().asStringValue())); + tgt.addExtension().setUrl(ACCEPT_UNKNOWN_EXTENSION_URL).setValue(new org.hl7.fhir.r5.model.CodeType(src.getAcceptUnknownElement().asStringValue())); for (org.hl7.fhir.dstu2016may.model.CodeType t : src.getFormat()) tgt.addFormat(t.getValue()); for (org.hl7.fhir.dstu2016may.model.Conformance.ConformanceRestComponent t : src.getRest()) tgt.addRest(convertConformanceRestComponent(t)); @@ -118,7 +124,7 @@ public class Conformance14_50 { if (src == null || src.isEmpty()) return null; org.hl7.fhir.dstu2016may.model.Conformance tgt = new org.hl7.fhir.dstu2016may.model.Conformance(); - ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyDomainResource(src, tgt); + ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyDomainResource(src, tgt, IGNORED_EXTENSION_URLS); if (src.hasUrl()) tgt.setUrlElement(Uri14_50.convertUri(src.getUrlElement())); if (src.hasVersion()) @@ -153,8 +159,8 @@ public class Conformance14_50 { if (src.hasImplementation()) tgt.setImplementation(convertConformanceImplementationComponent(src.getImplementation())); tgt.setFhirVersion(src.getFhirVersion().toCode()); - if (src.hasExtension("http://hl7.org/fhir/3.0/StructureDefinition/extension-CapabilityStatement.acceptUnknown")) - tgt.setAcceptUnknown(org.hl7.fhir.dstu2016may.model.Conformance.UnknownContentCode.fromCode(src.getExtensionByUrl("http://hl7.org/fhir/3.0/StructureDefinition/extension-CapabilityStatement.acceptUnknown").getValue().primitiveValue())); + if (src.hasExtension(ACCEPT_UNKNOWN_EXTENSION_URL)) + tgt.setAcceptUnknown(org.hl7.fhir.dstu2016may.model.Conformance.UnknownContentCode.fromCode(src.getExtensionByUrl(ACCEPT_UNKNOWN_EXTENSION_URL).getValue().primitiveValue())); for (org.hl7.fhir.r5.model.CodeType t : src.getFormat()) tgt.addFormat(t.getValue()); for (CapabilityStatementRestComponent r : src.getRest()) for (CapabilityStatementRestResourceComponent rr : r.getResource()) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/Resource14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/Resource14_50.java index c84d0d33b..d0cb14f8a 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/Resource14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/Resource14_50.java @@ -7,6 +7,8 @@ import org.hl7.fhir.convertors.conv14_50.datatypes14_50.Meta14_50; import org.hl7.fhir.convertors.conv14_50.datatypes14_50.Narrative14_50; import org.hl7.fhir.exceptions.FHIRException; +import java.util.Arrays; + public class Resource14_50 { public final BaseAdvisor_14_50 advisor; @@ -113,8 +115,10 @@ public class Resource14_50 { } } - public void copyDomainResource(org.hl7.fhir.dstu2016may.model.DomainResource src, - org.hl7.fhir.r5.model.DomainResource tgt) throws FHIRException { + public void copyDomainResource( + org.hl7.fhir.dstu2016may.model.DomainResource src, + org.hl7.fhir.r5.model.DomainResource tgt, + String... extensionUrlsToIgnore) throws FHIRException { copyResource(src, tgt); if (src.hasText()) tgt.setText(Narrative14_50.convertNarrative(src.getText())); src.getContained().stream() @@ -125,7 +129,7 @@ public class Resource14_50 { org.hl7.fhir.r5.model.Extension convertExtension = new org.hl7.fhir.r5.model.Extension(); advisor.handleExtension(ConversionContext14_50.INSTANCE.path(), extension, convertExtension); tgt.addExtension(convertExtension); - } else if (!advisor.ignoreExtension(ConversionContext14_50.INSTANCE.path(), extension)) { + } else if (!advisor.ignoreExtension(ConversionContext14_50.INSTANCE.path(), extension) && !Arrays.asList(extensionUrlsToIgnore).contains(extension.getUrl())) { tgt.addExtension(Extension14_50.convertExtension(extension)); } }); @@ -135,8 +139,10 @@ public class Resource14_50 { .forEach(tgt::addModifierExtension); } - public void copyDomainResource(org.hl7.fhir.r5.model.DomainResource src, - org.hl7.fhir.dstu2016may.model.DomainResource tgt) throws FHIRException { + public void copyDomainResource( + org.hl7.fhir.r5.model.DomainResource src, + org.hl7.fhir.dstu2016may.model.DomainResource tgt, + String... extensionUrlsToIgnore) throws FHIRException { copyResource(src, tgt); if (src.hasText()) tgt.setText(Narrative14_50.convertNarrative(src.getText())); src.getContained().stream() @@ -147,7 +153,7 @@ public class Resource14_50 { org.hl7.fhir.dstu2016may.model.Extension convertExtension = new org.hl7.fhir.dstu2016may.model.Extension(); advisor.handleExtension(ConversionContext14_50.INSTANCE.path(), extension, convertExtension); tgt.addExtension(convertExtension); - } else if (!advisor.ignoreExtension(ConversionContext14_50.INSTANCE.path(), extension)) { + } else if (!advisor.ignoreExtension(ConversionContext14_50.INSTANCE.path(), extension) && !Arrays.asList(extensionUrlsToIgnore).contains(extension.getUrl())) { tgt.addExtension(Extension14_50.convertExtension(extension)); } });