diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/ImplementationGuide30_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/ImplementationGuide30_50.java index e657fdd2e..b26c0f7cd 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/ImplementationGuide30_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/ImplementationGuide30_50.java @@ -22,10 +22,10 @@ import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r5.model.CanonicalType; import org.hl7.fhir.r5.model.Enumeration; -static final String EXT_IG_DEFINITION_RESOURCE_PROFILE = "http://hl7.org/fhir/5.0/StructureDefinition/extension-ImplementationGuide.definition.resource.profile"; - 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; @@ -211,8 +211,8 @@ public class ImplementationGuide30_50 { 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()-1)) { - tgt.addExtension(EXT_IG_DEFINITION_RESOURCE_PROFILE, Canonical30_50.convertCanonical(p)); + for (CanonicalType p: src.getProfile().subList(1, src.getProfile().size())) { + tgt.addExtension(EXT_IG_DEFINITION_RESOURCE_PROFILE, Reference30_50.convertCanonicalToReference(p)); } } } else if (src.hasIsExample()) @@ -234,8 +234,8 @@ 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 (Extension ext: src.getExtensionsByUrl(EXT_IG_DEFINITION_RESOURCE_PROFILE)) { - tgt.getProfile().add(Canonical30_50.convertCanonical((org.hl7.fhir.r3.model.CanonicalType)ext.getValue())); + for (org.hl7.fhir.dstu3.model.Extension ext: src.getExtensionsByUrl(EXT_IG_DEFINITION_RESOURCE_PROFILE)) { + tgt.getProfile().add(Reference30_50.convertReferenceToCanonical((org.hl7.fhir.dstu3.model.Reference)ext.getValue())); } if (src.hasExampleFor()) { tgt.getProfile().add(Reference30_50.convertReferenceToCanonical(src.getExampleFor())); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/ImplementationGuide40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/ImplementationGuide40_50.java index d0e8d2bfd..6aa82d66a 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/ImplementationGuide40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/ImplementationGuide40_50.java @@ -350,7 +350,7 @@ public class ImplementationGuide40_50 { 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()-1)) { + for (CanonicalType p: src.getProfile().subList(1, src.getProfile().size())) { tgt.addExtension(EXT_IG_DEFINITION_RESOURCE_PROFILE, Canonical40_50.convertCanonical(p)); } } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/ImplementationGuide43_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/ImplementationGuide43_50.java index d69d5549f..7e6999aee 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/ImplementationGuide43_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/ImplementationGuide43_50.java @@ -320,8 +320,8 @@ public class ImplementationGuide43_50 { tgt.setIsExample(true); tgt.getProfile().add(Canonical43_50.convertCanonical(src.getExampleCanonicalType())); } - for (Extension ext: src.getExtensionsByUrl(EXT_IG_DEFINITION_RESOURCE_PROFILE)) { - tgt.getProfile().add(Canonical43_50.convertCanonical((org.hl7.fhir.r43.model.CanonicalType)ext.getValue())); + 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())); @@ -347,7 +347,7 @@ public class ImplementationGuide43_50 { 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()-1)) { + for (CanonicalType p: src.getProfile().subList(1, src.getProfile().size())) { tgt.addExtension(EXT_IG_DEFINITION_RESOURCE_PROFILE, Canonical43_50.convertCanonical(p)); } } diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/ImplementationGuide40_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/ImplementationGuide40_50Test.java index df5919c64..6d71403d4 100644 --- a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/ImplementationGuide40_50Test.java +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/ImplementationGuide40_50Test.java @@ -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"); diff --git a/org.hl7.fhir.convertors/src/test/resources/implementation_guide_50.json b/org.hl7.fhir.convertors/src/test/resources/implementation_guide_50.json index 85e113f2f..f86eb441a 100644 --- a/org.hl7.fhir.convertors/src/test/resources/implementation_guide_50.json +++ b/org.hl7.fhir.convertors/src/test/resources/implementation_guide_50.json @@ -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" ] } ],