Sleep

In this article, we consider the Sleep log data from Fitbit for conversion to FHIR. The data below shows a part of the response received from Fitbit when an API request for sleep log for a particular date is made.

{ "sleep": [
        {
            "dateOfSleep": "2017-04-02",
            "duration": <value in milliseconds>,
            "efficiency": <value>,
            "isMainSleep": true,
            "levels": {
                "summary": {
                    "deep": {
                        "count": <value>,
                        "minutes": <value>,
                        "thirtyDayAvgMinutes": <value>
                    },
                    "light": {
                        "count": <value>,
                        "minutes": <value>,
                        "thirtyDayAvgMinutes": <value>
                    },
                    "rem": {
                        "count": <value>,
                        "minutes": <value>,
                        "thirtyDayAvgMinutes": <value>
                    },
                    "wake": {
                        "count": <value>,
                        "minutes": <value>,
                        "thirtyDayAvgMinutes": <value>
                    }
                }
         ]}

 

As seen, the response consists of the various attributes of sleep like the date and duration. The sleep log also consists of nested attributes such as the levels of sleep and their respective attributes.

Resources are used in FHIR to support granular concepts. These resources can be grouped together to represent a larger concept. The data above can be represented in FHIR using a bundle [https://www.hl7.org/fhir/bundle.html]of the resource ‘Observation’ which is commonly used to capture laboratory data, vital signs and clinical assessments. [https://www.hl7.org/fhir/DSTU2/observation.html] A resource called ‘DiagnosticReport’ is used to logically group these observation resources in the bundle.

Procedure to create sleep log :

The FHIR sleep log was created using a tool known as FRED (FHIR Resource Editor). These resources are JSON files that can also be created manually.

The first step is to create a new DiagnosticReport resource for a bundle of Observations. Go to ‘Blank Resource’ under the ‘Open source’ tab. Choose ‘DiagnosticReport’ as the resource and make sure to select ‘Create in a Bundle’.

Go to the ‘Add Element’ option and add necessary elements to the resource such as status, code, category, subject etc.

 

Next, we add an extension for ‘isMainSleep’ which has a Boolean value. This element corresponds to the ‘isMainSleep’ attribute in the Fitbit data.

For the other attributes such as sleep duration and levels, we add an element ‘result’ which refers to the other observations in the bundle.

The next step is to insert Observation resources in the bundle. Each of these resources correspond to the attributes like sleep levels (light, rem, deep, wake) and sleep duration.

Let’s consider the Observation for light sleep in the bundle. We add the element ‘component’ in the resource to represent the count and the minutes for each sleep level. The value and unit inside each component represents the actual reading and its unit. Other necessary elements can also be added.

 

In this way, a number of nested attributes can be represented as multiple Observations. Once the bundle is complete, the file can be exported as JSON.

This is just one example of representing the lifestyle data using the FHIR specification. A lot of other data from health apps can be made compatible with FHIR. For more profiles on lifestyle data, please visit our profile[https://simplifier.net/FhirFli/~resources] on Simplifier.net. This profile was created by the guidance received from experts and implementers on the FHIR chat (Zulip) by FHIR Foundation. [https://chat.fhir.org/#narrow/stream/implementers/topic/Fitness.20data]