Merge branch 'master' into 2515_MDM_survivorship_rules

This commit is contained in:
Nick Goupinets 2021-04-01 09:39:05 -04:00
commit fdef49d1aa
6 changed files with 188 additions and 223 deletions

View File

@ -32,14 +32,13 @@ import java.util.Date;
public class DateHelper { public class DateHelper {
/** /**
*
* @param date A date String in the format YYYY-MM-DD. * @param date A date String in the format YYYY-MM-DD.
* @return A {@link java.util.Date} object representing the String data that was passed in. * @return A {@link java.util.Date} object representing the String data that was passed in.
*/ */
public static Date resolveRequestDate(String date) { public static Date resolveRequestDate(String paramName, String date) {
if (StringUtils.isBlank(date)) { if (StringUtils.isBlank(date)) {
throw new IllegalArgumentException("date parameter cannot be blank!"); throw new IllegalArgumentException(paramName + " parameter cannot be blank!");
} }
return new DateTimeType(date).getValue(); return new DateTimeType(date).getValue();
} }
} }

View File

@ -43,14 +43,14 @@ public class MeasureEvaluationSeed {
private Measure measure; private Measure measure;
private Context context; private Context context;
private Interval measurementPeriod; private Interval measurementPeriod;
private LibraryLoader libraryLoader; private final LibraryLoader libraryLoader;
private LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider; private final LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider;
private EvaluationProviderFactory providerFactory; private final EvaluationProviderFactory providerFactory;
private DataProvider dataProvider; private DataProvider dataProvider;
private LibraryHelper libraryHelper; private final LibraryHelper libraryHelper;
public MeasureEvaluationSeed(EvaluationProviderFactory providerFactory, LibraryLoader libraryLoader, public MeasureEvaluationSeed(EvaluationProviderFactory providerFactory, LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider, LibraryHelper libraryHelper) { LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider, LibraryHelper libraryHelper) {
this.providerFactory = providerFactory; this.providerFactory = providerFactory;
this.libraryLoader = libraryLoader; this.libraryLoader = libraryLoader;
this.libraryResourceProvider = libraryResourceProvider; this.libraryResourceProvider = libraryResourceProvider;
@ -108,17 +108,17 @@ public class MeasureEvaluationSeed {
for (Triple<String, String, String> def : usingDefs) { for (Triple<String, String, String> def : usingDefs) {
this.dataProvider = this.providerFactory.createDataProvider(def.getLeft(), def.getMiddle(), this.dataProvider = this.providerFactory.createDataProvider(def.getLeft(), def.getMiddle(),
terminologyProvider); terminologyProvider);
context.registerDataProvider(def.getRight(), dataProvider); context.registerDataProvider(def.getRight(), dataProvider);
} }
// resolve the measurement period // resolve the measurement period
measurementPeriod = new Interval(DateHelper.resolveRequestDate(periodStart), true, measurementPeriod = new Interval(DateHelper.resolveRequestDate("periodStart", periodStart), true,
DateHelper.resolveRequestDate(periodEnd), true); DateHelper.resolveRequestDate("periodEnd", periodEnd), true);
context.setParameter(null, "Measurement Period", context.setParameter(null, "Measurement Period",
new Interval(DateTime.fromJavaDate((Date) measurementPeriod.getStart()), true, new Interval(DateTime.fromJavaDate((Date) measurementPeriod.getStart()), true,
DateTime.fromJavaDate((Date) measurementPeriod.getEnd()), true)); DateTime.fromJavaDate((Date) measurementPeriod.getEnd()), true));
if (productLine != null) { if (productLine != null) {
context.setParameter(null, "Product Line", productLine); context.setParameter(null, "Product Line", productLine);

View File

@ -23,6 +23,7 @@ package ca.uhn.fhir.cql.dstu3.helper;
import ca.uhn.fhir.cql.common.evaluation.LibraryLoader; import ca.uhn.fhir.cql.common.evaluation.LibraryLoader;
import ca.uhn.fhir.cql.common.provider.LibraryResolutionProvider; import ca.uhn.fhir.cql.common.provider.LibraryResolutionProvider;
import ca.uhn.fhir.cql.common.provider.LibrarySourceProvider; import ca.uhn.fhir.cql.common.provider.LibrarySourceProvider;
import org.apache.commons.lang3.StringUtils;
import org.cqframework.cql.cql2elm.LibraryManager; import org.cqframework.cql.cql2elm.LibraryManager;
import org.cqframework.cql.cql2elm.ModelManager; import org.cqframework.cql.cql2elm.ModelManager;
import org.cqframework.cql.cql2elm.model.Model; import org.cqframework.cql.cql2elm.model.Model;
@ -31,20 +32,22 @@ import org.cqframework.cql.elm.execution.VersionedIdentifier;
import org.hl7.fhir.dstu3.model.Attachment; import org.hl7.fhir.dstu3.model.Attachment;
import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Measure; import org.hl7.fhir.dstu3.model.Measure;
import org.hl7.fhir.dstu3.model.PlanDefinition;
import org.hl7.fhir.dstu3.model.Reference; import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.RelatedArtifact; import org.hl7.fhir.dstu3.model.RelatedArtifact;
import org.hl7.fhir.dstu3.model.Resource; import org.hl7.fhir.dstu3.model.Resource;
import org.opencds.cqf.cql.evaluator.cql2elm.model.CacheAwareModelManager; import org.opencds.cqf.cql.evaluator.cql2elm.model.CacheAwareModelManager;
import org.opencds.cqf.cql.evaluator.engine.execution.PrivateCachingLibraryLoaderDecorator; import org.opencds.cqf.cql.evaluator.engine.execution.PrivateCachingLibraryLoaderDecorator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class LibraryHelper { public class LibraryHelper {
private static final Logger ourLog = LoggerFactory.getLogger(LibraryHelper.class);
private Map<org.hl7.elm.r1.VersionedIdentifier, Model> modelCache; private final Map<org.hl7.elm.r1.VersionedIdentifier, Model> modelCache;
public LibraryHelper(Map<org.hl7.elm.r1.VersionedIdentifier, Model> modelCache) { public LibraryHelper(Map<org.hl7.elm.r1.VersionedIdentifier, Model> modelCache) {
this.modelCache = modelCache; this.modelCache = modelCache;
@ -64,9 +67,10 @@ public class LibraryHelper {
} }
public List<Library> loadLibraries(Measure measure, public List<Library> loadLibraries(Measure measure,
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader, org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) { LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) {
List<org.cqframework.cql.elm.execution.Library> libraries = new ArrayList<Library>(); List<org.cqframework.cql.elm.execution.Library> libraries = new ArrayList<Library>();
List<String> messages = new ArrayList<>();
// load libraries // load libraries
//TODO: if there's a bad measure argument, this blows up for an obscure error //TODO: if there's a bad measure argument, this blows up for an obscure error
@ -88,15 +92,21 @@ public class LibraryHelper {
} }
org.hl7.fhir.dstu3.model.Library library = libraryResourceProvider.resolveLibraryById(id); org.hl7.fhir.dstu3.model.Library library = libraryResourceProvider.resolveLibraryById(id);
if (library != null && isLogicLibrary(library)) { if (library != null) {
libraries.add(libraryLoader if (isLogicLibrary(library)) {
.load(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion()))); libraries.add(libraryLoader
.load(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion())));
} else {
String message = "Skipping library " + library.getId() + " is not a logic library. Probably missing type.coding.system=\"http://hl7.org/fhir/library-type\"";
messages.add(message);
ourLog.warn(message);
}
} }
} }
if (libraries.isEmpty()) { if (libraries.isEmpty()) {
throw new IllegalArgumentException(String throw new IllegalArgumentException(String
.format("Could not load library source for libraries referenced in Measure %s.", measure.getId())); .format("Could not load library source for libraries referenced in %s:\n%s", measure.getId(), StringUtils.join("\n", messages)));
} }
VersionedIdentifier primaryLibraryId = libraries.get(0).getIdentifier(); VersionedIdentifier primaryLibraryId = libraries.get(0).getIdentifier();
@ -152,34 +162,18 @@ public class LibraryHelper {
} }
public Library resolveLibraryById(String libraryId, public Library resolveLibraryById(String libraryId,
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader, org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) { LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) {
// Library library = null; // Library library = null;
org.hl7.fhir.dstu3.model.Library fhirLibrary = libraryResourceProvider.resolveLibraryById(libraryId); org.hl7.fhir.dstu3.model.Library fhirLibrary = libraryResourceProvider.resolveLibraryById(libraryId);
return libraryLoader return libraryLoader
.load(new VersionedIdentifier().withId(fhirLibrary.getName()).withVersion(fhirLibrary.getVersion())); .load(new VersionedIdentifier().withId(fhirLibrary.getName()).withVersion(fhirLibrary.getVersion()));
// for (Library l : libraryLoader.getLibraries()) {
// VersionedIdentifier vid = l.getIdentifier();
// if (vid.getId().equals(fhirLibrary.getName()) &&
// LibraryResourceHelper.compareVersions(fhirLibrary.getVersion(),
// vid.getVersion()) == 0) {
// library = l;
// break;
// }
// }
// if (library == null) {
// }
// return library;
} }
public Library resolvePrimaryLibrary(Measure measure, public Library resolvePrimaryLibrary(Measure measure,
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader, org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) { LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) {
// default is the first library reference // default is the first library reference
String id = measure.getLibraryFirstRep().getReferenceElement().getIdPart(); String id = measure.getLibraryFirstRep().getReferenceElement().getIdPart();
@ -192,18 +186,4 @@ public class LibraryHelper {
return library; return library;
} }
public Library resolvePrimaryLibrary(PlanDefinition planDefinition, org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) {
String id = planDefinition.getLibraryFirstRep().getReferenceElement().getIdPart();
Library library = resolveLibraryById(id, libraryLoader, libraryResourceProvider);
if (library == null) {
throw new IllegalArgumentException(String.format("Could not resolve primary library for PlanDefinition/%s",
planDefinition.getIdElement().getIdPart()));
}
return library;
}
} }

View File

@ -43,14 +43,14 @@ public class MeasureEvaluationSeed {
private Measure measure; private Measure measure;
private Context context; private Context context;
private Interval measurementPeriod; private Interval measurementPeriod;
private LibraryLoader libraryLoader; private final LibraryLoader libraryLoader;
private LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider; private final LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider;
private EvaluationProviderFactory providerFactory; private final EvaluationProviderFactory providerFactory;
private DataProvider dataProvider; private DataProvider dataProvider;
private LibraryHelper libraryHelper; private final LibraryHelper libraryHelper;
public MeasureEvaluationSeed(EvaluationProviderFactory providerFactory, LibraryLoader libraryLoader, public MeasureEvaluationSeed(EvaluationProviderFactory providerFactory, LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider, LibraryHelper libraryHelper) { LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider, LibraryHelper libraryHelper) {
this.providerFactory = providerFactory; this.providerFactory = providerFactory;
this.libraryLoader = libraryLoader; this.libraryLoader = libraryLoader;
this.libraryResourceProvider = libraryResourceProvider; this.libraryResourceProvider = libraryResourceProvider;
@ -115,8 +115,8 @@ public class MeasureEvaluationSeed {
if (periodStart != null && periodEnd != null) { if (periodStart != null && periodEnd != null) {
// resolve the measurement period // resolve the measurement period
measurementPeriod = new Interval(DateHelper.resolveRequestDate(periodStart), true, measurementPeriod = new Interval(DateHelper.resolveRequestDate("periodStart", periodStart), true,
DateHelper.resolveRequestDate(periodEnd), true); DateHelper.resolveRequestDate("periodEnd", periodEnd), true);
context.setParameter(null, "Measurement Period", context.setParameter(null, "Measurement Period",
new Interval(DateTime.fromJavaDate((Date) measurementPeriod.getStart()), true, new Interval(DateTime.fromJavaDate((Date) measurementPeriod.getStart()), true,

View File

@ -23,6 +23,7 @@ package ca.uhn.fhir.cql.r4.helper;
import ca.uhn.fhir.cql.common.evaluation.LibraryLoader; import ca.uhn.fhir.cql.common.evaluation.LibraryLoader;
import ca.uhn.fhir.cql.common.provider.LibraryResolutionProvider; import ca.uhn.fhir.cql.common.provider.LibraryResolutionProvider;
import ca.uhn.fhir.cql.common.provider.LibrarySourceProvider; import ca.uhn.fhir.cql.common.provider.LibrarySourceProvider;
import org.apache.commons.lang3.StringUtils;
import org.cqframework.cql.cql2elm.LibraryManager; import org.cqframework.cql.cql2elm.LibraryManager;
import org.cqframework.cql.cql2elm.ModelManager; import org.cqframework.cql.cql2elm.ModelManager;
import org.cqframework.cql.cql2elm.model.Model; import org.cqframework.cql.cql2elm.model.Model;
@ -32,11 +33,12 @@ import org.hl7.fhir.r4.model.Attachment;
import org.hl7.fhir.r4.model.CanonicalType; import org.hl7.fhir.r4.model.CanonicalType;
import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Measure; import org.hl7.fhir.r4.model.Measure;
import org.hl7.fhir.r4.model.PlanDefinition;
import org.hl7.fhir.r4.model.RelatedArtifact; import org.hl7.fhir.r4.model.RelatedArtifact;
import org.hl7.fhir.r4.model.Resource; import org.hl7.fhir.r4.model.Resource;
import org.opencds.cqf.cql.evaluator.cql2elm.model.CacheAwareModelManager; import org.opencds.cqf.cql.evaluator.cql2elm.model.CacheAwareModelManager;
import org.opencds.cqf.cql.evaluator.engine.execution.PrivateCachingLibraryLoaderDecorator; import org.opencds.cqf.cql.evaluator.engine.execution.PrivateCachingLibraryLoaderDecorator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -46,192 +48,176 @@ import java.util.Map;
* Created by Christopher on 1/11/2017. * Created by Christopher on 1/11/2017.
*/ */
public class LibraryHelper { public class LibraryHelper {
private static final Logger ourLog = LoggerFactory.getLogger(LibraryHelper.class);
private Map<org.hl7.elm.r1.VersionedIdentifier, Model> modelCache; private final Map<org.hl7.elm.r1.VersionedIdentifier, Model> modelCache;
public LibraryHelper(Map<org.hl7.elm.r1.VersionedIdentifier, Model> modelCache) { public LibraryHelper(Map<org.hl7.elm.r1.VersionedIdentifier, Model> modelCache) {
this.modelCache = modelCache; this.modelCache = modelCache;
} }
public org.opencds.cqf.cql.engine.execution.LibraryLoader createLibraryLoader(LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> provider) { public org.opencds.cqf.cql.engine.execution.LibraryLoader createLibraryLoader(LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> provider) {
ModelManager modelManager = new CacheAwareModelManager(this.modelCache); ModelManager modelManager = new CacheAwareModelManager(this.modelCache);
LibraryManager libraryManager = new LibraryManager(modelManager); LibraryManager libraryManager = new LibraryManager(modelManager);
libraryManager.getLibrarySourceLoader().clearProviders(); libraryManager.getLibrarySourceLoader().clearProviders();
libraryManager.getLibrarySourceLoader().registerProvider( libraryManager.getLibrarySourceLoader().registerProvider(
new LibrarySourceProvider<org.hl7.fhir.r4.model.Library, Attachment>(provider, new LibrarySourceProvider<org.hl7.fhir.r4.model.Library, Attachment>(provider,
x -> x.getContent(), x -> x.getContentType(), x -> x.getData())); x -> x.getContent(), x -> x.getContentType(), x -> x.getData()));
return new PrivateCachingLibraryLoaderDecorator(new LibraryLoader(libraryManager, modelManager)); return new PrivateCachingLibraryLoaderDecorator(new LibraryLoader(libraryManager, modelManager));
} }
public org.opencds.cqf.cql.engine.execution.LibraryLoader createLibraryLoader(org.cqframework.cql.cql2elm.LibrarySourceProvider provider) { public org.opencds.cqf.cql.engine.execution.LibraryLoader createLibraryLoader(org.cqframework.cql.cql2elm.LibrarySourceProvider provider) {
ModelManager modelManager = new CacheAwareModelManager(this.modelCache); ModelManager modelManager = new CacheAwareModelManager(this.modelCache);
LibraryManager libraryManager = new LibraryManager(modelManager); LibraryManager libraryManager = new LibraryManager(modelManager);
libraryManager.getLibrarySourceLoader().clearProviders(); libraryManager.getLibrarySourceLoader().clearProviders();
libraryManager.getLibrarySourceLoader().registerProvider(provider); libraryManager.getLibrarySourceLoader().registerProvider(provider);
return new PrivateCachingLibraryLoaderDecorator(new LibraryLoader(libraryManager, modelManager)); return new PrivateCachingLibraryLoaderDecorator(new LibraryLoader(libraryManager, modelManager));
} }
public org.hl7.fhir.r4.model.Library resolveLibraryReference(LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider, String reference) { public org.hl7.fhir.r4.model.Library resolveLibraryReference(LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider, String reference) {
// Raw references to Library/libraryId or libraryId // Raw references to Library/libraryId or libraryId
if (reference.startsWith("Library/") || !reference.contains("/")) { if (reference.startsWith("Library/") || !reference.contains("/")) {
return libraryResourceProvider.resolveLibraryById(reference.replace("Library/", "")); return libraryResourceProvider.resolveLibraryById(reference.replace("Library/", ""));
} }
// Full url (e.g. http://hl7.org/fhir/us/Library/FHIRHelpers) // Full url (e.g. http://hl7.org/fhir/us/Library/FHIRHelpers)
else if (reference.contains(("/Library/"))) { else if (reference.contains(("/Library/"))) {
return libraryResourceProvider.resolveLibraryByCanonicalUrl(reference); return libraryResourceProvider.resolveLibraryByCanonicalUrl(reference);
} }
return null; return null;
} }
public List<org.cqframework.cql.elm.execution.Library> loadLibraries(Measure measure, public List<org.cqframework.cql.elm.execution.Library> loadLibraries(Measure measure,
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader, org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider) { LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider) {
List<org.cqframework.cql.elm.execution.Library> libraries = new ArrayList<org.cqframework.cql.elm.execution.Library>(); List<org.cqframework.cql.elm.execution.Library> libraries = new ArrayList<org.cqframework.cql.elm.execution.Library>();
// load libraries List<String> messages = new ArrayList<>();
//TODO: if there's a bad measure argument, this blows up for an obscure error
org.hl7.fhir.r4.model.Library primaryLibrary = null;
for (CanonicalType ref : measure.getLibrary()) {
// if library is contained in measure, load it into server
String id = ref.getValue(); //CanonicalHelper.getId(ref);
if (id.startsWith("#")) {
id = id.substring(1);
for (Resource resource : measure.getContained()) {
if (resource instanceof org.hl7.fhir.r4.model.Library
&& resource.getIdElement().getIdPart().equals(id)) {
libraryResourceProvider.update((org.hl7.fhir.r4.model.Library) resource);
}
}
}
// We just loaded it into the server so we can access it by Id // load libraries
org.hl7.fhir.r4.model.Library library = resolveLibraryReference(libraryResourceProvider, id); //TODO: if there's a bad measure argument, this blows up for an obscure error
if (primaryLibrary == null) { org.hl7.fhir.r4.model.Library primaryLibrary = null;
primaryLibrary = library;
}
if (library != null && isLogicLibrary(library)) { List<CanonicalType> measureLibraries = measure.getLibrary();
libraries.add( if (measureLibraries.isEmpty()) {
libraryLoader.load(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion())) String message = "No libraries found on " + measure.getId() + ". Did you perhaps load a DSTU3 Measure onto an R4 server?";
); messages.add(message);
} ourLog.warn(message);
} }
for (CanonicalType ref : measureLibraries) {
// if library is contained in measure, load it into server
String id = ref.getValue(); //CanonicalHelper.getId(ref);
if (id.startsWith("#")) {
id = id.substring(1);
for (Resource resource : measure.getContained()) {
if (resource instanceof org.hl7.fhir.r4.model.Library
&& resource.getIdElement().getIdPart().equals(id)) {
libraryResourceProvider.update((org.hl7.fhir.r4.model.Library) resource);
}
}
}
if (libraries.isEmpty()) { // We just loaded it into the server so we can access it by Id
throw new IllegalArgumentException(String org.hl7.fhir.r4.model.Library library = resolveLibraryReference(libraryResourceProvider, id);
.format("Could not load library source for libraries referenced in %s.", measure.getId())); if (primaryLibrary == null) {
} primaryLibrary = library;
}
//VersionedIdentifier primaryLibraryId = libraries.get(0).getIdentifier();
//org.hl7.fhir.r4.model.Library primaryLibrary = libraryResourceProvider.resolveLibraryByName(primaryLibraryId.getId(), primaryLibraryId.getVersion());
for (RelatedArtifact artifact : primaryLibrary.getRelatedArtifact()) {
if (artifact.hasType() && artifact.getType().equals(RelatedArtifact.RelatedArtifactType.DEPENDSON) && artifact.hasResource()) {
org.hl7.fhir.r4.model.Library library = null;
library = resolveLibraryReference(libraryResourceProvider, artifact.getResource());
if (library != null && isLogicLibrary(library)) { if (library != null) {
libraries.add( if (isLogicLibrary(library)) {
libraryLoader.load(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion())) libraries.add(
); libraryLoader.load(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion()))
} );
} } else {
} String message = "Skipping library " + library.getId() + " is not a logic library. Probably missing type.coding.system=\"http://terminology.hl7.org/CodeSystem/library-type\"";
messages.add(message);
ourLog.warn(message);
}
}
}
return libraries; if (libraries.isEmpty()) {
} throw new IllegalArgumentException(String
.format("Could not load library source for libraries referenced in %s:\n%s", measure.getId(), StringUtils.join("\n", messages)));
}
private boolean isLogicLibrary(org.hl7.fhir.r4.model.Library library) { for (RelatedArtifact artifact : primaryLibrary.getRelatedArtifact()) {
if (library == null) { if (artifact.hasType() && artifact.getType().equals(RelatedArtifact.RelatedArtifactType.DEPENDSON) && artifact.hasResource()) {
return false; org.hl7.fhir.r4.model.Library library = null;
} library = resolveLibraryReference(libraryResourceProvider, artifact.getResource());
if (!library.hasType()) { if (library != null && isLogicLibrary(library)) {
// If no type is specified, assume it is a logic library based on whether there is a CQL content element. libraries.add(
if (library.hasContent()) { libraryLoader.load(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion()))
for (Attachment a : library.getContent()) { );
if (a.hasContentType() && (a.getContentType().equals("text/cql") }
|| a.getContentType().equals("application/elm+xml") }
|| a.getContentType().equals("application/elm+json"))) { }
return true;
}
}
}
return false;
}
if (!library.getType().hasCoding()) { return libraries;
return false; }
}
for (Coding c : library.getType().getCoding()) { private boolean isLogicLibrary(org.hl7.fhir.r4.model.Library library) {
if (c.hasSystem() && c.getSystem().equals("http://terminology.hl7.org/CodeSystem/library-type") if (library == null) {
&& c.hasCode() && c.getCode().equals("logic-library")) { return false;
return true; }
}
}
return false; if (!library.hasType()) {
} // If no type is specified, assume it is a logic library based on whether there is a CQL content element.
if (library.hasContent()) {
for (Attachment a : library.getContent()) {
if (a.hasContentType() && (a.getContentType().equals("text/cql")
|| a.getContentType().equals("application/elm+xml")
|| a.getContentType().equals("application/elm+json"))) {
return true;
}
}
}
return false;
}
public Library resolveLibraryById(String libraryId, if (!library.getType().hasCoding()) {
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader, return false;
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider) { }
// Library library = null;
org.hl7.fhir.r4.model.Library fhirLibrary = libraryResourceProvider.resolveLibraryById(libraryId); for (Coding c : library.getType().getCoding()) {
return libraryLoader if (c.hasSystem() && c.getSystem().equals("http://terminology.hl7.org/CodeSystem/library-type")
.load(new VersionedIdentifier().withId(fhirLibrary.getName()).withVersion(fhirLibrary.getVersion())); && c.hasCode() && c.getCode().equals("logic-library")) {
return true;
}
}
// for (Library l : libraryLoader.getLibraries()) { return false;
// VersionedIdentifier vid = l.getIdentifier(); }
// if (vid.getId().equals(fhirLibrary.getName()) &&
// LibraryResourceHelper.compareVersions(fhirLibrary.getVersion(),
// vid.getVersion()) == 0) {
// library = l;
// break;
// }
// }
// if (library == null) { public Library resolveLibraryById(String libraryId,
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider) {
// Library library = null;
// } org.hl7.fhir.r4.model.Library fhirLibrary = libraryResourceProvider.resolveLibraryById(libraryId);
return libraryLoader
.load(new VersionedIdentifier().withId(fhirLibrary.getName()).withVersion(fhirLibrary.getVersion()));
}
// return library; public Library resolvePrimaryLibrary(Measure measure,
} org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider) {
// default is the first library reference
String id = CanonicalHelper.getId(measure.getLibrary().get(0));
public Library resolvePrimaryLibrary(Measure measure, Library library = resolveLibraryById(id, libraryLoader, libraryResourceProvider);
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider) {
// default is the first library reference
String id = CanonicalHelper.getId(measure.getLibrary().get(0));
Library library = resolveLibraryById(id, libraryLoader, libraryResourceProvider); if (library == null) {
throw new IllegalArgumentException(String.format("Could not resolve primary library for Measure/%s.",
measure.getIdElement().getIdPart()));
}
if (library == null) { return library;
throw new IllegalArgumentException(String.format("Could not resolve primary library for Measure/%s.", }
measure.getIdElement().getIdPart()));
}
return library;
}
public Library resolvePrimaryLibrary(PlanDefinition planDefinition,
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider) {
String id = CanonicalHelper.getId(planDefinition.getLibrary().get(0));
Library library = resolveLibraryById(id, libraryLoader, libraryResourceProvider);
if (library == null) {
throw new IllegalArgumentException(String.format("Could not resolve primary library for PlanDefinition/%s",
planDefinition.getIdElement().getIdPart()));
}
return library;
}
} }

View File

@ -17,7 +17,7 @@ public class DateHelperTest {
@Test @Test
public void testDateHelperProperlyResolvesValidDate() { public void testDateHelperProperlyResolvesValidDate() {
DateHelper dateHelper = new DateHelper(); DateHelper dateHelper = new DateHelper();
Date result = dateHelper.resolveRequestDate("2001-01-29"); Date result = DateHelper.resolveRequestDate("param", "2001-01-29");
assertNotNull("result should not be NULL!", result); assertNotNull("result should not be NULL!", result);
GregorianCalendar cal = new GregorianCalendar(); GregorianCalendar cal = new GregorianCalendar();
cal.setTimeInMillis(result.getTime()); cal.setTimeInMillis(result.getTime());
@ -28,7 +28,7 @@ public class DateHelperTest {
@Test @Test
public void testDateHelperProperlyResolvesValidDateWithYearOnly() { public void testDateHelperProperlyResolvesValidDateWithYearOnly() {
DateHelper dateHelper = new DateHelper(); DateHelper dateHelper = new DateHelper();
Date result = dateHelper.resolveRequestDate("2001"); Date result = DateHelper.resolveRequestDate("param", "2001");
assertNotNull("result should not be NULL!", result); assertNotNull("result should not be NULL!", result);
} }
@ -37,7 +37,7 @@ public class DateHelperTest {
DateHelper dateHelper = new DateHelper(); DateHelper dateHelper = new DateHelper();
Date result = null; Date result = null;
try { try {
result = dateHelper.resolveRequestDate(null); result = DateHelper.resolveRequestDate("param", null);
fail(); fail();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertNull("result should be NULL!", result); assertNull("result should be NULL!", result);
@ -49,7 +49,7 @@ public class DateHelperTest {
DateHelper dateHelper = new DateHelper(); DateHelper dateHelper = new DateHelper();
Date result = null; Date result = null;
try { try {
result = dateHelper.resolveRequestDate("aaa-bbb-ccc"); result = DateHelper.resolveRequestDate("param", "aaa-bbb-ccc");
fail(); fail();
} catch (DataFormatException e) { } catch (DataFormatException e) {
assertNull("result should be NULL!", result); assertNull("result should be NULL!", result);