SlimSlim/Sleep

Get sleep statistics

  • Sandbox: available
  • Staging: available
  • Production: unknown
GET
/v1/slim/sleep/statistics

Returns a resident's sleep statistics for one night, grouped by device, with each metric compared against the average of the preceding nights. Use it for the sleep detail view.

Auth: bearer token. The caller must be a practitioner, an admin or a System Owner, and needs Observation:read and Observation:search. Scope: the caller's project (from the token). Sleep data is read with your token, so Medplum's access policy limits what you see.

Behaviour

  • The "night" is the calendar day, in the project's time zone, of endDate. A sleep recording belongs to the day its effectivePeriod.end falls on.
  • lastDayCount is how many earlier days feed average. It defaults to 7 and must be between 1 and 30.
  • Each device entry holds, per metric, current (the night of endDate), average (over the earlier nights that have a recording) and diff. A device with no recording for the night of endDate is left out.
  • When one night has several recordings, the one written last is used: the latest meta.lastUpdated. Its period and completeness do not count, so a shorter recording written later wins, and so can a same-day nap ending after the night. A metric it does not carry is null, never taken from another recording. The PDF export's sleep table uses the same rule, and so do the GET /v1/slim/trends/graphs charts where they can match a night's readings to its recordings.
  • average and diff use each earlier night's latest-written recording the same way.
  • Only recordings that end inside one of the resident's use periods of their device are counted, before a night's recording is picked. So a previous resident's night that ended before the device was handed over, but reached Ovok after it and was stored under this resident, is not shown. A resident with no device use history has all recordings counted. The PDF export and the GET /v1/slim/trends/graphs charts apply the same filter.
  • Once a resident has any use period, recordings of a device with no period of theirs, and those from before a device's earliest period, are not counted. A device assigned before use periods were recorded gets its first one on its next edit in Ovok, starting at the Device's last write before that edit. Each device whose recordings in a request all drop is counted in the sleep.device_use_device_dropped metric and logged at most once a minute.
  • Ovok reads the sleep-stats observations first and falls back to the LOINC pair 93832-4 (sleep duration) and 103216-8 (out-of-bed count) when there are none.
  • The response is {} when no qualifying recording exists.
  • Results are cached for up to 60 seconds per project, resident, endDate and lastDayCount. A write to the resident's data invalidates the cache sooner.

Example

curl -X GET 'https://api.sandbox.ovok.com/v1/slim/sleep/statistics?patientId=c3499c27-2973-0a7f-807e-fb8676a92dcb&endDate=2026-09-28T00:00:00Z&lastDayCount=7' \  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjcyNjg4MDAsImV4cCI6MTc2NzI3MjQwMH0.Ql3B_ztDvctlyZ2z0vp4sl3ExXRQGkzmxdmTAqxNzZk'

Authorization

bearer
headerAuthorizationBearer <JWT>

Query Parameters

endDate*string

The date to get the sleep statistics for, the full ISO 8601 date string is required

Formatdate-time
lastDayCount?string

The number of days to compare the sleep statistics with!

Default"7"
patientId*string

The patient ID to get the sleep statistics for

Formatuuid

Response Body

Successfully retrieved sleep statistics data grouped by device

application/json
  1. response
[key: string]?
Example Request
curl -X GET 'https://api.sandbox.ovok.com/v1/slim/sleep/statistics?endDate=2019-08-24T14%3A15%3A22Z&patientId=497f6eca-6276-4993-bfeb-53cbbbba6f08'
Example Response
{  "property1": {    "totalSleepTimeSeconds": {      "current": 0,      "average": 0,      "diff": 0    },    "sleepEfficiencyPercentage": {      "current": 0,      "average": 0,      "diff": 0    },    "wakeAfterSleepOnsetSeconds": {      "current": 0,      "average": 0,      "diff": 0    },    "totalBedTimeSeconds": {      "current": 0,      "average": 0,      "diff": 0    },    "sleepStartTime": {      "current": "string",      "average": "string",      "diff": 0    },    "sleepEndTime": {      "current": "string",      "average": "string",      "diff": 0    },    "sleepOnsetLatencySeconds": {      "current": 0,      "average": 0,      "diff": 0    },    "outOfBedCount": {      "current": 0,      "average": 0,      "diff": 0    },    "wakeUpLatencySeconds": {      "current": 0,      "average": 0,      "diff": 0    }  },  "property2": {    "totalSleepTimeSeconds": {      "current": 0,      "average": 0,      "diff": 0    },    "sleepEfficiencyPercentage": {      "current": 0,      "average": 0,      "diff": 0    },    "wakeAfterSleepOnsetSeconds": {      "current": 0,      "average": 0,      "diff": 0    },    "totalBedTimeSeconds": {      "current": 0,      "average": 0,      "diff": 0    },    "sleepStartTime": {      "current": "string",      "average": "string",      "diff": 0    },    "sleepEndTime": {      "current": "string",      "average": "string",      "diff": 0    },    "sleepOnsetLatencySeconds": {      "current": 0,      "average": 0,      "diff": 0    },    "outOfBedCount": {      "current": 0,      "average": 0,      "diff": 0    },    "wakeUpLatencySeconds": {      "current": 0,      "average": 0,      "diff": 0    }  }}

List users across projects (compatibility) GET

Compatibility route for older cross-project user list clients. Behaves exactly like `GET /v1/slim/query/user`. For new integrations, use `GET /v1/slim/project/{id}/users`. **Auth:** bearer token. The caller must be a practitioner, an admin or a System Owner, and needs `Practitioner:read`. No extra admin check is applied. **Scope:** the caller's project (from the token), or the project in `project=Project/<id>` when it is your project or one of its sub-projects. ## Behaviour - Same parameters, filters, sorting, paging and caching as `GET /v1/slim/query/user`. ## Example ```bash curl -X GET 'https://api.sandbox.ovok.com/v1/slim/query/admin/user?profileType=Practitioner&project=Project/c3499c27-2973-0a7f-807e-fb8676a92dcb' \ -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjcyNjg4MDAsImV4cCI6MTc2NzI3MjQwMH0.Ql3B_ztDvctlyZ2z0vp4sl3ExXRQGkzmxdmTAqxNzZk' ```

List effective observation ids by device GET

Returns the effective Observation ids for every device in your project, keyed by device identifier. These are the readings that produced each device's current heart rate, respiratory rate, sleep status and presence values. **Auth:** bearer token. The caller must be a practitioner, an admin or a System Owner, and needs `Device:read` and `Device:search`. **Scope:** the caller's project (from the token). ## Behaviour - Covers the devices that have telemetry, up to the first 1000 devices of the project, including devices without a resident. - Each value has the same shape as `GET /v1/slim/telemetry/{deviceId}/effectiveIds`. Fields are `null` when no reading has set them. ## Example ```bash curl -X GET 'https://api.sandbox.ovok.com/v1/slim/telemetry/effectiveIds' \ -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3NjcyNjg4MDAsImV4cCI6MTc2NzI3MjQwMH0.Ql3B_ztDvctlyZ2z0vp4sl3ExXRQGkzmxdmTAqxNzZk' ```