Product EngineeringFeaturesLab FormsFrontendlivehealth-frontend

Redux State Management

Redux slices for Lab Forms in livehealth-frontend — LAB_FORM, GENERIC, and LAB_FORM_VALUES.

👤 Ritu Kataria📅 Updated: Mar 13, 2026🏷️ feature

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 CreatorTypeBehavior
setLabFormStateThunkUpdates labForm + tracks instance ID diffs + updates updatedFields for trackable fields
updateSectionThunkUpdates section in both labForm and updatedFields, marks is_updated
removeSectionThunkRemoves from labForm, adds to removedSections if original, resequences remaining
addQuestionThunkAppends to section, updates updatedFields.subprocesses
updateQuestionThunkUpdates in section, marks is_updated, syncs updatedFields
removeQuestionAsync ThunkFor existing: sets is_disabled: true. For new: filters out. Tracks in removedQuestions. Resequences.
validateLabFormThunkFull validation, returns LabFormValidationState, auto-focuses first error
clearLabFormAsync ThunkResets entire slice to initial state

Dual-Track Pattern

Every write operation maintains two parallel states:

  1. labForm — the full, current version rendered in the UI
  2. updatedFields — 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+ interfaces
  • src/redux/reducers/LabFormReducer.ts — 15 reducer cases
  • src/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.

KeyTypePurpose
aoeFormsAOEForm[]All forms to capture for the current bill
aoeFormValues{ billLevel, testLevel }All captured values (see §6.4)
activeAOEFormIndexnumberCurrently active form index
activeAOEFormSectionIndexnumberCurrently active section within the form
activeAOEFormMetaAOEFormPropsComputed props for the current section
confirmationMessagestringActive confirmation modal message
pendingSkipConditionsanyPending skip conditions held during a confirmation dialog
pendingSkipValueanyPending skip value during confirmation
showValueConfirmationModalbooleanWhether the confirmation modal is visible
conditionalQuestionIdnumberQuestion that triggered the conditional/confirmation
billConsentExistsbooleanWhether consent exists for the current bill
billConsentDetailsConsentDetailsConsent response data
billAOEExistsbooleanWhether AOE exists for the current bill
billAOEDetailsAOEDetailsAOE response data for viewing/editing
updatedAOEResponsesAOEDetailsMutable copy of AOE responses during editing

10.3 LAB_FORM_VALUES Slice (History)

Used by the history/values viewing pages.

KeyPurpose
valuesFetched form value records from the API
timeRange{ start, end } date range for the current query
isLoadingLoading state flag

10.4 GLOBAL_STATE (Shared Globals)

Set once on form type page load, shared across all components:

KeySet ByPurpose
LAB_FORM_CONFIGURATIONSgetLabFormConfigList()All configs for the current form type
LAB_FORM_PRESETSgetLabFormPresetList()All presets for the current form type

On this page