From 373abb7dcc71b25ac7cccb20fc424e01b1c3dccf Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 31 Jan 2023 16:06:51 +1100 Subject: [PATCH 1/5] ignore ig-r4 when converting for generated package versions --- .../hl7/fhir/convertors/misc/NpmPackageVersionConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java index b51479978..bdca3aebd 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java @@ -81,7 +81,7 @@ public class NpmPackageVersionConverter { output.put("package/other/spec.internals", convertSpec(content.get("package/other/spec.internals"))); for (Entry e : content.entrySet()) { - if (!e.getKey().equals("package/package.json") && !e.getKey().equals("package/other/spec.internals")) { + if (!e.getKey().equals("package/package.json") && !e.getKey().equals("package/other/spec.internals") && !e.getKey().endsWith("ig-r4.json")) { byte[] cnv = e.getValue(); try { JsonObject json = JsonParser.parseObject(e.getValue()); From 1e6fd76ace04b25b7792263de6cf1cc18f34b0cf Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 31 Jan 2023 16:07:10 +1100 Subject: [PATCH 2/5] special case work around for old THO problem --- .../src/main/java/org/hl7/fhir/dstu3/model/Identifier.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Identifier.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Identifier.java index e3c112d13..95cbf20ca 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Identifier.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/Identifier.java @@ -129,7 +129,7 @@ public class Identifier extends Type implements ICompositeType { public static class IdentifierUseEnumFactory implements EnumFactory { public IdentifierUse fromCode(String codeString) throws IllegalArgumentException { if (codeString == null || "".equals(codeString)) - if (codeString == null || "".equals(codeString)) + if (codeString == null || "".equals(codeString) || "?".equals(codeString)) return null; if ("usual".equals(codeString)) return IdentifierUse.USUAL; From f9b386d5b2c650803d0657f9f6d81320bb2faf5b Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 31 Jan 2023 16:54:30 +1100 Subject: [PATCH 3/5] r5 extension extractor --- .../convertors/misc/ExtensionExtractor.java | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java new file mode 100644 index 000000000..85a061464 --- /dev/null +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java @@ -0,0 +1,152 @@ +package org.hl7.fhir.convertors.misc; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; + +import org.hl7.fhir.exceptions.FHIRFormatError; +import org.hl7.fhir.r5.context.CanonicalResourceManager; +import org.hl7.fhir.r5.formats.JsonParser; +import org.hl7.fhir.r5.formats.XmlParser; +import org.hl7.fhir.r5.model.CodeSystem; +import org.hl7.fhir.r5.model.ElementDefinition; +import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingAdditionalComponent; +import org.hl7.fhir.r5.model.StructureDefinition; +import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent; +import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule; +import org.hl7.fhir.r5.model.ValueSet; +import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent; +import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; +import org.hl7.fhir.utilities.npm.NpmPackage; + +import ca.uhn.fhir.model.api.IStreamingDatatype; + +public class ExtensionExtractor { + + public static void main(String[] args) throws FHIRFormatError, FileNotFoundException, IOException { + new ExtensionExtractor().process(args[0]); + + } + + private void process(String dst) throws IOException { + FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true); + NpmPackage r5 = pcm.loadPackage("hl7.fhir.r5.core", "current"); + CanonicalResourceManager cslist = new CanonicalResourceManager(true); + for (String r : r5.listResources("CodeSystem")) { + CodeSystem cs = (CodeSystem) new JsonParser().parse(r5.load(r)); + cslist.see(cs, null); + } + CanonicalResourceManager vslist = new CanonicalResourceManager(true); + for (String r : r5.listResources("ValueSet")) { + ValueSet vs = (ValueSet) new JsonParser().parse(r5.load(r)); + vslist.see(vs, null); + } + for (ValueSet vs : vslist.getList()) { + for (ConceptSetComponent inc : vs.getCompose().getInclude()) { + CodeSystem cs = cslist.get(inc.getSystem()); + if (cs != null) { + if (!cs.hasUserData("vsl")) { + cs.setUserData("vsl", new ArrayList()); + } + ((ArrayList) cs.getUserData("vsl")).add(vs); + } + } + } + for (String r : r5.listResources("StructureDefinition")) { + StructureDefinition sd = (StructureDefinition) new JsonParser().parse(r5.load(r)); + if (sd.getType().equals("Extension") && sd.getDerivation() == TypeDerivationRule.CONSTRAINT) { + String fn; + if (sd.getContext().size() == 0) { + fn = Utilities.path(dst, "null", sd.getId()+".json"); + } else if (sd.getContext().size() > 1) { + boolean dt = true; + for (StructureDefinitionContextComponent x : sd.getContext()) { + String s = extractType(x.getExpression()); + dt = dt && isDataType(s); + } + if (dt) { + fn = Utilities.path(dst, "datatypes", "multiple", sd.getId()+".xml"); + } else { + fn = Utilities.path(dst, "multiple", sd.getId()+".xml"); + } + } else { + String s = extractType(sd.getContextFirstRep().getExpression()); + if (isDataType(s)) { + fn = Utilities.path(dst, "datatypes", s, sd.getId()+".xml"); + } else { + fn = Utilities.path(dst, s, sd.getId()+".xml"); + } + Utilities.createDirectory(Utilities.getDirectoryForFile(fn)); + new XmlParser().compose(new FileOutputStream(fn), sd); + } + for (ElementDefinition ed : sd.getSnapshot().getElement()) { + seeBinding(ed.getBinding().getValueSet(), vslist, "ext", sd); + for (ElementDefinitionBindingAdditionalComponent ab : ed.getBinding().getAdditional()) { + seeBinding(ab.getValueSet(), vslist, "ext", sd); + } + } + } else { + for (ElementDefinition ed : sd.getSnapshot().getElement()) { + seeBinding(ed.getBinding().getValueSet(), vslist, "core", sd); + for (ElementDefinitionBindingAdditionalComponent ab : ed.getBinding().getAdditional()) { + seeBinding(ab.getValueSet(), vslist, "core", sd); + } + } + } + } + for (ValueSet vs : vslist.getList()) { + if (vs.hasUserData("core") || !vs.hasUserData("ext")) { + vslist.drop(vs.getId()); + } + } + for (CodeSystem cs : cslist.getList()) { + boolean keep = false; + if (cs.hasUserData("vsl" )) { + keep = true; + for (ValueSet vs : (ArrayList) cs.getUserData("vsl")) { + if (!vslist.has(vs.getUrl())) { + keep = false; + } + } + } + if (!keep) { + cslist.drop(cs.getId()); + } + } + for (ValueSet vs : vslist.getList()) { + System.out.println(vs.getUrl()); + } + for (CodeSystem cs : cslist.getList()) { + System.out.println(cs.getUrl()); + } + } + + private void seeBinding(String url, CanonicalResourceManager vslist, String name, StructureDefinition sd) { + ValueSet vs = vslist.get(url); + if (vs != null) { + vs.setUserData(name, sd); + } + } + + private boolean isDataType(String s) { + return Utilities.existsInList(s, + "PrimitiveType", "instant", "time", "date", "dateTime", "decimal", "boolean", "integer", "string", + "uri", "base64Binary", "code", "id", "oid", "unsignedInt", "positiveInt", "markdown", "url", "canonical", + "uuid", "integer64", "DataType", "BackboneType", "Identifier", "HumanName", "Address", "ContactPoint", + "Timing", "Quantity", "SimpleQuantity", "Attachment", "Range", "Period", "Ratio", "RatioRange", "CodeableConcept", + "Coding", "SampledData", "Age", "Distance", "Duration", "Count", "Money", "MoneyQuantity", "Annotation", "Signature", "DataType", + "ContactDetail", "Contributor", "DataRequirement", "ParameterDefinition", "RelatedArtifact", "TriggerDefinition", "UsageContext", + "Expression", "ExtendedContactDetail", "VirtualServiceDetail", "Availability", "MonetaryComponent", "DataType", + "BackboneType", "Reference", "Narrative", "Extension", "Meta", "ElementDefinition", "Dosage", "xhtml", "CodeableReference"); + } + + private String extractType(String x) { + String s = x; + if (s.contains(".")) { + s = s.substring(0, s.indexOf(".")); + } + return s; + } +} From 107fa0e3a227bde4ecf1ad41a29852d3e8e7d262 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 1 Feb 2023 14:48:48 +1100 Subject: [PATCH 4/5] update extension extractor --- .../convertors/analytics/PackageVisitor.java | 1 - .../resources30_40/Immunization30_40.java | 1 - .../CompartmentDefinition30_50.java | 1 - .../resources30_50/GraphDefinition30_50.java | 2 - .../primitive40_50/DateTime40_50.java | 1 - .../special40_50/Reference40_50.java | 3 - .../resources40_50/GraphDefinition40_50.java | 3 - .../special43_50/Reference43_50.java | 1 - .../resources43_50/GraphDefinition43_50.java | 3 - .../loaders/loaderR5/R5ToR5Loader.java | 2 - .../convertors/misc/ExtensionExtractor.java | 56 ++++++++++++------- .../fhir/convertors/misc/JsonProcessor.java | 1 - .../misc/NpmPackageVersionConverter.java | 11 ++-- .../convertors/misc/XMLPackageConvertor.java | 1 - .../xver/CorePackageVersionConvertor.java | 2 - .../conv30_40/Immunization30_40Test.java | 15 +++-- .../StructureDefinition40_50Test.java | 10 +--- .../misc/NpmPackageVersionConverterTests.java | 11 ++-- 18 files changed, 58 insertions(+), 67 deletions(-) diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java index fb7150f59..3fe9327fe 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/analytics/PackageVisitor.java @@ -17,7 +17,6 @@ import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.json.model.JsonArray; -import org.hl7.fhir.utilities.json.model.JsonElement; import org.hl7.fhir.utilities.json.model.JsonObject; import org.hl7.fhir.utilities.json.parser.JsonParser; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/resources30_40/Immunization30_40.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/resources30_40/Immunization30_40.java index cb10e04c8..51aa26e0d 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/resources30_40/Immunization30_40.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_40/resources30_40/Immunization30_40.java @@ -10,7 +10,6 @@ import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Bool import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.Date30_40; import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.DateTime30_40; import org.hl7.fhir.convertors.conv30_40.datatypes30_40.primitivetypes30_40.String30_40; - import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.Immunization; 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 dd6d45de1..23fbdfa0c 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 @@ -3,7 +3,6 @@ package org.hl7.fhir.convertors.conv30_50.resources30_50; import org.hl7.fhir.convertors.context.ConversionContext30_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; import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Boolean30_50; import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Code30_50; import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.DateTime30_50; diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/GraphDefinition30_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/GraphDefinition30_50.java index 150e80774..c9f000f25 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/GraphDefinition30_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv30_50/resources30_50/GraphDefinition30_50.java @@ -5,9 +5,7 @@ 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; import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Boolean30_50; -import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Code30_50; import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.DateTime30_50; -import org.hl7.fhir.convertors.conv30_50.datatypes30_50.primitivetypes30_50.Integer30_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; diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/DateTime40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/DateTime40_50.java index 6109fbbd1..93540c693 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/DateTime40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/primitive40_50/DateTime40_50.java @@ -1,7 +1,6 @@ package org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50; import org.hl7.fhir.convertors.context.ConversionContext40_50; -import org.hl7.fhir.convertors.context.ConversionContext43_50; import org.hl7.fhir.exceptions.FHIRException; public class DateTime40_50 { diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/special40_50/Reference40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/special40_50/Reference40_50.java index 6f31b713f..b9f714619 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/special40_50/Reference40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/datatypes40_50/special40_50/Reference40_50.java @@ -1,13 +1,10 @@ package org.hl7.fhir.convertors.conv40_50.datatypes40_50.special40_50; -import org.hl7.fhir.convertors.context.ConversionContext30_50; import org.hl7.fhir.convertors.context.ConversionContext40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.Identifier40_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.exceptions.FHIRException; -import org.hl7.fhir.r4.model.Reference; -import org.hl7.fhir.r5.model.CanonicalType; import org.hl7.fhir.r5.model.CodeableReference; public class Reference40_50 { diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/GraphDefinition40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/GraphDefinition40_50.java index 613757c88..fca0a0ad1 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/GraphDefinition40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv40_50/resources40_50/GraphDefinition40_50.java @@ -5,10 +5,7 @@ import org.hl7.fhir.convertors.conv40_50.datatypes40_50.general40_50.CodeableCon import org.hl7.fhir.convertors.conv40_50.datatypes40_50.metadata40_50.ContactDetail40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.metadata40_50.UsageContext40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Boolean40_50; -import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Canonical40_50; -import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Code40_50; import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.DateTime40_50; -import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.Integer40_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; diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/special43_50/Reference43_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/special43_50/Reference43_50.java index c4202ce7f..c70ccdf26 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/special43_50/Reference43_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/datatypes43_50/special43_50/Reference43_50.java @@ -1,6 +1,5 @@ package org.hl7.fhir.convertors.conv43_50.datatypes43_50.special43_50; -import org.hl7.fhir.convertors.context.ConversionContext40_50; import org.hl7.fhir.convertors.context.ConversionContext43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.Identifier43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.String43_50; diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/GraphDefinition43_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/GraphDefinition43_50.java index e78368dc6..c9324c785 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/GraphDefinition43_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/conv43_50/resources43_50/GraphDefinition43_50.java @@ -5,10 +5,7 @@ import org.hl7.fhir.convertors.conv43_50.datatypes43_50.general43_50.CodeableCon import org.hl7.fhir.convertors.conv43_50.datatypes43_50.metadata43_50.ContactDetail43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.metadata43_50.UsageContext43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Boolean43_50; -import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Canonical43_50; -import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Code43_50; import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.DateTime43_50; -import org.hl7.fhir.convertors.conv43_50.datatypes43_50.primitive43_50.Integer43_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; diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/loaderR5/R5ToR5Loader.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/loaderR5/R5ToR5Loader.java index d9161c27e..3a5494efa 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/loaderR5/R5ToR5Loader.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/loaders/loaderR5/R5ToR5Loader.java @@ -47,12 +47,10 @@ import org.hl7.fhir.r5.model.CanonicalType; import org.hl7.fhir.r5.model.CodeSystem; import org.hl7.fhir.r5.model.ElementDefinition; import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent; -import org.hl7.fhir.r5.model.Enumerations.BindingStrength; import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind; import org.hl7.fhir.r5.model.UriType; -import org.hl7.fhir.r5.utils.ToolingExtensions; public class R5ToR5Loader extends BaseLoaderR5 { diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java index 85a061464..ac3bd2467 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/ExtensionExtractor.java @@ -1,5 +1,6 @@ package org.hl7.fhir.convertors.misc; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -7,8 +8,10 @@ import java.util.ArrayList; import org.hl7.fhir.exceptions.FHIRFormatError; import org.hl7.fhir.r5.context.CanonicalResourceManager; +import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.formats.JsonParser; import org.hl7.fhir.r5.formats.XmlParser; +import org.hl7.fhir.r5.model.CanonicalResource; import org.hl7.fhir.r5.model.CodeSystem; import org.hl7.fhir.r5.model.ElementDefinition; import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingAdditionalComponent; @@ -21,8 +24,6 @@ import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.NpmPackage; -import ca.uhn.fhir.model.api.IStreamingDatatype; - public class ExtensionExtractor { public static void main(String[] args) throws FHIRFormatError, FileNotFoundException, IOException { @@ -57,9 +58,16 @@ public class ExtensionExtractor { for (String r : r5.listResources("StructureDefinition")) { StructureDefinition sd = (StructureDefinition) new JsonParser().parse(r5.load(r)); if (sd.getType().equals("Extension") && sd.getDerivation() == TypeDerivationRule.CONSTRAINT) { + for (ElementDefinition ed : sd.getSnapshot().getElement()) { + seeBinding(ed.getBinding().getValueSet(), vslist, "ext", sd); + for (ElementDefinitionBindingAdditionalComponent ab : ed.getBinding().getAdditional()) { + seeBinding(ab.getValueSet(), vslist, "ext", sd); + } + } + sd.setSnapshot(null); String fn; if (sd.getContext().size() == 0) { - fn = Utilities.path(dst, "null", sd.getId()+".json"); + save(sd, dst,"none"); } else if (sd.getContext().size() > 1) { boolean dt = true; for (StructureDefinitionContextComponent x : sd.getContext()) { @@ -67,24 +75,16 @@ public class ExtensionExtractor { dt = dt && isDataType(s); } if (dt) { - fn = Utilities.path(dst, "datatypes", "multiple", sd.getId()+".xml"); + save(sd, dst,"datatypes"); } else { - fn = Utilities.path(dst, "multiple", sd.getId()+".xml"); + save(sd, dst,"multiple"); } } else { String s = extractType(sd.getContextFirstRep().getExpression()); if (isDataType(s)) { - fn = Utilities.path(dst, "datatypes", s, sd.getId()+".xml"); + save(sd, dst,"datatypes"); } else { - fn = Utilities.path(dst, s, sd.getId()+".xml"); - } - Utilities.createDirectory(Utilities.getDirectoryForFile(fn)); - new XmlParser().compose(new FileOutputStream(fn), sd); - } - for (ElementDefinition ed : sd.getSnapshot().getElement()) { - seeBinding(ed.getBinding().getValueSet(), vslist, "ext", sd); - for (ElementDefinitionBindingAdditionalComponent ab : ed.getBinding().getAdditional()) { - seeBinding(ab.getValueSet(), vslist, "ext", sd); + save(sd, dst,s); } } } else { @@ -97,13 +97,13 @@ public class ExtensionExtractor { } } for (ValueSet vs : vslist.getList()) { - if (vs.hasUserData("core") || !vs.hasUserData("ext")) { + if (vs.hasUserData("core") || !vs.hasUserData("ext") || vs.getUrl().startsWith("http://terminology.")) { vslist.drop(vs.getId()); } } for (CodeSystem cs : cslist.getList()) { boolean keep = false; - if (cs.hasUserData("vsl" )) { + if (cs.hasUserData("vsl") && !cs.getUrl().startsWith("http://terminology.")) { keep = true; for (ValueSet vs : (ArrayList) cs.getUserData("vsl")) { if (!vslist.has(vs.getUrl())) { @@ -116,10 +116,28 @@ public class ExtensionExtractor { } } for (ValueSet vs : vslist.getList()) { - System.out.println(vs.getUrl()); + StructureDefinition sd = (StructureDefinition) vs.getUserData("ext"); + String s = sd.getUserString("folder"); + save(vs, dst, s); } for (CodeSystem cs : cslist.getList()) { - System.out.println(cs.getUrl()); + ValueSet vs = ((ArrayList) cs.getUserData("vsl")).get(0); + String s = vs.getUserString("folder"); + save(cs, dst,s); + } + } + + private void save(CanonicalResource cr, String dst, String folder) throws IOException { + // TODO Auto-generated method stub + cr.setText(null); + if (!cr.hasTitle()) { + cr.setTitle(Utilities.unCamelCase(cr.getName())); + } + String fn = Utilities.path(dst, folder, cr.fhirType()+"-"+cr.getId()+".xml"); + cr.setUserData("folder", folder); + if (!new File(fn).exists()) { + Utilities.createDirectory(Utilities.getDirectoryForFile(fn)); + new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), cr); } } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/JsonProcessor.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/JsonProcessor.java index 2a0b11ec2..34347ca39 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/JsonProcessor.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/JsonProcessor.java @@ -1,6 +1,5 @@ package org.hl7.fhir.convertors.misc; -import java.io.File; import java.io.FileOutputStream; import java.io.IOException; diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java index bdca3aebd..f6432f366 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverter.java @@ -1,6 +1,10 @@ package org.hl7.fhir.convertors.misc; -import java.io.*; +import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; @@ -8,6 +12,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import javax.annotation.Nonnull; + import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; @@ -35,9 +41,6 @@ import org.hl7.fhir.utilities.json.model.JsonObject; import org.hl7.fhir.utilities.json.parser.JsonParser; import org.hl7.fhir.utilities.npm.NpmPackageIndexBuilder; -import com.google.common.base.Charsets; -import javax.annotation.Nonnull; - public class NpmPackageVersionConverter { private static final int BUFFER_SIZE = 1024; diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/XMLPackageConvertor.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/XMLPackageConvertor.java index 8de59681a..b6c087ced 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/XMLPackageConvertor.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/XMLPackageConvertor.java @@ -3,7 +3,6 @@ package org.hl7.fhir.convertors.misc; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.util.Map.Entry; import org.hl7.fhir.utilities.json.model.JsonObject; import org.hl7.fhir.utilities.json.model.JsonProperty; 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 index 7c8069c53..ce3e00c8d 100644 --- 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 @@ -3,7 +3,6 @@ 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; @@ -14,7 +13,6 @@ 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.model.JsonArray; diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv30_40/Immunization30_40Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv30_40/Immunization30_40Test.java index 93157bc25..c9e0a7d31 100644 --- a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv30_40/Immunization30_40Test.java +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv30_40/Immunization30_40Test.java @@ -1,17 +1,16 @@ package org.hl7.fhir.convertors.conv30_40; -import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40; -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - import java.io.IOException; import java.io.InputStream; import java.util.stream.Stream; +import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + public class Immunization30_40Test { private org.hl7.fhir.r4.formats.JsonParser r4Parser = new org.hl7.fhir.r4.formats.JsonParser(); diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/StructureDefinition40_50Test.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/StructureDefinition40_50Test.java index 3df55d032..31a31f1e0 100644 --- a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/StructureDefinition40_50Test.java +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/conv40_50/StructureDefinition40_50Test.java @@ -1,20 +1,14 @@ package org.hl7.fhir.convertors.conv40_50; import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.InputStream; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.text.StringEscapeUtils; +import javax.annotation.Nullable; + import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50; -import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; -import javax.annotation.Nullable; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverterTests.java b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverterTests.java index 3d7d84fa4..b03502d05 100644 --- a/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverterTests.java +++ b/org.hl7.fhir.convertors/src/test/java/org/hl7/fhir/convertors/misc/NpmPackageVersionConverterTests.java @@ -1,17 +1,16 @@ package org.hl7.fhir.convertors.misc; -import org.hl7.fhir.utilities.npm.NpmPackage; -import org.hl7.fhir.utilities.tests.ResourceLoaderTests; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Map; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import org.hl7.fhir.utilities.tests.ResourceLoaderTests; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class NpmPackageVersionConverterTests implements ResourceLoaderTests { @org.junit.jupiter.api.Test From 2cc8ff5e2383496026d0f2e7dcc8d562e805b16b Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 1 Feb 2023 14:49:14 +1100 Subject: [PATCH 5/5] extension related validation fixes --- .../org/hl7/fhir/r5/context/CanonicalResourceManager.java | 2 ++ .../instance/type/StructureDefinitionValidator.java | 2 +- .../validation/instance/utils/FHIRPathExpressionFixer.java | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java index 62b35613d..5838a154d 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/CanonicalResourceManager.java @@ -326,6 +326,8 @@ public class CanonicalResourceManager { public void drop(CachedCanonicalResource cr) { while (map.values().remove(cr)); + while (listForId.values().remove(cr)); + while (listForUrl.values().remove(cr)); list.remove(cr); List> set = listForUrl.get(cr.getUrl()); if (set != null) { // it really should be diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java index 2f1e69d94..fcdd464dc 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java @@ -561,7 +561,7 @@ public class StructureDefinitionValidator extends BaseValidator { } else if (!VersionUtilities.isR5Ver(context.getVersion())) { ok = rule(errors, NO_RULE_DATE, IssueType.EXCEPTION, stack.getLiteralPath(), VersionUtilities.getCanonicalResourceNames(context.getVersion()).contains(t.getType()) || "Resource".equals(t.getType()), I18nConstants.SD_ED_TYPE_PROFILE_WRONG_TARGET, p, t, code, path, "Canonical Resource") && ok; } else { - ok = rule(errors, NO_RULE_DATE, IssueType.EXCEPTION, stack.getLiteralPath(), VersionUtilities.getCanonicalResourceNames(context.getVersion()).contains(t.getType()), I18nConstants.SD_ED_TYPE_PROFILE_WRONG_TARGET, p, t, code, path, "Canonical Resource") && ok; + ok = rule(errors, NO_RULE_DATE, IssueType.EXCEPTION, stack.getLiteralPath(), "CanonicalResource".equals(t.getType()) || VersionUtilities.getCanonicalResourceNames(context.getVersion()).contains(t.getType()), I18nConstants.SD_ED_TYPE_PROFILE_WRONG_TARGET, p, t, code, path, "Canonical Resource") && ok; } } } else { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/utils/FHIRPathExpressionFixer.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/utils/FHIRPathExpressionFixer.java index 07ae6b0d6..459f4c298 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/utils/FHIRPathExpressionFixer.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/utils/FHIRPathExpressionFixer.java @@ -47,9 +47,9 @@ public class FHIRPathExpressionFixer { if (expr.equals("url.matches('([^|#])*')")) { return ("$this.matches('([^|#])*')"); } - - - + if (expr.equals("((kind in 'resource' | 'complex-type') and (specialization = 'derivation')) implies differential.element.where((min != 0 and min != 1) or (max != '1' and max != '*')).empty()")) { + return "((kind in 'resource' | 'complex-type') and (derivation = 'specialization')) implies differential.element.where((min.exists() and min != 0 and min != 1) or (max.exists() and max != '1' and max != '*')).empty()"; + } // clarification in FHIRPath spec if ("eld-19".equals(key)) {