From 13254f39a2e64a190e431e6bd87ed7cc1f958fa4 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 9 May 2023 18:46:39 -0500 Subject: [PATCH] support for NamingSystem conversion of url, version, and title (for THO) --- .../convertors/VersionConvertorConstants.java | 3 ++ .../resources10_50/NamingSystem10_50.java | 26 +++++++++++++- .../resources14_50/NamingSystem14_50.java | 17 ++++++++- .../resources30_50/NamingSystem30_50.java | 27 +++++++++++++- .../resources40_50/NamingSystem40_50.java | 30 +++++++++++++++- .../primitive43_50/Uri43_50.java | 14 ++++++++ .../resources43_50/NamingSystem43_50.java | 25 ++++++++++++- .../conv40_50/NamingSystem40_50Test.java | 33 +++++++++++++++++ .../conv43_50/NamingSystem43_50Test.java | 33 +++++++++++++++++ .../src/test/resources/naming_system_r4.xml | 31 ++++++++++++++++ .../hl7/fhir/dstu2/model/DomainResource.java | 22 ++++++++++++ .../dstu2016may/model/DomainResource.java | 24 +++++++++++++ .../org/hl7/fhir/r5/model/DomainResource.java | 35 +++++++------------ 13 files changed, 293 insertions(+), 27 deletions(-) create mode 100644 org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/NamingSystem40_50Test.java create mode 100644 org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv43_50/NamingSystem43_50Test.java create mode 100644 org.hl7.fhir.convertors/src/test/resources/naming_system_r4.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 628779513..a334cd3f4 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 @@ -44,6 +44,9 @@ public class VersionConvertorConstants { public static final String EXT_OLD_CONCEPTMAP_EQUIVALENCE = "http://hl7.org/fhir/1.0/StructureDefinition/extension-ConceptMap.element.target.equivalence"; public static final String EXT_ACTUAL_RESOURCE_NAME = "http://hl7.org/fhir/tools/StructureDefinition/original-resource-name"; public static final String EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL = QuestionnaireRenderer.EXT_QUESTIONNAIRE_ITEM_TYPE_ORIGINAL; + 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 String refToVS(String url) { if (url == null) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/resources10_50/NamingSystem10_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/resources10_50/NamingSystem10_50.java index 1bbab8de2..08863bcb2 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/resources10_50/NamingSystem10_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_50/resources10_50/NamingSystem10_50.java @@ -1,5 +1,6 @@ package org.hl7.fhir.convertors.conv10_50.resources10_50; +import org.hl7.fhir.convertors.VersionConvertorConstants; import org.hl7.fhir.convertors.context.ConversionContext10_50; import org.hl7.fhir.convertors.conv10_50.VersionConvertor_10_50; import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.CodeableConcept10_50; @@ -8,6 +9,12 @@ import org.hl7.fhir.convertors.conv10_50.datatypes10_50.complextypes10_50.Period import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Boolean10_50; import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.DateTime10_50; import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.String10_50; +import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Uri10_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.String43_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Uri43_50; +import org.hl7.fhir.dstu2.model.Extension; +import org.hl7.fhir.dstu2.model.StringType; +import org.hl7.fhir.dstu2.model.UriType; import org.hl7.fhir.exceptions.FHIRException; public class NamingSystem10_50 { @@ -17,8 +24,14 @@ public class NamingSystem10_50 { return null; org.hl7.fhir.dstu2.model.NamingSystem tgt = new org.hl7.fhir.dstu2.model.NamingSystem(); ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt); + if (src.hasUrlElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL).setValue(Uri10_50.convertUri(src.getUrlElement()))); + if (src.hasVersionElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION).setValue(String10_50.convertString(src.getVersionElement()))); if (src.hasNameElement()) tgt.setNameElement(String10_50.convertString(src.getNameElement())); + if (src.hasTitleElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).setValue(String10_50.convertString(src.getTitleElement()))); if (src.hasStatus()) tgt.setStatusElement(Enumerations10_50.convertConformanceResourceStatus(src.getStatusElement())); if (src.hasKind()) @@ -51,9 +64,20 @@ public class NamingSystem10_50 { if (src == null || src.isEmpty()) return null; org.hl7.fhir.r5.model.NamingSystem tgt = new org.hl7.fhir.r5.model.NamingSystem(); - ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt); + ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyDomainResource(src, tgt, VersionConvertorConstants.EXT_NAMINGSYSTEM_URL, VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION, VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE); + + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL)) { + tgt.setUrlElement(Uri10_50.convertUri((UriType) src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL).getValue())); + } + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION)) { + tgt.setVersionElement(String10_50.convertString((StringType) src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION).getValue())); + } if (src.hasNameElement()) tgt.setNameElement(String10_50.convertString(src.getNameElement())); + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE)) { + tgt.setTitleElement(String10_50.convertString((StringType) src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).getValue())); + } + if (src.hasStatus()) tgt.setStatusElement(Enumerations10_50.convertConformanceResourceStatus(src.getStatusElement())); if (src.hasKind()) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/NamingSystem14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/NamingSystem14_50.java index 63c2f36a7..a41e3119d 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/NamingSystem14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/NamingSystem14_50.java @@ -1,5 +1,6 @@ package org.hl7.fhir.convertors.conv14_50.resources14_50; +import org.hl7.fhir.convertors.VersionConvertorConstants; import org.hl7.fhir.convertors.context.ConversionContext14_50; import org.hl7.fhir.convertors.conv14_50.datatypes14_50.complextypes14_50.CodeableConcept14_50; import org.hl7.fhir.convertors.conv14_50.datatypes14_50.complextypes14_50.ContactPoint14_50; @@ -7,6 +8,9 @@ import org.hl7.fhir.convertors.conv14_50.datatypes14_50.complextypes14_50.Period import org.hl7.fhir.convertors.conv14_50.datatypes14_50.primitivetypes14_50.Boolean14_50; import org.hl7.fhir.convertors.conv14_50.datatypes14_50.primitivetypes14_50.DateTime14_50; import org.hl7.fhir.convertors.conv14_50.datatypes14_50.primitivetypes14_50.String14_50; +import org.hl7.fhir.convertors.conv14_50.datatypes14_50.primitivetypes14_50.Uri14_50; +import org.hl7.fhir.dstu2016may.model.Extension; +import org.hl7.fhir.dstu2016may.model.StringType; import org.hl7.fhir.exceptions.FHIRException; public class NamingSystem14_50 { @@ -14,10 +18,14 @@ public class NamingSystem14_50 { public static org.hl7.fhir.r5.model.NamingSystem convertNamingSystem(org.hl7.fhir.dstu2016may.model.NamingSystem src) throws FHIRException { if (src == null || src.isEmpty()) return null; + org.hl7.fhir.r5.model.NamingSystem tgt = new org.hl7.fhir.r5.model.NamingSystem(); - ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyDomainResource(src, tgt); + ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyDomainResource(src, tgt, VersionConvertorConstants.EXT_NAMINGSYSTEM_URL, VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION, VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE); if (src.hasNameElement()) tgt.setNameElement(String14_50.convertString(src.getNameElement())); + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE)) { + tgt.setTitleElement(String14_50.convertString((StringType) src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).getValue())); + } if (src.hasStatus()) tgt.setStatusElement(Enumerations14_50.convertConformanceResourceStatus(src.getStatusElement())); if (src.hasKind()) @@ -51,8 +59,15 @@ public class NamingSystem14_50 { return null; org.hl7.fhir.dstu2016may.model.NamingSystem tgt = new org.hl7.fhir.dstu2016may.model.NamingSystem(); ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyDomainResource(src, tgt); + if (src.hasUrlElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL).setValue(Uri14_50.convertUri(src.getUrlElement()))); + if (src.hasVersionElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION).setValue(String14_50.convertString(src.getVersionElement()))); + if (src.hasNameElement()) tgt.setNameElement(String14_50.convertString(src.getNameElement())); + if (src.hasTitleElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).setValue(String14_50.convertString(src.getTitleElement()))); if (src.hasStatus()) tgt.setStatusElement(Enumerations14_50.convertConformanceResourceStatus(src.getStatusElement())); if (src.hasKind()) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/NamingSystem30_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/NamingSystem30_50.java index 951f7a3fe..7d8464f16 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/NamingSystem30_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/NamingSystem30_50.java @@ -1,6 +1,8 @@ package org.hl7.fhir.convertors.conv30_50.resources30_50; +import org.hl7.fhir.convertors.VersionConvertorConstants; import org.hl7.fhir.convertors.context.ConversionContext30_50; +import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Uri10_50; import org.hl7.fhir.convertors.conv30_50.datatypes30_50.ContactDetail30_50; import org.hl7.fhir.convertors.conv30_50.datatypes30_50.UsageContext30_50; import org.hl7.fhir.convertors.conv30_50.datatypes30_50.complextypes30_50.CodeableConcept30_50; @@ -9,6 +11,12 @@ import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Bool import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.DateTime30_50; import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.MarkDown30_50; import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.String30_50; +import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Uri30_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.String43_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Uri43_50; +import org.hl7.fhir.dstu3.model.Extension; +import org.hl7.fhir.dstu3.model.StringType; +import org.hl7.fhir.dstu3.model.UriType; import org.hl7.fhir.exceptions.FHIRException; public class NamingSystem30_50 { @@ -18,8 +26,15 @@ public class NamingSystem30_50 { return null; org.hl7.fhir.dstu3.model.NamingSystem tgt = new org.hl7.fhir.dstu3.model.NamingSystem(); ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt); + if (src.hasUrlElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL).setValue(Uri30_50.convertUri(src.getUrlElement()))); + if (src.hasVersionElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION).setValue(String30_50.convertString(src.getVersionElement()))); if (src.hasName()) tgt.setNameElement(String30_50.convertString(src.getNameElement())); + if (src.hasTitleElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).setValue(String30_50.convertString(src.getTitleElement()))); + if (src.hasStatus()) tgt.setStatusElement(Enumerations30_50.convertPublicationStatus(src.getStatusElement())); if (src.hasKind()) @@ -51,9 +66,19 @@ public class NamingSystem30_50 { if (src == null) return null; org.hl7.fhir.r5.model.NamingSystem tgt = new org.hl7.fhir.r5.model.NamingSystem(); - ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt); + ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyDomainResource(src, tgt, VersionConvertorConstants.EXT_NAMINGSYSTEM_URL, VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION, VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE); + + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL)) { + tgt.setUrlElement(Uri30_50.convertUri((UriType) src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL).getValue())); + } + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION)) { + tgt.setVersionElement(String30_50.convertString((StringType) src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION).getValue())); + } if (src.hasName()) tgt.setNameElement(String30_50.convertString(src.getNameElement())); + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE)) { + tgt.setTitleElement(String30_50.convertString((StringType) src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).getValue())); + } if (src.hasStatus()) tgt.setStatusElement(Enumerations30_50.convertPublicationStatus(src.getStatusElement())); if (src.hasKind()) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/NamingSystem40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/NamingSystem40_50.java index 92a0480d3..766c2dcd5 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/NamingSystem40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/NamingSystem40_50.java @@ -1,6 +1,9 @@ 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.conv10_50.datatypes10_50.primitivetypes10_50.String10_50; +import org.hl7.fhir.convertors.conv10_50.datatypes10_50.primitivetypes10_50.Uri10_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.CodeableConcept40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Period40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.metadata40_50.ContactDetail40_50; @@ -9,7 +12,13 @@ import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Boolean40 import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.DateTime40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.MarkDown40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.String40_50; +import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Uri40_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.String43_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Uri43_50; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.r4.model.Extension; +import org.hl7.fhir.r4.model.StringType; +import org.hl7.fhir.r4.model.UriType; /* Copyright (c) 2011+, HL7, Inc. @@ -45,10 +54,22 @@ public class NamingSystem40_50 { public static org.hl7.fhir.r5.model.NamingSystem convertNamingSystem(org.hl7.fhir.r4.model.NamingSystem src) throws FHIRException { if (src == null) return null; + org.hl7.fhir.r5.model.NamingSystem tgt = new org.hl7.fhir.r5.model.NamingSystem(); - ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt); + ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt, VersionConvertorConstants.EXT_NAMINGSYSTEM_URL, VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION, VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE); + + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL)) { + tgt.setUrlElement(Uri40_50.convertUri((UriType) src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL).getValue())); + } + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION)) { + tgt.setVersionElement(String40_50.convertString((StringType) src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION).getValue())); + } if (src.hasName()) tgt.setNameElement(String40_50.convertString(src.getNameElement())); + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE)) { + tgt.setTitleElement(String40_50.convertString((StringType) src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).getValue())); + } + if (src.hasStatus()) tgt.setStatusElement(Enumerations40_50.convertPublicationStatus(src.getStatusElement())); if (src.hasKind()) @@ -81,8 +102,15 @@ public class NamingSystem40_50 { return null; org.hl7.fhir.r4.model.NamingSystem tgt = new org.hl7.fhir.r4.model.NamingSystem(); ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyDomainResource(src, tgt); + if (src.hasUrlElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL).setValue(Uri40_50.convertUri(src.getUrlElement()))); + if (src.hasVersionElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION).setValue(String40_50.convertString(src.getVersionElement()))); if (src.hasName()) tgt.setNameElement(String40_50.convertString(src.getNameElement())); + if (src.hasTitleElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).setValue(String40_50.convertString(src.getTitleElement()))); + if (src.hasStatus()) tgt.setStatusElement(Enumerations40_50.convertPublicationStatus(src.getStatusElement())); if (src.hasKind()) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/primitive43_50/Uri43_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/primitive43_50/Uri43_50.java index 7dd80d0e4..dd12ca5d4 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/primitive43_50/Uri43_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/primitive43_50/Uri43_50.java @@ -2,6 +2,9 @@ package org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50; import org.hl7.fhir.convertors.context.ConversionContext43_50; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.r4b.model.DataType; +import org.hl7.fhir.r4b.model.PrimitiveType; +import org.hl7.fhir.r5.model.UriType; public class Uri43_50 { public static org.hl7.fhir.r5.model.UriType convertUri(org.hl7.fhir.r4b.model.UriType src) throws FHIRException { @@ -15,4 +18,15 @@ public class Uri43_50 { ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt); return tgt; } + + public static UriType convertToUri(DataType src) { + if (src instanceof PrimitiveType) { + PrimitiveType p = (PrimitiveType) src; + org.hl7.fhir.r5.model.UriType tgt = p.hasValue() ? new org.hl7.fhir.r5.model.UriType(p.getValueAsString()) : new org.hl7.fhir.r5.model.UriType(); + ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyElement(src, tgt); + return tgt; + } else { + throw new FHIRException("Unable to convert "+src.fhirType()+" to a URI Type"); + } + } } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/NamingSystem43_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/NamingSystem43_50.java index e0213c94c..a6549fcb1 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/NamingSystem43_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/NamingSystem43_50.java @@ -1,6 +1,9 @@ package org.hl7.fhir.convertors.conv43_50.resources43_50; +import org.hl7.fhir.convertors.VersionConvertorConstants; import org.hl7.fhir.convertors.context.ConversionContext43_50; +import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.String40_50; +import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Uri40_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.CodeableConcept43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.Period43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.metadata43_50.ContactDetail43_50; @@ -9,7 +12,9 @@ import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Boolean43 import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.DateTime43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.MarkDown43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.String43_50; +import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Uri43_50; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.r4b.model.Extension; /* Copyright (c) 2011+, HL7, Inc. @@ -46,9 +51,19 @@ public class NamingSystem43_50 { if (src == null) return null; org.hl7.fhir.r5.model.NamingSystem tgt = new org.hl7.fhir.r5.model.NamingSystem(); - ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt); + ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt, VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE); + + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL)) { + tgt.setUrlElement(Uri43_50.convertToUri(src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL).getValue())); + } + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION)) { + tgt.setVersionElement(String43_50.convertString(src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION).getValueStringType())); + } if (src.hasName()) tgt.setNameElement(String43_50.convertString(src.getNameElement())); + if (src.hasExtension(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE)) { + tgt.setTitleElement(String43_50.convertString(src.getExtensionByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).getValueStringType())); + } if (src.hasStatus()) tgt.setStatusElement(Enumerations43_50.convertPublicationStatus(src.getStatusElement())); if (src.hasKind()) @@ -81,8 +96,16 @@ public class NamingSystem43_50 { return null; org.hl7.fhir.r4b.model.NamingSystem tgt = new org.hl7.fhir.r4b.model.NamingSystem(); ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyDomainResource(src, tgt); + + if (src.hasUrlElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_URL).setValue(Uri43_50.convertUri(src.getUrlElement()))); + if (src.hasVersionElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_VERSION).setValue(String43_50.convertString(src.getVersionElement()))); if (src.hasName()) tgt.setNameElement(String43_50.convertString(src.getNameElement())); + if (src.hasTitleElement()) + tgt.getExtension().add(new Extension().setUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).setValue(String43_50.convertString(src.getTitleElement()))); + if (src.hasStatus()) tgt.setStatusElement(Enumerations43_50.convertPublicationStatus(src.getStatusElement())); if (src.hasKind()) diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/NamingSystem40_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/NamingSystem40_50Test.java new file mode 100644 index 000000000..5c8e027bf --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/NamingSystem40_50Test.java @@ -0,0 +1,33 @@ +package org.hl7.fhir.convertors.conv40_50; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.io.InputStream; + +import org.hl7.fhir.convertors.VersionConvertorConstants; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class NamingSystem40_50Test { + + + @Test + @DisplayName("Test r5 -> r4 NamingSystem conversion.") + public void testR5_R4() throws IOException { + InputStream r4b_input = this.getClass().getResourceAsStream("/naming_system_r4.xml"); + + org.hl7.fhir.r4.model.NamingSystem r4b_actual = (org.hl7.fhir.r4.model.NamingSystem) new org.hl7.fhir.r4.formats.XmlParser().parse(r4b_input); + org.hl7.fhir.r5.model.NamingSystem r5_conv = (org.hl7.fhir.r5.model.NamingSystem) VersionConvertorFactory_40_50.convertResource(r4b_actual); + org.hl7.fhir.r4.model.NamingSystem r4b_conv = (org.hl7.fhir.r4.model.NamingSystem) VersionConvertorFactory_40_50.convertResource(r5_conv); + + assertEquals(1, r4b_actual.getExtensionsByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).size()); + assertEquals(0, r5_conv.getExtensionsByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).size()); + assertEquals("American Dental Association Area of Oral Cavity System", r5_conv.getTitle()); + assertEquals("http://terminology.hl7.org/NamingSystem/ADAAreaOralCavitySystem", r5_conv.getUrl()); + assertEquals("1.0.0", r5_conv.getVersion()); + assertEquals(1, r4b_conv.getExtensionsByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).size()); + + } +} diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv43_50/NamingSystem43_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv43_50/NamingSystem43_50Test.java new file mode 100644 index 000000000..3cdf569a0 --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv43_50/NamingSystem43_50Test.java @@ -0,0 +1,33 @@ +package org.hl7.fhir.convertors.conv43_50; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.io.InputStream; + +import org.hl7.fhir.convertors.VersionConvertorConstants; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_43_50; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class NamingSystem43_50Test { + + + @Test + @DisplayName("Test r5 -> r4 NamingSystem conversion.") + public void testR5_R4() throws IOException { + InputStream r4b_input = this.getClass().getResourceAsStream("/naming_system_r4.xml"); + + org.hl7.fhir.r4b.model.NamingSystem r4b_actual = (org.hl7.fhir.r4b.model.NamingSystem) new org.hl7.fhir.r4b.formats.XmlParser().parse(r4b_input); + org.hl7.fhir.r5.model.NamingSystem r5_conv = (org.hl7.fhir.r5.model.NamingSystem) VersionConvertorFactory_43_50.convertResource(r4b_actual); + org.hl7.fhir.r4b.model.NamingSystem r4b_conv = (org.hl7.fhir.r4b.model.NamingSystem) VersionConvertorFactory_43_50.convertResource(r5_conv); + + assertEquals(1, r4b_actual.getExtensionsByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).size()); + assertEquals(0, r5_conv.getExtensionsByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).size()); + assertEquals("American Dental Association Area of Oral Cavity System", r5_conv.getTitle()); + assertEquals("http://terminology.hl7.org/NamingSystem/ADAAreaOralCavitySystem", r5_conv.getUrl()); + assertEquals("1.0.0", r5_conv.getVersion()); + assertEquals(1, r4b_conv.getExtensionsByUrl(VersionConvertorConstants.EXT_NAMINGSYSTEM_TITLE).size()); + + } +} diff --git a/org.hl7.fhir.convertors/src/test/resources/naming_system_r4.xml b/org.hl7.fhir.convertors/src/test/resources/naming_system_r4.xml new file mode 100644 index 000000000..2b4ec83cf --- /dev/null +++ b/org.hl7.fhir.convertors/src/test/resources/naming_system_r4.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/DomainResource.java b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/DomainResource.java index ee8abbc8e..04111d6a2 100644 --- a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/DomainResource.java +++ b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/DomainResource.java @@ -316,4 +316,26 @@ public abstract class DomainResource extends Resource implements IBaseHasExtensi } + public boolean hasExtension(String url) { + for (Extension e : getExtension()) + if (url.equals(e.getUrl())) + return true; + return false; + } + + public Extension getExtensionByUrl(String theUrl) { + org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null"); + ArrayList retVal = new ArrayList(); + for (Extension next : getExtension()) { + if (theUrl.equals(next.getUrl())) { + retVal.add(next); + } + } + if (retVal.size() == 0) + return null; + else { + org.apache.commons.lang3.Validate.isTrue(retVal.size() == 1, "Url "+theUrl+" must have only one match"); + return retVal.get(0); + } + } } \ No newline at end of file diff --git a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/DomainResource.java b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/DomainResource.java index b176c7cfd..a4bad5d7f 100644 --- a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/DomainResource.java +++ b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/DomainResource.java @@ -390,4 +390,28 @@ public abstract class DomainResource extends Resource implements IBaseHasExtensi } + + public boolean hasExtension(String url) { + for (Extension e : getExtension()) + if (url.equals(e.getUrl())) + return true; + return false; + } + + public Extension getExtensionByUrl(String theUrl) { + org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null"); + ArrayList retVal = new ArrayList(); + for (Extension next : getExtension()) { + if (theUrl.equals(next.getUrl())) { + retVal.add(next); + } + } + if (retVal.size() == 0) + return null; + else { + org.apache.commons.lang3.Validate.isTrue(retVal.size() == 1, "Url "+theUrl+" must have only one match"); + return retVal.get(0); + } + } + } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/DomainResource.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/DomainResource.java index 3fcfdfbac..fa34498e8 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/DomainResource.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/DomainResource.java @@ -32,29 +32,19 @@ package org.hl7.fhir.r5.model; // Generated on Thu, Mar 23, 2023 19:59+1100 for FHIR v5.0.0 import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import org.hl7.fhir.r5.model.Enumerations.*; -import org.hl7.fhir.instance.model.api.IBaseBackboneElement; -import org.hl7.fhir.exceptions.FHIRException; -import org.hl7.fhir.instance.model.api.ICompositeType; -import ca.uhn.fhir.model.api.annotation.ResourceDef; -import ca.uhn.fhir.model.api.annotation.SearchParamDefinition; -import org.hl7.fhir.instance.model.api.IBaseBackboneElement; -import ca.uhn.fhir.model.api.annotation.Child; -import ca.uhn.fhir.model.api.annotation.ChildOrder; -import ca.uhn.fhir.model.api.annotation.Description; -import ca.uhn.fhir.model.api.annotation.Block; - import java.util.Collections; -import java.util.Set; -import org.hl7.fhir.instance.model.api.IDomainResource; -import org.hl7.fhir.instance.model.api.IBaseDatatypeElement; -import org.hl7.fhir.instance.model.api.IBaseHasExtensions; -import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions; -import org.hl7.fhir.instance.model.api.IBaseBackboneElement; -import org.hl7.fhir.r5.utils.ToolingExtensions; -import org.hl7.fhir.utilities.StandardsStatus; +import java.util.List; + +import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.instance.model.api.IBaseHasExtensions; +import org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions; +import org.hl7.fhir.instance.model.api.IDomainResource; +import org.hl7.fhir.r5.utils.ToolingExtensions; +import org.hl7.fhir.utilities.StandardsStatus; + +import ca.uhn.fhir.model.api.annotation.Child; +import ca.uhn.fhir.model.api.annotation.Description; +import ca.uhn.fhir.model.api.annotation.SearchParamDefinition; /** * A resource that includes narrative, extensions, and contained resources. */ @@ -522,6 +512,7 @@ public void checkNoModifiers(String noun, String verb) throws FHIRException { ToolingExtensions.setStandardsStatus(this, status, null); } + // end addition }