From a5d6bc6a51784ed3a8a40d4ae773de9099f116b9 Mon Sep 17 00:00:00 2001 From: mukhlin <50941274+mukhlin@users.noreply.github.com> Date: Tue, 14 Jan 2020 22:22:53 +0700 Subject: [PATCH] feat: Custom Healthcare API endpoint (#1367) * Add ability to configure Google Cloud Healthcare API endpoint. * Fixed bug in script. * Fixed PR remark. * Set Healthcare API endpoint in proper place. --- .docker/Viewer-v2.x/entrypoint.sh | 32 +++++++++++++------ platform/viewer/public/config/google.js | 1 + platform/viewer/src/customHooks/useServer.js | 1 + .../src/googleCloud/api/GoogleCloudApi.js | 6 +++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/.docker/Viewer-v2.x/entrypoint.sh b/.docker/Viewer-v2.x/entrypoint.sh index 092bfd321..1255722cd 100644 --- a/.docker/Viewer-v2.x/entrypoint.sh +++ b/.docker/Viewer-v2.x/entrypoint.sh @@ -1,17 +1,31 @@ #!/bin/bash -# If CLIENT_ID is specified, use the google.js configuration with the modified ID -if [ ! -z "$CLIENT_ID" ] +if [ -n "$CLIENT_ID" ] || [ -n "$HEALTHCARE_API_ENDPOINT" ] then - echo "Google Cloud Healthcare $CLIENT_ID has been provided: " - echo $CLIENT_ID - echo "Updating config..." + # If CLIENT_ID is specified, use the google.js configuration with the modified ID + if [ -n "$CLIENT_ID" ] + then + echo "Google Cloud Healthcare \$CLIENT_ID has been provided: " + echo "$CLIENT_ID" + echo "Updating config..." - # - Use SED to replace the CLIENT_ID that is currently in google.js - sed -i -e "s/YOURCLIENTID.apps.googleusercontent.com/$CLIENT_ID/g" /usr/share/nginx/html/google.js + # - Use SED to replace the CLIENT_ID that is currently in google.js + sed -i -e "s/YOURCLIENTID.apps.googleusercontent.com/$CLIENT_ID/g" /usr/share/nginx/html/google.js + fi - # - Copy google.js to overwrite app-config.js - cp /usr/share/nginx/html/google.js /usr/share/nginx/html/app-config.js + # If HEALTHCARE_API_ENDPOINT is specified, use the google.js configuration with the modified endpoint + if [ -n "$HEALTHCARE_API_ENDPOINT" ] + then + echo "Google Cloud Healthcare \$HEALTHCARE_API_ENDPOINT has been provided: " + echo "$HEALTHCARE_API_ENDPOINT" + echo "Updating config..." + + # - Use SED to replace the HEALTHCARE_API_ENDPOINT that is currently in google.js + sed -i -e "s+https://healthcare.googleapis.com/v1beta1+$HEALTHCARE_API_ENDPOINT+g" /usr/share/nginx/html/google.js + fi + + # - Copy google.js to overwrite app-config.js + cp /usr/share/nginx/html/google.js /usr/share/nginx/html/app-config.js fi echo "Starting Nginx to serve the OHIF Viewer..." diff --git a/platform/viewer/public/config/google.js b/platform/viewer/public/config/google.js index b5d0c5904..67783d12c 100644 --- a/platform/viewer/public/config/google.js +++ b/platform/viewer/public/config/google.js @@ -2,6 +2,7 @@ window.config = { routerBasename: '/', whiteLabelling: {}, enableGoogleCloudAdapter: true, + healthcareApiEndpoint: 'https://healthcare.googleapis.com/v1beta1', servers: { // This is an array, but we'll only use the first entry for now dicomWeb: [], diff --git a/platform/viewer/src/customHooks/useServer.js b/platform/viewer/src/customHooks/useServer.js index 69b0fa525..b3d93e6b4 100644 --- a/platform/viewer/src/customHooks/useServer.js +++ b/platform/viewer/src/customHooks/useServer.js @@ -18,6 +18,7 @@ const getActiveServer = servers => { const getServers = (appConfig, project, location, dataset, dicomStore) => { let servers = []; if (appConfig.enableGoogleCloudAdapter) { + GoogleCloudApi.urlBase = appConfig.healthcareApiEndpoint; const pathUrl = GoogleCloudApi.getUrlBaseDicomWeb( project, location, diff --git a/platform/viewer/src/googleCloud/api/GoogleCloudApi.js b/platform/viewer/src/googleCloud/api/GoogleCloudApi.js index 334e84263..71941a69f 100644 --- a/platform/viewer/src/googleCloud/api/GoogleCloudApi.js +++ b/platform/viewer/src/googleCloud/api/GoogleCloudApi.js @@ -15,7 +15,11 @@ class GoogleCloudApi { } get urlBase() { - return `https://healthcare.googleapis.com/v1beta1`; + return this.healthcareApiEndpoint || 'https://healthcare.googleapis.com/v1beta1'; + } + + set urlBase(url) { + this.healthcareApiEndpoint = url; } get urlBaseProject() {