From 0363d5a329c6cef9e2af8695b75342095ea3a788 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 4 Dec 2024 11:04:16 +0300 Subject: [PATCH] extend CQLSubsystem to cover Measure, PlanDefinition, ActivityDefinition --- .../fhir/igtools/publisher/CqlSubSystem.java | 26 ++++- .../hl7/fhir/igtools/publisher/Publisher.java | 4 +- .../publisher/loaders/CqlResourceLoader.java | 109 ++++++++++++++++++ .../publisher/loaders/LibraryLoader.java | 44 ------- 4 files changed, 133 insertions(+), 50 deletions(-) create mode 100644 org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/CqlResourceLoader.java delete mode 100644 org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/LibraryLoader.java diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/CqlSubSystem.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/CqlSubSystem.java index 45ca3e580..f2884f726 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/CqlSubSystem.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/CqlSubSystem.java @@ -58,16 +58,31 @@ import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.exceptions.FHIRFormatError; import org.hl7.fhir.r5.context.ILoggingService; +import org.hl7.fhir.r5.model.ActivityDefinition; import org.hl7.fhir.r5.model.DataRequirement; import org.hl7.fhir.r5.model.Enumerations; import org.hl7.fhir.r5.model.Library; +import org.hl7.fhir.r5.model.Measure; import org.hl7.fhir.r5.model.ParameterDefinition; +import org.hl7.fhir.r5.model.PlanDefinition; import org.hl7.fhir.r5.model.RelatedArtifact; import org.hl7.fhir.utilities.npm.NpmPackage; import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; +/** + * What this system does + * + * Library: + * + * Measure: + * + * PlanDefinition: + * + * ActivityDefinition: + * + */ public class CqlSubSystem { /** @@ -184,11 +199,14 @@ public ModelInfo load(ModelIdentifier modelIdentifier) { /** * The Implementation Guide build supports multiple versions. This code runs as R5 code. - * The library reader loads the library from the NpmPackage and returns an R5 library, + * The library reader loads the library etc from the NpmPackage and returns an R5 library etc, * irrespective of what version the IG is */ - public interface ILibraryReader { + public interface ICqlResourceReader { public Library readLibrary(InputStream stream) throws FHIRFormatError, IOException; + public Measure readMeasure(InputStream stream) throws FHIRFormatError, IOException; + public PlanDefinition readPlanDefinition(InputStream stream) throws FHIRFormatError, IOException; + public ActivityDefinition readActivityDefinition(InputStream stream) throws FHIRFormatError, IOException; } /** @@ -210,7 +228,7 @@ public interface ILibraryReader { /** * Version indepedent reader */ - private ILibraryReader reader; + private ICqlResourceReader reader; /** * use this to write to the standard IG log @@ -244,7 +262,7 @@ public interface ILibraryReader { private NamespaceInfo namespaceInfo; - public CqlSubSystem(List packages, List folders, ILibraryReader reader, ILoggingService logger, UcumService ucumService, String packageId, String canonicalBase) { + public CqlSubSystem(List packages, List folders, ICqlResourceReader reader, ILoggingService logger, UcumService ucumService, String packageId, String canonicalBase) { super(); this.packages = packages; this.folders = folders; diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java index 8a191fe07..a7ffdbf68 100644 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/Publisher.java @@ -97,7 +97,7 @@ import org.hl7.fhir.igtools.publisher.comparators.IpsComparator; import org.hl7.fhir.igtools.publisher.comparators.PreviousVersionComparator; import org.hl7.fhir.igtools.publisher.loaders.AdjunctFileLoader; -import org.hl7.fhir.igtools.publisher.loaders.LibraryLoader; +import org.hl7.fhir.igtools.publisher.loaders.CqlResourceLoader; import org.hl7.fhir.igtools.publisher.loaders.PatchLoaderKnowledgeProvider; import org.hl7.fhir.igtools.publisher.loaders.PublisherLoader; import org.hl7.fhir.igtools.publisher.modules.CrossVersionModule; @@ -4476,7 +4476,7 @@ private boolean load() throws Exception { packageInfo = new PackageInformation(publishedIg.getPackageId(), publishedIg.getVersion(), context.getVersion(), new Date(), publishedIg.getName(), igpkp.getCanonical(), targetOutput); // Cql Compile - cql = new CqlSubSystem(npmList, binaryPaths, new LibraryLoader(version), this, context.getUcumService(), publishedIg.getPackageId(), igpkp.getCanonical()); + cql = new CqlSubSystem(npmList, binaryPaths, new CqlResourceLoader(version), this, context.getUcumService(), publishedIg.getPackageId(), igpkp.getCanonical()); if (binaryPaths.size() > 0) { cql.execute(); } diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/CqlResourceLoader.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/CqlResourceLoader.java new file mode 100644 index 000000000..9874606a4 --- /dev/null +++ b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/CqlResourceLoader.java @@ -0,0 +1,109 @@ +package org.hl7.fhir.igtools.publisher.loaders; + +import java.io.IOException; +import java.io.InputStream; + +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50; +import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50; +import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.exceptions.FHIRFormatError; +import org.hl7.fhir.igtools.publisher.CqlSubSystem.ICqlResourceReader; +import org.hl7.fhir.r5.formats.JsonParser; +import org.hl7.fhir.r5.model.ActivityDefinition; +import org.hl7.fhir.r5.model.Library; +import org.hl7.fhir.r5.model.Measure; +import org.hl7.fhir.r5.model.PlanDefinition; +import org.hl7.fhir.utilities.VersionUtilities; + +public class CqlResourceLoader implements ICqlResourceReader { + + private String version; + + public CqlResourceLoader(String version) { + this.version = version; + } + + @Override + public Library readLibrary(InputStream stream) throws FHIRFormatError, IOException { + if (VersionUtilities.isR2Ver(version)) { + throw new FHIRException("Library is not supported in R2"); + } else if (VersionUtilities.isR2BVer(version)) { + org.hl7.fhir.dstu2016may.model.Resource res = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(stream); + return (Library) VersionConvertorFactory_14_50.convertResource(res); + } else if (VersionUtilities.isR3Ver(version)) { + org.hl7.fhir.dstu3.model.Resource res = new org.hl7.fhir.dstu3.formats.JsonParser().parse(stream); + return (Library) VersionConvertorFactory_30_50.convertResource(res); + } else if (VersionUtilities.isR4Ver(version)) { + org.hl7.fhir.r4.model.Resource res = new org.hl7.fhir.r4.formats.JsonParser().parse(stream); + return (Library) VersionConvertorFactory_40_50.convertResource(res); + } else if (VersionUtilities.isR5Plus(version)) { + return (Library) new JsonParser().parse(stream); + } else { + throw new FHIRException("Unknown Version '"+version+"'"); + } + } + + + @Override + public Measure readMeasure(InputStream stream) throws FHIRFormatError, IOException { + if (VersionUtilities.isR2Ver(version)) { + throw new FHIRException("Measure is not supported in R2"); + } else if (VersionUtilities.isR2BVer(version)) { + org.hl7.fhir.dstu2016may.model.Resource res = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(stream); + return (Measure) VersionConvertorFactory_14_50.convertResource(res); + } else if (VersionUtilities.isR3Ver(version)) { + org.hl7.fhir.dstu3.model.Resource res = new org.hl7.fhir.dstu3.formats.JsonParser().parse(stream); + return (Measure) VersionConvertorFactory_30_50.convertResource(res); + } else if (VersionUtilities.isR4Ver(version)) { + org.hl7.fhir.r4.model.Resource res = new org.hl7.fhir.r4.formats.JsonParser().parse(stream); + return (Measure) VersionConvertorFactory_40_50.convertResource(res); + } else if (VersionUtilities.isR5Plus(version)) { + return (Measure) new JsonParser().parse(stream); + } else { + throw new FHIRException("Unknown Version '"+version+"'"); + } + } + + @Override + public PlanDefinition readPlanDefinition(InputStream stream) throws FHIRFormatError, IOException { + if (VersionUtilities.isR2Ver(version)) { + throw new FHIRException("PlanDefinition is not supported in R2"); + } else if (VersionUtilities.isR2BVer(version)) { + org.hl7.fhir.dstu2016may.model.Resource res = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(stream); + return (PlanDefinition) VersionConvertorFactory_14_50.convertResource(res); + } else if (VersionUtilities.isR3Ver(version)) { + org.hl7.fhir.dstu3.model.Resource res = new org.hl7.fhir.dstu3.formats.JsonParser().parse(stream); + return (PlanDefinition) VersionConvertorFactory_30_50.convertResource(res); + } else if (VersionUtilities.isR4Ver(version)) { + org.hl7.fhir.r4.model.Resource res = new org.hl7.fhir.r4.formats.JsonParser().parse(stream); + return (PlanDefinition) VersionConvertorFactory_40_50.convertResource(res); + } else if (VersionUtilities.isR5Plus(version)) { + return (PlanDefinition) new JsonParser().parse(stream); + } else { + throw new FHIRException("Unknown Version '"+version+"'"); + } + } + + @Override + public ActivityDefinition readActivityDefinition(InputStream stream) throws FHIRFormatError, IOException { + if (VersionUtilities.isR2Ver(version)) { + throw new FHIRException("ActivityDefinition is not supported in R2"); + } else if (VersionUtilities.isR2BVer(version)) { + org.hl7.fhir.dstu2016may.model.Resource res = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(stream); + return (ActivityDefinition) VersionConvertorFactory_14_50.convertResource(res); + } else if (VersionUtilities.isR3Ver(version)) { + org.hl7.fhir.dstu3.model.Resource res = new org.hl7.fhir.dstu3.formats.JsonParser().parse(stream); + return (ActivityDefinition) VersionConvertorFactory_30_50.convertResource(res); + } else if (VersionUtilities.isR4Ver(version)) { + org.hl7.fhir.r4.model.Resource res = new org.hl7.fhir.r4.formats.JsonParser().parse(stream); + return (ActivityDefinition) VersionConvertorFactory_40_50.convertResource(res); + } else if (VersionUtilities.isR5Plus(version)) { + return (ActivityDefinition) new JsonParser().parse(stream); + } else { + throw new FHIRException("Unknown Version '"+version+"'"); + } + } + + +} diff --git a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/LibraryLoader.java b/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/LibraryLoader.java deleted file mode 100644 index 0dbeede06..000000000 --- a/org.hl7.fhir.publisher.core/src/main/java/org/hl7/fhir/igtools/publisher/loaders/LibraryLoader.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.hl7.fhir.igtools.publisher.loaders; - -import java.io.IOException; -import java.io.InputStream; - -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_14_50; -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_50; -import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50; -import org.hl7.fhir.exceptions.FHIRException; -import org.hl7.fhir.exceptions.FHIRFormatError; -import org.hl7.fhir.igtools.publisher.CqlSubSystem.ILibraryReader; -import org.hl7.fhir.r5.formats.JsonParser; -import org.hl7.fhir.r5.model.Library; -import org.hl7.fhir.utilities.VersionUtilities; - -public class LibraryLoader implements ILibraryReader { - - private String version; - - public LibraryLoader(String version) { - this.version = version; - } - - @Override - public Library readLibrary(InputStream stream) throws FHIRFormatError, IOException { - if (VersionUtilities.isR2Ver(version)) { - throw new FHIRException("Library is not supported in R2"); - } else if (VersionUtilities.isR2BVer(version)) { - org.hl7.fhir.dstu2016may.model.Resource res = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(stream); - return (Library) VersionConvertorFactory_14_50.convertResource(res); - } else if (VersionUtilities.isR3Ver(version)) { - org.hl7.fhir.dstu3.model.Resource res = new org.hl7.fhir.dstu3.formats.JsonParser().parse(stream); - return (Library) VersionConvertorFactory_30_50.convertResource(res); - } else if (VersionUtilities.isR4Ver(version)) { - org.hl7.fhir.r4.model.Resource res = new org.hl7.fhir.r4.formats.JsonParser().parse(stream); - return (Library) VersionConvertorFactory_40_50.convertResource(res); - } else if (VersionUtilities.isR5Plus(version)) { - return (Library) new JsonParser().parse(stream); - } else { - throw new FHIRException("Unknown Version '"+version+"'"); - } - } - -}