Create a health research app using Samsung Health Stack
Create a health research app that collects and processes participant's health data, survey responses, and task results using Samsung Health Stack.
Samsung Health Stack is an open-source technology stack offering end-to-end solutions for collecting and analyzing data from wearable devices in Android and Wear OS environments. With applications ranging from medical research to clinician services and beyond, this tech stack provides the tools and infrastructure necessary to expedite the development and deployment of health-based studies.
The framework includes:
- Samsung Health Stack App SDK - a Software Development Kit (SDK) for building Android and Wear OS apps capable of collecting data from wearable devices.
- Web Portal - a customizable interface for creating surveys, managing team members, tracking participants, and analyzing data.
- Backend Services - API endpoints to access and interact with a robust data engine.
See Samsung Health Stack descriptions for detailed information.
Set up your environment
You will need the following:
- Installed and running Samsung Health Stack Backend System
- Installed Samsung Health Stack Web Portal
- Firebase private key used during the backend system installation
- Android Studio (latest version recommended)
- Android Jetpack Compose (latest version recommended)
- Samsung Galaxy mobile device with Health Connect app and Samsung Health app installed
- Samsung Galaxy Watch synced to the mobile device
- Google Account
Here is a sample code for you to start coding in this Code Lab. Download it and start your learning experience!
Create a Firebase project
Follow the instructions at firebase.google.com/docs/android/setup to add a Firebase project to the Firebase account you created during the backend system installation.
Set applicationId as
healthstack.sample and download the resulting
google-services.json file from Firebase.
To learn more, see Installing the App SDK - Create a Firebase Project.
Create a new study
- Sign in to the web portal page you deployed.
- On the Study Collection page, click the Create new study button.
- Set your study name and logo. Then click the Continue button to create your study.
- Select the Principal Investigator role and click the Confirm button.
- The Overview page appears like below:
- To connect your app to the backend system of your Web portal, you need to know the ID of your study. You can get the study ID by opening Chrome's developer tools.
- Right-click on the web portal page and select Inspect. Then, open the Network panel.
- Click Study Settings from the left navigation bar.
- You can see activities recorded on the Network tab.
- The value after
projectId=is the ID of the study, which you need to set up in the research app.
Connect the research app to the backend system
- In Android Studio, click Open to open the project files of the research app.
- Locate the downloaded Android Project (codelab-before) from the directory and click OK.
- Copy and paste the downloaded
google-services.jsonfrom Firebase to samples > researchsample module.
Go to samples > researchsample > res > values, and in the
strings.xmlfile, set the following values to connect the app to the backend system:
research_platform_endpoint- backend system’s endpoint, including the port number
research_project_id- ID of the study created
<!-- backend integration --> <string name="research_platform_endpoint">http://you.must.set.backend.url</string> <string name="research_project_id">study_id</string>
Customize the introduction page and eligibility survey
The sample research app already includes introduction page and eligibility survey, which you can customize to align with the objective of your study.
To modify the introduction page and eligibility survey questions, go to samples > researchsample > java > healthstack.sample and open the
Go to the
IntroModel constructor within the
intro function, and create two
IntroSections as below:
- Overview - "A study on walking over an hour daily versus non-walkers."
- Description - "We want to conduct a study to compare the daily life patterns of people who walk more than an hour each day and those who don't."
sections = listOf( IntroSection( "Overview", "A study on walking over an hour daily versus non-walkers.", ), IntroSection( "Description", "We want to conduct a study to compare the daily life patterns of people " + "who walk more than an hour each day and those who don’t." ) )
The introduction page would look like as below:
Part of the onboarding process is asking the participants questions through an eligibility survey to determine their suitability for your study.
The eligibility survey consists of three steps:
EligibilityIntroStep- displays an introduction about the survey
EligibilityCheckerStep- displays the eligibility questions
EligibilityResultStep- displays the result of the survey based on the answers
EligibilityCheckerStep receives the
eligibilityQuestions. The questions can be a
MultiChoiceQuestionModel, depending on the type of survey question model you set.
Modify the eligibility question pages as below:
|Eligibility Question 1|
|query||How many minutes on average do you spend walking each day?|
|candidates||listOf(0, 30, 60, 90, 120)|
|Eligibility Question 2|
|query||Are you willing to wear a tracking device to monitor your daily|
|candidates||listOf("Yes, I'm willing to use a tracking device", "No, I'm not|
comfortable using any tracking device")
|answer||Yes, I’m willing to use a tracking device|
|Eligibility Question 3|
|query||Are you available and willing to commit to participating in the|
study for a specified duration?
|candidates||listOf("Yes, I'm available and willing to commit", "No, I'm not|
available or willing to commit")
|answer||Yes, I’m available and willing to commit.|
private val eligibilityQuestions: List<QuestionModel<Any>> = listOf( ChoiceQuestionModel( id = "average_walking_time", query = "How many minutes on average do you spend walking each day?", explanation = "Unit: minute", candidates = listOf(0, 30, 60, 90, 120), viewType = Slider ), ChoiceQuestionModel( id = "tracking_device", query = "Are you willing to wear a tracking device to monitor your daily walking activity?", candidates = listOf( "Yes, I’m willing to use a tracking device", "No, I’m not comfortable using any tracking device" ), answer = "Yes, I’m willing to use a tracking device" ), ChoiceQuestionModel( id = "participate", query = "Are you available and willing to commit to participating in the study for a specified duration?", candidates = listOf("Yes, I’m available and willing to commit", "No, I’m not available or willing to commit"), answer = "Yes, I’m available and willing to commit" ) )
You can make a pass condition for each question by setting the
A failed result means the participant is not eligible for the study.
After defining eligibility questions, the eligibility survey pages would look like as below:
Set health data permissions
You can request permission to collect health data from your study participants.
However, before requesting permissions, your app must first declare them in the manifest.
Go to researchsample module > res > values.
health_permissions.xml, you can declare permissions to read or write data on Health Connect for
BloodPressure data types.
HeartRatedata is already declared in the project.
<item>androidx.health.permission.Steps.READ</item> <item>androidx.health.permission.Steps.WRITE</item> <item>androidx.health.permission.SleepSession.READ</item> <item>androidx.health.permission.SleepSession.WRITE</item> <item>androidx.health.permission.SleepStage.READ</item> <item>androidx.health.permission.SleepStage.WRITE</item> <item>androidx.health.permission.OxygenSaturation.READ</item> <item>androidx.health.permission.OxygenSaturation.WRITE</item> <item>androidx.health.permission.BloodPressure.READ</item> <item>androidx.health.permission.BloodPressure.WRITE</item>
Then, go back to healthstack.sample folder.
ResearchApplication.kt, request permissions from the participants to collect required health data.
val healthDataRequired = listOf("HeartRate", "SleepSession", "SleepStage", "BloodPressure", "Steps", "OxygenSaturation")
Set sync interval and choose health data to display
You can set the sync interval per health data type.
However, it is recommended to set a minimum interval of 15 minutes because the app is using Android's WorkManager.
healthDataSyncSpecs as below:
|Health Data Type||Sync Interval|
val healthDataSyncSpecs = listOf( SyncManager.HealthDataSyncSpec("HeartRate", 15, TimeUnit.MINUTES), SyncManager.HealthDataSyncSpec("Steps", 20, TimeUnit.HOURS), SyncManager.HealthDataSyncSpec("SleepSession", 1, TimeUnit.DAYS), SyncManager.HealthDataSyncSpec("SleepStage", 1, TimeUnit.DAYS), SyncManager.HealthDataSyncSpec("OxygenSaturation", 30, TimeUnit.MINUTES), SyncManager.HealthDataSyncSpec("BloodPressure", 30, TimeUnit.MINUTES), )
You can set which data type to display in the research app.
The status card for heart rate is already set to display.
To show other status cards, such as
SleepSessionStatus, add them to the list of
val healthDataToDisplay = listOf(HeartRateStatus, SleepSessionStatus, TaskStatus)
Run the app, join the study and sync your health data
Build and run the app on a Samsung Galaxy mobile device.
Ensure the Samsung Health app and Health Connect app is installed on the device and a Galaxy Watch is connected.
Reset the app to its initial state by clearing its data.
- Go to your phone's settings and then swipe to and tap Apps.
- Select or search for the ResearchSample app.
- Tap Storage, tap Clear data, and then click OK.
In the research app, you can join the study by signing in with your Google Account after passing the eligibility survey, providing consent, and allowing data access to Health Connect.
The research app shows your heart rate data (BPM) and the time you spent sleeping (hrs) based on the data from your Galaxy Watch and mobile device.
The web portal also displays and processes the data from the research.
To see the average heart rate data, go to the Overview section.
Scroll to the Participant List table, then click the participant data row.
The Participant Management shows health data collected on average, such as heart rate.
Create a survey task
A survey is a sequence of questions that collect information from the participants in your study.
In this step, create a survey task and see the result from the web portal.
- Go to the Study Management section and expand the Task Management.
- Open the Surveys tab and click the Create survey button on the top right corner.
- Set survey title as Daily Survey. Then, write three questions as below:
- After writing all the survey questions, click the Publish button.
- Set the Frequency as Daily and the Publish time as early as possible.
- Then, click the Publish button on the bottom right corner.
- You can find your survey task on the Published list.
- Go to the research app and touch the refresh button next to Upcoming Tasks or Today to see the survey you created.
- Answer and complete the survey task.
- Go back to the web portal. Click your survey task from the Published list.
- Reload the web page or re-login to get the result.
- You can see the survey report in the Responses and Analytics tab.
Create an activity task
Activities allow researchers to collect specific types of data from users.
For this study, add an activity to collect measurements related to manual dexterity.
- In Study Management, go to the Activities tab and click the Create activity button.
- Select Motor for the activity category and choose Tapping Speed.
- Click the Create button.
- Click the Publish button on the task edit page.
- Set Frequency as Daily and Publish time as early as possible.
- Then, click the Publish button.
- You can find your activity task on the Published list.
- In the research app, touch the refresh button to see the newly added activity.
- Open and perform the activity task.
- In the web portal, click your activity task from the Published list.
- Enter the Participant Id to see the collected data.
Congratulations! You have successfully achieved the goal of this Code Lab. Now, you can create your own research app that can collect and process users’ health data, answers to survey and activity task results for research purposes by yourself! If you face any trouble, you may download this file:
To learn more, see Samsung Health Stack.