From aa6daa3ea00167b0e620f0968927768b452c04d0 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 11 Nov 2022 12:29:24 +1100 Subject: [PATCH 1/6] build core packages in other versions --- .../ElementDefinition10_40.java | 10 +- .../resources14_30/ConceptMap14_30.java | 2 +- .../ElementDefinition14_40.java | 7 +- .../resources14_40/ConceptMap14_40.java | 2 +- .../ImplementationGuide14_40.java | 2 +- .../conv14_50/datatypes14_50/Type14_50.java | 2 + .../primitivetypes14_50/Integer14_50.java | 21 + .../resources14_50/ConceptMap14_50.java | 2 +- .../ImplementationGuide14_50.java | 2 +- .../ImplementationGuide30_40.java | 2 +- .../CompartmentDefinition30_50.java | 4 - .../conv40_50/datatypes40_50/Type40_50.java | 2 + .../primitive40_50/Integer40_50.java | 21 + .../xver/CorePackageVersionConvertor.java | 594 ++++++++++++++++++ 14 files changed, 656 insertions(+), 17 deletions(-) create mode 100644 org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/xver/CorePackageVersionConvertor.java diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/datatypes10_40/ElementDefinition10_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/datatypes10_40/ElementDefinition10_40.java index a7c8be702..8e3b4990b 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/datatypes10_40/ElementDefinition10_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv10_40/datatypes10_40/ElementDefinition10_40.java @@ -449,10 +449,12 @@ public class ElementDefinition10_40 { ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt); if (src.hasStrength()) tgt.setStrengthElement(convertBindingStrength(src.getStrengthElement())); if (src.hasDescriptionElement()) tgt.setDescriptionElement(String10_40.convertString(src.getDescriptionElement())); - org.hl7.fhir.r4.model.Type vs = ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getValueSet()); - if (vs != null) { - tgt.setValueSet(vs instanceof org.hl7.fhir.r4.model.Reference ? ((org.hl7.fhir.r4.model.Reference) vs).getReference() : vs.primitiveValue()); - tgt.setValueSet(VersionConvertorConstants.refToVS(tgt.getValueSet())); + if (src.hasValueSet()) { + org.hl7.fhir.r4.model.Type vs = ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getValueSet()); + if (vs != null) { + tgt.setValueSet(vs instanceof org.hl7.fhir.r4.model.Reference ? ((org.hl7.fhir.r4.model.Reference) vs).getReference() : vs.primitiveValue()); + tgt.setValueSet(VersionConvertorConstants.refToVS(tgt.getValueSet())); + } } return tgt; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/resources14_30/ConceptMap14_30.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/resources14_30/ConceptMap14_30.java index 063f9021f..1eabef9fe 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/resources14_30/ConceptMap14_30.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_30/resources14_30/ConceptMap14_30.java @@ -311,7 +311,7 @@ public class ConceptMap14_30 { static public ConceptMapGroupComponent getGroup(ConceptMap map, String srcs, String tgts) { for (ConceptMapGroupComponent grp : map.getGroup()) { - if (grp.getSource().equals(srcs) && grp.getTarget().equals(tgts)) + if (grp.hasSource() && grp.getSource().equals(srcs) && grp.getTarget().equals(tgts)) return grp; } ConceptMapGroupComponent grp = map.addGroup(); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/datatypes14_40/ElementDefinition14_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/datatypes14_40/ElementDefinition14_40.java index ad1cf2729..b8ff2cbb6 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/datatypes14_40/ElementDefinition14_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/datatypes14_40/ElementDefinition14_40.java @@ -360,9 +360,10 @@ public class ElementDefinition14_40 { if (src.hasTarget()) { for (org.hl7.fhir.r4.model.UriType u : src.getTargetProfile()) { tgt.addProfile(u.getValue()); - String baseName = u.getValue().toLowerCase(); - if (baseName.contains("reference") && !baseName.contains("documentreference")) - throw new Error("2016May Target profile contains the word 'reference':" + u); + // disabled 2022-11-11 - gdg - I don't see what value this is bringing anywhere? +// String baseName = u.getValue().toLowerCase(); +// if (baseName.contains("reference") && !baseName.contains("documentreference")) +// throw new Error("2016May Target profile contains the word 'reference':" + u); } for (org.hl7.fhir.r4.model.UriType u : src.getProfile()) { if (src.getCode().equals("Reference")) { diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/resources14_40/ConceptMap14_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/resources14_40/ConceptMap14_40.java index 765369cc8..1cc4a4268 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/resources14_40/ConceptMap14_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/resources14_40/ConceptMap14_40.java @@ -320,7 +320,7 @@ public class ConceptMap14_40 { static public ConceptMapGroupComponent getGroup(ConceptMap map, String srcs, String tgts) { for (ConceptMapGroupComponent grp : map.getGroup()) { - if (grp.getSource().equals(srcs) && grp.getTarget().equals(tgts)) + if (grp.hasSource() && grp.getSource().equals(srcs) && grp.getTarget().equals(tgts)) return grp; } ConceptMapGroupComponent grp = map.addGroup(); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/resources14_40/ImplementationGuide14_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/resources14_40/ImplementationGuide14_40.java index a3b9bae07..506e0a700 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/resources14_40/ImplementationGuide14_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_40/resources14_40/ImplementationGuide14_40.java @@ -320,7 +320,7 @@ public class ImplementationGuide14_40 { static public org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageComponent findPackage(List definition, String id) { for (org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageComponent t : definition) - if (t.getId().equals(id)) + if (t.hasId() && t.getId().equals(id)) return t; org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageComponent t = new org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageComponent(); t.setName("Default Package"); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/Type14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/Type14_50.java index aa14be253..a79fafba6 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/Type14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/Type14_50.java @@ -169,6 +169,8 @@ public class Type14_50 { return UnsignedInt14_50.convertUnsignedInt((org.hl7.fhir.r5.model.UnsignedIntType) src); if (src instanceof org.hl7.fhir.r5.model.IntegerType) return Integer14_50.convertInteger((org.hl7.fhir.r5.model.IntegerType) src); + if (src instanceof org.hl7.fhir.r5.model.Integer64Type) + return Integer14_50.convertInteger64((org.hl7.fhir.r5.model.Integer64Type) src); if (src instanceof org.hl7.fhir.r5.model.UuidType) return Uuid14_50.convertUuid((org.hl7.fhir.r5.model.UuidType) src); if (src instanceof org.hl7.fhir.r5.model.UriType) return Uri14_50.convertUri((org.hl7.fhir.r5.model.UriType) src); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/primitivetypes14_50/Integer14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/primitivetypes14_50/Integer14_50.java index 82ccc7f73..d04a4d2c8 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/primitivetypes14_50/Integer14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/datatypes14_50/primitivetypes14_50/Integer14_50.java @@ -15,4 +15,25 @@ public class Integer14_50 { ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt); return tgt; } + + public static org.hl7.fhir.r5.model.Integer64Type convertInteger64(org.hl7.fhir.dstu2016may.model.IntegerType src) throws FHIRException { + org.hl7.fhir.r5.model.Integer64Type tgt = src.hasValue() ? new org.hl7.fhir.r5.model.Integer64Type(src.getValueAsString()) : new org.hl7.fhir.r5.model.Integer64Type(); + ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt); + return tgt; + } + + public static org.hl7.fhir.dstu2016may.model.IntegerType convertInteger64(org.hl7.fhir.r5.model.Integer64Type src) throws FHIRException { + org.hl7.fhir.dstu2016may.model.IntegerType tgt = new org.hl7.fhir.dstu2016may.model.IntegerType(); + if (src.hasValue()) { + try { + tgt.setValueAsString(src.getValueAsString()); + } catch (Exception e) { + // nothing? + tgt.setValueAsString("0"); + } + } + ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt); + return tgt; + } + } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/ConceptMap14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/ConceptMap14_50.java index 790bac02f..7e73a5ba0 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/ConceptMap14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/ConceptMap14_50.java @@ -329,7 +329,7 @@ public class ConceptMap14_50 { static public ConceptMapGroupComponent getGroup(ConceptMap map, String srcs, String tgts) { for (ConceptMapGroupComponent grp : map.getGroup()) { - if (grp.getSource().equals(srcs) && grp.getTarget().equals(tgts)) + if (grp.hasSource() && grp.getSource().equals(srcs) && grp.getTarget().equals(tgts)) return grp; } ConceptMapGroupComponent grp = map.addGroup(); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/ImplementationGuide14_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/ImplementationGuide14_50.java index 81140d2e7..3d5985a5c 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/ImplementationGuide14_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv14_50/resources14_50/ImplementationGuide14_50.java @@ -321,7 +321,7 @@ public class ImplementationGuide14_50 { static public org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageComponent findPackage(List definition, String id) { for (org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageComponent t : definition) - if (t.getId().equals(id)) + if (t.hasId() && t.getId().equals(id)) return t; org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageComponent t = new org.hl7.fhir.dstu2016may.model.ImplementationGuide.ImplementationGuidePackageComponent(); t.setName("Default Package"); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/resources30_40/ImplementationGuide30_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/resources30_40/ImplementationGuide30_40.java index 842945042..cbdafc328 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/resources30_40/ImplementationGuide30_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/resources30_40/ImplementationGuide30_40.java @@ -286,7 +286,7 @@ public class ImplementationGuide30_40 { static public org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent findPackage(List definition, String id) { for (org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent t : definition) - if (t.getId().equals(id)) + if (t.hasId() && t.getId().equals(id)) return t; org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent t1 = new org.hl7.fhir.dstu3.model.ImplementationGuide.ImplementationGuidePackageComponent(); t1.setName("Default Package"); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/CompartmentDefinition30_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/CompartmentDefinition30_50.java index 21246f079..dd6d45de1 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/CompartmentDefinition30_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/CompartmentDefinition30_50.java @@ -41,8 +41,6 @@ public class CompartmentDefinition30_50 { tgt.setPurposeElement(MarkDown30_50.convertMarkdown(src.getPurposeElement())); for (org.hl7.fhir.dstu3.model.UsageContext t : src.getUseContext()) tgt.addUseContext(UsageContext30_50.convertUsageContext(t)); - for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getJurisdiction()) - tgt.addJurisdiction(CodeableConcept30_50.convertCodeableConcept(t)); if (src.hasCode()) tgt.setCodeElement(convertCompartmentType(src.getCodeElement())); if (src.hasSearch()) @@ -79,8 +77,6 @@ public class CompartmentDefinition30_50 { tgt.setPurposeElement(MarkDown30_50.convertMarkdown(src.getPurposeElement())); for (org.hl7.fhir.r5.model.UsageContext t : src.getUseContext()) tgt.addUseContext(UsageContext30_50.convertUsageContext(t)); - for (org.hl7.fhir.r5.model.CodeableConcept t : src.getJurisdiction()) - tgt.addJurisdiction(CodeableConcept30_50.convertCodeableConcept(t)); if (src.hasCode()) tgt.setCodeElement(convertCompartmentType(src.getCodeElement())); if (src.hasSearch()) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/Type40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/Type40_50.java index 53c97d087..96412224f 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/Type40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/Type40_50.java @@ -222,6 +222,8 @@ public class Type40_50 { return UnsignedInt40_50.convertUnsignedInt((org.hl7.fhir.r5.model.UnsignedIntType) src); if (src instanceof org.hl7.fhir.r5.model.IntegerType) return Integer40_50.convertInteger((org.hl7.fhir.r5.model.IntegerType) src); + if (src instanceof org.hl7.fhir.r5.model.Integer64Type) + return Integer40_50.convertInteger64((org.hl7.fhir.r5.model.Integer64Type) src); if (src instanceof org.hl7.fhir.r5.model.UrlType) return Url40_50.convertUrl((org.hl7.fhir.r5.model.UrlType) src); if (src instanceof org.hl7.fhir.r5.model.UuidType) return Uuid40_50.convertUuid((org.hl7.fhir.r5.model.UuidType) src); diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/Integer40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/Integer40_50.java index 9bbcde66a..a47218482 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/Integer40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/Integer40_50.java @@ -15,4 +15,25 @@ public class Integer40_50 { ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); return tgt; } + + public static org.hl7.fhir.r5.model.Integer64Type convertInteger64(org.hl7.fhir.r4.model.IntegerType src) throws FHIRException { + org.hl7.fhir.r5.model.Integer64Type tgt = src.hasValue() ? new org.hl7.fhir.r5.model.Integer64Type(src.getValueAsString()) : new org.hl7.fhir.r5.model.Integer64Type(); + ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); + return tgt; + } + + public static org.hl7.fhir.r4.model.IntegerType convertInteger64(org.hl7.fhir.r5.model.Integer64Type src) throws FHIRException { + org.hl7.fhir.r4.model.IntegerType tgt = new org.hl7.fhir.r4.model.IntegerType(); + if (src.hasValue()) { + try { + tgt.setValueAsString(src.getValueAsString()); + } catch (Exception e) { + // nothing? + tgt.setValueAsString("0"); + } + } + ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt); + return tgt; + } + } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/xver/CorePackageVersionConvertor.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/xver/CorePackageVersionConvertor.java new file mode 100644 index 000000000..5df0aaadd --- /dev/null +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/xver/CorePackageVersionConvertor.java @@ -0,0 +1,594 @@ +package org.hl7.fhir.convertors.misc.xver; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; + +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_30; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_40; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_10_50; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_30; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_40; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50; +import org.hl7.fhir.convertors.misc.xver.CorePackageVersionConvertor.BaseConvertor; +import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.VersionUtilities; +import org.hl7.fhir.utilities.json.JsonTrackingParser; +import org.hl7.fhir.utilities.json.JsonUtilities; +import org.hl7.fhir.utilities.npm.NpmPackage; +import org.hl7.fhir.utilities.npm.NpmPackage.NpmPackageFolder; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +public class CorePackageVersionConvertor { + + public interface IContentConvertor { + byte[] convert(byte[] cnt) throws IOException; + } + + public class BaseConvertor { + protected String version; + + public BaseConvertor(String version) { + super(); + this.version = version; + } + } + + public class ContentConverter3to4 extends BaseConvertor implements IContentConvertor { + + public ContentConverter3to4(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.dstu3.model.Resource r3 = new org.hl7.fhir.dstu3.formats.JsonParser().parse(cnt); + if (r3 instanceof org.hl7.fhir.dstu3.model.MetadataResource) { + org.hl7.fhir.dstu3.model.MetadataResource cr = (org.hl7.fhir.dstu3.model.MetadataResource) r3; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_30_40.convertResource(r3); + return new org.hl7.fhir.r4.formats.JsonParser().composeBytes(r4); + } + } + public class ContentConverter2to4 extends BaseConvertor implements IContentConvertor { + + public ContentConverter2to4(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.dstu2.model.Resource r2 = new org.hl7.fhir.dstu2.formats.JsonParser().parse(cnt); + org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_10_40.convertResource(r2); + if (r4 instanceof org.hl7.fhir.r4.model.MetadataResource) { + org.hl7.fhir.r4.model.MetadataResource cr = (org.hl7.fhir.r4.model.MetadataResource) r4; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + return new org.hl7.fhir.r4.formats.JsonParser().composeBytes(r4); + } + } + public class ContentConverter2Bto4 extends BaseConvertor implements IContentConvertor { + + public ContentConverter2Bto4(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.dstu2016may.model.Resource r2 = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(cnt); + org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_14_40.convertResource(r2); + if (r4 instanceof org.hl7.fhir.r4.model.MetadataResource) { + org.hl7.fhir.r4.model.MetadataResource cr = (org.hl7.fhir.r4.model.MetadataResource) r4; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + return new org.hl7.fhir.r4.formats.JsonParser().composeBytes(r4); + } + } + public class ContentConverter5to4 extends BaseConvertor implements IContentConvertor { + public ContentConverter5to4(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.r5.model.Resource r5 = new org.hl7.fhir.r5.formats.JsonParser().parse(cnt); + if (r5 instanceof org.hl7.fhir.r5.model.MetadataResource) { + org.hl7.fhir.r5.model.MetadataResource cr = (org.hl7.fhir.r5.model.MetadataResource) r5; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_40_50.convertResource(r5); + return new org.hl7.fhir.r4.formats.JsonParser().composeBytes(r4); + } + } + + public class ContentConverter4to3 extends BaseConvertor implements IContentConvertor { + + public ContentConverter4to3(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.r4.model.Resource r4 = new org.hl7.fhir.r4.formats.JsonParser().parse(cnt); + if (r4 instanceof org.hl7.fhir.r4.model.MessageDefinition) { + return null; + } + if (r4 instanceof org.hl7.fhir.r4.model.GraphDefinition) { + return null; + } + if (r4 instanceof org.hl7.fhir.r4.model.TerminologyCapabilities) { + return null; + } + + if (r4 instanceof org.hl7.fhir.r4.model.MetadataResource) { + org.hl7.fhir.r4.model.MetadataResource cr = (org.hl7.fhir.r4.model.MetadataResource) r4; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.dstu3.model.Resource r3 = VersionConvertorFactory_30_40.convertResource(r4); + return new org.hl7.fhir.dstu3.formats.JsonParser().composeBytes(r3); + } + } + public class ContentConverter2to3 extends BaseConvertor implements IContentConvertor { + + public ContentConverter2to3(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.dstu2.model.Resource r2 = new org.hl7.fhir.dstu2.formats.JsonParser().parse(cnt); + org.hl7.fhir.dstu3.model.Resource r3 = VersionConvertorFactory_10_30.convertResource(r2); + if (r3 instanceof org.hl7.fhir.dstu3.model.MetadataResource) { + org.hl7.fhir.dstu3.model.MetadataResource cr = (org.hl7.fhir.dstu3.model.MetadataResource) r3; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + return new org.hl7.fhir.dstu3.formats.JsonParser().composeBytes(r3); + } + } + public class ContentConverter2Bto3 extends BaseConvertor implements IContentConvertor { + + public ContentConverter2Bto3(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.dstu2016may.model.Resource r2 = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(cnt); + if (r2 instanceof org.hl7.fhir.dstu2016may.model.StructureMap) { + return null; + } + org.hl7.fhir.dstu3.model.Resource r3 = VersionConvertorFactory_14_30.convertResource(r2); + if (r3 instanceof org.hl7.fhir.dstu3.model.MetadataResource) { + org.hl7.fhir.dstu3.model.MetadataResource cr = (org.hl7.fhir.dstu3.model.MetadataResource) r3; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + return new org.hl7.fhir.dstu3.formats.JsonParser().composeBytes(r3); + } + } + public class ContentConverter5to3 extends BaseConvertor implements IContentConvertor { + public ContentConverter5to3(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.r5.model.Resource r5 = new org.hl7.fhir.r5.formats.JsonParser().parse(cnt); + if (r5 instanceof org.hl7.fhir.r5.model.TerminologyCapabilities) { + return null; + } + + if (r5 instanceof org.hl7.fhir.r5.model.MetadataResource) { + org.hl7.fhir.r5.model.MetadataResource cr = (org.hl7.fhir.r5.model.MetadataResource) r5; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.dstu3.model.Resource r3 = VersionConvertorFactory_30_50.convertResource(r5); + return new org.hl7.fhir.dstu3.formats.JsonParser().composeBytes(r3); + } + } + + public class ContentConverter3to5 extends BaseConvertor implements IContentConvertor { + + public ContentConverter3to5(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.dstu3.model.Resource r3 = new org.hl7.fhir.dstu3.formats.JsonParser().parse(cnt); + if (r3 instanceof org.hl7.fhir.dstu3.model.MetadataResource) { + org.hl7.fhir.dstu3.model.MetadataResource cr = (org.hl7.fhir.dstu3.model.MetadataResource) r3; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_30_50.convertResource(r3); + return new org.hl7.fhir.r5.formats.JsonParser().composeBytes(r5); + } + } + public class ContentConverter2to5 extends BaseConvertor implements IContentConvertor { + + public ContentConverter2to5(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.dstu2.model.Resource r2 = new org.hl7.fhir.dstu2.formats.JsonParser().parse(cnt); + org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_10_50.convertResource(r2); + if (r5 instanceof org.hl7.fhir.r5.model.MetadataResource) { + org.hl7.fhir.r5.model.MetadataResource cr = (org.hl7.fhir.r5.model.MetadataResource) r5; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + return new org.hl7.fhir.r5.formats.JsonParser().composeBytes(r5); + } + } + public class ContentConverter2Bto5 extends BaseConvertor implements IContentConvertor { + + public ContentConverter2Bto5(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.dstu2016may.model.Resource r2 = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(cnt); + org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_14_50.convertResource(r2); + if (r5 instanceof org.hl7.fhir.r5.model.MetadataResource) { + org.hl7.fhir.r5.model.MetadataResource cr = (org.hl7.fhir.r5.model.MetadataResource) r5; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + return new org.hl7.fhir.r5.formats.JsonParser().composeBytes(r5); + } + } + public class ContentConverter4to5 extends BaseConvertor implements IContentConvertor { + public ContentConverter4to5(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.r4.model.Resource r4 = new org.hl7.fhir.r4.formats.JsonParser().parse(cnt); + if (r4 instanceof org.hl7.fhir.r4.model.MetadataResource) { + org.hl7.fhir.r4.model.MetadataResource cr = (org.hl7.fhir.r4.model.MetadataResource) r4; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_40_50.convertResource(r4); + return new org.hl7.fhir.r5.formats.JsonParser().composeBytes(r5); + } + } + + public class ContentConverter5to2 extends BaseConvertor implements IContentConvertor { + + public ContentConverter5to2(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.r5.model.Resource r5 = new org.hl7.fhir.r5.formats.JsonParser().parse(cnt); + if (r5 instanceof org.hl7.fhir.r5.model.MetadataResource) { + org.hl7.fhir.r5.model.MetadataResource cr = (org.hl7.fhir.r5.model.MetadataResource) r5; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.dstu2.model.Resource r2 = VersionConvertorFactory_10_50.convertResource(r5); + return new org.hl7.fhir.dstu2.formats.JsonParser().composeBytes(r2); + } + } + + public class ContentConverter5to2B extends BaseConvertor implements IContentConvertor { + + public ContentConverter5to2B(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.r5.model.Resource r5 = new org.hl7.fhir.r5.formats.JsonParser().parse(cnt); + if (r5 instanceof org.hl7.fhir.r5.model.MessageDefinition) { + return null; + } + if (r5 instanceof org.hl7.fhir.r5.model.GraphDefinition) { + return null; + } + if (r5 instanceof org.hl7.fhir.r5.model.TerminologyCapabilities) { + return null; + } + + if (r5 instanceof org.hl7.fhir.r5.model.MetadataResource) { + org.hl7.fhir.r5.model.MetadataResource cr = (org.hl7.fhir.r5.model.MetadataResource) r5; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.dstu2016may.model.Resource r2 = VersionConvertorFactory_14_50.convertResource(r5); + return new org.hl7.fhir.dstu2016may.formats.JsonParser().composeBytes(r2); + } + } + + public class ContentConverter4to2 extends BaseConvertor implements IContentConvertor { + + public ContentConverter4to2(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.r4.model.Resource r4 = new org.hl7.fhir.r4.formats.JsonParser().parse(cnt); + if (r4 instanceof org.hl7.fhir.r4.model.MetadataResource) { + org.hl7.fhir.r4.model.MetadataResource cr = (org.hl7.fhir.r4.model.MetadataResource) r4; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.dstu2.model.Resource r2 = VersionConvertorFactory_10_40.convertResource(r4); + return new org.hl7.fhir.dstu2.formats.JsonParser().composeBytes(r2); + } + } + + public class ContentConverter4to2B extends BaseConvertor implements IContentConvertor { + + public ContentConverter4to2B(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.r4.model.Resource r4 = new org.hl7.fhir.r4.formats.JsonParser().parse(cnt); + if (r4 instanceof org.hl7.fhir.r4.model.MessageDefinition) { + return null; + } + if (r4 instanceof org.hl7.fhir.r4.model.GraphDefinition) { + return null; + } + if (r4 instanceof org.hl7.fhir.r4.model.TerminologyCapabilities) { + return null; + } + if (r4 instanceof org.hl7.fhir.r4.model.MetadataResource) { + org.hl7.fhir.r4.model.MetadataResource cr = (org.hl7.fhir.r4.model.MetadataResource) r4; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.dstu2016may.model.Resource r2 = VersionConvertorFactory_14_40.convertResource(r4); + return new org.hl7.fhir.dstu2016may.formats.JsonParser().composeBytes(r2); + } + } + + public class ContentConverter3to2 extends BaseConvertor implements IContentConvertor { + + public ContentConverter3to2(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.dstu3.model.Resource r3 = new org.hl7.fhir.dstu3.formats.JsonParser().parse(cnt); + if (r3 instanceof org.hl7.fhir.dstu3.model.MetadataResource) { + org.hl7.fhir.dstu3.model.MetadataResource cr = (org.hl7.fhir.dstu3.model.MetadataResource) r3; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.dstu2.model.Resource r2 = VersionConvertorFactory_10_30.convertResource(r3); + return new org.hl7.fhir.dstu2.formats.JsonParser().composeBytes(r2); + } + } + + public class ContentConverter3to2B extends BaseConvertor implements IContentConvertor { + + public ContentConverter3to2B(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.dstu3.model.Resource r3 = new org.hl7.fhir.dstu3.formats.JsonParser().parse(cnt); + if (r3 instanceof org.hl7.fhir.dstu3.model.StructureMap) { + return null; + } + + if (r3 instanceof org.hl7.fhir.dstu3.model.MetadataResource) { + org.hl7.fhir.dstu3.model.MetadataResource cr = (org.hl7.fhir.dstu3.model.MetadataResource) r3; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + org.hl7.fhir.dstu2016may.model.Resource r2 = VersionConvertorFactory_14_30.convertResource(r3); + return new org.hl7.fhir.dstu2016may.formats.JsonParser().composeBytes(r2); + } + } + + public class ContentConverter4to4 extends BaseConvertor implements IContentConvertor { + + public ContentConverter4to4(String version) { + super(version); + } + + @Override + public byte[] convert(byte[] cnt) throws IOException { + org.hl7.fhir.r4.model.Resource r4 = new org.hl7.fhir.r4.formats.JsonParser().parse(cnt); + if (r4 instanceof org.hl7.fhir.r4.model.MetadataResource) { + org.hl7.fhir.r4.model.MetadataResource cr = (org.hl7.fhir.r4.model.MetadataResource) r4; + if (!cr.hasVersion()) { + cr.setVersion(version); + } + } + return new org.hl7.fhir.r4.formats.JsonParser().composeBytes(r4); + } + } + + + public static void main(String[] args) throws Exception { + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r2b.core.tgz"), "3.0.1"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r2b.core.tgz"), "4.0.1"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r2b.core.tgz"), "4.3.0"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r2b.core.tgz"), "5.0.0"); + + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r3.core.tgz"), "1.4.0"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r3.core.tgz"), "4.0.1"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r3.core.tgz"), "4.3.0"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r3.core.tgz"), "5.0.0"); + + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r4.core.tgz"), "1.4.0"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r4.core.tgz"), "3.0.1"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r4.core.tgz"), "4.3.0"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r4.core.tgz"), "5.0.0"); + + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r4b.core.tgz"), "1.4.0"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r4b.core.tgz"), "3.0.1"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r4b.core.tgz"), "4.0.1"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r4b.core.tgz"), "5.0.0"); + + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r5.core.tgz"), "1.4.0"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r5.core.tgz"), "3.0.1"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r5.core.tgz"), "4.0.1"); + new CorePackageVersionConvertor().execute(Utilities.path(args[0], "hl7.fhir.r5.core.tgz"), "4.3.0"); + + } + + public void execute(String packageSource, String versionTarget) throws Exception { + // open the existing package + // chose the version converter + // build a new package + System.out.println("Convert "+packageSource+" to "+versionTarget); + + NpmPackage src = NpmPackage.fromPackage(new FileInputStream(packageSource)); + IContentConvertor conv = contentConvertorFactory(src.fhirVersion(), versionTarget); + + NpmPackage dst = NpmPackage.empty(); + + for (NpmPackageFolder folder : src.getFolders().values()) { + for (String s : folder.getContent().keySet()) { + byte[] cnt = folder.getContent().get(s); + if (s.endsWith(".json")) { + if (s.equals("package.json")) { + cnt = convertPackage(cnt, versionTarget); + } else { + String sJ = new String(cnt); + if (sJ.contains("\"resourceType\"") && !s.equals(".index.json") && !s.endsWith(".schema.json")) { + try { + cnt = conv.convert(cnt); + } catch (Exception e) { + throw new Exception("Error processing "+folder.getName()+"/"+s+": "+e.getMessage(), e); + } + } else { + // nothing + } + } + if (cnt != null) { + dst.addFile(folder.getName(), s, cnt, null); + } + } else { + dst.addFile(folder.getName(), s, cnt, null); + } + } + } + dst.save(new FileOutputStream(Utilities.changeFileExt(packageSource, ".as."+VersionUtilities.getNameForVersion(versionTarget).toLowerCase()+".tgz"))); + } + + private IContentConvertor contentConvertorFactory(String fhirVersion, String versionTarget) throws Exception { + if (VersionUtilities.isR3Ver(fhirVersion)) { + if (VersionUtilities.isR4Ver(versionTarget) || VersionUtilities.isR4BVer(versionTarget)) { + return new ContentConverter3to4(fhirVersion); + } else if (VersionUtilities.isR5Ver(versionTarget)) { + return new ContentConverter3to5(fhirVersion); + } else if (VersionUtilities.isR2Ver(versionTarget)) { + return new ContentConverter3to2(fhirVersion); + } else if (VersionUtilities.isR2BVer(versionTarget)) { + return new ContentConverter3to2B(fhirVersion); + } + } else if (VersionUtilities.isR2Ver(fhirVersion)) { + if (VersionUtilities.isR4Ver(versionTarget) || VersionUtilities.isR4BVer(versionTarget)) { + return new ContentConverter2to4(fhirVersion); + } else if (VersionUtilities.isR5Ver(versionTarget)) { + return new ContentConverter2to5(fhirVersion); + } else if (VersionUtilities.isR3Ver(versionTarget)) { + return new ContentConverter2to3(fhirVersion); + } + } else if (VersionUtilities.isR2BVer(fhirVersion)) { + if (VersionUtilities.isR4Ver(versionTarget) || VersionUtilities.isR4BVer(versionTarget)) { + return new ContentConverter2Bto4(fhirVersion); + } else if (VersionUtilities.isR5Ver(versionTarget)) { + return new ContentConverter2Bto5(fhirVersion); + } else if (VersionUtilities.isR3Ver(versionTarget)) { + return new ContentConverter2Bto3(fhirVersion); + } + } else if (VersionUtilities.isR4Ver(fhirVersion)) { + if (VersionUtilities.isR3Ver(versionTarget)) { + return new ContentConverter4to3(fhirVersion); + } else if (VersionUtilities.isR5Ver(versionTarget)) { + return new ContentConverter4to5(fhirVersion); + } else if (VersionUtilities.isR2Ver(versionTarget)) { + return new ContentConverter4to2(fhirVersion); + } else if (VersionUtilities.isR4BVer(versionTarget)) { + return new ContentConverter4to4(fhirVersion); + } else if (VersionUtilities.isR2BVer(versionTarget)) { + return new ContentConverter4to2B(fhirVersion); + } + } else if (VersionUtilities.isR4BVer(fhirVersion)) { + if (VersionUtilities.isR3Ver(versionTarget)) { + return new ContentConverter4to3(fhirVersion); + } else if (VersionUtilities.isR5Ver(versionTarget)) { + return new ContentConverter4to5(fhirVersion); + } else if (VersionUtilities.isR4Ver(versionTarget)) { + return new ContentConverter4to4(fhirVersion); + } else if (VersionUtilities.isR2Ver(versionTarget)) { + return new ContentConverter4to2(fhirVersion); + } else if (VersionUtilities.isR2BVer(versionTarget)) { + return new ContentConverter4to2B(fhirVersion); + } + } else if (VersionUtilities.isR5Ver(fhirVersion)) { + if (VersionUtilities.isR4Ver(versionTarget) || VersionUtilities.isR4BVer(versionTarget)) { + return new ContentConverter5to4(fhirVersion); + } else if (VersionUtilities.isR3Ver(versionTarget)) { + return new ContentConverter5to3(fhirVersion); + } else if (VersionUtilities.isR2Ver(versionTarget)) { + return new ContentConverter5to2(fhirVersion); + } else if (VersionUtilities.isR2BVer(versionTarget)) { + return new ContentConverter5to2B(fhirVersion); + } + } + throw new Exception("Unable to convert from "+fhirVersion+" to "+versionTarget); + } + + private byte[] convertPackage(byte[] cnt, String version) throws IOException { + JsonObject json = JsonTrackingParser.parseJson(cnt); + json.remove("fhir-version-list"); + JsonArray vl = new JsonArray(); + json.add("fhirVersions", vl); + vl.add(version); + json.addProperty("name", JsonUtilities.str(json, "name")+".as."+VersionUtilities.getNameForVersion(version).toLowerCase()); + json.addProperty("title", JsonUtilities.str(json, "title")+" (as Version "+VersionUtilities.getNameForVersion(version).toLowerCase()+")"); + return JsonTrackingParser.write(json).getBytes(StandardCharsets.UTF_8); + } +} From e01216b7f3ee3fce92499d818363140e468f35c1 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 11 Nov 2022 12:29:45 +1100 Subject: [PATCH 2/6] more xver package related changes --- .../hl7/fhir/r4/conformance/ProfileUtilities.java | 1 + org.hl7.fhir.r4b/.project | 4 ++-- .../org/hl7/fhir/utilities/VersionUtilities.java | 15 ++++++++++++++- .../org/hl7/fhir/utilities/npm/NpmPackage.java | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java index e831a773a..80aebef51 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java @@ -4680,6 +4680,7 @@ public class ProfileUtilities extends TranslatingUtilities { case PROFILE: return t.getPath()+"/@profile"; case TYPE: return t.getPath()+"/@type"; case VALUE: return t.getPath(); + case PATTERN: return t.getPath(); case EXISTS: return t.getPath(); // determination of value vs. exists is based on whether there's only 2 slices - one with minOccurs=1 and other with maxOccur=0 default: throw new FHIRException("Unable to represent "+t.getType().toCode()+":"+t.getPath()+" in R2"); } diff --git a/org.hl7.fhir.r4b/.project b/org.hl7.fhir.r4b/.project index 50e7ef90f..dc20d573e 100644 --- a/org.hl7.fhir.r4b/.project +++ b/org.hl7.fhir.r4b/.project @@ -22,12 +22,12 @@ - 1662504185037 + 1668080803768 30 org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java index 3f9fae531..2df607c7d 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/VersionUtilities.java @@ -570,12 +570,25 @@ public class VersionUtilities { case "1.4" : return "http://hl7.org/fhir/DSTU2"; case "3.0" : return "http://hl7.org/fhir/STU3"; case "4.0" : return "http://hl7.org/fhir/R4"; - case "4.5" : return "http://build.fhir.org"; + case "4.3" : return "http://hl7.org/fhir/R4B"; case "5.0" : return "http://build.fhir.org"; default: return "http://hl7.org/fhir"; } } + public static String getNameForVersion(String v) { + switch (getMajMin(v)) { + case "1.0" : return "R2"; + case "1.4" : return "R2B"; + case "3.0" : return "R3"; + case "4.0" : return "R4"; + case "4.3" : return "R4B"; + case "5.0" : return "R5"; + default: + return "R?"; + } + } + } \ No newline at end of file diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java index fa812425f..7d5a38edd 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java @@ -283,6 +283,14 @@ public class NpmPackage { return retVal; } + /** + * Factory method that starts a new empty package using the given PackageGenerator to create the manifest + */ + public static NpmPackage empty() { + NpmPackage retVal = new NpmPackage(); + return retVal; + } + public Map getUserData() { return userData; } @@ -1061,6 +1069,12 @@ public class NpmPackage { if (!folder.types.containsKey(type)) folder.types.put(type, new ArrayList<>()); folder.types.get(type).add(name); + if ("package".equals(folderName) && "package.json".equals(name)) { + try { + npm = JsonTrackingParser.parseJson(cnt); + } catch (IOException e) { + } + } } public void loadAllFiles() throws IOException { From cb72792b7e51857f368273843cb45885b4469d4b Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 14 Nov 2022 18:03:22 +1100 Subject: [PATCH 3/6] More work on R4 <-> R4B guides --- .../ImplementationGuide43_50.java | 2 +- .../org/hl7/fhir/r4b/formats/JsonParser.java | 6 ++-- .../org/hl7/fhir/r4b/formats/RdfParser.java | 2 +- .../org/hl7/fhir/r4b/formats/XmlParser.java | 4 +-- .../fhir/r4b/model/ImplementationGuide.java | 35 +++++++++---------- .../java/org/hl7/fhir/r4b/utils/IGHelper.java | 8 ++--- 6 files changed, 27 insertions(+), 30 deletions(-) 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 9ead6b044..139a874dc 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 @@ -2516,7 +2516,7 @@ public class ImplementationGuide43_50 { org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionParameterComponent tgt = new org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionParameterComponent(); ConversionContext43_50.INSTANCE.getVersionConvertor_43_50().copyBackboneElement(src, tgt); if (src.hasCode()) - tgt.getCode().setCode(src.getCode().toCode()); + tgt.getCode().setCode(src.getCode()); if (src.hasValue()) tgt.setValueElement(String43_50.convertString(src.getValueElement())); return tgt; diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/JsonParser.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/JsonParser.java index 760dc5a69..22e5b5a31 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/JsonParser.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/JsonParser.java @@ -15842,7 +15842,7 @@ public class JsonParser extends JsonParserBase { protected void parseImplementationGuideDefinitionParameterComponentProperties(JsonObject json, ImplementationGuide.ImplementationGuideDefinitionParameterComponent res) throws IOException, FHIRFormatError { parseBackboneElementProperties(json, res); if (json.has("code")) - res.setCodeElement(parseEnumeration(json.get("code").getAsString(), ImplementationGuide.GuideParameterCode.NULL, new ImplementationGuide.GuideParameterCodeEnumFactory())); + res.setCodeElement(parseString(json.get("code").getAsString())); if (json.has("_code")) parseElementProperties(getJObject(json, "_code"), res.getCodeElement()); if (json.has("value")) @@ -46799,8 +46799,8 @@ public class JsonParser extends JsonParserBase { protected void composeImplementationGuideDefinitionParameterComponentProperties(ImplementationGuide.ImplementationGuideDefinitionParameterComponent element) throws IOException { composeBackboneElementProperties(element); if (element.hasCodeElement()) { - composeEnumerationCore("code", element.getCodeElement(), new ImplementationGuide.GuideParameterCodeEnumFactory(), false); - composeEnumerationExtras("code", element.getCodeElement(), new ImplementationGuide.GuideParameterCodeEnumFactory(), false); + composeStringCore("code", element.getCodeElement(), false); + composeStringExtras("code", element.getCodeElement(), false); } if (element.hasValueElement()) { composeStringCore("value", element.getValueElement(), false); diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/RdfParser.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/RdfParser.java index 2a37bd43a..a710229ae 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/RdfParser.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/RdfParser.java @@ -12577,7 +12577,7 @@ public class RdfParser extends RdfParserBase { } composeBackboneElement(t, "parameter", name, element, index); if (element.hasCodeElement()) { - composeEnum(t, "ImplementationGuideDefinitionParameterComponent", "code", element.getCodeElement(), -1); + composeString(t, "ImplementationGuideDefinitionParameterComponent", "code", element.getCodeElement(), -1); } if (element.hasValueElement()) { composeString(t, "ImplementationGuideDefinitionParameterComponent", "value", element.getValueElement(), -1); diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/XmlParser.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/XmlParser.java index e10130cf8..ec42ceead 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/XmlParser.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/formats/XmlParser.java @@ -13779,7 +13779,7 @@ public class XmlParser extends XmlParserBase { protected boolean parseImplementationGuideDefinitionParameterComponentContent(int eventType, XmlPullParser xpp, ImplementationGuide.ImplementationGuideDefinitionParameterComponent res) throws XmlPullParserException, IOException, FHIRFormatError { if (eventType == XmlPullParser.START_TAG && xpp.getName().equals("code")) { - res.setCodeElement(parseEnumeration(xpp, ImplementationGuide.GuideParameterCode.NULL, new ImplementationGuide.GuideParameterCodeEnumFactory())); + res.setCodeElement(parseString(xpp)); } else if (eventType == XmlPullParser.START_TAG && xpp.getName().equals("value")) { res.setValueElement(parseString(xpp)); } else if (!parseBackboneElementContent(eventType, xpp, res)){ @@ -40194,7 +40194,7 @@ public class XmlParser extends XmlParserBase { protected void composeImplementationGuideDefinitionParameterComponentElements(ImplementationGuide.ImplementationGuideDefinitionParameterComponent element) throws IOException { composeBackboneElementElements(element); if (element.hasCodeElement()) - composeEnumeration("code", element.getCodeElement(), new ImplementationGuide.GuideParameterCodeEnumFactory()); + composeString("code", element.getCodeElement()); if (element.hasValueElement()) { composeString("value", element.getValueElement()); } diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/ImplementationGuide.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/ImplementationGuide.java index 69ec09191..23a0e2812 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/ImplementationGuide.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/ImplementationGuide.java @@ -8282,10 +8282,9 @@ public class ImplementationGuide extends CanonicalResource { /** * apply | path-resource | path-pages | path-tx-cache | expansion-parameter | rule-broken-links | generate-xml | generate-json | generate-turtle | html-template. */ - @Child(name = "code", type = {CodeType.class}, order=1, min=1, max=1, modifier=false, summary=false) + @Child(name = "code", type = {StringType.class}, order=1, min=1, max=1, modifier=false, summary=false) @Description(shortDefinition="apply | path-resource | path-pages | path-tx-cache | expansion-parameter | rule-broken-links | generate-xml | generate-json | generate-turtle | html-template", formalDefinition="apply | path-resource | path-pages | path-tx-cache | expansion-parameter | rule-broken-links | generate-xml | generate-json | generate-turtle | html-template." ) - @ca.uhn.fhir.model.api.annotation.Binding(valueSet="http://hl7.org/fhir/ValueSet/guide-parameter-code") - protected Enumeration code; + protected StringType code; /** * Value for named type. @@ -8306,21 +8305,21 @@ public class ImplementationGuide extends CanonicalResource { /** * Constructor */ - public ImplementationGuideDefinitionParameterComponent(GuideParameterCode code, String value) { + public ImplementationGuideDefinitionParameterComponent(StringType code, StringType value) { super(); - this.setCode(code); - this.setValue(value); + this.code = code; + this.value = value; } /** * @return {@link #code} (apply | path-resource | path-pages | path-tx-cache | expansion-parameter | rule-broken-links | generate-xml | generate-json | generate-turtle | html-template.). This is the underlying object with id, value and extensions. The accessor "getCode" gives direct access to the value */ - public Enumeration getCodeElement() { + public StringType getCodeElement() { if (this.code == null) if (Configuration.errorOnAutoCreate()) throw new Error("Attempt to auto-create ImplementationGuideDefinitionParameterComponent.code"); else if (Configuration.doAutoCreate()) - this.code = new Enumeration(new GuideParameterCodeEnumFactory()); // bb + this.code = new StringType(); // bb return this.code; } @@ -8335,7 +8334,7 @@ public class ImplementationGuide extends CanonicalResource { /** * @param value {@link #code} (apply | path-resource | path-pages | path-tx-cache | expansion-parameter | rule-broken-links | generate-xml | generate-json | generate-turtle | html-template.). This is the underlying object with id, value and extensions. The accessor "getCode" gives direct access to the value */ - public ImplementationGuideDefinitionParameterComponent setCodeElement(Enumeration value) { + public ImplementationGuideDefinitionParameterComponent setCodeElement(StringType value) { this.code = value; return this; } @@ -8343,16 +8342,16 @@ public class ImplementationGuide extends CanonicalResource { /** * @return apply | path-resource | path-pages | path-tx-cache | expansion-parameter | rule-broken-links | generate-xml | generate-json | generate-turtle | html-template. */ - public GuideParameterCode getCode() { + public String getCode() { return this.code == null ? null : this.code.getValue(); } /** * @param value apply | path-resource | path-pages | path-tx-cache | expansion-parameter | rule-broken-links | generate-xml | generate-json | generate-turtle | html-template. */ - public ImplementationGuideDefinitionParameterComponent setCode(GuideParameterCode value) { + public ImplementationGuideDefinitionParameterComponent setCode(String value) { if (this.code == null) - this.code = new Enumeration(new GuideParameterCodeEnumFactory()); + this.code = new StringType(); this.code.setValue(value); return this; } @@ -8404,14 +8403,14 @@ public class ImplementationGuide extends CanonicalResource { protected void listChildren(List children) { super.listChildren(children); - children.add(new Property("code", "code", "apply | path-resource | path-pages | path-tx-cache | expansion-parameter | rule-broken-links | generate-xml | generate-json | generate-turtle | html-template.", 0, 1, code)); + children.add(new Property("code", "string", "apply | path-resource | path-pages | path-tx-cache | expansion-parameter | rule-broken-links | generate-xml | generate-json | generate-turtle | html-template.", 0, 1, code)); children.add(new Property("value", "string", "Value for named type.", 0, 1, value)); } @Override public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { switch (_hash) { - case 3059181: /*code*/ return new Property("code", "code", "apply | path-resource | path-pages | path-tx-cache | expansion-parameter | rule-broken-links | generate-xml | generate-json | generate-turtle | html-template.", 0, 1, code); + case 3059181: /*code*/ return new Property("code", "string", "apply | path-resource | path-pages | path-tx-cache | expansion-parameter | rule-broken-links | generate-xml | generate-json | generate-turtle | html-template.", 0, 1, code); case 111972721: /*value*/ return new Property("value", "string", "Value for named type.", 0, 1, value); default: return super.getNamedProperty(_hash, _name, _checkValid); } @@ -8432,8 +8431,7 @@ public class ImplementationGuide extends CanonicalResource { public Base setProperty(int hash, String name, Base value) throws FHIRException { switch (hash) { case 3059181: // code - value = new GuideParameterCodeEnumFactory().fromType(TypeConvertor.castToCode(value)); - this.code = (Enumeration) value; // Enumeration + this.code = TypeConvertor.castToString(value); // StringType return value; case 111972721: // value this.value = TypeConvertor.castToString(value); // StringType @@ -8446,8 +8444,7 @@ public class ImplementationGuide extends CanonicalResource { @Override public Base setProperty(String name, Base value) throws FHIRException { if (name.equals("code")) { - value = new GuideParameterCodeEnumFactory().fromType(TypeConvertor.castToCode(value)); - this.code = (Enumeration) value; // Enumeration + this.code = TypeConvertor.castToString(value); // StringType } else if (name.equals("value")) { this.value = TypeConvertor.castToString(value); // StringType } else @@ -8468,7 +8465,7 @@ public class ImplementationGuide extends CanonicalResource { @Override public String[] getTypesForProperty(int hash, String name) throws FHIRException { switch (hash) { - case 3059181: /*code*/ return new String[] {"code"}; + case 3059181: /*code*/ return new String[] {"string"}; case 111972721: /*value*/ return new String[] {"string"}; default: return super.getTypesForProperty(hash, name); } diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/IGHelper.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/IGHelper.java index 253c749ec..18982c9b7 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/IGHelper.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/IGHelper.java @@ -45,7 +45,7 @@ public class IGHelper { public static String readStringParameter(ImplementationGuideDefinitionComponent ig, String name) { for (ImplementationGuideDefinitionParameterComponent p : ig.getParameter()) { - if (name == p.getCode().toCode()) { + if (name == p.getCode()) { return p.getValue(); } } @@ -59,19 +59,19 @@ public class IGHelper { public static void setParameter(ImplementationGuideDefinitionComponent ig, String name, String value) { for (ImplementationGuideDefinitionParameterComponent p : ig.getParameter()) { - if (name == p.getCode().toCode()) { + if (name == p.getCode()) { p.setValue(value); return; } } ImplementationGuideDefinitionParameterComponent p = ig.addParameter(); - p.setCode(org.hl7.fhir.r4b.model.ImplementationGuide.GuideParameterCode.fromCode(name)); + p.setCode(name); p.setValue(value); } public static void addParameter(ImplementationGuideDefinitionComponent ig, String name, String value) { ImplementationGuideDefinitionParameterComponent p = ig.addParameter(); - p.setCode(org.hl7.fhir.r4b.model.ImplementationGuide.GuideParameterCode.fromCode(name)); + p.setCode(name); p.setValue(value); } From 4d16fe46c0503ebddf10175fa51c42ed9e7314a2 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 14 Nov 2022 18:03:55 +1100 Subject: [PATCH 4/6] Fix problem with value set validator hiding errors --- .../main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java | 5 +++++ .../org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java | 2 +- .../hl7/fhir/validation/instance/type/ValueSetValidator.java | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java index a4c3ab65f..91b64651b 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/BaseWorkerContext.java @@ -1016,6 +1016,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte return res; } + String localError = null; if (options.isUseClient()) { // ok, first we try to validate locally try { @@ -1028,6 +1029,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte return res; } } catch (Exception e) { + localError = e.getMessage(); } } @@ -1055,6 +1057,9 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte } catch (Exception e) { res = new ValidationResult(IssueSeverity.ERROR, e.getMessage() == null ? e.getClass().getName() : e.getMessage()).setTxLink(txLog == null ? null : txLog.getLastId()).setErrorClass(TerminologyServiceErrorClass.SERVER_ERROR); } + if (!res.isOk() && localError != null) { + res.setMessage("Local Error: "+localError+". Server Error: "+res.getMessage()); + } updateUnsupportedCodeSystems(res, code, codeKey); if (txCache != null) { // we never cache unsupported code systems - we always keep trying (but only once per run) txCache.cacheValidation(cacheToken, res, TerminologyCache.PERMANENT); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java index 677754432..ea0ea3006 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ValueSetCheckerSimple.java @@ -240,7 +240,7 @@ public class ValueSetCheckerSimple extends ValueSetWorker implements ValueSetChe return new ValidationResult(IssueSeverity.ERROR, context.formatMessage(I18nConstants.CODESYSTEM_CS_NO_SUPPLEMENT, cs.getUrl())); } if (cs!=null && cs.getContent() != CodeSystemContentMode.COMPLETE) { - warningMessage = "Resolved system "+system+", but the definition is not complete"; + warningMessage = "Resolved system "+system+(cs.hasVersion() ? " (v"+cs.getVersion()+")" : "")+", but the definition is not complete"; if (!inExpansion && cs.getContent() != CodeSystemContentMode.FRAGMENT) { // we're going to give it a go if it's a fragment throw new FHIRException(warningMessage); } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java index c31479014..6bb5a0633 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java @@ -179,7 +179,6 @@ public class ValueSetValidator extends BaseValidator { } cf++; } - warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), systemOk, version == null ? I18nConstants.VALUESET_UNC_SYSTEM_WARNING : I18nConstants.VALUESET_UNC_SYSTEM_WARNING_VER, system); } else { warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), filters.size() == 0 && concepts.size() == 0, I18nConstants.VALUESET_NO_SYSTEM_WARNING); } @@ -191,6 +190,7 @@ public class ValueSetValidator extends BaseValidator { if (version == null) { ValidationResult vv = context.validateCode(ValidationOptions.defaults(), new Coding(system, code, null), null); if (vv.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) { + warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), false, I18nConstants.VALUESET_UNC_SYSTEM_WARNING, system, vv.getMessage()); return false; } else { boolean ok = vv.isOk(); @@ -199,6 +199,7 @@ public class ValueSetValidator extends BaseValidator { } else { ValidationResult vv = context.validateCode(ValidationOptions.defaults(), new Coding(system, code, null).setVersion(version), null); if (vv.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) { + warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), false, I18nConstants.VALUESET_UNC_SYSTEM_WARNING_VER, system+"#"+version, vv.getMessage()); return false; } else { boolean ok = vv.isOk(); From 231aae60435a1526afebfe4c78dc8d24dedad9fe Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 14 Nov 2022 18:04:27 +1100 Subject: [PATCH 5/6] Fix issue rendering resource by name --- .../r5/renderers/utils/DirectWrappers.java | 20 +++++++++++++++++-- .../hl7/fhir/utilities/npm/NpmPackage.java | 9 +++++++-- .../src/main/resources/Messages.properties | 4 ++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DirectWrappers.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DirectWrappers.java index d89e34c01..a3117b396 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DirectWrappers.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/utils/DirectWrappers.java @@ -223,8 +223,24 @@ public class DirectWrappers { s = s + " " + family.getValues().get(0).primitiveValue().toUpperCase(); return s; } else { - // it might be a human name? - throw new Error("What to do? Type is "+b.fhirType()); + Property p = b.getChildByName("name"); + if (p == null || !p.hasValues()) { + p = b.getChildByName("name"); + } + if (p == null || !p.hasValues()) { + p = b.getChildByName("text"); + } + if (p == null || !p.hasValues()) { + p = b.getChildByName("value"); + } + if (p == null || !p.hasValues()) { + p = b.getChildByName("productName"); // MedicinalProductDefinition + } + if (p == null || !p.hasValues()) { + throw new Error("What to render for 'name'? Type is "+b.fhirType()); + } else { + return p.getValues().get(0).primitiveValue(); + } } } return null; diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java index 7d5a38edd..701709d92 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/NpmPackage.java @@ -559,7 +559,7 @@ public class NpmPackage { for (JsonElement e : folder.index.getAsJsonArray("files")) { JsonObject fi = e.getAsJsonObject(); if (Utilities.existsInList(JsonUtilities.str(fi, "resourceType"), types)) { - res.add(new PackageResourceInformation(folder.folder.getAbsolutePath(), fi)); + res.add(new PackageResourceInformation(folder.folder == null ? "@"+folder.getName() : folder.folder.getAbsolutePath(), fi)); } } } @@ -1159,7 +1159,12 @@ public class NpmPackage { } public InputStream load(PackageResourceInformation p) throws FileNotFoundException { - return new FileInputStream(p.filename); + if (p.filename.startsWith("@")) { + String[] pl = p.filename.substring(1).split("\\/"); + return new ByteArrayInputStream(folders.get(pl[0]).content.get(pl[1])); + } else { + return new FileInputStream(p.filename); + } } public Date dateAsDate() { diff --git a/org.hl7.fhir.utilities/src/main/resources/Messages.properties b/org.hl7.fhir.utilities/src/main/resources/Messages.properties index 732f591d3..988599ed8 100644 --- a/org.hl7.fhir.utilities/src/main/resources/Messages.properties +++ b/org.hl7.fhir.utilities/src/main/resources/Messages.properties @@ -550,8 +550,8 @@ SEARCHPARAMETER_EXP_WRONG = The expression ''{2}'' is not compatible with the ex VALUESET_NO_SYSTEM_WARNING = No System specified, so Concepts and Filters can't be checked VALUESET_INCLUDE_INVALID_CONCEPT_CODE = The code {1} is not valid in the system {0} VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER = The code {2} is not valid in the system {0} version {1} -VALUESET_UNC_SYSTEM_WARNING = Unknown System ''{0}'' specified, so Concepts and Filters can't be checked -VALUESET_UNC_SYSTEM_WARNING_VER = Unknown System/Version ''{0}'' specified, so Concepts and Filters can't be checked +VALUESET_UNC_SYSTEM_WARNING = Unknown System ''{0}'' specified, so Concepts and Filters can''t be checked (Details: {1}) +VALUESET_UNC_SYSTEM_WARNING_VER = Unknown System/Version ''{0}'' specified, so Concepts and Filters can''t be checked (Details: {1}) Extension_PROF_Type = The Profile ''{0}'' definition allows for the type {1} but found type {2} TYPE_CHECKS_PATTERN_CC = The pattern [system {0}, code {1}, and display ''{2}''] defined in the profile {3} not found. Issues: {4} TYPE_CHECKS_PATTERN_CC_US = The pattern [system {0}, code {1}, display ''{2}'' and userSelected {5}] defined in the profile {3} not found. Issues: {4} From dcb27e53a6beb83e5dfcbac91fa343c1895de216 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Mon, 14 Nov 2022 21:02:11 +1100 Subject: [PATCH 6/6] fix error location --- .../fhir/validation/instance/type/ValueSetValidator.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java index 6bb5a0633..297a92284 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java @@ -147,7 +147,7 @@ public class ValueSetValidator extends BaseValidator { for (Element concept : concepts) { // we treat the first differently because we want to know if tbe system is worth validating. if it is, then we batch the rest if (first) { - systemOk = validateValueSetIncludeConcept(errors, concept, stack.push(concept, cc, null, null), system, version); + systemOk = validateValueSetIncludeConcept(errors, concept, stack, stack.push(concept, cc, null, null), system, version); first = false; } else if (systemOk) { batch.add(prepareValidateValueSetIncludeConcept(errors, concept, stack.push(concept, cc, null, null), system, version)); @@ -185,12 +185,12 @@ public class ValueSetValidator extends BaseValidator { return ok; } - private boolean validateValueSetIncludeConcept(List errors, Element concept, NodeStack stack, String system, String version) { + private boolean validateValueSetIncludeConcept(List errors, Element concept, NodeStack stackInc, NodeStack stack, String system, String version) { String code = concept.getChildValue("code"); if (version == null) { ValidationResult vv = context.validateCode(ValidationOptions.defaults(), new Coding(system, code, null), null); if (vv.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) { - warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), false, I18nConstants.VALUESET_UNC_SYSTEM_WARNING, system, vv.getMessage()); + warning(errors, IssueType.BUSINESSRULE, stackInc.getLiteralPath(), false, I18nConstants.VALUESET_UNC_SYSTEM_WARNING, system, vv.getMessage()); return false; } else { boolean ok = vv.isOk(); @@ -199,7 +199,7 @@ public class ValueSetValidator extends BaseValidator { } else { ValidationResult vv = context.validateCode(ValidationOptions.defaults(), new Coding(system, code, null).setVersion(version), null); if (vv.getErrorClass() == TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED) { - warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), false, I18nConstants.VALUESET_UNC_SYSTEM_WARNING_VER, system+"#"+version, vv.getMessage()); + warning(errors, IssueType.BUSINESSRULE, stackInc.getLiteralPath(), false, I18nConstants.VALUESET_UNC_SYSTEM_WARNING_VER, system+"#"+version, vv.getMessage()); return false; } else { boolean ok = vv.isOk();