Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package operation updates #486

Merged
merged 46 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a69a71e
Remove non CRMI logic. Update PackageProcessor to use visitor.
barhodes Jun 5, 2024
9661b2d
Add adapters for Questionnaire and StructureDefinition
barhodes Jun 5, 2024
4e9cb63
Shortening some class names
barhodes Jun 5, 2024
163748a
Add type and dataRequirement
barhodes Jun 5, 2024
bf10c56
Merge branch 'master' into package-operation-updates
barhodes Jun 5, 2024
39cb3de
Refactor ValueSet expansion
barhodes Jun 6, 2024
e34df80
Merge branch 'master' into package-operation-updates
barhodes Jun 27, 2024
c0c114d
Extract expansion logic out of PackageVisitor
barhodes Jun 28, 2024
aff70ba
Add tests
barhodes Jun 28, 2024
59c517d
Fix class name
barhodes Jul 1, 2024
b32701d
Merge branch 'master' into package-operation-updates
barhodes Jul 1, 2024
5a70e75
clean up adapters
barhodes Jul 2, 2024
481a516
stop expecting getRelatedArtifacts to pass a mutable ref
Jul 2, 2024
552b284
Enable test
barhodes Jul 2, 2024
2da47a1
Merge branch 'master' into package-operation-updates
barhodes Jul 2, 2024
107d905
Add tests
barhodes Jul 2, 2024
5bec3b3
Add tests
barhodes Jul 2, 2024
e0cd099
Update terminology client to use url param (#488)
TahaAttari Jul 3, 2024
7bf5f40
Add tests
barhodes Jul 3, 2024
cad1f1e
Fix test
barhodes Jul 3, 2024
e0dc77f
shorter
Jul 3, 2024
73a75e2
Add test
barhodes Jul 3, 2024
28a4283
Merge branch 'package-operation-updates' of github.com:cqframework/cl…
barhodes Jul 3, 2024
4aaba04
cleanup
barhodes Jul 3, 2024
7ebc822
cleanup
barhodes Jul 3, 2024
78b3623
Merge branch 'master' into package-operation-updates
barhodes Jul 4, 2024
e249b44
Questionnaire and StructureDefinition adapter work and DSTU3 extensio…
barhodes Jul 29, 2024
950f929
Merge branch 'master' into activity-def-unit-tests
barhodes Jul 29, 2024
a92cf90
spotless
barhodes Jul 29, 2024
d3030a3
add tests
barhodes Jul 29, 2024
916e4b3
add tests
barhodes Aug 8, 2024
f3a2393
cleanup and add tests
barhodes Aug 8, 2024
15d639b
add tests
barhodes Aug 8, 2024
e68aadd
cleanup and tests
barhodes Aug 13, 2024
c6fff89
cleanup
barhodes Aug 13, 2024
6f2f820
add tests
barhodes Aug 13, 2024
5b618a5
spotless
barhodes Aug 13, 2024
bc8c8a1
add tests
barhodes Aug 13, 2024
68ee811
Merge branch 'master' into package-operation-updates
barhodes Aug 14, 2024
51fbd47
Add MeasureAdapter
barhodes Aug 14, 2024
95ac742
fix method signatures
barhodes Aug 14, 2024
e463611
Add tests
barhodes Aug 14, 2024
e93b44f
add tests
barhodes Aug 14, 2024
2c995fb
Add dependency tracing logic to MeasureAdapters
barhodes Aug 14, 2024
46dc456
add tests
barhodes Aug 15, 2024
9e3f2cd
add tests
barhodes Aug 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions cqf-fhir-cql/src/main/java/org/opencds/cqf/fhir/cql/Engines.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.cql.cql2elm.content.RepositoryFhirLibrarySourceProvider;
import org.opencds.cqf.fhir.cql.cql2elm.util.LibraryVersionSelector;
import org.opencds.cqf.fhir.cql.engine.model.FhirModelResolverCache;
import org.opencds.cqf.fhir.cql.engine.parameters.CqlFhirParametersConverter;
import org.opencds.cqf.fhir.cql.engine.retrieve.FederatedDataProvider;
import org.opencds.cqf.fhir.cql.engine.retrieve.RepositoryRetrieveProvider;
import org.opencds.cqf.fhir.cql.engine.retrieve.RetrieveSettings;
import org.opencds.cqf.fhir.cql.engine.terminology.RepositoryTerminologyProvider;
import org.opencds.cqf.fhir.utility.Constants;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.model.FhirModelResolverCache;
import org.opencds.cqf.fhir.utility.repository.InMemoryFhirRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -106,7 +106,7 @@ public static CqlEngine forRepositoryAndSettings(
}

private static LibrarySourceProvider buildLibrarySource(Repository repository) {
AdapterFactory adapterFactory = getAdapterFactory(repository.fhirContext());
var adapterFactory = AdapterFactory.forFhirContext(repository.fhirContext());
return new RepositoryFhirLibrarySourceProvider(
repository, adapterFactory, new LibraryVersionSelector(adapterFactory));
}
Expand Down Expand Up @@ -186,22 +186,10 @@ private static Map<String, DataProvider> buildDataProviders(
return dataProviders;
}

public static AdapterFactory getAdapterFactory(FhirContext fhirContext) {
switch (fhirContext.getVersion().getVersion()) {
case DSTU3:
return new org.opencds.cqf.fhir.utility.adapter.dstu3.AdapterFactory();
case R4:
return new org.opencds.cqf.fhir.utility.adapter.r4.AdapterFactory();
case R5:
return new org.opencds.cqf.fhir.utility.adapter.r5.AdapterFactory();
default:
throw new IllegalArgumentException(String.format("unsupported FHIR version: %s", fhirContext));
}
}

public static CqlFhirParametersConverter getCqlFhirParametersConverter(FhirContext fhirContext) {
var fhirTypeConverter =
new FhirTypeConverterFactory().create(fhirContext.getVersion().getVersion());
return new CqlFhirParametersConverter(fhirContext, getAdapterFactory(fhirContext), fhirTypeConverter);
return new CqlFhirParametersConverter(
fhirContext, AdapterFactory.forFhirContext(fhirContext), fhirTypeConverter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.instance.model.api.IIdType;
import org.opencds.cqf.fhir.utility.Constants;
import org.opencds.cqf.fhir.utility.CqfExpression;

/**
* This class is used to resolve any CQFExpression extensions that exist on an extension.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.fhirpath.IFhirPath;
import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -46,10 +47,15 @@ private void constructExpression(StringBuilder sb, String expression) {
sb.append(String.format("%ndefine \"return\":%n %s", expression));
}

private String getFhirVersionString(FhirVersionEnum fhirVersion) {
// The version of the DSTU3 enum is 3.0.2 which the CQL Engine does not support.
return fhirVersion == FhirVersionEnum.DSTU3 ? "3.0.1" : fhirVersion.getFhirVersionString();
}

private void constructIncludes(StringBuilder sb, List<Pair<String, String>> libraries) {
sb.append(String.format(
"include FHIRHelpers version '%s' called FHIRHelpers%n",
fhirContext.getVersion().getVersion().getFhirVersionString()));
getFhirVersionString(fhirContext.getVersion().getVersion())));

if (libraries != null) {
for (Pair<String, String> library : libraries) {
Expand Down Expand Up @@ -93,7 +99,7 @@ private String getTypeDeclaration(String type, Boolean isList) {
private void constructUsings(StringBuilder sb) {
sb.append(String.format(
"using FHIR version '%s'%n",
fhirContext.getVersion().getVersion().getFhirVersionString()));
getFhirVersionString(fhirContext.getVersion().getVersion())));
}

private void constructHeader(StringBuilder sb) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.cqframework.cql.cql2elm.LibrarySourceProvider;
import org.cqframework.cql.cql2elm.StringLibrarySourceProvider;
Expand All @@ -20,6 +22,8 @@
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.cql.engine.parameters.CqlParameterDefinition;
import org.opencds.cqf.fhir.utility.Canonicals;
import org.opencds.cqf.fhir.utility.CqfExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -161,8 +165,13 @@ public List<IBase> getExpressionResult(
case "text/cql.expression":
case "text/cql-expression":
case "text/fhirpath":
var libraries = new ArrayList<Pair<String, String>>();
if (!StringUtils.isBlank(libraryToBeEvaluated)) {
libraries.add(new ImmutablePair<String, String>(
libraryToBeEvaluated, Canonicals.getIdPart(libraryToBeEvaluated)));
}
parametersResult = this.evaluateExpression(
expression, parameters, subjectId, null, bundle, contextParameter, resourceParameter);
expression, parameters, subjectId, libraries, bundle, contextParameter, resourceParameter);
// The expression is assumed to be the parameter component name
// The expression evaluator creates a library with a single expression defined as "return"
results = resolveParameterValues(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected InputStream getContentStream(IBaseResource library, String contentType
for (ICompositeType attachment : libraryAdapter.getContent()) {
AttachmentAdapter attachmentAdapter = this.adapterFactory.createAttachment(attachment);
if (attachmentAdapter.getContentType().equals(contentType)) {
// get externalized extension if present and add custom load data
return new ByteArrayInputStream(attachmentAdapter.getData());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import org.opencds.cqf.cql.engine.execution.ExpressionResult;
import org.opencds.cqf.cql.engine.fhir.converter.FhirTypeConverter;
import org.opencds.cqf.cql.engine.model.ModelResolver;
import org.opencds.cqf.fhir.cql.engine.model.FhirModelResolverCache;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.ParametersAdapter;
import org.opencds.cqf.fhir.utility.adapter.ParametersParameterComponentAdapter;
import org.opencds.cqf.fhir.utility.model.FhirModelResolverCache;
import org.slf4j.LoggerFactory;

public class CqlFhirParametersConverter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.cql.engine.terminology.TerminologySettings.VALUESET_EXPANSION_MODE;
import org.opencds.cqf.fhir.cql.engine.terminology.TerminologySettings.VALUESET_PRE_EXPANSION_MODE;
import org.opencds.cqf.fhir.cql.engine.utility.ValueSets;
import org.opencds.cqf.fhir.utility.FhirPathCache;
import org.opencds.cqf.fhir.utility.ValueSets;
import org.opencds.cqf.fhir.utility.search.Searches;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.Task;
import org.junit.jupiter.api.Test;
import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.utility.CqfExpression;
import org.opencds.cqf.fhir.utility.repository.ig.IgRepository;

class LibraryEngineTests {
Repository repository =
new IgRepository(FhirContext.forR4Cached(), Paths.get(getResourcePath(LibraryEngineTests.class)));
LibraryEngine libraryEngine = new LibraryEngine(repository, EvaluationSettings.getDefault());

@Test
void fhirPath() {
var patientId = "Patient/Patient1";
var repository =
new IgRepository(FhirContext.forR4Cached(), Paths.get(getResourcePath(LibraryEngineTests.class)));
var libraryEngine = new LibraryEngine(repository, EvaluationSettings.getDefault());

var params = parameters();
params.addParameter(part("%subject", new Patient().addName(new HumanName().addGiven("Alice"))));
params.addParameter(part("%practitioner", new Practitioner().addName(new HumanName().addGiven("Michael"))));
Expand All @@ -48,10 +49,6 @@ void fhirPath() {
@Test
void fhirPathWithResource() {
var patientId = "Patient/Patient1";
var repository =
new IgRepository(FhirContext.forR4Cached(), Paths.get(getResourcePath(LibraryEngineTests.class)));
var libraryEngine = new LibraryEngine(repository, EvaluationSettings.getDefault());

var params = parameters();
params.addParameter(part("%subject", new Patient().addName(new HumanName().addGiven("Alice"))));
params.addParameter(part("%practitioner", new Practitioner().addName(new HumanName().addGiven("Michael"))));
Expand All @@ -67,4 +64,13 @@ void fhirPathWithResource() {
"test-code",
((CodeableConcept) result.get(0)).getCodingFirstRep().getCode());
}

@Test
void expressionWithLibraryReference() {
var patientId = "Patient/Patient1";
var expression =
new CqfExpression("text/cql", "TestLibrary.testExpression", "http://fhir.test/Library/TestLibrary");
var result = libraryEngine.resolveExpression(patientId, expression, null, null, null, null);
assertEquals(((StringType) result.get(0)).getValue(), "I am a test");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
library TestLibrary version '1.0.0'

using FHIR version '4.0.1'

context Patient

define "testExpression":
'I am a test'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"resourceType": "Library",
"id": "TestLibrary",
"url": "http://fhir.test/Library/TestLibrary",
"version": "1.0.0",
"name": "TestLibrary",
"content": [
{
"contentType": "text/cql",
"url": "../cql/TestLibrary.cql"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import org.opencds.cqf.fhir.cql.EvaluationSettings;
import org.opencds.cqf.fhir.cql.ExtensionResolver;
import org.opencds.cqf.fhir.cql.LibraryEngine;
import org.opencds.cqf.fhir.cql.engine.model.FhirModelResolverCache;
import org.opencds.cqf.fhir.cr.activitydefinition.apply.ApplyProcessor;
import org.opencds.cqf.fhir.cr.activitydefinition.apply.ApplyRequest;
import org.opencds.cqf.fhir.cr.activitydefinition.apply.IApplyProcessor;
import org.opencds.cqf.fhir.cr.activitydefinition.apply.IRequestResolverFactory;
import org.opencds.cqf.fhir.cr.common.ResourceResolver;
import org.opencds.cqf.fhir.utility.Ids;
import org.opencds.cqf.fhir.utility.model.FhirModelResolverCache;
import org.opencds.cqf.fhir.utility.monad.Either3;
import org.opencds.cqf.fhir.utility.repository.operations.IActivityDefinitionProcessor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.opencds.cqf.fhir.cql.CqfExpression;
import org.opencds.cqf.fhir.utility.CqfExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opencds.cqf.fhir.cr.common;

import ca.uhn.fhir.context.FhirVersionEnum;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -8,8 +9,8 @@
import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
import org.hl7.fhir.instance.model.api.IBaseExtension;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.opencds.cqf.fhir.cql.CqfExpression;
import org.opencds.cqf.fhir.utility.Constants;
import org.opencds.cqf.fhir.utility.CqfExpression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -90,37 +91,42 @@ public List<IBase> getExpressionResult(
.filter(e -> e.getUrl().equals(extensionUrl))
.findFirst()
.orElse(null);
if (extension == null) {
return null;
}
switch (request.getFhirVersion()) {
case DSTU3:
var languageExtension = extensions.stream()
.filter(e -> e.getUrl().equals(Constants.CQF_EXPRESSION_LANGUAGE))
.findFirst()
.orElse(null);
var libraryExtension = extensions.stream()
.filter(e -> e.getUrl().equals(Constants.CQF_LIBRARY))
.findFirst()
.orElse(null);
return new CqfExpression(
languageExtension == null
? null
: languageExtension.getValue().toString(),
extension.getValue().toString(),
libraryExtension == null
? request.getDefaultLibraryUrl()
: libraryExtension.getValue().toString());
case R4:
return CqfExpression.of(
(org.hl7.fhir.r4.model.Expression) extension.getValue(), request.getDefaultLibraryUrl());
case R5:
return CqfExpression.of(
(org.hl7.fhir.r5.model.Expression) extension.getValue(), request.getDefaultLibraryUrl());
return extension == null ? null : CqfExpression.of(extension, request.getDefaultLibraryUrl());
// if (extension == null) {
// return null;
// }
// switch (request.getFhirVersion()) {
// case DSTU3:
// // var languageExtension = extensions.stream()
// var languageExtension = extension.getExtension().stream()
// .map(e -> (IBaseExtension<?, ?>) e)
// .filter(e -> e.getUrl().equals(Constants.CQF_EXPRESSION_LANGUAGE))
// .findFirst()
// .orElse(null);
// // var libraryExtension = extensions.stream()
// var libraryExtension = extension.getExtension().stream()
// .map(e -> (IBaseExtension<?, ?>) e)
// .filter(e -> e.getUrl().equals(Constants.CQF_LIBRARY))
// .findFirst()
// .orElse(null);
// return new CqfExpression(
// languageExtension == null
// ? null
// : languageExtension.getValue().toString(),
// extension.getValue().toString(),
// libraryExtension == null
// ? request.getDefaultLibraryUrl()
// : libraryExtension.getValue().toString());
// case R4:
// return CqfExpression.of(
// (org.hl7.fhir.r4.model.Expression) extension.getValue(), request.getDefaultLibraryUrl());
// case R5:
// return CqfExpression.of(
// (org.hl7.fhir.r5.model.Expression) extension.getValue(), request.getDefaultLibraryUrl());

default:
return null;
}
// default:
// return null;
// }
}

/**
Expand Down Expand Up @@ -166,7 +172,10 @@ public CqfExpression getItemInitialExpression(IOperationRequest request, IBaseBa
if (!item.hasExtension()) {
return null;
}
var cqfExpression = getCqfExpression(request, item.getExtension(), Constants.CQF_EXPRESSION);
var expressionExtensionUrl = request.getFhirVersion() == FhirVersionEnum.DSTU3
? Constants.CQIF_CQL_EXPRESSION
: Constants.CQF_EXPRESSION;
var cqfExpression = getCqfExpression(request, item.getExtension(), expressionExtensionUrl);
return cqfExpression != null
? cqfExpression
: getCqfExpression(request, item.getExtension(), Constants.SDC_QUESTIONNAIRE_INITIAL_EXPRESSION);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.opencds.cqf.fhir.cr.common;

import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.instance.model.api.IBaseResource;

public interface IPackageProcessor {
@Deprecated
IBaseBundle packageResource(IBaseResource resource);

@Deprecated
IBaseBundle packageResource(IBaseResource resource, String method);

IBaseBundle packageResource(IBaseResource resource, IBaseParameters parameters);
}
Loading