Repository navigation
Conversation
Evaluate text/cql-identifier (and text/cql) initialExpression values from linked cqf-library extensions when opening a new questionnaire, and cover the flow with a unit test.
delcroip
marked this pull request as ready for review
August 5, 2026 10:01
delcroip
marked this pull request as draft
August 5, 2026 10:02
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IMPORTANT: Where possible all PRs must be linked to a Github issue
Import of the EMCARE app logic done by AI
Engineer Checklist
strings.xmlfile./gradlew spotlessApplyand./gradlew spotlessCheckto check my code follows the project's style guide (java 21)Code Reviewer Checklist
strings.xmlfileCQL
initialExpressionPopulation on Questionnairesandroid/)feature/register-tricc.md(PlanDefinition$apply/ CQL usage precedent)Valid status values:
Draft→Approved→Implemented→Superseded.Part I — Business spec
1. Problem
SDC Questionnaires support
item.extensioninitialExpressionto pre-populate an answer from acomputed expression instead of a static
initialvalue. TRICC-generated content expresses thesecomputations in CQL (
language = text/cql-identifierortext/cql), referencingdefinestatements in a
Librarylinked to the Questionnaire via acqf-libraryextension. Before thischange, the app only evaluated FHIRPath-based
initialExpressions (via the Android FHIR SDK'sbuilt-in
ResourceMapper.populate) — CQL-based ones were silently ignored, so any TRICC form relyingon a CQL default (e.g. a computed BMI, a derived risk flag, a value copied from an earlier
encounter) opened with that field blank.
2. Goal
When a Questionnaire declares one or more
cqf-libraryextensions, evaluate any CQLinitialExpressionitems against that library before the SDC library populates theQuestionnaireResponse, so CQL-derived defaults appear exactly like any other prepopulated answer.3. Decisions
text/cql-identifierandtext/cqlonly (FHIRPathinitialExpressioncontinues to go through the SDC library unchanged).cqf-libraryextension value typesvalueCanonical,valueUri, andvalueString(TRICC/authoring tools are inconsistent about which type they emit).FhirOperator.evaluateLibraryper distinct library URL, with the launch-context subject resource as the CQL context resource, andpatient/encounteridpassed as CQL parameters when those resources are present in the launch context.initialandinitialExpressioncannot coexist on the same item per the SDC populate contract, so once a CQL value is resolved, theinitialExpressionextension is removed from the item and replaced with a plaininitialvalue carrying the CQL result.Timber.e); they do not block loading the rest of the questionnaire or other libraries' expressions.Part II — Technical spec
4. Where it lives
cqf-libraryvalue extraction (multi-type)engine/src/main/java/org/smartregister/fhircore/engine/util/extension/QuestionnaireExtension.kt—cqfLibraryIds(),cqfLibraryUrls(), privateExtension.cqfLibraryValue()quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt—evaluateCqlInitialExpressions,collectCqlInitialExpressionItems,applyCqlExpressionResultsToInitialQuestionnaireViewModelquestionnaire-loading path, invoked beforefetchRepositoryQuestionnaireResponse/populate, gated by awillLoadSavedResponsecheckquest/src/test/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModelTest.kt5. Flow
6. Notable implementation details
questionnaire.subjectTypeagainst thelaunchContextResourceslist, falling back to the first launch-context resource if no type matchis found.
initialExpression.languageis in{text/cql-identifier, text/cql}arecollected/evaluated; FHIRPath and other languages pass through untouched.
Parameters.getParameter(exprName)results may come back as either.valueor.resourcedepending on the CQL return type — both are checked.
item.item) so nested groups are covered.7. Success criteria
initialExpressionreferencing a linkedLibraryopens with thatfield pre-filled from the CQL evaluation result.
evaluation or overwrite the saved answer.
cqf-libraryextension is unaffected (no behavior change, no performancecost).
libraries' expressions from being evaluated.
8. Open items
populates as expected on a physical device/emulator, including timing relative to CarePlan/Task
launch-context loading.