Merge pull request #1598 from hapifhir/HandleExtraProfiles

Handle extra profiles on resources in an IG
This commit is contained in:
Grahame Grieve 2024-06-25 23:15:59 +10:00 committed by GitHub
commit 92a3d65942
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 51 additions and 2 deletions

View File

@ -16,10 +16,14 @@ import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Stri
import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Uri30_50;
import org.hl7.fhir.dstu3.model.ImplementationGuide;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r5.model.CanonicalType;
import org.hl7.fhir.r5.model.Enumeration;
public class ImplementationGuide30_50 {
static final String EXT_IG_DEFINITION_RESOURCE_PROFILE = "http://hl7.org/fhir/5.0/StructureDefinition/extension-ImplementationGuide.definition.resource.profile";
public static org.hl7.fhir.dstu3.model.ImplementationGuide convertImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide src) throws FHIRException {
if (src == null)
return null;
@ -204,10 +208,16 @@ public class ImplementationGuide30_50 {
if (src.hasProfile()) {
tgt.setExampleFor(Reference30_50.convertCanonicalToReference(src.getProfile().get(0)));
tgt.setExample(true);
if (src.getProfile().size() > 1) {
for (CanonicalType p: src.getProfile().subList(1, src.getProfile().size())) {
tgt.addExtension(EXT_IG_DEFINITION_RESOURCE_PROFILE, Uri30_50.convertUri(p));
}
}
} else if (src.hasIsExample())
tgt.setExample(src.getIsExample());
else
tgt.setExample(false);
if (src.hasName())
tgt.setNameElement(String30_50.convertString(src.getNameElement()));
if (src.hasDescription())
@ -222,6 +232,9 @@ public class ImplementationGuide30_50 {
return null;
org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent tgt = new org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent();
ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyBackboneElement(src,tgt);
for (org.hl7.fhir.dstu3.model.Extension ext: src.getExtensionsByUrl(EXT_IG_DEFINITION_RESOURCE_PROFILE)) {
tgt.getProfile().add(Uri30_50.convertCanonical((org.hl7.fhir.dstu3.model.UriType)ext.getValue()));
}
if (src.hasExampleFor()) {
tgt.getProfile().add(Reference30_50.convertReferenceToCanonical(src.getExampleFor()));
} else if (src.hasExample())

View File

@ -17,7 +17,9 @@ import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Uri40_50;
import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Url40_50;
import org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50.Reference40_50;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.UrlType;
import org.hl7.fhir.r5.model.CanonicalType;
import org.hl7.fhir.r5.model.ImplementationGuide;
import org.hl7.fhir.utilities.Utilities;
@ -56,6 +58,7 @@ public class ImplementationGuide40_50 {
static final String EXT_IG_DEFINITION_PARAMETER = "http://hl7.org/fhir/tools/StructureDefinition/ig-parameter";
static final String EXT_IG_DEFINITION_PARAM_URL_EXT = "http://hl7.org/fhir/tools/CodeSystem/ig-parameters";
static final String EXT_IG_DEFINITION_PARAM_URL_BASE = "http://hl7.org/fhir/guide-parameter-code";
static final String EXT_IG_DEFINITION_RESOURCE_PROFILE = "http://hl7.org/fhir/5.0/StructureDefinition/extension-ImplementationGuide.definition.resource.profile";
public static org.hl7.fhir.r5.model.ImplementationGuide convertImplementationGuide(org.hl7.fhir.r4.model.ImplementationGuide src) throws FHIRException {
if (src == null)
@ -322,6 +325,9 @@ public class ImplementationGuide40_50 {
tgt.setIsExample(true);
tgt.getProfile().add(Canonical40_50.convertCanonical(src.getExampleCanonicalType()));
}
for (Extension ext: src.getExtensionsByUrl(EXT_IG_DEFINITION_RESOURCE_PROFILE)) {
tgt.getProfile().add(Canonical40_50.convertCanonical((org.hl7.fhir.r4.model.CanonicalType)ext.getValue()));
}
if (src.hasGroupingId())
tgt.setGroupingIdElement(Id40_50.convertId(src.getGroupingIdElement()));
return tgt;
@ -343,6 +349,11 @@ public class ImplementationGuide40_50 {
if (src.hasProfile() && (!src.hasIsExample() || src.getIsExample())) {
tgt.setExample(ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().convertType(src.getProfile().get(0)));
}
if (src.getProfile().size() > 1) {
for (CanonicalType p: src.getProfile().subList(1, src.getProfile().size())) {
tgt.addExtension(EXT_IG_DEFINITION_RESOURCE_PROFILE, Canonical40_50.convertCanonical(p));
}
}
if (src.hasGroupingId())
tgt.setGroupingIdElement(Id40_50.convertId(src.getGroupingIdElement()));
return tgt;

View File

@ -3,6 +3,7 @@ package org.hl7.fhir.convertors.conv43_50.resources43_50;
import java.util.stream.Collectors;
import org.hl7.fhir.convertors.context.ConversionContext43_50;
import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Canonical40_50;
import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.CodeableConcept43_50;
import org.hl7.fhir.convertors.conv43_50.datatypes43_50.metadata43_50.ContactDetail43_50;
import org.hl7.fhir.convertors.conv43_50.datatypes43_50.metadata43_50.UsageContext43_50;
@ -17,6 +18,8 @@ import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Uri43_50;
import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Url43_50;
import org.hl7.fhir.convertors.conv43_50.datatypes43_50.special43_50.Reference43_50;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r5.model.CanonicalType;
import org.hl7.fhir.utilities.Utilities;
/*
@ -51,6 +54,7 @@ import org.hl7.fhir.utilities.Utilities;
public class ImplementationGuide43_50 {
static final String EXT_IG_DEFINITION_PARAMETER = "http://hl7.org/fhir/tools/StructureDefinition/ig-parameter";
static final String EXT_IG_DEFINITION_RESOURCE_PROFILE = "http://hl7.org/fhir/5.0/StructureDefinition/extension-ImplementationGuide.definition.resource.profile";
public static org.hl7.fhir.r5.model.ImplementationGuide convertImplementationGuide(org.hl7.fhir.r4b.model.ImplementationGuide src) throws FHIRException {
if (src == null)
@ -312,8 +316,13 @@ public class ImplementationGuide43_50 {
tgt.setDescriptionElement(String43_50.convertStringToMarkdown(src.getDescriptionElement()));
if (src.hasExampleBooleanType())
tgt.setIsExampleElement(Boolean43_50.convertBoolean(src.getExampleBooleanType()));
if (src.hasExampleCanonicalType())
if (src.hasExampleCanonicalType()) {
tgt.setIsExample(true);
tgt.getProfile().add(Canonical43_50.convertCanonical(src.getExampleCanonicalType()));
}
for (org.hl7.fhir.r4b.model.Extension ext: src.getExtensionsByUrl(EXT_IG_DEFINITION_RESOURCE_PROFILE)) {
tgt.getProfile().add(Canonical43_50.convertCanonical((org.hl7.fhir.r4b.model.CanonicalType)ext.getValue()));
}
if (src.hasGroupingId())
tgt.setGroupingIdElement(Id43_50.convertId(src.getGroupingIdElement()));
return tgt;
@ -337,6 +346,11 @@ public class ImplementationGuide43_50 {
tgt.setExample(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getIsExampleElement()));
if (src.hasProfile())
tgt.setExample(ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().convertType(src.getProfile().get(0)));
if (src.getProfile().size() > 1) {
for (CanonicalType p: src.getProfile().subList(1, src.getProfile().size())) {
tgt.addExtension(EXT_IG_DEFINITION_RESOURCE_PROFILE, Canonical43_50.convertCanonical(p));
}
}
if (src.hasGroupingId())
tgt.setGroupingIdElement(Id43_50.convertId(src.getGroupingIdElement()));
return tgt;

View File

@ -36,6 +36,16 @@ public class ImplementationGuide40_50Test {
}
@Test
public void testRoundTripProfiles() throws IOException {
ImplementationGuide r5_actual = getR5ImplementationGuide();
org.hl7.fhir.r4.model.ImplementationGuide converted = (org.hl7.fhir.r4.model.ImplementationGuide) VersionConvertorFactory_40_50.convertResource(r5_actual);
ImplementationGuide r5_converted = (ImplementationGuide) VersionConvertorFactory_40_50.convertResource(converted);
assertEquals(r5_actual.getDefinition().getResourceFirstRep().getProfile().size(), r5_converted.getDefinition().getResourceFirstRep().getProfile().size());
}
private ImplementationGuide getR5ImplementationGuide() throws IOException {
ImplementationGuide r5_actual;
InputStream r5_stream = this.getClass().getResourceAsStream("/implementation_guide_50.json");

View File

@ -75,7 +75,8 @@
"name": "Test Example",
"description": "A test example to show how an implementation guide works",
"profile": [
"http://hl7.org/fhir/us/core/StructureDefinition/patient"
"http://hl7.org/fhir/us/core/StructureDefinition/patient",
"http://hl7.org/fhir/uv/ips/StructureDefinition/Patient-uv-ips"
]
}
],