useEcgRecording
Use useEcgRecording() to load ECG observations and expose a mapped ECG recording alongside the query state in a React component.
Before you use it
Render the component below OvokProvider and keep it in a client-side React component. The hook uses the configured client to search ECG observations.
Input
| Input | Required | What it does |
|---|---|---|
id | No | Targets an ECG Observation lookup and a related-resource search through FHIR's has-member parameter. |
The hook does not accept patient or date filters. Without an ID, it searches ECG observations. With an ID, it performs two searches in parallel: one for the ECG observation with that ID, and one using FHIR's has-member search parameter to retrieve related observations. When a screen needs patient or period filters, use useObservations with the ECG measurement category.
Return value
| Field | Meaning |
|---|---|
recording | The first ECG measurement mapped from the matching observations, or undefined when none can be mapped. It can include optional heart rate, waveform points, diagnostic result, duration, and recorded time. |
measurements | The raw observation resources from the ECG search. Despite the field name, this is not the mapped ECG measurement. |
loading | The search loading state. |
error | The search error, when one occurs. |
The hook does not return a separate observations field. Use measurements for the underlying observation list and recording for the mapped ECG result.
How the ID filter works
An ECG recording may be represented by a main ECG observation and related observations. With no id, the hook maps the returned ECG observations. With an id, it combines the matching observation and resources found through the has-member search, then maps those resources into a recording. The server search and mapper determine which related resources are returned; the hook does not apply a patient or time filter.
The hook returns one mapped recording. If the selected observations do not produce a recording, recording is undefined; render that state separately from loading and error states.
Clinical workflow
This hook assembles data for an ECG experience. It does not interpret the recording or determine clinical significance. Agree on interpretation, thresholds, and follow-up with the responsible clinical team.
Example
Pass an observation ID when the screen should show one recording. Without an ID, the hook maps the ECG observations returned by the search:
import { useEcgRecording } from '@ovok/core';
export function EcgSummary({ observationId }: { observationId?: string }) {
const { recording, loading, error } = useEcgRecording(observationId);
if (loading) return <p>Loading ECG…</p>;
if (error) return <p role="alert">{error.message}</p>;
if (!recording) return <p>No ECG recording found.</p>;
return <p>Recorded heart rate: {recording.heartRate ?? 'Unavailable'}</p>;
}
Related pages
- Generated API reference for the recording and search state types.
- React applications
- useObservations
- useSaveMeasurement