Skip to content

Commit

Permalink
Feature cql 849 (#677)
Browse files Browse the repository at this point in the history
* Added the queryBatchThreshold config point

* Changed maxCodesPerQuery and queryBatchThreshold to Integer and accounted for nulls
  • Loading branch information
Adam Stevenson authored Dec 6, 2022
1 parent 76d5345 commit c76b154
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public void setExpandValueSets(boolean expandValueSets) {
this.expandValueSets = expandValueSets;
}

private Integer queryBatchThreshold;

public Integer getQueryBatchThreshold() {
return queryBatchThreshold;
}

public void setQueryBatchThreshold(Integer queryBatchThreshold) {
this.queryBatchThreshold = queryBatchThreshold;
}

private SearchStyleEnum searchStyle;

public SearchStyleEnum getSearchStyle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ private void logRequestInfo(CdsHooksRequest request, String jsonRequest) {
logger.info("cds-hooks hook instance: {}", request.hookInstance);
logger.info("cds-hooks maxCodesPerQuery: {}", this.getProviderConfiguration().getMaxCodesPerQuery());
logger.info("cds-hooks expandValueSets: {}", this.getProviderConfiguration().getExpandValueSets());
logger.info("cds-hooks queryBatchThreshold: {}", this.getProviderConfiguration().getQueryBatchThreshold());
logger.info("cds-hooks searchStyle: {}", this.getProviderConfiguration().getSearchStyle());
logger.info("cds-hooks prefetch maxUriLength: {}", this.getProviderConfiguration().getMaxUriLength());
logger.info("cds-hooks local server address: {}", myAppProperties.getServer_address());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@

public class ProviderConfiguration {

public static final ProviderConfiguration DEFAULT_PROVIDER_CONFIGURATION = new ProviderConfiguration(true, 64,
SearchStyleEnum.GET, 8000, false);
public static final ProviderConfiguration DEFAULT_PROVIDER_CONFIGURATION = new ProviderConfiguration(true, null,
SearchStyleEnum.GET, 8000, false, null);

private int maxCodesPerQuery;
private Integer maxCodesPerQuery;
private SearchStyleEnum searchStyle;
private boolean expandValueSets;
private Integer queryBatchThreshold;
private int maxUriLength;
private boolean cqlLoggingEnabled;

public ProviderConfiguration(boolean expandValueSets, int maxCodesPerQuery, SearchStyleEnum searchStyle,
int maxUriLength, boolean cqlLoggingEnabled) {
public ProviderConfiguration(boolean expandValueSets, Integer maxCodesPerQuery, SearchStyleEnum searchStyle,
int maxUriLength, boolean cqlLoggingEnabled, Integer queryBatchThreshold) {
this.maxCodesPerQuery = maxCodesPerQuery;
this.searchStyle = searchStyle;
this.expandValueSets = expandValueSets;
this.maxUriLength = maxUriLength;
this.cqlLoggingEnabled = cqlLoggingEnabled;
this.queryBatchThreshold = queryBatchThreshold;
}

public ProviderConfiguration(CdsHooksProperties cdsProperties, CqlProperties cqlProperties) {
this.expandValueSets = cdsProperties.getFhirServer().getExpandValueSets();
this.maxCodesPerQuery = cdsProperties.getFhirServer().getMaxCodesPerQuery();
this.searchStyle = cdsProperties.getFhirServer().getSearchStyle();
this.maxUriLength = cdsProperties.getPrefetch().getMaxUriLength();
this.queryBatchThreshold = cdsProperties.getFhirServer().getQueryBatchThreshold();
this.cqlLoggingEnabled = cqlProperties.getOptions().getCqlEngineOptions().isDebugLoggingEnabled();
}

Expand All @@ -45,6 +48,8 @@ public boolean getExpandValueSets() {
return this.expandValueSets;
}

public int getQueryBatchThreshold() { return this.queryBatchThreshold; }

public int getMaxUriLength() {
return this.maxUriLength;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ private void logRequestInfo(CdsHooksRequest request, String jsonRequest) {
logger.info("cds-hooks hook instance: {}", request.hookInstance);
logger.info("cds-hooks maxCodesPerQuery: {}", this.getProviderConfiguration().getMaxCodesPerQuery());
logger.info("cds-hooks expandValueSets: {}", this.getProviderConfiguration().getExpandValueSets());
logger.info("cds-hooks queryBatchThreshold: {}", this.getProviderConfiguration().getQueryBatchThreshold());
logger.info("cds-hooks searchStyle: {}", this.getProviderConfiguration().getSearchStyle());
logger.info("cds-hooks prefetch maxUriLength: {}", this.getProviderConfiguration().getMaxUriLength());
logger.info("cds-hooks local server address: {}", myAppProperties.getServer_address());
Expand Down
1 change: 1 addition & 0 deletions plugin/cds-hooks/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ hapi:
fhirserver:
expandValueSets: true
maxCodesPerQuery: 64
queryBatchThreshold: 5
searchStyle: GET
prefetch:
maxUriLength: 8000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ JpaDataProviderFactory jpaDataProviderFactory(ModelResolver modelResolver, DaoRe
provider.setTerminologyProvider(t);
provider.setExpandValueSets(true);
provider.setMaxCodesPerQuery(2048);
provider.setQueryBatchThreshold(5);
provider.setModelResolver(modelResolver);
}
return new CompositeDataProvider(modelResolver, provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

/**
* This class provides an implementation of the cql-engine's RetrieveProvider
* interface which is used for loading
* data during CQL evaluation.
* interface which is used for loading data during CQL evaluation.
*/
public class JpaFhirRetrieveProvider extends SearchParamFhirRetrieveProvider implements DaoRegistryUser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.hl7.fhir.r4.model.RelatedArtifact;
import org.opencds.cqf.cql.engine.fhir.searchparam.SearchParameterResolver;
import org.opencds.cqf.cql.engine.model.ModelResolver;
import org.opencds.cqf.cql.evaluator.CqlOptions;
import org.opencds.cqf.cql.evaluator.cql2elm.content.fhir.BundleFhirLibrarySourceProvider;
import org.opencds.cqf.cql.evaluator.cql2elm.util.LibraryVersionSelector;
import org.opencds.cqf.cql.evaluator.fhir.adapter.AdapterFactory;
Expand Down Expand Up @@ -79,6 +80,9 @@ public class DataOperationsProvider extends DaoRegistryOperationProvider {
@Autowired
CqlTranslatorOptions cqlTranslatorOptions;

@Autowired
CqlOptions cqlOptions;

@Operation(name = "$data-requirements", idempotent = true, type = Library.class)
public Library dataRequirements(@IdParam IdType theId,
@OperationParam(name = "target") String target,
Expand Down Expand Up @@ -168,10 +172,11 @@ private Library processDataRequirements(Library library, RequestDetails theReque
LibraryManager libraryManager = createLibraryManager(library, theRequestDetails);
CqlTranslator translator = translateLibrary(library, libraryManager);

cqlOptions.setCqlTranslatorOptions(cqlTranslatorOptions);
// TODO: Pass the server's capability statement
// TODO: Enable passing a capability statement as a parameter to the operation
return DataRequirements.getModuleDefinitionLibraryR4(libraryManager, translator.getTranslatedLibrary(),
cqlTranslatorOptions, searchParameterResolver,
cqlOptions, searchParameterResolver,
jpaTerminologyProviderFactory.create(theRequestDetails),
myModelResolver, null);
}
Expand All @@ -180,10 +185,12 @@ private Library processDataRequirements(Measure measure, Library library, Reques
LibraryManager libraryManager = createLibraryManager(library, theRequestDetails);
CqlTranslator translator = translateLibrary(library, libraryManager);

cqlOptions.setCqlTranslatorOptions(cqlTranslatorOptions);

// TODO: Pass the server's capability statement
// TODO: Enable passing a capabiliity statement as a parameter to the operation
// TODO: Enable passing a capability statement as a parameter to the operation
return DataRequirements.getModuleDefinitionLibraryR4(measure, libraryManager, translator.getTranslatedLibrary(),
cqlTranslatorOptions, searchParameterResolver,
cqlOptions, searchParameterResolver,
jpaTerminologyProviderFactory.create(theRequestDetails),
myModelResolver, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.opencds.cqf.cql.engine.fhir.searchparam.SearchParameterResolver;
import org.opencds.cqf.cql.engine.model.ModelResolver;
import org.opencds.cqf.cql.engine.terminology.TerminologyProvider;
import org.opencds.cqf.cql.evaluator.CqlOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -99,7 +100,7 @@ public static org.hl7.fhir.dstu3.model.Library getModuleDefinitionLibraryDstu3(L
public static org.hl7.fhir.r4.model.Library getModuleDefinitionLibraryR4(org.hl7.fhir.r4.model.Measure measureToUse,
LibraryManager libraryManager,
CompiledLibrary translatedLibrary,
CqlTranslatorOptions options,
CqlOptions cqlOptions,
SearchParameterResolver searchParameterResolver,
TerminologyProvider terminologyProvider,
ModelResolver modelResolver,
Expand All @@ -111,28 +112,28 @@ public static org.hl7.fhir.r4.model.Library getModuleDefinitionLibraryR4(org.hl7
Set<String> expressionList = getExpressions(r5Measure);
DataRequirementsProcessor dqReqTrans = new DataRequirementsProcessor();
org.hl7.fhir.r5.model.Library effectiveDataRequirements = dqReqTrans.gatherDataRequirements(libraryManager,
translatedLibrary, options, expressionList, true);
translatedLibrary, cqlOptions.getCqlTranslatorOptions(), expressionList, true);
org.hl7.fhir.r4.model.Library r4EffectiveDataRequirements = (org.hl7.fhir.r4.model.Library) versionConvertor_40_50
.convertResource(effectiveDataRequirements);
r4EffectiveDataRequirements = addDataRequirementFhirQueries(r4EffectiveDataRequirements, searchParameterResolver,
terminologyProvider, modelResolver, capStatement);
terminologyProvider, modelResolver, cqlOptions, capStatement);
return r4EffectiveDataRequirements;
}

public static org.hl7.fhir.r4.model.Library getModuleDefinitionLibraryR4(LibraryManager libraryManager,
CompiledLibrary translatedLibrary,
CqlTranslatorOptions options,
CqlOptions cqlOptions,
SearchParameterResolver searchParameterResolver,
TerminologyProvider terminologyProvider,
ModelResolver modelResolver,
IBaseConformance capStatement) {
org.hl7.fhir.r5.model.Library libraryR5 = getModuleDefinitionLibraryR5(libraryManager, translatedLibrary,
options);
cqlOptions.getCqlTranslatorOptions());
VersionConvertor_40_50 versionConvertor_40_50 = new VersionConvertor_40_50(new BaseAdvisor_40_50());
org.hl7.fhir.r4.model.Library libraryR4 = (org.hl7.fhir.r4.model.Library) versionConvertor_40_50
.convertResource(libraryR5);
libraryR4 = addDataRequirementFhirQueries(libraryR4, searchParameterResolver, terminologyProvider, modelResolver,
capStatement);
cqlOptions, capStatement);
return libraryR4;
}

Expand All @@ -153,13 +154,29 @@ private static org.hl7.fhir.r4.model.Library addDataRequirementFhirQueries(org.h
SearchParameterResolver searchParameterResolver,
TerminologyProvider terminologyProvider,
ModelResolver modelResolver,
CqlOptions cqlOptions,
IBaseConformance capStatement) {
List<org.hl7.fhir.r4.model.DataRequirement> dataReqs = library.getDataRequirement();

try {
BaseFhirQueryGenerator fhirQueryGenerator = new R4FhirQueryGenerator(searchParameterResolver,
terminologyProvider, modelResolver);

if (cqlOptions.getCqlEngineOptions().getPageSize() != null) {
fhirQueryGenerator.setPageSize(cqlOptions.getCqlEngineOptions().getPageSize());
}
fhirQueryGenerator.setExpandValueSets(cqlOptions.getCqlEngineOptions().shouldExpandValueSets());

Integer maxCodesPerQuery = cqlOptions.getCqlEngineOptions().getMaxCodesPerQuery();
if (maxCodesPerQuery != null && maxCodesPerQuery > 0) {
fhirQueryGenerator.setMaxCodesPerQuery(cqlOptions.getCqlEngineOptions().getMaxCodesPerQuery());
}

Integer queryBatchThreshold = cqlOptions.getCqlEngineOptions().getQueryBatchThreshold();
if (queryBatchThreshold != null && queryBatchThreshold > 0) {
fhirQueryGenerator.setQueryBatchThreshold(cqlOptions.getCqlEngineOptions().getQueryBatchThreshold());
}

Map<String, Object> contextValues = new HashMap<String, Object>();
SubjectContext contextValue = getContextForSubject(library.getSubject());
if (contextValue != null) {
Expand Down
9 changes: 7 additions & 2 deletions server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ hapi:
engine:
# debug_logging_enabled: false
options: "EnableExpressionCaching"
# max_codes_per_query: 64
# query_batch_threshold: 10


# use_embedded_libraries: true
# translator:
# analyzeDataRequirements: false
Expand Down Expand Up @@ -96,8 +100,9 @@ hapi:
cdshooks:
enabled: true
fhirserver:
expandValueSets: true
maxCodesPerQuery: 64
# expandValueSets: true
# maxCodesPerQuery: 64
# queryBatchThreshold: 10
searchStyle: GET
prefetch:
maxUriLength: 8000

0 comments on commit c76b154

Please sign in to comment.