Data APIs¶
Send Data Events¶
The following actions are involved in sending data to the DMS:
- Open session
- Send data
- Keep session alive
- Close session
They are described in more detail below.
Open Session¶
POST to /api/v1/data/device-session/acquire
Data for POST:
1 2 3 4 5 | |
Example:
1 2 3 4 5 | |
Note
The maximum for watchdog_timeout is 3600.
Form of the response:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Send Data¶
POST to `/api/v1/data/device-session/SESSION_ID/push-data
e.g. /api/v1/data/device-session/5edf7aaf-70ae-4a44-a216-3e986780622e/push-data
Data for POST:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
The response will be the device session.
The payload is validated with the following JSON schema:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
Data_templates
Any additional properties can be added to the payload. For the data templates to work (e.g. for data explorer and data export) the content of data has to be of the form:
columns: list of columns in dataindex: index of the data, should be sortable, e.g. a number or timestamp (UTC, ISO8601 formatted e.g. 2020-11-23T07:09:24.080000Z). The functionreplace-indexin data templates is used in case theindexis a number and the timestamp is stored in a column as part of the data payload.data: array of array of data- Each inner array is a list of one data point per column
- The outer array is a list of data for each index
- Alternatively, the same data structure can be provided as sting in
data_jsoninstead ofdata
Device State¶
For each device, a device state is maintained on the DMS e.g. about its battery level. The device state can be updated by appending it to the POST as described above.
Using the same example as above:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
Keep Session Alive¶
To keep a session alive without posting additional data:
POST to /api/v1/data/device-session/SESSION_ID/keep-alive
Close Session¶
To close the session after all data has been sent:
POST to /api/v1/data/device-session/SESSION_ID/close
Query Data Events¶
To query events from the DMS event log, the following API endpoint can be used:
https://<DMS_URL>/api/v1/device-event-log/query-events
Query parameters:
page(required)page_size(required)devicefilter events by device UUID (eitherdeviceormodelhas to be specified)modelfilter events by model ID (eitherdeviceormodelhas to be specified)start_timefilter events by start time (ISO 8601)end_timefilter events by end time (ISO 8601)identityfilter events by stream identityevent_typefilter events by event type
Example:
https://next-dms.leitwert.ch/api/v1/device-event-log/query-events?device=53713a8c-91cc-4b7c-b33f-461144f44418&page=1&page_size=2&identity=ppg_file&start_time=2021-09-09T00:00:00.000Z&end_time=2021-09-10T00:00:00.000Z
This will return the first 2 events for device 53713a8c-91cc-4b7c-b33f-461144f44418 of the stream ppg_file between
2021-09-09 and 2021-09-10.
The response will be of the form:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
The value of data_json has the format of
a pandas DataFrame.
Data Export Script¶
Export per Device¶
The following is an example in Python to export data of a device to a CSV file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
Export per Patient/Participant¶
The following is an example in Python to export data of a patient/participant to a CSV file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |