improved error messages for common mishaps (#2518)
* improved error messages for common mishaps * review feedback
This commit is contained in:
parent
c8ce261054
commit
b27559caa4
|
@ -32,14 +32,13 @@ import java.util.Date;
|
|||
public class DateHelper {
|
||||
|
||||
/**
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public static Date resolveRequestDate(String date) {
|
||||
if (StringUtils.isBlank(date)) {
|
||||
throw new IllegalArgumentException("date parameter cannot be blank!");
|
||||
}
|
||||
return new DateTimeType(date).getValue();
|
||||
}
|
||||
public static Date resolveRequestDate(String paramName, String date) {
|
||||
if (StringUtils.isBlank(date)) {
|
||||
throw new IllegalArgumentException(paramName + " parameter cannot be blank!");
|
||||
}
|
||||
return new DateTimeType(date).getValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,14 +43,14 @@ public class MeasureEvaluationSeed {
|
|||
private Measure measure;
|
||||
private Context context;
|
||||
private Interval measurementPeriod;
|
||||
private LibraryLoader libraryLoader;
|
||||
private LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider;
|
||||
private EvaluationProviderFactory providerFactory;
|
||||
private final LibraryLoader libraryLoader;
|
||||
private final LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider;
|
||||
private final EvaluationProviderFactory providerFactory;
|
||||
private DataProvider dataProvider;
|
||||
private LibraryHelper libraryHelper;
|
||||
private final LibraryHelper libraryHelper;
|
||||
|
||||
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.libraryLoader = libraryLoader;
|
||||
this.libraryResourceProvider = libraryResourceProvider;
|
||||
|
@ -108,17 +108,17 @@ public class MeasureEvaluationSeed {
|
|||
|
||||
for (Triple<String, String, String> def : usingDefs) {
|
||||
this.dataProvider = this.providerFactory.createDataProvider(def.getLeft(), def.getMiddle(),
|
||||
terminologyProvider);
|
||||
terminologyProvider);
|
||||
context.registerDataProvider(def.getRight(), dataProvider);
|
||||
}
|
||||
|
||||
// resolve the measurement period
|
||||
measurementPeriod = new Interval(DateHelper.resolveRequestDate(periodStart), true,
|
||||
DateHelper.resolveRequestDate(periodEnd), true);
|
||||
measurementPeriod = new Interval(DateHelper.resolveRequestDate("periodStart", periodStart), true,
|
||||
DateHelper.resolveRequestDate("periodEnd", periodEnd), true);
|
||||
|
||||
context.setParameter(null, "Measurement Period",
|
||||
new Interval(DateTime.fromJavaDate((Date) measurementPeriod.getStart()), true,
|
||||
DateTime.fromJavaDate((Date) measurementPeriod.getEnd()), true));
|
||||
new Interval(DateTime.fromJavaDate((Date) measurementPeriod.getStart()), true,
|
||||
DateTime.fromJavaDate((Date) measurementPeriod.getEnd()), true));
|
||||
|
||||
if (productLine != null) {
|
||||
context.setParameter(null, "Product Line", productLine);
|
||||
|
|
|
@ -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.provider.LibraryResolutionProvider;
|
||||
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.ModelManager;
|
||||
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.Coding;
|
||||
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.RelatedArtifact;
|
||||
import org.hl7.fhir.dstu3.model.Resource;
|
||||
import org.opencds.cqf.cql.evaluator.cql2elm.model.CacheAwareModelManager;
|
||||
import org.opencds.cqf.cql.evaluator.engine.execution.PrivateCachingLibraryLoaderDecorator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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) {
|
||||
this.modelCache = modelCache;
|
||||
|
@ -64,9 +67,10 @@ public class LibraryHelper {
|
|||
}
|
||||
|
||||
public List<Library> loadLibraries(Measure measure,
|
||||
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
|
||||
LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) {
|
||||
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
|
||||
LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) {
|
||||
List<org.cqframework.cql.elm.execution.Library> libraries = new ArrayList<Library>();
|
||||
List<String> messages = new ArrayList<>();
|
||||
|
||||
// load libraries
|
||||
//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);
|
||||
if (library != null && isLogicLibrary(library)) {
|
||||
libraries.add(libraryLoader
|
||||
.load(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion())));
|
||||
if (library != null) {
|
||||
if (isLogicLibrary(library)) {
|
||||
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()) {
|
||||
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();
|
||||
|
@ -152,34 +162,18 @@ public class LibraryHelper {
|
|||
}
|
||||
|
||||
public Library resolveLibraryById(String libraryId,
|
||||
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
|
||||
LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) {
|
||||
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
|
||||
LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) {
|
||||
// Library library = null;
|
||||
|
||||
org.hl7.fhir.dstu3.model.Library fhirLibrary = libraryResourceProvider.resolveLibraryById(libraryId);
|
||||
return libraryLoader
|
||||
.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,
|
||||
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
|
||||
LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) {
|
||||
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
|
||||
LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> libraryResourceProvider) {
|
||||
// default is the first library reference
|
||||
String id = measure.getLibraryFirstRep().getReferenceElement().getIdPart();
|
||||
|
||||
|
@ -192,18 +186,4 @@ public class LibraryHelper {
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,14 +43,14 @@ public class MeasureEvaluationSeed {
|
|||
private Measure measure;
|
||||
private Context context;
|
||||
private Interval measurementPeriod;
|
||||
private LibraryLoader libraryLoader;
|
||||
private LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider;
|
||||
private EvaluationProviderFactory providerFactory;
|
||||
private final LibraryLoader libraryLoader;
|
||||
private final LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider;
|
||||
private final EvaluationProviderFactory providerFactory;
|
||||
private DataProvider dataProvider;
|
||||
private LibraryHelper libraryHelper;
|
||||
private final LibraryHelper libraryHelper;
|
||||
|
||||
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.libraryLoader = libraryLoader;
|
||||
this.libraryResourceProvider = libraryResourceProvider;
|
||||
|
@ -115,8 +115,8 @@ public class MeasureEvaluationSeed {
|
|||
|
||||
if (periodStart != null && periodEnd != null) {
|
||||
// resolve the measurement period
|
||||
measurementPeriod = new Interval(DateHelper.resolveRequestDate(periodStart), true,
|
||||
DateHelper.resolveRequestDate(periodEnd), true);
|
||||
measurementPeriod = new Interval(DateHelper.resolveRequestDate("periodStart", periodStart), true,
|
||||
DateHelper.resolveRequestDate("periodEnd", periodEnd), true);
|
||||
|
||||
context.setParameter(null, "Measurement Period",
|
||||
new Interval(DateTime.fromJavaDate((Date) measurementPeriod.getStart()), true,
|
||||
|
|
|
@ -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.provider.LibraryResolutionProvider;
|
||||
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.ModelManager;
|
||||
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.Coding;
|
||||
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.Resource;
|
||||
import org.opencds.cqf.cql.evaluator.cql2elm.model.CacheAwareModelManager;
|
||||
import org.opencds.cqf.cql.evaluator.engine.execution.PrivateCachingLibraryLoaderDecorator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -46,192 +48,176 @@ import java.util.Map;
|
|||
* Created by Christopher on 1/11/2017.
|
||||
*/
|
||||
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) {
|
||||
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);
|
||||
LibraryManager libraryManager = new LibraryManager(modelManager);
|
||||
libraryManager.getLibrarySourceLoader().clearProviders();
|
||||
LibraryManager libraryManager = new LibraryManager(modelManager);
|
||||
libraryManager.getLibrarySourceLoader().clearProviders();
|
||||
|
||||
libraryManager.getLibrarySourceLoader().registerProvider(
|
||||
new LibrarySourceProvider<org.hl7.fhir.r4.model.Library, Attachment>(provider,
|
||||
x -> x.getContent(), x -> x.getContentType(), x -> x.getData()));
|
||||
libraryManager.getLibrarySourceLoader().registerProvider(
|
||||
new LibrarySourceProvider<org.hl7.fhir.r4.model.Library, Attachment>(provider,
|
||||
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) {
|
||||
ModelManager modelManager = new CacheAwareModelManager(this.modelCache);
|
||||
LibraryManager libraryManager = new LibraryManager(modelManager);
|
||||
libraryManager.getLibrarySourceLoader().clearProviders();
|
||||
public org.opencds.cqf.cql.engine.execution.LibraryLoader createLibraryLoader(org.cqframework.cql.cql2elm.LibrarySourceProvider provider) {
|
||||
ModelManager modelManager = new CacheAwareModelManager(this.modelCache);
|
||||
LibraryManager libraryManager = new LibraryManager(modelManager);
|
||||
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) {
|
||||
// Raw references to Library/libraryId or libraryId
|
||||
if (reference.startsWith("Library/") || !reference.contains("/")) {
|
||||
return libraryResourceProvider.resolveLibraryById(reference.replace("Library/", ""));
|
||||
}
|
||||
// Full url (e.g. http://hl7.org/fhir/us/Library/FHIRHelpers)
|
||||
else if (reference.contains(("/Library/"))) {
|
||||
return libraryResourceProvider.resolveLibraryByCanonicalUrl(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
|
||||
if (reference.startsWith("Library/") || !reference.contains("/")) {
|
||||
return libraryResourceProvider.resolveLibraryById(reference.replace("Library/", ""));
|
||||
}
|
||||
// Full url (e.g. http://hl7.org/fhir/us/Library/FHIRHelpers)
|
||||
else if (reference.contains(("/Library/"))) {
|
||||
return libraryResourceProvider.resolveLibraryByCanonicalUrl(reference);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<org.cqframework.cql.elm.execution.Library> loadLibraries(Measure measure,
|
||||
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
|
||||
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider) {
|
||||
List<org.cqframework.cql.elm.execution.Library> libraries = new ArrayList<org.cqframework.cql.elm.execution.Library>();
|
||||
public List<org.cqframework.cql.elm.execution.Library> loadLibraries(Measure measure,
|
||||
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
|
||||
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider) {
|
||||
List<org.cqframework.cql.elm.execution.Library> libraries = new ArrayList<org.cqframework.cql.elm.execution.Library>();
|
||||
|
||||
// load libraries
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<String> messages = new ArrayList<>();
|
||||
|
||||
// We just loaded it into the server so we can access it by Id
|
||||
org.hl7.fhir.r4.model.Library library = resolveLibraryReference(libraryResourceProvider, id);
|
||||
if (primaryLibrary == null) {
|
||||
primaryLibrary = library;
|
||||
}
|
||||
// load libraries
|
||||
//TODO: if there's a bad measure argument, this blows up for an obscure error
|
||||
org.hl7.fhir.r4.model.Library primaryLibrary = null;
|
||||
|
||||
if (library != null && isLogicLibrary(library)) {
|
||||
libraries.add(
|
||||
libraryLoader.load(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion()))
|
||||
);
|
||||
}
|
||||
}
|
||||
List<CanonicalType> measureLibraries = measure.getLibrary();
|
||||
if (measureLibraries.isEmpty()) {
|
||||
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()) {
|
||||
throw new IllegalArgumentException(String
|
||||
.format("Could not load library source for libraries referenced in %s.", measure.getId()));
|
||||
}
|
||||
// We just loaded it into the server so we can access it by Id
|
||||
org.hl7.fhir.r4.model.Library library = resolveLibraryReference(libraryResourceProvider, id);
|
||||
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)) {
|
||||
libraries.add(
|
||||
libraryLoader.load(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion()))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (library != null) {
|
||||
if (isLogicLibrary(library)) {
|
||||
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) {
|
||||
if (library == null) {
|
||||
return false;
|
||||
}
|
||||
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.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;
|
||||
}
|
||||
if (library != null && isLogicLibrary(library)) {
|
||||
libraries.add(
|
||||
libraryLoader.load(new VersionedIdentifier().withId(library.getName()).withVersion(library.getVersion()))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!library.getType().hasCoding()) {
|
||||
return false;
|
||||
}
|
||||
return libraries;
|
||||
}
|
||||
|
||||
for (Coding c : library.getType().getCoding()) {
|
||||
if (c.hasSystem() && c.getSystem().equals("http://terminology.hl7.org/CodeSystem/library-type")
|
||||
&& c.hasCode() && c.getCode().equals("logic-library")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
private boolean isLogicLibrary(org.hl7.fhir.r4.model.Library library) {
|
||||
if (library == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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,
|
||||
org.opencds.cqf.cql.engine.execution.LibraryLoader libraryLoader,
|
||||
LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> libraryResourceProvider) {
|
||||
// Library library = null;
|
||||
if (!library.getType().hasCoding()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
org.hl7.fhir.r4.model.Library fhirLibrary = libraryResourceProvider.resolveLibraryById(libraryId);
|
||||
return libraryLoader
|
||||
.load(new VersionedIdentifier().withId(fhirLibrary.getName()).withVersion(fhirLibrary.getVersion()));
|
||||
for (Coding c : library.getType().getCoding()) {
|
||||
if (c.hasSystem() && c.getSystem().equals("http://terminology.hl7.org/CodeSystem/library-type")
|
||||
&& c.hasCode() && c.getCode().equals("logic-library")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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,
|
||||
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);
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
return library;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class DateHelperTest {
|
|||
@Test
|
||||
public void testDateHelperProperlyResolvesValidDate() {
|
||||
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);
|
||||
GregorianCalendar cal = new GregorianCalendar();
|
||||
cal.setTimeInMillis(result.getTime());
|
||||
|
@ -28,7 +28,7 @@ public class DateHelperTest {
|
|||
@Test
|
||||
public void testDateHelperProperlyResolvesValidDateWithYearOnly() {
|
||||
DateHelper dateHelper = new DateHelper();
|
||||
Date result = dateHelper.resolveRequestDate("2001");
|
||||
Date result = DateHelper.resolveRequestDate("param", "2001");
|
||||
assertNotNull("result should not be NULL!", result);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class DateHelperTest {
|
|||
DateHelper dateHelper = new DateHelper();
|
||||
Date result = null;
|
||||
try {
|
||||
result = dateHelper.resolveRequestDate(null);
|
||||
result = DateHelper.resolveRequestDate("param", null);
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertNull("result should be NULL!", result);
|
||||
|
@ -49,7 +49,7 @@ public class DateHelperTest {
|
|||
DateHelper dateHelper = new DateHelper();
|
||||
Date result = null;
|
||||
try {
|
||||
result = dateHelper.resolveRequestDate("aaa-bbb-ccc");
|
||||
result = DateHelper.resolveRequestDate("param", "aaa-bbb-ccc");
|
||||
fail();
|
||||
} catch (DataFormatException e) {
|
||||
assertNull("result should be NULL!", result);
|
||||
|
|
Loading…
Reference in New Issue