Skip to content

Commit

Permalink
extend CQLSubsystem to cover Measure, PlanDefinition, ActivityDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
Grahame Grieve committed Dec 4, 2024
1 parent a024eb4 commit 0363d5a
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -244,7 +262,7 @@ public interface ILibraryReader {

private NamespaceInfo namespaceInfo;

public CqlSubSystem(List<NpmPackage> packages, List<String> folders, ILibraryReader reader, ILoggingService logger, UcumService ucumService, String packageId, String canonicalBase) {
public CqlSubSystem(List<NpmPackage> packages, List<String> folders, ICqlResourceReader reader, ILoggingService logger, UcumService ucumService, String packageId, String canonicalBase) {
super();
this.packages = packages;
this.folders = folders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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+"'");
}
}


}

This file was deleted.

0 comments on commit 0363d5a

Please sign in to comment.