From 7c48c0d66a6abd9148b3e24e6e8377080d0eb470 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 11 Mar 2021 01:08:09 +1100 Subject: [PATCH] Gg 20201mar r4b 3 (#454) * fix bug generating htmlized XML with no namespaces * Add R4B support to FHIRVersions * Add resource name mapping for DataRequirement * R4B fixes * release notes --- RELEASE_NOTES.md | 1 + .../convertors/VersionConvertor_40_50.java | 21 +++++++++++++++++-- .../org/hl7/fhir/r5/model/Enumerations.java | 6 +++++- .../fhir/r5/utils/GraphQLSchemaGenerator.java | 8 ++++--- .../fhir/r5/utils/NPMPackageGenerator.java | 2 ++ .../org/hl7/fhir/r5/utils/TypesUtilities.java | 2 +- .../hl7/fhir/utilities/xml/XmlGenerator.java | 2 +- 7 files changed, 34 insertions(+), 8 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e69de29bb..abcc03105 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -0,0 +1 @@ +* minor fixes in code generators for R4B diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_40_50.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_40_50.java index b6b7af5dc..3bc4ded03 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_40_50.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/VersionConvertor_40_50.java @@ -967,7 +967,7 @@ public class VersionConvertor_40_50 { if (src == null) return null; org.hl7.fhir.r5.model.DataRequirement tgt = new org.hl7.fhir.r5.model.DataRequirement(); copyElement(src, tgt); - if (src.hasType()) tgt.setType(org.hl7.fhir.r5.model.Enumerations.FHIRAllTypes.fromCode(src.getType())); + if (src.hasType()) tgt.setType(org.hl7.fhir.r5.model.Enumerations.FHIRAllTypes.fromCode(convertResourceName4to5(src.getType()))); for (org.hl7.fhir.r4.model.CanonicalType t : src.getProfile()) tgt.getProfile().add(convertCanonical(t)); if (src.hasSubject()) tgt.setSubject(convertType(src.getSubject())); for (org.hl7.fhir.r4.model.StringType t : src.getMustSupport()) tgt.getMustSupport().add(convertString(t)); @@ -981,11 +981,12 @@ public class VersionConvertor_40_50 { return tgt; } + public static org.hl7.fhir.r4.model.DataRequirement convertDataRequirement(org.hl7.fhir.r5.model.DataRequirement src) throws FHIRException { if (src == null) return null; org.hl7.fhir.r4.model.DataRequirement tgt = new org.hl7.fhir.r4.model.DataRequirement(); copyElement(src, tgt); - if (src.hasType()) tgt.setType(src.getType().toCode()); + if (src.hasType()) tgt.setType(convertResourceName5to4(src.getType().toCode())); for (org.hl7.fhir.r5.model.CanonicalType t : src.getProfile()) tgt.getProfile().add(convertCanonical(t)); if (src.hasSubject()) tgt.setSubject(convertType(src.getSubject())); for (org.hl7.fhir.r5.model.StringType t : src.getMustSupport()) tgt.getMustSupport().add(convertString(t)); @@ -999,6 +1000,22 @@ public class VersionConvertor_40_50 { return tgt; } + private static String convertResourceName4to5(String name) { + if (name == null) return null; + if (name.equals("MedicationStatement")) { + return "MedicationUsage"; + } + return name; + } + + private static String convertResourceName5to4(String name) { + if (name == null) return null; + if (name.equals("MedicationUsage")) { + return "MedicationStatement"; + } + return name; + } + public static org.hl7.fhir.r5.model.DataRequirement.DataRequirementCodeFilterComponent convertDataRequirementCodeFilterComponent(org.hl7.fhir.r4.model.DataRequirement.DataRequirementCodeFilterComponent src) throws FHIRException { if (src == null) return null; org.hl7.fhir.r5.model.DataRequirement.DataRequirementCodeFilterComponent tgt = new org.hl7.fhir.r5.model.DataRequirement.DataRequirementCodeFilterComponent(); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Enumerations.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Enumerations.java index 7ff2f46fa..c283fd6d1 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Enumerations.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Enumerations.java @@ -6568,7 +6568,7 @@ The primary difference between a medicationusage and a medicationadministration */ NULL; - public static final FHIRVersion R4B = FHIRVersion._4_0_1; + public static final FHIRVersion R4B = FHIRVersion._4_1_0; public static FHIRVersion fromCode(String codeString) throws FHIRException { if (codeString == null || "".equals(codeString)) @@ -6824,6 +6824,10 @@ public String toCode(int len) { public String toString() { return toCode(); } + + public boolean isR4B() { + return toCode().startsWith("4.1"); + } // end addition } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java index 450d143a0..186ee3d9c 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java @@ -67,10 +67,12 @@ public class GraphQLSchemaGenerator { private static final String INNER_TYPE_NAME = "gql.type.name"; IWorkerContext context; private ProfileUtilities profileUtilities; + private String version; - public GraphQLSchemaGenerator(IWorkerContext context) { + public GraphQLSchemaGenerator(IWorkerContext context, String version) { super(); this.context = context; + this.version = version; profileUtilities = new ProfileUtilities(context, null, null); } @@ -87,7 +89,7 @@ public class GraphQLSchemaGenerator { tl.put(sd.getName(), sd); } } - writer.write("# FHIR GraphQL Schema. Version "+Constants.VERSION+"\r\n\r\n"); + writer.write("# FHIR GraphQL Schema. Version "+version+"\r\n\r\n"); writer.write("# FHIR Defined Primitive types\r\n"); for (String n : sorted(pl.keySet())) generatePrimitive(writer, pl.get(n)); @@ -107,7 +109,7 @@ public class GraphQLSchemaGenerator { public void generateResource(OutputStream stream, StructureDefinition sd, List parameters, EnumSet operations) throws IOException, FHIRException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stream)); - writer.write("# FHIR GraphQL Schema. Version "+Constants.VERSION+"\r\n\r\n"); + writer.write("# FHIR GraphQL Schema. Version "+version+"\r\n\r\n"); writer.write("# import the types from 'types.graphql'\r\n\r\n"); generateType(writer, sd); if (operations.contains(FHIROperationType.READ)) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NPMPackageGenerator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NPMPackageGenerator.java index 3bbfe0ed3..8a7596a80 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NPMPackageGenerator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/NPMPackageGenerator.java @@ -276,6 +276,8 @@ public class NPMPackageGenerator { return "hl7.fhir.r3.core"; if (v.startsWith("4.0")) return "hl7.fhir.r4.core"; + if (v.startsWith("4.1")) + return "hl7.fhir.r4b.core"; return null; } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/TypesUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/TypesUtilities.java index 24c2169f7..7c210a247 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/TypesUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/TypesUtilities.java @@ -111,7 +111,7 @@ public class TypesUtilities { res.add(new WildcardInformation("id", TypeClassification.PRIMITIVE)); res.add(new WildcardInformation("instant", TypeClassification.PRIMITIVE)); res.add(new WildcardInformation("integer", TypeClassification.PRIMITIVE)); - if (!version.startsWith("4.0")) { + if (!version.startsWith("4.1")) { res.add(new WildcardInformation("integer64", TypeClassification.PRIMITIVE)); } res.add(new WildcardInformation("markdown", TypeClassification.PRIMITIVE)); diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XmlGenerator.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XmlGenerator.java index 9b1091e14..a8cbc6ec9 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XmlGenerator.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XmlGenerator.java @@ -111,7 +111,7 @@ public class XmlGenerator { } private void processElement(Element element) throws IOException, FHIRException { - if (!xml.getDefaultNamespace().equals(element.getNamespaceURI())) + if (xml.getDefaultNamespace() == null || !xml.getDefaultNamespace().equals(element.getNamespaceURI())) xml.setDefaultNamespace(element.getNamespaceURI()); processAttributes(element);