GCP Patient everything - kind-lab/mimic-fhir GitHub Wiki

The process to get patient bundles from the Google Healthcare API.

Patient-everything background

Patient-everything requests get all resources associated with a patient resource. The REST request will typically look like:

GET [base url]/Patient/[id]/$everything

The main argument that can be added is _type, which allows users to request certain types of resources associated with a patient (ie only Conditions and Procedures). A request with _type looks like:

GET [base url]/Patient/[id]/$everything?_type=Patient,Condition,Procedure

Configuring Patient-everything requests in GCP

Initialize project

To start from the command line, initialize gcloud:

gcloud init

Set some environment variables:

export GOOGLE_LOCATION=us-central1
export GOOGLE_TOPIC='patient-everything'
export GCP_BUCKET=mimic-fhir

Setting up PubSub

Create a topic to submit patient-everything requests

gcloud pubsub topics create $GOOGLE_TOPIC

Cloud Function

The cloud function will be triggered by the Topic, and take the patient_id to do the following:

  • The cloud function will accomplish:
    • Start a patient-everything request on the datastore
      • Include resource_types argument if present to narrow the resources to be output
    • Store patient bundle in Cloud Storage
    • Iterate over pages (if there are more resources than can fit in one page response)
      • store each page as in Cloud Storage with patient_id and page #
  • Create cloud function
    • First move into the directory gcp/functions/patient_everything
    • Then run the command:
gcloud functions deploy patient_everything \
--runtime=python39 \
--region=$GOOGLE_LOCATION \
--source=. \
--entry-point=patient_everything \
--trigger-topic=$GOOGLE_TOPIC

Setting up logging

bq mk -f=true mimic_fhir_log
bq query < pat_everything_pass.sql --use_legacy_sql=false
bq query < pat_everything_error.sql --use_legacy_sql=false

Running patient-everything from py_mimic_fhir

Send the command:

py_mimic_fhir export --patient_bundle --num_patients=10 --resources='Patient,Encounter,Condition' --count=100

Where:

Argument Default Description
patient_bundle false a flag to set export to patient-everything
num_patients 1 Sets the number of patients to export
resources Patient,Encounter,Condition,Procedure A comma separated list of all the resource types to export
count 100 The size of the page returned from the fhir server (for pagination)

Storage Notes

The final bundles will be sent to Cloud Storage at $GCP_BUCKET/patient-everything/[patient_id]-[current_time]