Move ignore extension logic in 10_40 convertors

This commit is contained in:
dotasek 2023-05-08 12:57:17 -04:00
parent 8c86328002
commit 6f1b57dc15
4 changed files with 37 additions and 23 deletions

View File

@ -26,9 +26,8 @@ public class BaseAdvisor_10_40 extends BaseAdvisor40<org.hl7.fhir.dstu2.model.Ex
@Override
public boolean ignoreExtension(@Nonnull String path,
@Nonnull String url) {
final List<String> paths = Arrays.asList(path.split(","));
final String lastPath = paths.get(paths.size() - 1);
return (lastPath.equals("CapabilityStatement")) && (conformanceIgnoredUrls.contains(url));
// no globally ignored extensions here.
return false;
}
@Override

View File

@ -143,14 +143,18 @@ public class VersionConvertor_10_40 {
}
}
public void copyDomainResource(@Nonnull org.hl7.fhir.dstu2.model.DomainResource src,
@Nonnull org.hl7.fhir.r4.model.DomainResource tgt) throws FHIRException {
resourceConvertor.copyDomainResource(src, tgt);
public void copyDomainResource(
@Nonnull org.hl7.fhir.dstu2.model.DomainResource src,
@Nonnull org.hl7.fhir.r4.model.DomainResource tgt,
String ... extensionUrlsToIgnore) throws FHIRException {
resourceConvertor.copyDomainResource(src, tgt, extensionUrlsToIgnore);
}
public void copyDomainResource(@Nonnull org.hl7.fhir.r4.model.DomainResource src,
@Nonnull org.hl7.fhir.dstu2.model.DomainResource tgt) throws FHIRException {
resourceConvertor.copyDomainResource(src, tgt);
public void copyDomainResource(
@Nonnull org.hl7.fhir.r4.model.DomainResource src,
@Nonnull org.hl7.fhir.dstu2.model.DomainResource tgt,
String ... extensionUrlsToIgnore) throws FHIRException {
resourceConvertor.copyDomainResource(src, tgt, extensionUrlsToIgnore);
}
public void copyElement(@Nonnull org.hl7.fhir.dstu2.model.Element src,

View File

@ -21,6 +21,11 @@ import org.hl7.fhir.r4.model.CapabilityStatement.SystemRestfulInteraction;
public class Conformance10_40 {
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.dstu2.model.Enumeration<org.hl7.fhir.dstu2.model.Conformance.ConditionalDeleteStatus> convertConditionalDeleteStatus(org.hl7.fhir.r4.model.Enumeration<org.hl7.fhir.r4.model.CapabilityStatement.ConditionalDeleteStatus> src) throws FHIRException {
if (src == null || src.isEmpty())
return null;
@ -69,7 +74,7 @@ public class Conformance10_40 {
if (src == null || src.isEmpty())
return null;
org.hl7.fhir.dstu2.model.Conformance tgt = new org.hl7.fhir.dstu2.model.Conformance();
ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt, IGNORED_EXTENSION_URLS);
if (src.hasUrlElement())
tgt.setUrlElement(Uri10_40.convertUri(src.getUrlElement()));
if (src.hasVersionElement())
@ -100,8 +105,8 @@ public class Conformance10_40 {
tgt.setImplementation(convertConformanceImplementationComponent(src.getImplementation()));
if (src.hasFhirVersion())
tgt.setFhirVersion(src.getFhirVersion().toCode());
if (src.hasExtension("http://hl7.org/fhir/3.0/StructureDefinition/extension-CapabilityStatement.acceptUnknown"))
tgt.setAcceptUnknown(org.hl7.fhir.dstu2.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.dstu2.model.Conformance.UnknownContentCode.fromCode(src.getExtensionByUrl(ACCEPT_UNKNOWN_EXTENSION_URL).getValue().primitiveValue()));
for (org.hl7.fhir.r4.model.CodeType t : src.getFormat()) tgt.addFormat(t.getValue());
for (CapabilityStatementRestComponent r : src.getRest())
for (CapabilityStatementRestResourceComponent rr : r.getResource())
@ -152,7 +157,7 @@ public class Conformance10_40 {
if (src.hasFhirVersion())
tgt.setFhirVersion(org.hl7.fhir.r4.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.r4.model.CodeType(src.getAcceptUnknownElement().asStringValue()));
tgt.addExtension().setUrl(ACCEPT_UNKNOWN_EXTENSION_URL).setValue(new org.hl7.fhir.r4.model.CodeType(src.getAcceptUnknownElement().asStringValue()));
for (org.hl7.fhir.dstu2.model.CodeType t : src.getFormat()) tgt.addFormat(t.getValue());
for (org.hl7.fhir.dstu2.model.Conformance.ConformanceRestComponent t : src.getRest())
tgt.addRest(convertConformanceRestComponent(t));

View File

@ -8,6 +8,8 @@ import org.hl7.fhir.convertors.conv10_40.datatypes10_40.Narrative10_40;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.Extension;
import java.util.Arrays;
public class Resource10_40 {
public final BaseAdvisor_10_40 advisor;
@ -272,20 +274,22 @@ public class Resource10_40 {
}
}
public void copyDomainResource(org.hl7.fhir.dstu2.model.DomainResource src,
org.hl7.fhir.r4.model.DomainResource tgt) throws FHIRException {
public void copyDomainResource(
org.hl7.fhir.dstu2.model.DomainResource src,
org.hl7.fhir.r4.model.DomainResource tgt,
String ... extensionUrlsToIgnore) throws FHIRException {
copyResource(src, tgt);
if (src.hasText()) tgt.setText(Narrative10_40.convertNarrative(src.getText()));
src.getContained().stream()
.map(this::convertResource)
.forEach(tgt::addContained);
src.getExtension().forEach(ext -> {
if (advisor.useAdvisorForExtension(ConversionContext10_40.INSTANCE.path(), ext)) {
src.getExtension().forEach(extension -> {
if (advisor.useAdvisorForExtension(ConversionContext10_40.INSTANCE.path(), extension)) {
Extension convertExtension = new Extension();
advisor.handleExtension(ConversionContext10_40.INSTANCE.path(), ext, convertExtension);
advisor.handleExtension(ConversionContext10_40.INSTANCE.path(), extension, convertExtension);
tgt.addExtension(convertExtension);
} else if (!advisor.ignoreExtension(ConversionContext10_40.INSTANCE.path(), ext)) {
tgt.addExtension(Extension10_40.convertExtension(ext));
} else if (!advisor.ignoreExtension(ConversionContext10_40.INSTANCE.path(), extension) && !Arrays.asList(extensionUrlsToIgnore).contains(extension.getUrl())) {
tgt.addExtension(Extension10_40.convertExtension(extension));
}
});
src.getModifierExtension().stream()
@ -294,8 +298,10 @@ public class Resource10_40 {
.forEach(tgt::addModifierExtension);
}
public void copyDomainResource(org.hl7.fhir.r4.model.DomainResource src,
org.hl7.fhir.dstu2.model.DomainResource tgt) throws FHIRException {
public void copyDomainResource(
org.hl7.fhir.r4.model.DomainResource src,
org.hl7.fhir.dstu2.model.DomainResource tgt,
String ... extensionUrlsToIgnore) throws FHIRException {
copyResource(src, tgt);
if (src.hasText()) tgt.setText(Narrative10_40.convertNarrative(src.getText()));
src.getContained().stream()
@ -306,7 +312,7 @@ public class Resource10_40 {
org.hl7.fhir.dstu2.model.Extension convertExtension = new org.hl7.fhir.dstu2.model.Extension();
advisor.handleExtension(ConversionContext10_40.INSTANCE.path(), extension, convertExtension);
tgt.addExtension(convertExtension);
} else if (!advisor.ignoreExtension(ConversionContext10_40.INSTANCE.path(), extension)) {
} else if (!advisor.ignoreExtension(ConversionContext10_40.INSTANCE.path(), extension)&& !Arrays.asList(extensionUrlsToIgnore).contains(extension.getUrl())) {
tgt.addExtension(Extension10_40.convertExtension(extension));
}
});