Created
March 21, 2024 23:07
-
-
Save jasonklotzer/5f0f174055550a37313ed31ea9b95c58 to your computer and use it in GitHub Desktop.
This example script allows a Google Cloud Healthcare API DICOM Store user to change the StorageClass across all studies. The script reads all StudyUIDs from a metadata BigQuery table, assuming the study metadata has been streamed to BigQuery, then creates a CloudStorage list with those study resources, and finally makes a call to a Healthare API…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# set -x | |
# This example script allows a Google Cloud Healthcare API DICOM Store user to change the StorageClass across all studies. | |
# High level instructions can be found at the following: | |
# https://cloud.google.com/healthcare-api/docs/dicom-storage-class#use_filters | |
STUDIES_FILE=studies.lst | |
REQUEST_FILE=request.json | |
#TODO: Set to your DICOM store path | |
DICOM_STORE_PATH=projects/medical-imaging-demos/locations/us-central1/datasets/demo_datasets/dicomStores/cxr | |
#TODO: Set to a bucket you created | |
GCS_BUCKET=gs://tmp_bucket_storageclass | |
#TODO: Set to the BQ table view for your DICOM metadata | |
BQ_TABLE="\`medical-imaging-demos\`.demo_datasets.metadataView" | |
#TODO: Set to the StorageClass you prefer | |
STORAGE_CLASS=COLDLINE | |
# Query for all studies grouped by StudyInstanceUID and construct study resource paths | |
QUERY='SELECT CONCAT("/studies/", StudyInstanceUID) FROM '$BQ_TABLE' GROUP BY StudyInstanceUID' | |
printf "[*] Creating study list from query\n" | |
bq query --max_rows=100000000 --format=csv --use_legacy_sql=false $QUERY 2>/dev/null | awk 'NR>1' > $STUDIES_FILE | |
FOUND=`wc -l $STUDIES_FILE | cut -d' ' -f1` | |
if [ "$FOUND" = 0 ]; then | |
printf "[*] No studies found. Check query?\n"; exit 1 | |
fi | |
# TODO: If you need to make the bucket | |
# gsutil mb $GCS_BUCKET | |
printf "[*] Confirm changing the StorageClass for $FOUND studies to $STORAGE_CLASS (y/n)? " | |
read cont | |
if [ "$cont" == "${cont#[Yy]}" ]; then | |
exit 0 | |
fi | |
# Put the file with all studies into a GCS object | |
gsutil cp $STUDIES_FILE $GCS_BUCKET | |
# Create a request file for the POST body | |
echo "{\"filter_config\":{\"resource_paths_gcs_uri\":\"$GCS_BUCKET/$STUDIES_FILE\"},\"blobStorageSettings\":{\"blob_storage_class\":\"$STORAGE_CLASS\"}}" > $REQUEST_FILE | |
# Create the request, which should yield a Long-Running Operation | |
curl -X POST \ | |
-H "Authorization: Bearer $(gcloud auth print-access-token)" \ | |
-H "Content-Type: application/json" \ | |
-d @request.json \ | |
"https://healthcare.googleapis.com/v1beta1/$DICOM_STORE_PATH:setBlobStorageSettings" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment