From 0df311294dbc6400f702910c3ac97df0e19155c2 Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Tue, 10 Mar 2026 00:19:28 +0000 Subject: [PATCH 1/2] fix(healthcare): set responseType to JSON instead of Buffer --- healthcare/fhir/importFhirResources.js | 56 +++++++++++++++++--------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/healthcare/fhir/importFhirResources.js b/healthcare/fhir/importFhirResources.js index 4fae19bf55..6856937635 100644 --- a/healthcare/fhir/importFhirResources.js +++ b/healthcare/fhir/importFhirResources.js @@ -28,6 +28,7 @@ const main = ( auth: new google.auth.GoogleAuth({ scopes: ['https://www.googleapis.com/auth/cloud-platform'], }), + responseType: 'json', }); const sleep = ms => { return new Promise(resolve => setTimeout(resolve, ms)); @@ -50,32 +51,47 @@ const main = ( }, }, }; + try { + const operation = + await healthcare.projects.locations.datasets.fhirStores.import(request); + const operationName = operation.data.name; - const operation = - await healthcare.projects.locations.datasets.fhirStores.import(request); - const operationName = operation.data.name; + console.log(`Import operation started: ${operationName}`); - const operationRequest = {name: operationName}; + let done = false; + let operationStatus; + let attempts = 0; - // Wait twenty seconds for the LRO to finish. - await sleep(20000); + while (!done && attempts < 100) { + console.log('Waiting for import operation to complete...'); + attempts++; + await sleep(5000); // Wait 5 seconds between polls - // Check the LRO's status - const operationStatus = - await healthcare.projects.locations.datasets.operations.get( - operationRequest - ); + operationStatus = + await healthcare.projects.locations.datasets.operations.get({ + name: operationName, + }); - const success = operationStatus.data.metadata.counter.success; + done = operationStatus.data.done; + } - if (typeof success !== 'undefined') { - console.log( - `Import FHIR resources succeeded. ${success} resources imported.` - ); - } else { - console.log( - 'Imported FHIR resources failed. Details available in Cloud Logging at the following URL:\n', - operationStatus.data.metadata.logsUrl + if (operationStatus.data.error) { + console.error( + 'Import FHIR resources failed:', + operationStatus.data.error + ); + } else if (done) { + const successCount = operationStatus.data.metadata.counter.success || 0; + console.log( + `Import FHIR resources succeeded. ${successCount} resources imported.` + ); + } else { + console.error('Import operation timed out in the sample.'); + } + } catch (error) { + console.error( + 'An error occurred during the import process:', + error.message || error ); } }; From 45ee5b109b404fdd68c82693568a1626c00a5645 Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Tue, 10 Mar 2026 00:32:20 +0000 Subject: [PATCH 2/2] fix(healthcare): use optional chaining for safe metadata access in FHIR import --- healthcare/fhir/importFhirResources.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/healthcare/fhir/importFhirResources.js b/healthcare/fhir/importFhirResources.js index 6856937635..2503b6ef72 100644 --- a/healthcare/fhir/importFhirResources.js +++ b/healthcare/fhir/importFhirResources.js @@ -81,7 +81,8 @@ const main = ( operationStatus.data.error ); } else if (done) { - const successCount = operationStatus.data.metadata.counter.success || 0; + const successCount = + operationStatus.data.metadata?.counter?.success || 0; console.log( `Import FHIR resources succeeded. ${successCount} resources imported.` );