Redux State Management
Redux slices for Lab Forms in livehealth-frontend — LAB_FORM, GENERIC, and LAB_FORM_VALUES.
Redux State Management
Lab Forms uses three dedicated Redux slices plus shared globals. Each slice covers a distinct concern: configuration editing, runtime capture, and history viewing.
10.1 LAB_FORM Slice (Admin Configuration)
File: src/redux/reducers/LabFormReducer.ts
Used during form configuration (add/edit page). Tracks the full form state and a delta of only changed fields.
interface LabFormState {
labForm: LabFormConfig; // Full form being edited (UI state)
updatedFields: Partial<LabFormConfig>; // Delta for PATCH API
addedInstanceIds: number[]; // New instance mappings added
removedInstanceIds: number[]; // Instance mappings removed
removedSections: number[]; // Section IDs to be deleted
removedQuestions: number[]; // Question IDs to be disabled
affectedProcesses: number[]; // Other configs affected by section changes
selectedSection: LabFormSection; // Active section in builder sidebar
activeSectionIndex: number;
selectedQuestion: LabFormQuestion | undefined;
activeQuestionIndex: number;
validationState: LabFormValidationState;
}Key Action Patterns
| Action Creator | Type | Behavior |
|---|---|---|
setLabFormState | Thunk | Updates labForm + tracks instance ID diffs + updates updatedFields for trackable fields |
updateSection | Thunk | Updates section in both labForm and updatedFields, marks is_updated |
removeSection | Thunk | Removes from labForm, adds to removedSections if original, resequences remaining |
addQuestion | Thunk | Appends to section, updates updatedFields.subprocesses |
updateQuestion | Thunk | Updates in section, marks is_updated, syncs updatedFields |
removeQuestion | Async Thunk | For existing: sets is_disabled: true. For new: filters out. Tracks in removedQuestions. Resequences. |
validateLabForm | Thunk | Full validation, returns LabFormValidationState, auto-focuses first error |
clearLabForm | Async Thunk | Resets entire slice to initial state |
Dual-Track Pattern
Every write operation maintains two parallel states:
labForm— the full, current version rendered in the UIupdatedFields— only the delta of changes, sent to the API on save
This avoids sending unchanged data to the backend on update (PATCH-style efficiency).
Files:
src/redux/types/LabFormTypes.ts— 23 action constants, 20+ interfacessrc/redux/reducers/LabFormReducer.ts— 15 reducer casessrc/redux/actions/LabFormActions.ts— 26 exports (sync actions, thunks, validators)
10.2 GENERIC Slice (Runtime AOE/Consent)
Used during billing to manage active AOE form capture state. Persists only for the duration of the billing session.
| Key | Type | Purpose |
|---|---|---|
aoeForms | AOEForm[] | All forms to capture for the current bill |
aoeFormValues | { billLevel, testLevel } | All captured values (see §6.4) |
activeAOEFormIndex | number | Currently active form index |
activeAOEFormSectionIndex | number | Currently active section within the form |
activeAOEFormMeta | AOEFormProps | Computed props for the current section |
confirmationMessage | string | Active confirmation modal message |
pendingSkipConditions | any | Pending skip conditions held during a confirmation dialog |
pendingSkipValue | any | Pending skip value during confirmation |
showValueConfirmationModal | boolean | Whether the confirmation modal is visible |
conditionalQuestionId | number | Question that triggered the conditional/confirmation |
billConsentExists | boolean | Whether consent exists for the current bill |
billConsentDetails | ConsentDetails | Consent response data |
billAOEExists | boolean | Whether AOE exists for the current bill |
billAOEDetails | AOEDetails | AOE response data for viewing/editing |
updatedAOEResponses | AOEDetails | Mutable copy of AOE responses during editing |
10.3 LAB_FORM_VALUES Slice (History)
Used by the history/values viewing pages.
| Key | Purpose |
|---|---|
values | Fetched form value records from the API |
timeRange | { start, end } date range for the current query |
isLoading | Loading state flag |
10.4 GLOBAL_STATE (Shared Globals)
Set once on form type page load, shared across all components:
| Key | Set By | Purpose |
|---|---|---|
LAB_FORM_CONFIGURATIONS | getLabFormConfigList() | All configs for the current form type |
LAB_FORM_PRESETS | getLabFormPresetList() | All presets for the current form type |