Move ignore extension logic in 30_40 convertors

This commit is contained in:
dotasek 2023-05-08 11:11:34 -04:00
parent 33f28daf33
commit 42cf58cfbb
5 changed files with 29 additions and 21 deletions

View File

@ -25,13 +25,7 @@ public class BaseAdvisor_30_40 extends BaseAdvisor40<org.hl7.fhir.dstu3.model.Ex
@Override
public boolean ignoreExtension(@Nonnull String path,
@Nonnull String url) throws FHIRException {
final List<String> paths = Arrays.asList(path.split(","));
final String lastPath = paths.get(paths.size() - 1);
if (lastPath.equals("CapabilityStatement")) {
return capabilityStatementIgnoredUrls.contains(url);
} else if (lastPath.equals("Immunization")) {
return immunizationIgnoredUrls.contains(url);
}
// no globally ignored extensions here.
return false;
}
}

View File

@ -133,13 +133,13 @@ public class VersionConvertor_30_40 {
}
public void copyDomainResource(@Nonnull org.hl7.fhir.dstu3.model.DomainResource src,
@Nonnull org.hl7.fhir.r4.model.DomainResource tgt) throws FHIRException {
resourceConvertor.copyDomainResource(src, tgt);
@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.dstu3.model.DomainResource tgt) throws FHIRException {
resourceConvertor.copyDomainResource(src, tgt);
@Nonnull org.hl7.fhir.dstu3.model.DomainResource tgt, String... extensionUrlsToIgnore) throws FHIRException {
resourceConvertor.copyDomainResource(src, tgt, extensionUrlsToIgnore);
}
public void copyElement(@Nonnull org.hl7.fhir.dstu3.model.Element src,

View File

@ -20,11 +20,17 @@ import org.hl7.fhir.exceptions.FHIRException;
public class CapabilityStatement30_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
};
public static org.hl7.fhir.dstu3.model.CapabilityStatement convertCapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.dstu3.model.CapabilityStatement tgt = new org.hl7.fhir.dstu3.model.CapabilityStatement();
ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt, IGNORED_EXTENSION_URLS);
if (src.hasUrl())
tgt.setUrlElement(Uri30_40.convertUri(src.getUrlElement()));
if (src.hasVersion())
@ -62,8 +68,8 @@ public class CapabilityStatement30_40 {
tgt.setImplementation(convertCapabilityStatementImplementationComponent(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.dstu3.model.CapabilityStatement.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.dstu3.model.CapabilityStatement.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 (org.hl7.fhir.r4.model.CodeType t : src.getPatchFormat()) tgt.addPatchFormat(t.getValue());
for (org.hl7.fhir.r4.model.UriType t : src.getImplementationGuide()) tgt.addImplementationGuide(t.getValue());
@ -128,7 +134,7 @@ public class CapabilityStatement30_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.dstu3.model.CodeType t : src.getFormat()) tgt.addFormat(t.getValue());
for (org.hl7.fhir.dstu3.model.CodeType t : src.getPatchFormat()) tgt.addPatchFormat(t.getValue());
for (org.hl7.fhir.dstu3.model.UriType t : src.getImplementationGuide()) tgt.addImplementationGuide(t.getValue());

View File

@ -20,6 +20,10 @@ public class Immunization30_40 {
public static final String NOT_GIVEN_EXTENSION_URL = "http://hl7.org/fhir/3.0/StructureDefinition/extension-Immunization.notGiven";
private static final String[] IGNORED_EXTENSION_URLS = new String[]{
NOT_GIVEN_EXTENSION_URL
};
public static org.hl7.fhir.r4.model.Immunization convertImmunization(org.hl7.fhir.dstu3.model.Immunization src) throws FHIRException {
if (src == null)
return null;
@ -82,8 +86,8 @@ public class Immunization30_40 {
if (src == null)
return null;
org.hl7.fhir.dstu3.model.Immunization tgt = new org.hl7.fhir.dstu3.model.Immunization();
//FIXME add ignore
ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt, IGNORED_EXTENSION_URLS);
for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier())
tgt.addIdentifier(Identifier30_40.convertIdentifier(t));
if (src.hasStatus()) {

View File

@ -7,6 +7,8 @@ import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Meta30_40;
import org.hl7.fhir.convertors.conv30_40.datatypes30_40.Narrative30_40;
import org.hl7.fhir.exceptions.FHIRException;
import java.util.Arrays;
public class Resource30_40 {
public final BaseAdvisor_30_40 advisor;
@ -384,7 +386,8 @@ public class Resource30_40 {
}
public void copyDomainResource(org.hl7.fhir.dstu3.model.DomainResource src,
org.hl7.fhir.r4.model.DomainResource tgt) throws FHIRException {
org.hl7.fhir.r4.model.DomainResource tgt,
String... extensionUrlsToIgnore) throws FHIRException {
copyResource(src, tgt);
if (src.hasText()) tgt.setText(Narrative30_40.convertNarrative(src.getText()));
src.getContained().stream()
@ -396,7 +399,7 @@ public class Resource30_40 {
org.hl7.fhir.r4.model.Extension convertExtension = new org.hl7.fhir.r4.model.Extension();
advisor.handleExtension(ConversionContext30_40.INSTANCE.path(), extension, convertExtension);
tgt.addExtension(convertExtension);
} else if (!advisor.ignoreExtension(ConversionContext30_40.INSTANCE.path(), extension)) {
} else if (!advisor.ignoreExtension(ConversionContext30_40.INSTANCE.path(), extension)&& !Arrays.asList(extensionUrlsToIgnore).contains(extension.getUrl())) {
tgt.addExtension(Extension30_40.convertExtension(extension));
}
});
@ -407,7 +410,8 @@ public class Resource30_40 {
}
public void copyDomainResource(org.hl7.fhir.r4.model.DomainResource src,
org.hl7.fhir.dstu3.model.DomainResource tgt) throws FHIRException {
org.hl7.fhir.dstu3.model.DomainResource tgt,
String... extensionUrlsToIgnore) throws FHIRException {
copyResource(src, tgt);
if (src.hasText()) tgt.setText(Narrative30_40.convertNarrative(src.getText()));
src.getContained().stream()
@ -418,7 +422,7 @@ public class Resource30_40 {
org.hl7.fhir.dstu3.model.Extension convertExtension = new org.hl7.fhir.dstu3.model.Extension();
advisor.handleExtension(ConversionContext30_40.INSTANCE.path(), extension, convertExtension);
tgt.addExtension(convertExtension);
} else if (!advisor.ignoreExtension(ConversionContext30_40.INSTANCE.path(), extension)) {
} else if (!advisor.ignoreExtension(ConversionContext30_40.INSTANCE.path(), extension) && !Arrays.asList(extensionUrlsToIgnore).contains(extension.getUrl())) {
tgt.addExtension(Extension30_40.convertExtension(extension));
}
});