From 6956f395025c5f9c86a2d77678aa65fbb27bdf1f Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 5 Jul 2023 07:17:08 +1000 Subject: [PATCH] #1329 Fix up type handling for conversions between R4/R4B and R5 (OperationDefinition.parameter.type) --- .../convertors/VersionConvertorConstants.java | 1 + .../datatypes40_50/Utilities40_50.java | 72 ++++++++++++++++++ .../metadata40_50/DataRequirement40_50.java | 26 ++----- .../ParameterDefinition40_50.java | 9 ++- .../OperationDefinition40_50.java | 13 +++- .../convertors/conv43_50/Utilities43_50.java | 73 +++++++++++++++++++ .../metadata43_50/DataRequirement43_50.java | 26 ++----- .../ParameterDefinition43_50.java | 9 ++- .../OperationDefinition43_50.java | 12 ++- .../OperationDefinition40_50Test.java | 35 +++++++++ .../src/test/resources/opdef-4.xml | 22 ++++++ 11 files changed, 248 insertions(+), 50 deletions(-) create mode 100644 org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/Utilities40_50.java create mode 100644 org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/Utilities43_50.java create mode 100644 org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/OperationDefinition40_50Test.java create mode 100644 org.hl7.fhir.convertors/src/test/resources/opdef-4.xml diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorConstants.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorConstants.java index a334cd3f4..74dd8352e 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorConstants.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertorConstants.java @@ -47,6 +47,7 @@ public class VersionConvertorConstants { public static final String EXT_NAMINGSYSTEM_TITLE = "http://hl7.org/fhir/5.0/StructureDefinition/extension-NamingSystem.title"; public static final String EXT_NAMINGSYSTEM_URL = "http://hl7.org/fhir/5.0/StructureDefinition/extension-NamingSystem.url"; public static final String EXT_NAMINGSYSTEM_VERSION = "http://hl7.org/fhir/5.0/StructureDefinition/extension-NamingSystem.version"; + public static final String EXT_OPDEF_ORIGINAL_TYPE = "http://hl7.org/fhir/4.0/StructureDefinition/extension-OperationDefinition.parameter.type"; public static String refToVS(String url) { if (url == null) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/Utilities40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/Utilities40_50.java new file mode 100644 index 000000000..7ce96d06c --- /dev/null +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/Utilities40_50.java @@ -0,0 +1,72 @@ +package org.hl7.fhir.convertors.conv40_50.datatypes40_50; + +import org.hl7.fhir.convertors.VersionConvertorConstants; +import org.hl7.fhir.r5.model.CodeType; +import org.hl7.fhir.r5.model.Extension; +import org.hl7.fhir.r5.model.Enumeration; +import org.hl7.fhir.r5.model.Enumerations.FHIRTypes; +import org.hl7.fhir.utilities.Utilities; + +public class Utilities40_50 { + + public static void convertType(org.hl7.fhir.r4.model.CodeType src, org.hl7.fhir.r5.model.Enumeration tgt) { + if (Utilities.existsInList(src.primitiveValue(), "Media")) { + setType(tgt, src.primitiveValue(), "DocumentReference"); + + } else if (Utilities.existsInList(src.primitiveValue(), "DeviceUseStatement")) { + setType(tgt, src.primitiveValue(), "DeviceUsage"); + + } else if (Utilities.existsInList(src.primitiveValue(), "DocumentManifest")) { + setType(tgt, src.primitiveValue(), "List"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProduct")) { + setType(tgt, src.primitiveValue(), "MedicinalProductDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductAuthorization")) { + setType(tgt, src.primitiveValue(), "RegulatedAuthorization"); + + } else if (Utilities.existsInList(src.primitiveValue(), "RequestGroup")) { + setType(tgt, src.primitiveValue(), "RequestOrchestration"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductIngredient")) { + setType(tgt, src.primitiveValue(), "Ingredient"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductManufactured")) { + setType(tgt, src.primitiveValue(), "ManufacturedItemDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductPackaged")) { + setType(tgt, src.primitiveValue(), "PackagedProductDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductPharmaceutical")) { + setType(tgt, src.primitiveValue(), "AdministrableProductDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "SubstanceSpecification")) { + setType(tgt, src.primitiveValue(), "SubstanceDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductContraindication", "MedicinalProductIndication", "MedicinalProductInteraction", "MedicinalProductUndesirableEffect", "ClinicalUseDefinition")) { + setType(tgt, src.primitiveValue(), "SubstanceDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "EffectEvidenceSynthesis", "CatalogEntry", "ResearchDefinition", "ResearchElementDefinition", "RiskEvidenceSynthesis", + "Contributor", "ProdCharacteristic", "SubstanceAmount")) { + setType(tgt, src.primitiveValue(), "Basic"); + + } else { + tgt.setValue(org.hl7.fhir.r5.model.Enumerations.FHIRTypes.fromCode(src.primitiveValue())); + } + } + + private static void setType(org.hl7.fhir.r5.model.Enumeration tgt, String original, String value) { + tgt.setValueAsString(value); + tgt.addExtension(new Extension().setUrl(VersionConvertorConstants.EXT_OPDEF_ORIGINAL_TYPE).setValue(new CodeType(original))); + } + + public static void convertType(org.hl7.fhir.r5.model.Enumeration src, org.hl7.fhir.r4.model.CodeType tgt) { + if (src.hasExtension(VersionConvertorConstants.EXT_OPDEF_ORIGINAL_TYPE)) { + tgt.setValueAsString(src.getExtensionString(VersionConvertorConstants.EXT_OPDEF_ORIGINAL_TYPE)); + } else { + tgt.setValue(src.asStringValue()); + } + + } + +} diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/metadata40_50/DataRequirement40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/metadata40_50/DataRequirement40_50.java index 9ced2333b..f13dd92e2 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/metadata40_50/DataRequirement40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/metadata40_50/DataRequirement40_50.java @@ -1,6 +1,7 @@ package org.hl7.fhir.convertors.conv40_50.datatypes40_50.metadata40_50; import org.hl7.fhir.convertors.context.ConversionContext40_50; +import org.hl7.fhir.convertors.conv40_50.datatypes40_50.Utilities40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Coding40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Canonical40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.PositiveInt40_50; @@ -12,8 +13,9 @@ public class DataRequirement40_50 { if (src == null) return null; org.hl7.fhir.r5.model.DataRequirement tgt = new org.hl7.fhir.r5.model.DataRequirement(); ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); - if (src.hasType()) - tgt.setType(org.hl7.fhir.r5.model.Enumerations.FHIRTypes.fromCode(convertResourceName4to5(src.getType()))); + if (src.hasType()) { + Utilities40_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } for (org.hl7.fhir.r4.model.CanonicalType t : src.getProfile()) tgt.getProfile().add(Canonical40_50.convertCanonical(t)); if (src.hasSubject()) @@ -34,7 +36,9 @@ public class DataRequirement40_50 { if (src == null) return null; org.hl7.fhir.r4.model.DataRequirement tgt = new org.hl7.fhir.r4.model.DataRequirement(); ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); - if (src.hasType()) tgt.setType(convertResourceName5to4(src.getType().toCode())); + if (src.hasType()) { + Utilities40_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } for (org.hl7.fhir.r5.model.CanonicalType t : src.getProfile()) tgt.getProfile().add(Canonical40_50.convertCanonical(t)); if (src.hasSubject()) @@ -51,22 +55,6 @@ public class DataRequirement40_50 { return tgt; } - private static String convertResourceName4to5(String name) { - if (name == null) return null; - if (name.equals("DeviceUseStatement")) { - return "DeviceUsage"; - } - return name; - } - - private static String convertResourceName5to4(String name) { - if (name == null) return null; - if (name.equals("DeviceUsage")) { - return "DeviceUseStatement"; - } - return name; - } - public static org.hl7.fhir.r5.model.DataRequirement.DataRequirementCodeFilterComponent convertDataRequirementCodeFilterComponent(org.hl7.fhir.r4.model.DataRequirement.DataRequirementCodeFilterComponent src) throws FHIRException { if (src == null) return null; org.hl7.fhir.r5.model.DataRequirement.DataRequirementCodeFilterComponent tgt = new org.hl7.fhir.r5.model.DataRequirement.DataRequirementCodeFilterComponent(); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/metadata40_50/ParameterDefinition40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/metadata40_50/ParameterDefinition40_50.java index e36b71456..8838e3021 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/metadata40_50/ParameterDefinition40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/metadata40_50/ParameterDefinition40_50.java @@ -1,6 +1,7 @@ package org.hl7.fhir.convertors.conv40_50.datatypes40_50.metadata40_50; import org.hl7.fhir.convertors.context.ConversionContext40_50; +import org.hl7.fhir.convertors.conv40_50.datatypes40_50.Utilities40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Canonical40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Code40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Integer40_50; @@ -17,7 +18,9 @@ public class ParameterDefinition40_50 { if (src.hasMin()) tgt.setMinElement(Integer40_50.convertInteger(src.getMinElement())); if (src.hasMax()) tgt.setMaxElement(String40_50.convertString(src.getMaxElement())); if (src.hasDocumentation()) tgt.setDocumentationElement(String40_50.convertString(src.getDocumentationElement())); - if (src.hasType()) tgt.setType(org.hl7.fhir.r5.model.Enumerations.FHIRTypes.fromCode(src.getType())); + if (src.hasType()) { + Utilities40_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } if (src.hasProfile()) tgt.setProfileElement(Canonical40_50.convertCanonical(src.getProfileElement())); return tgt; } @@ -31,7 +34,9 @@ public class ParameterDefinition40_50 { if (src.hasMin()) tgt.setMinElement(Integer40_50.convertInteger(src.getMinElement())); if (src.hasMax()) tgt.setMaxElement(String40_50.convertString(src.getMaxElement())); if (src.hasDocumentation()) tgt.setDocumentationElement(String40_50.convertString(src.getDocumentationElement())); - if (src.hasType()) tgt.setType(src.getType().toCode()); + if (src.hasType()) { + Utilities40_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } if (src.hasProfile()) tgt.setProfileElement(Canonical40_50.convertCanonical(src.getProfileElement())); return tgt; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/OperationDefinition40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/OperationDefinition40_50.java index d4088c0e6..6334bfbf1 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/OperationDefinition40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/OperationDefinition40_50.java @@ -1,6 +1,8 @@ package org.hl7.fhir.convertors.conv40_50.resources40_50; +import org.hl7.fhir.convertors.VersionConvertorConstants; import org.hl7.fhir.convertors.context.ConversionContext40_50; +import org.hl7.fhir.convertors.conv40_50.datatypes40_50.Utilities40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.CodeableConcept40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.metadata40_50.ContactDetail40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.metadata40_50.UsageContext40_50; @@ -18,6 +20,7 @@ import org.hl7.fhir.r5.model.CodeType; import org.hl7.fhir.r5.model.Enumeration; import org.hl7.fhir.r5.model.Enumerations.VersionIndependentResourceTypesAll; import org.hl7.fhir.r5.model.Enumerations.VersionIndependentResourceTypesAllEnumFactory; +import org.hl7.fhir.utilities.Utilities; /* Copyright (c) 2011+, HL7, Inc. @@ -221,8 +224,9 @@ public class OperationDefinition40_50 { tgt.setMaxElement(String40_50.convertString(src.getMaxElement())); if (src.hasDocumentation()) tgt.setDocumentationElement(String40_50.convertStringToMarkdown(src.getDocumentationElement())); - if (src.hasType()) - tgt.getTypeElement().setValue(org.hl7.fhir.r5.model.Enumerations.FHIRTypes.fromCode(src.getType())); + if (src.hasType()) { + Utilities40_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } for (org.hl7.fhir.r4.model.CanonicalType t : src.getTargetProfile()) tgt.getTargetProfile().add(Canonical40_50.convertCanonical(t)); if (src.hasSearchType()) @@ -251,8 +255,9 @@ public class OperationDefinition40_50 { tgt.setMaxElement(String40_50.convertString(src.getMaxElement())); if (src.hasDocumentation()) tgt.setDocumentationElement(String40_50.convertString(src.getDocumentationElement())); - if (src.hasType()) - tgt.setTypeElement(new org.hl7.fhir.r4.model.CodeType(src.getType().toCode())); + if (src.hasType()) { + Utilities40_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } for (org.hl7.fhir.r5.model.CanonicalType t : src.getTargetProfile()) tgt.getTargetProfile().add(Canonical40_50.convertCanonical(t)); if (src.hasSearchType()) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/Utilities43_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/Utilities43_50.java new file mode 100644 index 000000000..0cd968660 --- /dev/null +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/Utilities43_50.java @@ -0,0 +1,73 @@ +package org.hl7.fhir.convertors.conv43_50; + +import org.hl7.fhir.convertors.VersionConvertorConstants; +import org.hl7.fhir.r4b.model.Enumerations.FHIRAllTypes; +import org.hl7.fhir.r5.model.CodeType; +import org.hl7.fhir.r5.model.Extension; +import org.hl7.fhir.r5.model.Enumeration; +import org.hl7.fhir.r5.model.Enumerations.FHIRTypes; +import org.hl7.fhir.utilities.Utilities; + +public class Utilities43_50 { + + public static void convertType(org.hl7.fhir.r4b.model.Enumeration src, org.hl7.fhir.r5.model.Enumeration tgt) { + if (Utilities.existsInList(src.primitiveValue(), "Media")) { + setType(tgt, src.primitiveValue(), "DocumentReference"); + + } else if (Utilities.existsInList(src.primitiveValue(), "DeviceUseStatement")) { + setType(tgt, src.primitiveValue(), "DeviceUsage"); + + } else if (Utilities.existsInList(src.primitiveValue(), "DocumentManifest")) { + setType(tgt, src.primitiveValue(), "List"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProduct")) { + setType(tgt, src.primitiveValue(), "MedicinalProductDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductAuthorization")) { + setType(tgt, src.primitiveValue(), "RegulatedAuthorization"); + + } else if (Utilities.existsInList(src.primitiveValue(), "RequestGroup")) { + setType(tgt, src.primitiveValue(), "RequestOrchestration"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductIngredient")) { + setType(tgt, src.primitiveValue(), "Ingredient"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductManufactured")) { + setType(tgt, src.primitiveValue(), "ManufacturedItemDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductPackaged")) { + setType(tgt, src.primitiveValue(), "PackagedProductDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductPharmaceutical")) { + setType(tgt, src.primitiveValue(), "AdministrableProductDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "SubstanceSpecification")) { + setType(tgt, src.primitiveValue(), "SubstanceDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "MedicinalProductContraindication", "MedicinalProductIndication", "MedicinalProductInteraction", "MedicinalProductUndesirableEffect", "ClinicalUseDefinition")) { + setType(tgt, src.primitiveValue(), "SubstanceDefinition"); + + } else if (Utilities.existsInList(src.primitiveValue(), "EffectEvidenceSynthesis", "CatalogEntry", "ResearchDefinition", "ResearchElementDefinition", "RiskEvidenceSynthesis", + "Contributor", "ProdCharacteristic", "SubstanceAmount")) { + setType(tgt, src.primitiveValue(), "Basic"); + + } else { + tgt.setValue(org.hl7.fhir.r5.model.Enumerations.FHIRTypes.fromCode(src.primitiveValue())); + } + } + + private static void setType(org.hl7.fhir.r5.model.Enumeration tgt, String original, String value) { + tgt.setValueAsString(value); + tgt.addExtension(new Extension().setUrl(VersionConvertorConstants.EXT_OPDEF_ORIGINAL_TYPE).setValue(new CodeType(original))); + } + + public static void convertType(org.hl7.fhir.r5.model.Enumeration src, org.hl7.fhir.r4b.model.Enumeration tgt) { + if (src.hasExtension(VersionConvertorConstants.EXT_OPDEF_ORIGINAL_TYPE)) { + tgt.setValueAsString(src.getExtensionString(VersionConvertorConstants.EXT_OPDEF_ORIGINAL_TYPE)); + } else { + tgt.setValueAsString(src.asStringValue()); + } + + } + +} diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/metadata43_50/DataRequirement43_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/metadata43_50/DataRequirement43_50.java index eb4de6330..d2608057f 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/metadata43_50/DataRequirement43_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/metadata43_50/DataRequirement43_50.java @@ -1,6 +1,7 @@ package org.hl7.fhir.convertors.conv43_50.datatypes43_50.metadata43_50; import org.hl7.fhir.convertors.context.ConversionContext43_50; +import org.hl7.fhir.convertors.conv43_50.Utilities43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.Coding43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Canonical43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.PositiveInt43_50; @@ -12,8 +13,9 @@ public class DataRequirement43_50 { if (src == null) return null; org.hl7.fhir.r5.model.DataRequirement tgt = new org.hl7.fhir.r5.model.DataRequirement(); ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt); - if (src.hasType()) - tgt.setType(org.hl7.fhir.r5.model.Enumerations.FHIRTypes.fromCode(convertResourceName4to5(src.getType().toCode()))); + if (src.hasType()) { + Utilities43_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } for (org.hl7.fhir.r4b.model.CanonicalType t : src.getProfile()) tgt.getProfile().add(Canonical43_50.convertCanonical(t)); if (src.hasSubject()) @@ -34,7 +36,9 @@ public class DataRequirement43_50 { if (src == null) return null; org.hl7.fhir.r4b.model.DataRequirement tgt = new org.hl7.fhir.r4b.model.DataRequirement(); ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt); - if (src.hasType()) tgt.getTypeElement().setValueAsString(convertResourceName5to4(src.getType().toCode())); + if (src.hasType()) { + Utilities43_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } for (org.hl7.fhir.r5.model.CanonicalType t : src.getProfile()) tgt.getProfile().add(Canonical43_50.convertCanonical(t)); if (src.hasSubject()) @@ -51,22 +55,6 @@ public class DataRequirement43_50 { return tgt; } - private static String convertResourceName4to5(String name) { - if (name == null) return null; - if (name.equals("DeviceUseStatement")) { - return "DeviceUsage"; - } - return name; - } - - private static String convertResourceName5to4(String name) { - if (name == null) return null; - if (name.equals("DeviceUsage")) { - return "DeviceUseStatement"; - } - return name; - } - public static org.hl7.fhir.r5.model.DataRequirement.DataRequirementCodeFilterComponent convertDataRequirementCodeFilterComponent(org.hl7.fhir.r4b.model.DataRequirement.DataRequirementCodeFilterComponent src) throws FHIRException { if (src == null) return null; org.hl7.fhir.r5.model.DataRequirement.DataRequirementCodeFilterComponent tgt = new org.hl7.fhir.r5.model.DataRequirement.DataRequirementCodeFilterComponent(); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/metadata43_50/ParameterDefinition43_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/metadata43_50/ParameterDefinition43_50.java index 98a738cfd..461dc791c 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/metadata43_50/ParameterDefinition43_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/metadata43_50/ParameterDefinition43_50.java @@ -1,6 +1,7 @@ package org.hl7.fhir.convertors.conv43_50.datatypes43_50.metadata43_50; import org.hl7.fhir.convertors.context.ConversionContext43_50; +import org.hl7.fhir.convertors.conv43_50.Utilities43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Canonical43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Code43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Integer43_50; @@ -17,7 +18,9 @@ public class ParameterDefinition43_50 { if (src.hasMin()) tgt.setMinElement(Integer43_50.convertInteger(src.getMinElement())); if (src.hasMax()) tgt.setMaxElement(String43_50.convertString(src.getMaxElement())); if (src.hasDocumentation()) tgt.setDocumentationElement(String43_50.convertString(src.getDocumentationElement())); - if (src.hasType()) tgt.setType(org.hl7.fhir.r5.model.Enumerations.FHIRTypes.fromCode(src.getType().toCode())); + if (src.hasType()) { + Utilities43_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } if (src.hasProfile()) tgt.setProfileElement(Canonical43_50.convertCanonical(src.getProfileElement())); return tgt; } @@ -31,7 +34,9 @@ public class ParameterDefinition43_50 { if (src.hasMin()) tgt.setMinElement(Integer43_50.convertInteger(src.getMinElement())); if (src.hasMax()) tgt.setMaxElement(String43_50.convertString(src.getMaxElement())); if (src.hasDocumentation()) tgt.setDocumentationElement(String43_50.convertString(src.getDocumentationElement())); - if (src.hasType()) tgt.getTypeElement().setValueAsString(src.getType().toCode()); + if (src.hasType()) { + Utilities43_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } if (src.hasProfile()) tgt.setProfileElement(Canonical43_50.convertCanonical(src.getProfileElement())); return tgt; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/OperationDefinition43_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/OperationDefinition43_50.java index 6484bf154..1f5b8731a 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/OperationDefinition43_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/OperationDefinition43_50.java @@ -1,6 +1,8 @@ package org.hl7.fhir.convertors.conv43_50.resources43_50; import org.hl7.fhir.convertors.context.ConversionContext43_50; +import org.hl7.fhir.convertors.conv40_50.datatypes40_50.Utilities40_50; +import org.hl7.fhir.convertors.conv43_50.Utilities43_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; @@ -220,8 +222,9 @@ public class OperationDefinition43_50 { tgt.setMaxElement(String43_50.convertString(src.getMaxElement())); if (src.hasDocumentation()) tgt.setDocumentationElement(String43_50.convertStringToMarkdown(src.getDocumentationElement())); - if (src.hasType()) - tgt.getTypeElement().setValue(org.hl7.fhir.r5.model.Enumerations.FHIRTypes.fromCode(src.getType().toCode())); + if (src.hasType()) { + Utilities43_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } for (org.hl7.fhir.r4b.model.CanonicalType t : src.getTargetProfile()) tgt.getTargetProfile().add(Canonical43_50.convertCanonical(t)); if (src.hasSearchType()) @@ -250,8 +253,9 @@ public class OperationDefinition43_50 { tgt.setMaxElement(String43_50.convertString(src.getMaxElement())); if (src.hasDocumentation()) tgt.setDocumentationElement(String43_50.convertString(src.getDocumentationElement())); - if (src.hasType()) - tgt.getTypeElement().setValueAsString(src.getType().toCode()); + if (src.hasType()) { + Utilities43_50.convertType(src.getTypeElement(), tgt.getTypeElement()); + } for (org.hl7.fhir.r5.model.CanonicalType t : src.getTargetProfile()) tgt.getTargetProfile().add(Canonical43_50.convertCanonical(t)); if (src.hasSearchType()) diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/OperationDefinition40_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/OperationDefinition40_50Test.java new file mode 100644 index 000000000..881d2eb2a --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/OperationDefinition40_50Test.java @@ -0,0 +1,35 @@ +package org.hl7.fhir.convertors.conv40_50; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class OperationDefinition40_50Test { + + + @Test + @DisplayName("Test r5 -> r4 OperationDefinition conversion.") + public void testR5_R4() throws IOException { + InputStream r4_input = this.getClass().getResourceAsStream("/opdef-4.xml"); + + org.hl7.fhir.r4.model.OperationDefinition r4_actual = (org.hl7.fhir.r4.model.OperationDefinition) new org.hl7.fhir.r4.formats.XmlParser().parse(r4_input); + org.hl7.fhir.r5.model.Resource r5_conv = VersionConvertorFactory_40_50.convertResource(r4_actual); + + org.hl7.fhir.r5.formats.XmlParser r5_parser = new org.hl7.fhir.r5.formats.XmlParser(); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + r5_parser.compose(stream, r5_conv); + + org.hl7.fhir.r5.model.Resource r5_streamed = (org.hl7.fhir.r5.model.OperationDefinition) new org.hl7.fhir.r5.formats.XmlParser().parse(new ByteArrayInputStream(stream.toByteArray())); + org.hl7.fhir.r4.model.Resource r4_conv = VersionConvertorFactory_40_50.convertResource(r5_streamed); + + assertTrue(r4_actual.equalsDeep(r4_conv), "should be the same"); + } +} diff --git a/org.hl7.fhir.convertors/src/test/resources/opdef-4.xml b/org.hl7.fhir.convertors/src/test/resources/opdef-4.xml new file mode 100644 index 000000000..87e87c503 --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/opdef-4.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file