# Get trends graphs from Signals

Canonical page: https://docs.ovok.com/api/slim/trends/get-trends-graphs-from-signals

`GET /v2/slim/trends/graphs`

Returns a resident's vitals and sleep episodes over a date range, grouped by graph type and device, with threshold and baseline values and summary statistics. Use it to draw the trend charts: within a day it returns every reading Signals holds, over several days the daily means.

**Auth:** The caller needs `Organization:read`, `Device:read`, `Patient:read` and `DocumentReference:read`.
**Scope:** the caller's project (from the token). The resident is read with your token, so Medplum's access policy limits who you can chart.

## Behaviour

- `graphType` is a comma-separated list of `heartRate`, `respiratoryRate`, `oxygenSaturation`, `pulseRate`, `perfusionIndex`, `bodyTemperature`, `systolicBloodPressure`, `diastolicBloodPressure`, `heartRateVariability` and `sleepEpisodes`. Repeated entries are ignored. `startDate` must not be after `endDate`. With `sleepEpisodes` in the list the range must be an in-day chart, one local calendar day (24 hours, 23 or 25 on a clock change) or an exact window, else the route answers `422` and charts nothing; the vitals alone take any range.
- Days run from midnight to midnight in the project's time zone (default `Europe/Berlin`), the days Signals computes its daily means over.
- A range of one day or less is an in-day chart: every reading of the local calendar day of `startDate`, from midnight to midnight, each at the time it was taken. `endDate` only decides which kind of chart you get, unless `window=exact` asks for the window itself. Readings sent on their own and inside a combined device reading both count; a combined reading at a time the vital already has a reading is charted once. Readings without a value are left out. A sensor sending once a second gives up to 86,400 readings per vital per day; a day Signals cannot return in one read (more than 500,000 readings, or more than 12 seconds) answers `503` like a Signals outage.
- A range of two or more days is an over-day chart: one point per local calendar day from `startDate`, stamped at the day's last instant. Each point is the day's mean, from midnight to midnight, as the home's derived-reading triggers record it in Signals. A day with no mean shows the night Medplum's statistics hold ending on that day, with batch readings filling nights that have none.
- Heart and respiratory rate fall back to Medplum where Signals cannot chart them: an in-day chart Signals holds no reading of, or an over-day chart with a day Signals has no mean for. The other vitals come from Signals only.
- Signals readings are kept to the resident's use periods of the device that sent them: a reading counts when its device was in use by the resident at the reading's time. A resident with no device use history keeps every reading; once they have one, a reading that names no device is dropped.
- Readings older than Signals keeps in its database are read from its archive, in the same way.
- `sleepEpisodes` has one point per episode that overlaps the range, oldest first. `timestamp` is the episode's start and `pointTimestampRange` its start and end; `data` is the seconds asleep inside it. The episode still running has no `end` and `data: null`. Episodes are recorded by the home's live sleep trigger as the combined device readings arrive, and are not bucketed: an episode starts at the first reading that finds the resident in bed and asleep, and ends at the first reading that finds them awake or out of bed, or 30 minutes after the device last sent while they slept. `stats` are over the seconds asleep.
- The Medplum fallback keeps the rules it always had. Before a night's recording is picked, it drops the readings and sleep statistics that end outside the resident's use periods of their device, as `GET /v1/slim/sleep/statistics` does. When a night has several sleep recordings left, it shows only the readings of the one whose sleep statistics were written last (latest `meta.lastUpdated`), matching statistics by the recording's exact period and batch blocks by their start.
- The use periods are read on every uncached call. When Medplum answers that read with an error, the route answers `502` rather than chart a night it cannot check.
- If Signals cannot be read, the route answers `503` with `error: "signals_unavailable"` and `retryAfterSec`, never a partial or empty chart. It answers the same, before reading anything, when the server is already running its limit of Signals reads.
- An over-day chart returns every day, and a day without a reading has `data: null`; `pointTimestamp` and `pointTimestampRange` show which reading filled it. An in-day chart returns readings only, so it has no empty points.
- `maxThreshold`, `minThreshold`, `maxBaseLine` and `minBaseLine` are the values that applied at that time. They are left out when none apply, and when the threshold lookup fails the chart still returns without them. Only `heartRate` and `respiratoryRate` carry them.
- Devices are keyed `<manufacturer>-<device id>`. Signals series are keyed by the resident's current device, else the device they wore last, else `Patient/<id>`; a Medplum fallback series is keyed by the device that sent it.
- A graph type with no data in the range comes back as `{}`. When nothing at all can be charted, both `heartRate` and `respiratoryRate` are `{}`.
- `window=exact` charts exactly `startDate` to `endDate`, whatever local days it falls across, so the last few hours still read right after midnight. It returns every reading in the window at the time it was taken, and the sleep episodes that overlap it, with the same threshold and baseline values as a day chart. The window may cover at most 24 hours, else the route answers `422`. Without it, or with `window=day`, the chart is the local calendar day of `startDate` as before.
- Results are cached for up to 15 seconds while the range may still be running, and up to 60 seconds once it has ended. A day chart and an exact window of the same dates are cached apart. A batch or statistics write to the resident's data invalidates the cache sooner.

## Example

```bash
curl -X GET 'https://api.sandbox.ovok.com/v2/slim/trends/graphs?patientId=c3499c27-2973-0a7f-807e-fb8676a92dcb&startDate=2026-09-02T00:00:00Z&endDate=2026-09-02T00:00:00Z&graphType=heartRate,respiratoryRate,sleepEpisodes' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjcyNjg4MDAsImV4cCI6MTc2NzI3MjQwMH0.Ql3B_ztDvctlyZ2z0vp4sl3ExXRQGkzmxdmTAqxNzZk'
```

The last six hours, wherever local midnight falls in them:

```bash
curl -X GET 'https://api.sandbox.ovok.com/v2/slim/trends/graphs?patientId=c3499c27-2973-0a7f-807e-fb8676a92dcb&startDate=2026-09-02T19:00:00Z&endDate=2026-09-03T01:00:00Z&graphType=heartRate,respiratoryRate,sleepEpisodes&window=exact' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjcyNjg4MDAsImV4cCI6MTc2NzI3MjQwMH0.Ql3B_ztDvctlyZ2z0vp4sl3ExXRQGkzmxdmTAqxNzZk'
```

```json
{
  "heartRate": {
    "Sleepiz-5f0c...": {
      "dataPoints": [
        {
          "timestamp": "2026-09-02T03:12:30.000Z",
          "timestampMs": 1788318750000,
          "data": 58,
          "maxThreshold": 100,
          "minThreshold": 60,
          "pointTimestamp": "2026-09-02T03:12:30.000Z"
        }
      ],
      "stats": { "average": 58, "max": 58, "min": 58, "total": 1 }
    }
  },
  "respiratoryRate": {},
  "sleepEpisodes": {
    "Sleepiz-5f0c...": {
      "dataPoints": [
        {
          "timestamp": "2026-09-01T20:10:00.000Z",
          "timestampMs": 1788293400000,
          "data": 27000,
          "pointTimestampRange": { "start": "2026-09-01T20:10:00.000Z", "end": "2026-09-02T04:40:00.000Z" }
        }
      ],
      "stats": { "average": 27000, "max": 27000, "min": 27000, "total": 1 }
    }
  }
}
```

**Who can call it:** a practitioner, a project admin or a System Owner session. See [roles](/access-policies#who-can-call-a-route).