Scheduled HL7 store and FHIR store backup process

Business Scenario

Healthcare Data Engine (HDE) is a Google Cloud offering that helps healthcare organizations ingest, transform, and analyze healthcare data in a secure and compliant way. Data can be ingested in CSV, CCDA or HL7 format and HDE helps convert and store it in FHIR format which is a structured data representing clinical data, such as patients, encounters, and medications. This data is then stored in data stores like the HL7 store and a Fast Healthcare Interoperability Resources (FHIR) store, which are provided by Google Cloud Healthcare (CHC) API.

CHC API is going to include Data Resiliency of all HDE data stores like HL7 stores and FHIR stores in near future. As an interim mechanism, customers of HDE can set up scheduled backups of their HL7 stores and FHIR stores to mitigate the possibility of any accidental deletion of these stores at their end.

This article talks about how to set up periodic backups for a HL7 store and FHIR store in HDE projects, which can then be used in case any accidental deletion of these stores takes place.

What do we need

CHC API offers a suite of APIs that helps healthcare organizations store, process, analyze, and share healthcare data securely and at scale. We will leverage CHC API’s HL7 store “export” option to export HL7 store data and FHIR store “export” option to export FHIR store data into a Google Cloud Storage bucket and use parameters like ‘startTime’/ ‘endTime’ for HL7 store and ‘_since’ for FHIR store to take incremental backups on these stores.

Cloud Scheduler will help us set the frequency of backups. Cloud Function to set the ‘_since’, ‘startTime’ and ‘endTime’ parameters.

We will use Cloud Workflow to orchestrate the flow from Cloud Function to Cloud Healthcare API to export the HL7 store and FHIR store data.

Exported backups will reside in Google Cloud Storage buckets.

Note: Please do ensure the frequency of Cloud Scheduler runs, matches with the date set in Cloud Function. If these 2 timelines don’t match, then you might end up with either overlapping backups or missing some data in backups.

ashwinshetty_5-1697476097885.png

Steps to setup the Backup Process

For this blog, let’s set up backups to run every Sunday (weekly backup).

Step 1

Create a Cloud Function to set the date to be used in ‘startTime’ parameter for HL7 store export and ‘_since’ parameter for FHIR store export. We will use below python code to fetch the current date and subtract it by 7 days to get last week’s date.

E.g. — If the current run is on 04/23/2023 (Sunday), our parameters will be set to 04/16/2023 to export data from 04/16/2023 till 04/23/2023.

backup-process-functions.png

#requirement.txt

datetime
timedelta
#main.py


from datetime import datetime, timedelta
def fetch_date_start(request):
dateStart = (datetime.now() - timedelta(days=7)).strftime('%Y-%m-%d')
dateStart += "T00:00:00Z"
return dateStart

Create another Cloud Function to set the date to be used in ‘endTime’ parameter (current date) for HL7 store export. We will use below python code to fetch the current date to do so.

#main.py


from datetime import datetime, timedelta
def fetch_date_end(request):
dateEnd = (datetime.now()).strftime('%Y-%m-%d')
dateEnd += "T00:00:00Z"
return dateEnd

Step 2

Create a 2 step Cloud Workflow to orchestrate exporting of HL7 store and FHIR store data.

Step 2.1 (callDateStartFunc) — Trigger the Cloud Function ‘fetch_date_start’ shown above and set the ‘startTime’ parameter for HL7 store and ‘_since’ parameter for FHIR store.

Step 2.2 (callDateEndFunc) — Trigger the Cloud Function ‘fetch_date_end’ and set the ‘endTime’ parameter for HL7 store.

Step 2.3 (exportHl7StoreData) — Trigger Cloud Healthcare API’s export API with the ‘startTime’ and ‘endTime’ parameter to export last week’s HL7 store data into a Cloud Storage Bucket.

Step 2.4 (exportFhirStoreData) — Trigger Cloud Healthcare API’s export API with the ‘_since’ parameter to export last week’s FHIR store data into a Cloud Storage Bucket.

ashwinshetty_6-1697476310745.png

main:
params: [input]
steps:
- callDateStartFunc:
call: http.get
args:
url: https://us-central1-<project-prefix>-<env>-data.cloudfunctions.net/fetch_date_start
auth:
type: OIDC
audience: https://us-central1-<project-prefix>-<env>-data.cloudfunctions.net/fetch_date_start
result: dateStart
- callDateEndFunc:
call: http.get
args:
url: https://us-central1-<project-prefix>-<env>-data.cloudfunctions.net/fetch_date_end
auth:
type: OIDC
audience: https://us-central1-<project-prefix>-<env>-data.cloudfunctions.net/fetch_date_end
result: dateEnd
- exportHl7StoreData:
call: http.post
args:
url: https://healthcare.googleapis.com/v1/projects/<project-prefix>-<env>-data/locations/us-central1/datasets/healthcare-dataset/hl7V2Stores/source1-ashwin:export
body:
startTime: ${dateStart.body}
endTime: ${dateEnd.body}
gcsDestination:
contentStructure: "CONTENT_STRUCTURE_UNSPECIFIED"
uriPrefix: "gs://<project-prefix>-backup/hl7"
auth:
type: OAuth2
scopes: "https://www.googleapis.com/auth/cloud-platform"
result: hl7Export
- exportFhirStoreData:
call: http.post
args:
url: https://healthcare.googleapis.com/v1/projects/<project-prefix>-<env>-data/locations/us-central1/datasets/healthcare-dataset/fhirStores/final-fhir-store-ashwin:export
body:
_since: ${dateStart.body}
gcsDestination:
uriPrefix: "gs://<project-prefix>-backup/fhir"
auth:
type: OAuth2
scopes: "https://www.googleapis.com/auth/cloud-platform"
result: fhirExport

Step 3

Create a weekly backup process using Cloud Scheduler which will run every Sunday (0 0 * * 0) and kick off Cloud Workflow. Ensure the Service account has ‘Workflows Invoker’ permission.

ashwinshetty_7-1697476324637.png

Once the Cloud Scheduler cron job runs successfully, you will find the exported HL7 and FHIR store data in GCS bucket.

ashwinshetty_8-1697476341442.png

Step 4

In case of an accidental HL7 store OR FHIR Store deletion, use CHC API’s Import HL7 store OR Import FHIR store feature to restore the deleted data stores back again.

Conclusion

This setup of automated HL7 store and FHIR store backups is just a precautionary step to be used in case of an accidental deletion of a data store in HDE. It gives HDE customers complete control over when to take backup and when to restore HL7/FHIR data. HDE customers will have to bear the cost of additional Google Cloud resources like Cloud Scheduler, Cloud Workflow, Cloud Function, and Cloud Storage used for backup. You can use the ‘Archive’ Storage class option, as this backup is not expected to be used frequently and is just a precautionary option.

Reference Links

Version history
Last update:
‎10-16-2023 10:16 AM
Updated by: