feat(formulus-formplayer): Add dynamic choice lists with WHERE clause and age filtering support #277
+1,485,720
−6,869
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.
Description
This PR introduces a comprehensive dynamic choice list feature that enables form fields to populate dropdown options dynamically from the local database at runtime. This eliminates the need for static enum values that can become outdated, allowing forms to always display current data.
Key Features
DynamicEnumControl) that supportsx-dynamicEnumschema extensiongetDynamicChoiceListfunction that queries local observations via the Formulus WebView bridgedata.sex = 'male',age_from_dob(data.dob) >= 18)age_from_dob(data.dob)function that calculates age from date of birthFormEvaluationContext) that provides extension functions to form componentsTechnical Implementation
formulus-formplayer:
DynamicEnumControl.tsx- Custom renderer for dynamic enumsbuiltinExtensions.ts- Built-ingetDynamicChoiceListfunction with age calculation logicFormEvaluationContext.tsx- Context provider for extension functionsApp.tsx- Integrated built-in extensions and removed error message displayExtensionsLoader.ts- Support for built-in extension functionsformulus:
FormplayerModal.tsx- Fixed extension base path to/formsdirectoryExtensionService.ts- Enhanced extension loading logicreact-native.config.js- Added webview assets to React Native configandroid/app/build.gradle- Added JSX and HTML file copying for webview assetsDocumentation:
DYNAMIC_CHOICE_LISTS.md- Comprehensive 780-line reference guide with examplesWhat This Enables
Forms can now:
hh_person,household) for dropdown optionssex: 'male'+age_from_dob(data.dob) >= 18)Example Usage
{ "select_person": { "type": "string", "x-dynamicEnum": { "function": "getDynamicChoiceList", "query": "hh_person", "params": { "whereClause": "age_from_dob(data.dob) >= 18 AND data.sex = 'male'" }, "valueField": "observationId", "labelField": "data.names" } } }Type of Change
Component(s) Affected
Related Issue(s)
Closes/Fixes/Resolves:
Testing
age_from_dob()functionTesting Notes
test_dynamicformBreaking Changes
If breaking changes, please describe migration steps:
N/A - This is a purely additive feature. Existing forms continue to work unchanged. The
x-dynamicEnumextension is optional and only used when specified in the schema.Documentation Updates
Documentation Added
DYNAMIC_CHOICE_LISTS.md: Comprehensive 780-line reference guide including:age_from_dob()functionChecklist
Implementation Details
Files Changed
Core Feature Files:
formulus-formplayer/src/DynamicEnumControl.tsx(359 lines) - Custom rendererformulus-formplayer/src/builtinExtensions.ts(583 lines) - Query function with age logicformulus-formplayer/src/FormEvaluationContext.tsx(74 lines) - Context providerformulus-formplayer/src/App.tsx- Integration and error handling updatesformulus/src/components/FormplayerModal.tsx- Extension path fixformulus/src/services/ExtensionService.ts- Extension loading enhancementsDYNAMIC_CHOICE_LISTS.md(779 lines) - Complete documentation