Jump to Content
Healthcare & Life Sciences

Manage FHIR Data from Android App with Open Health Stack and Google Cloud

August 17, 2023
Abirami Sukumaran

Developer Advocate, Google

Omar Ismail

Software Engineer, Google

Cloud enablement has the potential to generate a value of $100 billion to $170 billion in 2030 for healthcare companies, according to McKinsey. This means all healthcare companies, organizations and startups are already engaging in digital transformation by adopting cloud providers for enabling business. Also, the shift to mobile healthcare apps makes it easy for patients to reach medical help around the clock, schedule appointments, connect to healthcare anytime, monitor patients remotely, and improve workflow! It is highly imperative that we focus on solutions, libraries and use cases in this area for enabling developers, healthcare providers, and related organizations to make the transformation to digital healthcare accessible, simple, secure, robust, mobile-friendly and remote-capable. 

That is exactly what Open Health Stack and Google Cloud Healthcare API offer. In this blog, we will learn how OHS and Google Cloud Healthcare API can be used to create innovative healthcare solutions that are secure, scalable, and compliant. The combination of these powerful tools provide healthcare workers and developers with the ability to create data-driven solutions that can significantly improve patient care and outcomes. We intend to leverage the power of Open Health Stack and Google Cloud Healthcare API in a mobile app that uses Android-FHIR SDK to enable users to handle FHIR patient records in Google Cloud. 

Open Health Stack (OHS)

Open Health Stack is a suite of open source components and developer resources designed to help accelerate development of applications with healthcare data. OHS is designed to be modular, and scalable, and is built on industry standards such as FHIR and OAuth 2.0. OHS is a powerful stack of components that enables healthcare workers in low-resource environments to access secure, offline-capable, data-driven solutions. Learn more about OHS here.

Google Cloud Healthcare API

The Google Cloud Healthcare API provides an entry point to a fully-managed service that allows for easy and standardized data exchange between healthcare applications and solutions built on Google Cloud. It provides a suite of APIs that enable developers to access healthcare data from various sources, including FHIR, DICOM, or HL7v2 stores. It also supports intelligent analytics and machine learning capabilities in Google Cloud with pre-built connectors for streaming data processing in Dataflow,  scalable analytics with BigQuery and machine learning with Vertex AI. With Google Cloud Healthcare API, FHIR data can be exported, streamed or programmatically saved to a BigQuery dataset and Pub/Sub topics, enabling downstream applications to leverage the data. We showcase this capability by creating a patient record in a mobile app and displaying the BigQuery dataset, which contains the FHIR store data just populated by the app.

Android FHIR SDK

The Android FHIR SDK is an important component of the OHS suite. It is a set of Kotlin libraries for building offline-capable, mobile-first applications on Android. It benefits developers by enabling easy leverage FHIR specification, saves them time and effort with built-in widgets that  quickly turn FHIR questionnaires into forms and on-device processing of patient and clinical data.

The SDK has three libraries:

1. Structured Data Capture (SDC) Library 
This library is used to collect, validate and process healthcare data on Android

2. FHIR Engine Library
This library enables storing and managing FHIR data locally and on the server

3. Workflow Library
This library intends to provide point-of-care decision support and compute clinical measures on Android

In this implementation, we will use the Structured Data Capture Library to render a Questionnaire, and the FHIR Engine library to store  the FHIR content of the response. The data will then be uploaded to the Cloud FHIR Store using the Cloud Healthcare API, but prior to uploading we will first authenticate ourselves using Firebase. This is visualized in the diagram below:

https://storage.googleapis.com/gweb-cloudblog-publish/images/1_FvGbaNb.max-2000x2000.jpg

Patient data in FHIR on Cloud

In this section, we will see the implementation details of the project. To begin with, let's walkthrough  a high level overview of the design components:

Healthcare API Setup

In this section, we will enable Google Cloud Healthcare API, set up Healthcare Dataset and create FHIR Datastore.

Enabling Healthcare API

  1. Go to the Google Cloud Console API Library

  2. From the projects list, select your project

  3. In the API Library, select the API you want to enable. If you need help finding the API, use the search field and the filters

  4. On the API page, click ENABLE, it will enable the Healthcare API

  5. It will add the Healthcare API Service Account to the project

Granting BigQuery Admin permissions to the Service Account1

  1. Note your PROJECT_ID and PROJECT_NUMBER from the console, refer doc for identification

  2. Enable Cloud Shell and execute the below gcloud command to grant permission

Loading...

Create Healthcare dataset

1. In Cloud Shell, execute the following command to create the Healthcare Dataset:
gcloud beta healthcare datasets create <<DATASET_ID>> --location=us-central1

2. The same can be done from Google Cloud Healthcare console:
a. Go to https://console.cloud.google.com/healthcare/browser?

https://storage.googleapis.com/gweb-cloudblog-publish/images/2_rWjDL8Y.max-2000x2000.jpg

b. Click CREATE DATASET

c. Provide Dataset Name, Region and click CREATE

https://storage.googleapis.com/gweb-cloudblog-publish/images/3_KJNhNRI.max-2000x2000.jpg

That’s it. We have successfully created the Healthcare Dataset.

Create FHIR Data store

1. In Cloud Shell, execute the following command:

Loading...

2. Alternatively, you can do the same using the Healthcare console:
a. Go to Google Cloud Healthcare Browser page and click on the newly created Dataset

https://storage.googleapis.com/gweb-cloudblog-publish/images/4_9GqMZIz.max-2000x2000.jpg

b. Click CREATE DATA STORE

https://storage.googleapis.com/gweb-cloudblog-publish/images/5_VR4Vm4A.max-2000x2000.jpg

c. Select type as FHIR and provide an ID for the data store

https://storage.googleapis.com/gweb-cloudblog-publish/images/6_hx2NCFH.max-2000x2000.jpg

d. Choose Version as R4

e. Click CREATE

The Cloud Healthcare FHIR Data store is successfully created. If you would like to write queries, operations like creating views on FHIR, reference notebooks are available in this repo. For performing quality checks on FHIR resources, use the metrics in fhir-dbt-analytics.

BigQuery Setup and Streaming

This project covers saving FHIR Store data in BigQuery Dataset so it can be queried, programmed and analyzed leveraging the power of BigQuery and BQML. 

Create BigQuery Dataset

1. Run the following command from Cloud Shell:
bq mk --location=us-central1 --dataset <<PROJECT_ID>>:<<BQ_DATASET>>

2. Alternatively, you can also do this from BigQuery Console:
a. Go to Biguery Explorer section, click on the 3 dots next to the Project Name and select “Create data set”

https://storage.googleapis.com/gweb-cloudblog-publish/images/7_Ql7OxOS.max-2000x2000.jpg

b. Provide Dataset Name, Region and click CREATE DATA SET

https://storage.googleapis.com/gweb-cloudblog-publish/images/8_myWc5ZN.max-2000x2000.jpg

Create BigQuery Streaming

Streaming is required in order to export resource changes to BigQuery each time a FHIR resource is created, updated, patched or deleted in an FHIR store. Each store is allowed to have up to 10 streaming configs.

  1. Go to Google Cloud Healthcare console, browser page

  2. Click the newly created DATASET

  3. Click the newly created DATA STORE

https://storage.googleapis.com/gweb-cloudblog-publish/images/9_NgglduZ.max-2000x2000.jpg

4. Click ADD NEW STREAMING CONFIGURATION

https://storage.googleapis.com/gweb-cloudblog-publish/images/10_hK51zQ5.max-2000x2000.jpg

5. Select the newly created BigQuery Dataset from the list, Schema type as “Analytics V2” and Resource Type “Patient” from the list (You can choose as many resource types) and click Done

https://storage.googleapis.com/gweb-cloudblog-publish/images/11_dGSfqQs.max-2000x2000.jpg

That’s it. You are all set to save FHIR store data and stream it to BigQuery.

Cloud Functions to Write R4 Data to FHIR Datastore using Healthcare API

Cloud Functions allows you to conveniently write your code and deploy to the cloud in a  serverless manner. It is scalable, pay-as-you-go, event-driven and open in terms of technology and language support. Refer to the documentation for more features. 

The function we will write intends to authenticate and write data that is coming in the FHIR R4 format into the FHIR Data Store using the Cloud Healthcare API. To create the Cloud Function:

1. Go to Cloud Functions and click CREATE FUNCTION

2. Set the name to fhir-datastore-proxy, the region to us-central1 and the Authentication option to “Require Authentication”

3. Expand the Runtime, build, connections, and security settings. You will add five Runtime environment variables:
a. Name: CLOUD_FUNCTIONS_ENDPOINT | Value: the URL endpoint of the Function. You will see this in Authentication block above and will be of the form: https://us-central1-PROJECT_ID.cloudfunctions.net/fhir-datastore-proxy
b. Name: PROJECT_ID | Value: your project id
c. Name: DATASET_LOCATION | Value:  the location of your FHIR Datastore
d. Name: DATASET_ID | Value: the Healthcare Datastore ID
e. Name: FHIR_STORE_ID | Value: the FHIR Store ID

4. Press Next to go to the next page, where we will add our code

5. An inline editor should now be displayed, select Java 17 as the language, and go to the HelloHttpFunction.java class. Rename it to FhirDatastoreProxy.java. Don’t forget to also rename the entry point to gcfv2.FhirDatastoreProxy 

6. Copy the code from the repo and paste it in the inline editor

7. Go to the pom.xml file, and copy the pom file in the repo into the inline editor

8. Click DEPLOY, and your function will get created and run soon

Note:

1. The Cloud Healthcare API used in this function uses the Application Default Credential to authenticate the requests coming to the Healthcare API

2. Save the deployed function URL to be able to invoke from the Android application

So far we have created all the pieces required for the Android App to write FHIR data to BigQuery using Healthcare API independently. Now let’s make sure all the pieces are connected and the API is invoked on a questionnaire submission.

Android Project and Firebase Setup

We will be using a recent version of Android Studio and an Android Emulator set up (you can use your physical Android device as well). Once it’s ready follow the steps below:

1. Clone the FHIR App Examples repo:
https://github.com/google/fhir-app-examples

2. Open Android Studio, select Import Project (Gradle, Eclipse ADT, etc.) and choose the cloudfunction/ folder from the source code that you have downloaded earlier.Open app/google-services.json. It is empty and needs to be filled. 
a. Generate a SHA-1 key using ./gradlew signingReport, and take note of the SHA1 field under the debug variant
b. Add the app to Firebase using the Firebase Console (follow Steps 1 and 2) using the Firebase Console. In the “Debug signing certificate SHA-1 “ field, fill in the value from the previous step
c. Download google-services.json and replace the content from Firebase into the empty file in the app folder
d. The Firebase SDK has already been added in the build Gradle files

3. Open the FhirApplication.kt, and set the baseUrl field to the URL of your Cloud Function

4. Select “Sync your project with Gradle files” from the Android Studio toolbar

We have now completed the set up and dependency inclusion portion of the implementation.

Questionnaire Setup and Response

We are already set up with the Questionnaire setup in the repo. But let’s go over the code: 

1. Make sure the FragmentContainerView is present inside the ConstraintLayout in the app/src/main/res\layout/activity_main.xml file

2. Make sure the QuestionnaireFragment has a JSON encoded FHIR Questionnaire to render the fragment  
a. In this case we will be using the json - "new-patient-registration-paginated.json" to render the fragment. Check files MainActivity.kt, AddPatientFragment.kt and AddPatientViewModel.kt
b. Now that we have verified the fragment, json and the model, go ahead and run the app and try out entering answers for the fields in the questionnaire
c. You will notice the validation of string, date, numeric fields and other conditions
d. You can run the app and check the log to see your record created

https://storage.googleapis.com/gweb-cloudblog-publish/images/12_XgnoE14.max-2000x2000.jpg

You can learn more about using fragments here. That’s pretty much it for the questionnaire fragment and response setup.

FHIRStore and BigQuery Dataset Result Display

Now that we are all set with setup and updates, click “Sync Project with Gradle Files”. Once complete, 

  1. Run the app on the Android Emulator and watch your questionnaire load

  2. Answer the questions and click submit on top

  3. You should see the message “Patient is saved” on the app

View FHIR Store Result

Navigate to Google Cloud Healthcare FHIRViewer console

https://storage.googleapis.com/gweb-cloudblog-publish/images/13_zyCz8Tw.max-2000x2000.jpg

Select your FHIR Store, query and hit RUN SEARCH and you should see the search results right below

https://storage.googleapis.com/gweb-cloudblog-publish/images/14_kfylAwK.max-2000x2000.jpg

View BigQuery Dataset Result

Navigate to Google Cloud BigQuery console and on the Explorer pane, go the dataset that you created for this project.

https://storage.googleapis.com/gweb-cloudblog-publish/images/15_nPy02Xk.max-2000x2000.jpg

Click Preview and you should see the same number and resulting data you found in the Healthcare FHIR Store in the BigQuery Dataset.

https://storage.googleapis.com/gweb-cloudblog-publish/images/16_FsHbdjY.max-2000x2000.jpg

You can now perform BigQuery SQL, Analytics and ML on the FHIR data you just saved into the cloud dataset. 

Search and Offline Capability
To ensure offline capability on the OHS powered Android FHIR SDK app, do make sure to follow the design guideline that needs to be enabled in the implementation we discuss here. For searching FHIR resources, we have two ways:

  1. FHIR Viewer in the Google Cloud Console

  2. FHIR Search Method using GET or POST requests

App Demo

Now that our app is developed, let’s play with it and see the result in the cloud.

https://storage.googleapis.com/gweb-cloudblog-publish/original_images/OHS-GCP-FHIR.gif

Summary

In this project, we have successfully created an Android application to store and query Patient FHIR data on cloud healthcare FHIR Store and BigQuery dataset using Cloud Healthcare API in just 7 steps: 

  1. Setup the Android App

  2. Set up Google Cloud Healthcare API

  3. Created Healthcare Dataset and FHIR Datastore

  4. Created BigQuery Dataset

  5. Configured a BigQuery Stream to write FHIR Datastore data to BigQuery Dataset

  6. Deployed a Cloud Function to write R4 data to FHIR Datastore

  7. Triggered Cloud Functions from the Android App on questionnaire response submit

Now that the steps are clear, feel free to try out the same steps for the Patient FHIR edit sync to cloud. 


Thank you for the review and collaboration Venkat Subramanian, Justin Tansuwan, Jing Tang, Fred Hersch, Vivian Neilley, Vishwaraj Anand.

Posted in