Frontend
Frontend responsibilities, state shapes, UI behavior, and key components for Toxicology.
Frontend
What Frontend Owns
| Concern | Frontend responsibility |
|---|---|
| Entry points | Drug Master, Panel Master, and Brand Master under Drug Master / Panel Master |
| Report setup | Toxicology test type and toxicology report parameter components in Test List |
| UI state | List tabs, selected rows, filters, modal form values, selected drugs, reflex toggles, component configuration tabs |
| Validation | Required fields such as drug selection, panel name/code, brand name, component title, referring list, and selected fields |
| API calls | Fetch, create, update, disable, download, bulk-action, system-default request actions, and report-parameter save actions |
| Display / statuses | Enabled/disabled status, system default/custom/disabled tabs, row action menus, report component configuration |
Frontend Perspective
- The sidebar exposes
Drug Master / Panel Masteras the entry point. - Drug Master shows the drug catalog with tabs for all, system default, custom, and disabled drugs.
- Panel Master lets users search and add drugs to a panel, then optionally enable screening or prescription reflex behavior.
- Brand Master lets users search and add drugs to a brand-based collection.
- List pages support download, bulk actions, filtering, row actions, and system-default requests.
- Test List lets users create a report/test with test type
Toxicology. - Report Parameters lets users add toxicology components such as Screening, Confirmation, Prescription, Summary, History, Image, and Clinical Notes.
- Screening configuration controls report-entry fields, billing availability, default drugs/panels/brands, and display ordering metadata.
- Confirmation uses the same configuration pattern as Screening and adds a Reflex tab.
- Prescription captures prescribed drugs and can expose selected drugs/panels/brands during billing.
- Summary links to Screening or Confirmation and summarizes the selected component's findings.
- History links to a result component and summarizes prior reports using report count, display type, summary classes, date format, date filter, and ordering.
- Image configures an upload grid using max rows and max columns.
- Clinical Notes links to a result component and controls note fields and drug visibility.
Core Frontend State Objects
| State key | What it stores | Why it exists |
|---|---|---|
selectedDrugs | Drugs added to the current panel or brand modal | Persists the collection before save |
activeTab | Current list tab such as all/system/custom/disabled | Controls list filtering |
selectedRows | Rows selected for bulk actions | Enables bulk update behavior |
screeningReflexEnabled | Panel-level screening reflex toggle | Controls automatic confirmation/reflex behavior |
prescriptionReflexEnabled | Panel-level prescription reflex toggle | Controls prescription-based reflex behavior |
selectedComponent | Current report parameter component, such as Screening | Drives the right-side component configuration panel |
selectedFields | Fields selected for a component | Controls report-entry fields and labels |
componentDefaults | Default drugs/panels/brands for the component | Auto-adds defaults when the toxicology test is billed |
availableDuringBilling | Whether selected drugs/panels/brands are available in billing | Exposes orderable items in billing workflows |
componentMeta | Group by, sort by, and order by settings | Controls report-entry/report-display organization |
reflexConfig | Confirmation reflex toggles | Controls screening reflex, prescription reflex, and bill-entry reflex behavior |
linkedComponent | Component selected by Summary | Tells Summary which Screening or Confirmation result set to summarize |
summaryTypes | Selected summary classifications | Controls which summary categories are available |
historyReportCount | Number of previous reports to summarize | Controls History's Summary for Last X Reports setting |
historyDisplayPreference | Sample-type display scope for History | Controls whether history displays all sample types |
historyDateFormat | Date format selected for History | Controls date rendering in historical summaries |
historyDateFilter | Date basis selected for History | Controls whether history uses report date or another date filter |
imageGrid | Max rows, max columns, and uploaded files | Controls Image component grid preview and report output |
clinicalNoteScope | All-drugs vs selected-drugs note visibility | Controls where Clinical Notes are available |
Visibility Rules
The feature appears when the user has access to the Drug Master / Panel Master sidebar section. Exact permission keys are TBD.
The panel and brand modals require drug master data because both flows depend on searching and adding drugs.
Toxicology report components appear from the Add New Parameter menu after the test/report is configured with test type Toxicology.
Runtime UI Behaviors
- When a user adds a drug to a panel or brand, it appears in the selected-drug table.
- When a user removes a drug, it is removed from the selected collection before save.
- When a user updates an existing panel or brand, previously mapped drugs are loaded into the modal.
- When validation fails, the modal should keep entered data and show actionable validation feedback.
- When save succeeds, the modal closes and the list reflects the updated record.
- When the user selects test type
Toxicology, the Report Parameters tab can add toxicology components. - When the user adds
Screening, the component opens with Configuration, Meta, and Defaults tabs. - When
Available during Billingis checked, the UI allows specific drugs, panels, or brands to be selected for billing availability. - When defaults are added, those drugs or panels are inserted by default once the toxicology test is billed.
- When Confirmation is configured, the Reflex tab can decide whether confirmation drugs are added automatically or only when requested during billing.
- When Prescription is configured, selected drugs/panels/brands represent prescribed medications that should be tracked for the patient.
- When Summary is configured, it must link to Screening or Confirmation before it can summarize findings.
- When History is configured, it links to a component and generates historical summary output for the selected number of previous reports.
- When Image is configured, the row/column counts generate a preview grid and upload slots.
- When Clinical Notes is configured, the user chooses whether notes apply to all drugs or selected drugs.
Important Toxicology Snippets (Frontend)
Report entry component renderer
Source: livehealth-frontend/src/components/reusable/Modals/Report/EditReportView/index.tsx
renderComponent(...) is the report-entry switchboard. It reads component_type from each report format row and renders the matching toxicology component.
Important behavior:
SCREENINGandCONFIRMATIONrender collapsible drug grids.- Both use
SearchDrugsto add drugs into the component. - Both pass component
metaintoprepareColumnDef(...), so configured labels, hidden fields, editable fields, grouping, sorting, and ordering affect the grid. CONFIRMATIONpassescomponent_typetoprepareColumnDef(...), allowing confirmation-specific column behavior.PRESCRIPTIONalso usesSearchDrugs, but if the selected drug has metabolites it callsfindDrugsMetabolitesAndFill(...)before adding the drug.PRESCRIPTIONusestranslation.PRESCRIPTION_COLUMNS; ifenable_prn_descriptionis false, only the first prescription column is rendered.IMAGErendersImageComponentand passes image-grid meta pluslabReportIdfor upload keying.SUMMARYrenders a Calculate button, a summary-info tooltip, and a summary grid usingprepareSummaryComponentColumnDef(...).HISTORYsupports both chart and table output based onmeta.sub_type.HISTORYwarns when the date grouping saved in report values differs from the current configureddate_filter.
Minimal control flow:
const { component_type, meta, testName = "" } = format;
const newMeta = JSON.parse(meta || "{}");
switch (component_type?.toUpperCase()) {
case "SCREENING":
case "CONFIRMATION":
// SearchDrugs + GridComponent using prepareColumnDef(...)
break;
case "PRESCRIPTION":
// SearchDrugs + metabolite expansion + prescription columns
break;
case "IMAGE":
// ImageComponent using grid metadata
break;
case "SUMMARY":
// Calculate + SummaryInfoComponent + summary grid
break;
case "HISTORY":
// Calculate History + ChartComponent or GridComponent
break;
}Summary and clinical-note columns
Source: livehealth-frontend/src/components/reusable/Modals/Report/EditReportView/AgGrid/helpers.tsx
prepareSummaryComponentColumnDef(...) builds the grid columns from component meta.columns. It also applies:
group_by,sort_by,order_by,- red highlighting when
result_1hashighlightFlag.
For Clinical Notes, the helper keeps only name and result_2, so the clinical-note grid is intentionally narrower than the full toxicology drug grid.
Metabolite expansion
Source: livehealth-frontend/src/components/reusable/Billing/utils/helpers.ts
findDrugsMetabolitesAndFill(...) expands selected drugs before they are added to Prescription. It:
- keeps selected brand/panel records separately,
- collects metabolite ids from selected drugs,
- builds a unique drug-id set from selected drugs plus metabolites,
- preserves brand name context when available.
This is why Prescription can add a selected drug and still carry its metabolite context into report entry.
Device mapping grid
Source: livehealth-frontend/src/components/Operations/DeviceManagement/components/ToxicologyDrugGrid.tsx
ToxicologyDrugGrid is separate from report entry. It is used in device management to map toxicology device keys to drugs.
Important behavior:
- fetches mapped device drugs with
deviceDrugApi(deviceId), - fetches unmapped device keys for the last 30 days with
getUnmappedResultsApi(...), - stores mapped drugs in
MODEL.deviceDrug, - lets the user map a device key to a drug through
CreateSelectField, - shows validation state as
ValidatedorNot Validated, - supports deleting a device-drug mapping through
DeleteModal.
Drug Master container
Source: livehealth-frontend/src/components/reusable/Drug/container/index.tsx
DrugMaster owns the Drug Master list screen shown under Drug Master / Panel Master.
Important behavior:
- initial load calls
getDrugListApi("/reporting/drugs/?is_panel=0&is_disabled=0"), - stores active drugs in
MODEL.allDrugs, Disabled Drugstab lazily callsgetDrugListApi("/reporting/drugs/?is_panel=0&is_disabled=1"),- tabs split the same list into
All Drugs,System Defaults,Custom Drug, andDisabled Drugs, Add DrugopensCreateDrug,- row click/edit loads related drugs through
fetchRelatedDrugs(...), - copy creates a new drug by cloning the selected row and prefixing the name with
Copy of, - enable calls
/reporting/drugs/{id}/enable/, - disable first calls
/reporting/drugs/{id}/related/brands-panels/?is_disabled=0to warn about linked panels/brands, then calls/reporting/drugs/{id}/disable/, Enable Custom Drug setupcopies system defaults into custom setup throughenableCustomDrugSetup(...),- bulk upload/action state is handled through
BulkModal.
Panel Master container
Source: livehealth-frontend/src/components/reusable/Panel/container/index.tsx
PanelMaster owns the Panel Master list screen. Panels are backed by the same drug API/table as drugs, but are loaded and saved with is_panel=1.
Important behavior:
- initial load calls
getDrugListApi("/reporting/drugs/?is_panel=1&is_disabled=0"), - stores active panels in
MODEL.allPanel, Disabled Panelstab lazily callsgetDrugListApi("/reporting/drugs/?is_panel=1&is_disabled=1"),- tabs split the same list into
All Panels,System Defaults,Custom Panels, andDisabled Panels, Add PanelopensCreatePanel,- row click/edit opens the update flow for the selected panel,
- copy creates a new panel by cloning the selected row and prefixing the name with
Copy of, - create/copy/update uses the drug create/update helpers because a panel is represented as a
Drugrecord withis_panel=1, - enable calls
/reporting/drugs/{id}/enable/, - disable calls
/reporting/drugs/{id}/disable/.
Brand Master container
Source: livehealth-frontend/src/components/reusable/Brand/container/index.tsx
BrandMaster owns the Brand Master list screen. Brands are separate records that maintain drug mappings through the brand-to-drug relationship.
Important behavior:
- initial load calls
getDrugListApi("/reporting/brands/?is_disabled=0"), - stores active brands in
MODEL.allBrands, Disabled Brandstab lazily callsgetDrugListApi("/reporting/brands/?is_disabled=1"),- tabs split the same list into
All Brands,System Defaults,Custom Brands, andDisabled Brands, Add BrandopensCreateBrand,- row click/edit opens the update flow for the selected brand,
- copy creates a new brand by cloning the selected row and prefixing the name with
Copy of, - create/copy/update uses brand helpers such as
createBrand(...)andaddAndUpdate(...), - enable calls
/reporting/brands/{id}/enable/, - disable calls
/reporting/brands/{id}/disable/, - unmount clears
MODEL.drugsListso stale selected-drug options do not leak into later brand flows.
Key Frontend Locations & Helpers
| Area | Function / component | Path | Role |
|---|---|---|---|
| Drug Master list | DrugMaster | livehealth-frontend/src/components/reusable/Drug/container/index.tsx | Lists all/system/custom/disabled drugs, opens create/update modal, handles copy, enable, disable, bulk actions |
| Panel Master list | PanelMaster | livehealth-frontend/src/components/reusable/Panel/container/index.tsx | Lists all/system/custom/disabled panels, opens create/update modal, handles copy, enable, disable |
| Brand Master list | BrandMaster | livehealth-frontend/src/components/reusable/Brand/container/index.tsx | Lists all/system/custom/disabled brands, opens create/update modal, handles copy, enable, disable |
| Report entry renderer | renderComponent | livehealth-frontend/src/components/reusable/Modals/Report/EditReportView/index.tsx | Renders Screening, Confirmation, Prescription, Summary, History, Image, and other component types |
| Screening report-entry grid | SCREENING case in renderComponent | livehealth-frontend/src/components/reusable/Modals/Report/EditReportView/index.tsx | Search and add drugs, render configured grid columns |
| Confirmation report-entry grid | CONFIRMATION case in renderComponent | livehealth-frontend/src/components/reusable/Modals/Report/EditReportView/index.tsx | Search and add drugs, render confirmation-specific grid columns |
| Prescription report-entry grid | PRESCRIPTION case in renderComponent | livehealth-frontend/src/components/reusable/Modals/Report/EditReportView/index.tsx | Adds prescribed drugs and expands metabolites when configured |
| Summary report-entry grid | SUMMARY case in renderComponent | livehealth-frontend/src/components/reusable/Modals/Report/EditReportView/index.tsx | Calculates and displays linked-component summary |
| History report-entry view | HISTORY case in renderComponent | livehealth-frontend/src/components/reusable/Modals/Report/EditReportView/index.tsx | Calculates history and renders chart/table output |
| Image report-entry view | IMAGE case in renderComponent | livehealth-frontend/src/components/reusable/Modals/Report/EditReportView/index.tsx | Renders toxicology image grid/uploads |
| Summary column helper | prepareSummaryComponentColumnDef | livehealth-frontend/src/components/reusable/Modals/Report/EditReportView/AgGrid/helpers.tsx | Builds Summary and Clinical Notes grid columns from meta |
| Metabolite expansion helper | findDrugsMetabolitesAndFill | livehealth-frontend/src/components/reusable/Billing/utils/helpers.ts | Adds metabolites for selected prescription drugs |
| Toxicology device mapping grid | ToxicologyDrugGrid | livehealth-frontend/src/components/Operations/DeviceManagement/components/ToxicologyDrugGrid.tsx | Maps toxicology device keys to drug records |