Utility Functions
Utility files live in memberportal/src/utils/ and contain pure helper functions used across multiple pages and components.
labUtils.ts​
File: memberportal/src/utils/labUtils.ts
Handles lab result status determination and trend analysis. Used by the Lab Results page and the Dashboard.
getLabStatus(observation)​
Takes a FHIR Observation and returns one of: High, Low, Borderline, Normal, or Unknown.
Logic:
- Reads
valueQuantity.value(the actual result) andreferenceRange[0].low/high(the normal range) from theObservation. - If value > high →
High - If value < low →
Low - If value is within 10% of either boundary →
Borderline - Otherwise →
Normal - If no value is present →
Unknown
const status = getLabStatus(observation); // 'High' | 'Low' | 'Borderline' | 'Normal' | 'Unknown'
getLabStatusColor(status)​
Maps a LabStatus to a Mantine color string for badge coloring.
| Status | Color |
|---|---|
High | red |
Low | red |
Borderline | yellow |
Normal | green |
Unknown | gray |
getLabTrend(observations)​
Takes an array of Observation resources for the same test and returns a trend: improving, declining, or stable.
Logic:
- Sorts observations chronologically.
- Compares the two most recent values.
- If the change is less than 2% →
stable - If the latest value is
Normal→improving - If
Highand value is decreasing →improving, increasing →declining - If
Lowand value is increasing →improving, decreasing →declining
fhirHelpers.ts​
File: memberportal/src/utils/fhirHelpers.ts
Small helper functions for extracting display values from FHIR resources.
getConditionStatus(condition)​
Returns the clinical status code of a Condition resource (e.g., active, resolved, inactive).
const status = getConditionStatus(condition); // 'active' | 'resolved' | ...
getSeverityLevel(condition)​
Returns the severity display text of a Condition (e.g., Mild, Moderate, Severe). Falls back to 'Unknown' if not set.
getEncounterType(encounter)​
Returns the type display text of an Encounter (e.g., Office Visit, Telehealth). Falls back to 'Visit' if not set.
formatCPTCode(code)​
Returns the CPT code string, or 'N/A' if undefined.
ehrUtils.ts​
File: memberportal/src/utils/ehrUtils.ts
EHR provider definitions and resource-to-provider resolution. Documented in detail in the EHR Integration page.