use of org.opencds.cqf.cql.engine.terminology.ValueSetInfo in project cqf-ruler by DBCG.
the class PrefetchDataProviderR4 method retrieve.
@Override
public Iterable<Object> retrieve(String context, String contextPath, Object contextValue, String dataType, String templateId, String codePath, Iterable<Code> codes, String valueSet, String datePath, String dateLowPath, String dateHighPath, Interval dateRange) {
if (codePath == null && (codes != null || valueSet != null)) {
throw new IllegalArgumentException("A code path must be provided when filtering on codes or a valueset.");
}
if (dataType == null) {
throw new IllegalArgumentException("A data type (i.e. Procedure, Valueset, etc...) must be specified for clinical data retrieval");
}
// not be in the pre-fetch bundle, or might required a lookup by Id
if (context.equals("Patient") && contextPath == null) {
return Collections.emptyList();
}
List<Object> resourcesOfType = prefetchResources.get(dataType);
if (resourcesOfType == null) {
return Collections.emptyList();
}
// no resources or no filtering -> return list
if (resourcesOfType.isEmpty() || (dateRange == null && codePath == null)) {
return resourcesOfType;
}
List<Object> returnList = new ArrayList<>();
for (Object resource : resourcesOfType) {
boolean includeResource = true;
if (dateRange != null) {
if (datePath != null) {
if (dateHighPath != null || dateLowPath != null) {
throw new IllegalArgumentException("If the datePath is specified, the dateLowPath and dateHighPath attributes must not be present.");
}
Object dateObject = PrefetchDataProviderHelper.getR4DateTime(this.resolver.resolvePath(resource, datePath));
DateTime date = dateObject instanceof DateTime ? (DateTime) dateObject : null;
Interval dateInterval = dateObject instanceof Interval ? (Interval) dateObject : null;
String precision = PrefetchDataProviderHelper.getPrecision(Arrays.asList(dateRange, date));
if (date != null && !(InEvaluator.in(date, dateRange, precision))) {
includeResource = false;
} else // TODO - add precision to includes evaluator
if (dateInterval != null && !(IncludesEvaluator.includes(dateRange, dateInterval, precision))) {
includeResource = false;
}
} else {
if (dateHighPath == null && dateLowPath == null) {
throw new IllegalArgumentException("If the datePath is not given, either the lowDatePath or highDatePath must be provided.");
}
DateTime lowDate = dateLowPath == null ? null : (DateTime) PrefetchDataProviderHelper.getR4DateTime(this.resolver.resolvePath(resource, dateLowPath));
DateTime highDate = dateHighPath == null ? null : (DateTime) PrefetchDataProviderHelper.getR4DateTime(this.resolver.resolvePath(resource, dateHighPath));
String precision = PrefetchDataProviderHelper.getPrecision(Arrays.asList(dateRange, lowDate, highDate));
Interval interval = new Interval(lowDate, true, highDate, true);
// TODO - add precision to includes evaluator
if (!IncludesEvaluator.includes(dateRange, interval, precision)) {
includeResource = false;
}
}
}
if (codePath != null && !codePath.equals("") && includeResource) {
if (valueSet != null && terminologyProvider != null) {
if (valueSet.startsWith("urn:oid:")) {
valueSet = valueSet.replace("urn:oid:", "");
}
ValueSetInfo valueSetInfo = new ValueSetInfo().withId(valueSet);
codes = terminologyProvider.expand(valueSetInfo);
}
if (codes != null) {
Object codeObject = PrefetchDataProviderHelper.getR4Code(this.resolver.resolvePath(resource, codePath));
includeResource = PrefetchDataProviderHelper.checkCodeMembership(codes, codeObject, this.codeUtil);
}
}
if (includeResource) {
returnList.add(resource);
}
}
return returnList;
}
use of org.opencds.cqf.cql.engine.terminology.ValueSetInfo in project cqf-ruler by DBCG.
the class PrefetchDataProviderStu3 method retrieve.
@Override
public Iterable<Object> retrieve(String context, String contextPath, Object contextValue, String dataType, String templateId, String codePath, Iterable<Code> codes, String valueSet, String datePath, String dateLowPath, String dateHighPath, Interval dateRange) {
if (codePath == null && (codes != null || valueSet != null)) {
throw new IllegalArgumentException("A code path must be provided when filtering on codes or a valueset.");
}
if (dataType == null) {
throw new IllegalArgumentException("A data type (i.e. Procedure, Valueset, etc...) must be specified for clinical data retrieval");
}
// not be in the pre-fetch bundle, or might required a lookup by Id
if (context.equals("Patient") && contextPath == null) {
return Collections.emptyList();
}
List<Object> resourcesOfType = prefetchResources.get(dataType);
if (resourcesOfType == null) {
return Collections.emptyList();
}
// no resources or no filtering -> return list
if (resourcesOfType.isEmpty() || (dateRange == null && codePath == null)) {
return resourcesOfType;
}
List<Object> returnList = new ArrayList<>();
for (Object resource : resourcesOfType) {
boolean includeResource = true;
if (dateRange != null) {
if (datePath != null) {
if (dateHighPath != null || dateLowPath != null) {
throw new IllegalArgumentException("If the datePath is specified, the dateLowPath and dateHighPath attributes must not be present.");
}
Object dateObject = PrefetchDataProviderHelper.getStu3DateTime(this.resolver.resolvePath(resource, datePath));
DateTime date = dateObject instanceof DateTime ? (DateTime) dateObject : null;
Interval dateInterval = dateObject instanceof Interval ? (Interval) dateObject : null;
String precision = PrefetchDataProviderHelper.getPrecision(Arrays.asList(dateRange, date));
if (date != null && !(InEvaluator.in(date, dateRange, precision))) {
includeResource = false;
} else // TODO - add precision to includes evaluator
if (dateInterval != null && !(IncludesEvaluator.includes(dateRange, dateInterval, precision))) {
includeResource = false;
}
} else {
if (dateHighPath == null && dateLowPath == null) {
throw new IllegalArgumentException("If the datePath is not given, either the lowDatePath or highDatePath must be provided.");
}
DateTime lowDate = dateLowPath == null ? null : (DateTime) PrefetchDataProviderHelper.getStu3DateTime(this.resolver.resolvePath(resource, dateLowPath));
DateTime highDate = dateHighPath == null ? null : (DateTime) PrefetchDataProviderHelper.getStu3DateTime(this.resolver.resolvePath(resource, dateHighPath));
String precision = PrefetchDataProviderHelper.getPrecision(Arrays.asList(dateRange, lowDate, highDate));
Interval interval = new Interval(lowDate, true, highDate, true);
// TODO - add precision to includes evaluator
if (!IncludesEvaluator.includes(dateRange, interval, precision)) {
includeResource = false;
}
}
}
if (codePath != null && !codePath.equals("") && includeResource) {
if (valueSet != null && terminologyProvider != null) {
if (valueSet.startsWith("urn:oid:")) {
valueSet = valueSet.replace("urn:oid:", "");
}
ValueSetInfo valueSetInfo = new ValueSetInfo().withId(valueSet);
codes = terminologyProvider.expand(valueSetInfo);
}
if (codes != null) {
Object codeObject = PrefetchDataProviderHelper.getStu3Code(this.resolver.resolvePath(resource, codePath));
includeResource = PrefetchDataProviderHelper.checkCodeMembership(codes, codeObject, this.codeUtil);
}
}
if (includeResource) {
returnList.add(resource);
}
}
return returnList;
}
use of org.opencds.cqf.cql.engine.terminology.ValueSetInfo in project cqf-ruler by DBCG.
the class PrefetchDataProviderDstu2 method retrieve.
@Override
public Iterable<Object> retrieve(String context, String contextPath, Object contextValue, String dataType, String templateId, String codePath, Iterable<Code> codes, String valueSet, String datePath, String dateLowPath, String dateHighPath, Interval dateRange) {
if (codePath == null && (codes != null || valueSet != null)) {
throw new IllegalArgumentException("A code path must be provided when filtering on codes or a valueset.");
}
if (dataType == null) {
throw new IllegalArgumentException("A data type (i.e. Procedure, Valueset, etc...) must be specified for clinical data retrieval");
}
// not be in the pre-fetch bundle, or might required a lookup by Id
if (context.equals("Patient") && contextPath == null) {
return Collections.emptyList();
}
List<Object> resourcesOfType = prefetchResources.get(dataType);
if (resourcesOfType == null) {
return Collections.emptyList();
}
// no resources or no filtering -> return list
if (resourcesOfType.isEmpty() || (dateRange == null && codePath == null)) {
return resourcesOfType;
}
List<Object> returnList = new ArrayList<>();
for (Object resource : resourcesOfType) {
boolean includeResource = true;
if (dateRange != null) {
if (datePath != null) {
if (dateHighPath != null || dateLowPath != null) {
throw new IllegalArgumentException("If the datePath is specified, the dateLowPath and dateHighPath attributes must not be present.");
}
Object dateObject = PrefetchDataProviderHelper.getDstu2DateTime(this.resolver.resolvePath(resource, datePath));
DateTime date = dateObject instanceof DateTime ? (DateTime) dateObject : null;
Interval dateInterval = dateObject instanceof Interval ? (Interval) dateObject : null;
String precision = PrefetchDataProviderHelper.getPrecision(Arrays.asList(dateRange, date));
if (date != null && !(InEvaluator.in(date, dateRange, precision))) {
includeResource = false;
} else // TODO - add precision to includes evaluator
if (dateInterval != null && !(IncludesEvaluator.includes(dateRange, dateInterval, precision))) {
includeResource = false;
}
} else {
if (dateHighPath == null && dateLowPath == null) {
throw new IllegalArgumentException("If the datePath is not given, either the lowDatePath or highDatePath must be provided.");
}
DateTime lowDate = dateLowPath == null ? null : (DateTime) PrefetchDataProviderHelper.getDstu2DateTime(this.resolver.resolvePath(resource, dateLowPath));
DateTime highDate = dateHighPath == null ? null : (DateTime) PrefetchDataProviderHelper.getDstu2DateTime(this.resolver.resolvePath(resource, dateHighPath));
String precision = PrefetchDataProviderHelper.getPrecision(Arrays.asList(dateRange, lowDate, highDate));
Interval interval = new Interval(lowDate, true, highDate, true);
// TODO - add precision to includes evaluator
if (!IncludesEvaluator.includes(dateRange, interval, precision)) {
includeResource = false;
}
}
}
if (codePath != null && !codePath.equals("") && includeResource) {
if (valueSet != null && terminologyProvider != null) {
if (valueSet.startsWith("urn:oid:")) {
valueSet = valueSet.replace("urn:oid:", "");
}
ValueSetInfo valueSetInfo = new ValueSetInfo().withId(valueSet);
codes = terminologyProvider.expand(valueSetInfo);
}
if (codes != null) {
Object codeObject = PrefetchDataProviderHelper.getDstu2Code(this.resolver.resolvePath(resource, codePath));
includeResource = PrefetchDataProviderHelper.checkCodeMembership(codes, codeObject, this.codeUtil);
}
}
if (includeResource) {
returnList.add(resource);
}
}
return returnList;
}
use of org.opencds.cqf.cql.engine.terminology.ValueSetInfo in project quality-measure-and-cohort-service by Alvearie.
the class CQLParameterTests method runTest.
public void runTest(String type, Object expectedOutput, String defaultValue) throws Exception {
String cql = "library \"Test\" version '1.0.0'\n";
cql += "codesystem \"DUMMY\": 'urn:mysystem'\n";
cql += "parameter Input " + type;
if (defaultValue != null) {
cql += " default ";
cql += defaultValue;
}
cql += "\n";
cql += "define Output:\n\tInput\n";
Map<String, Object> parameters = null;
if (defaultValue == null) {
parameters = new HashMap<>();
parameters.put("Input", expectedOutput);
}
TerminologyProvider tp = new TerminologyProvider() {
@Override
public boolean in(Code code, ValueSetInfo valueSet) {
return false;
}
@Override
public Iterable<Code> expand(ValueSetInfo valueSet) {
return null;
}
@Override
public Code lookup(Code code, CodeSystemInfo codeSystem) {
return code;
}
};
LibraryLoader ll = new InMemoryLibraryLoader(Arrays.asList(toLibrary(cql)));
CqlEngine engine = new CqlEngine(ll, Collections.<String, DataProvider>emptyMap(), tp);
EvaluationResult result = engine.evaluate("Test", parameters);
assertEquals(1, result.expressionResults.size());
Object actual = result.forExpression("Output");
assertEquals(expectedOutput.toString(), actual.toString());
}
use of org.opencds.cqf.cql.engine.terminology.ValueSetInfo in project quality-measure-and-cohort-service by Alvearie.
the class R4RestFhirTerminologyProviderTest method inOperationReturnsFalseWhenFhirReturnsFalse.
@Test
public void inOperationReturnsFalseWhenFhirReturnsFalse() throws Exception {
ValueSetInfo info = new ValueSetInfo();
info.setId("urn:oid:Test");
Code code = new Code();
code.setSystem(TEST_SYSTEM);
code.setCode(TEST_CODE);
code.setDisplay(TEST_DISPLAY);
Parameters parameters = new Parameters();
parameters.getParameterFirstRep().setName("result").setValue(new BooleanType(false));
mockFhirResourceRetrieval("/ValueSet/Test/$validate-code?code=" + urlencode(code.getCode()) + "&system=" + urlencode(code.getSystem()) + "&_format=json", parameters);
boolean result = provider.in(code, info);
assertFalse(result);
}
Aggregations