-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(healthcare): set responseType to JSON instead of Buffer in importFhirResources.js #4251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
angelcaamal
wants to merge
1
commit into
GoogleCloudPlatform:main
from
angelcaamal:fix-fhir-import-resources
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,33 +51,42 @@ 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}; | ||
| // --- POLLING STRATEGY --- | ||
| let done = false; | ||
| let operationStatus; | ||
|
|
||
| // Wait twenty seconds for the LRO to finish. | ||
| await sleep(20000); | ||
| while (!done) { | ||
| console.log('Waiting for import operation to complete...'); | ||
| 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 { | ||
| const successCount = operationStatus.data.metadata.counter.success || 0; | ||
| console.log( | ||
| `Import FHIR resources succeeded. ${successCount} resources imported.` | ||
| ); | ||
| } | ||
| } catch (error) { | ||
| console.error('Error initiating import:', error.message || error); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current error message "Error initiating import:" is misleading. If an error occurs while polling for the operation's status, this message would be incorrect. A more generic error message would be more appropriate to cover all potential failure points within the console.error('An error occurred during the import process:', error.message || error); |
||
| } | ||
| }; | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The polling loop for the long-running operation could potentially run indefinitely if the operation never reaches a 'done' state. To improve robustness, it's good practice to add a timeout mechanism, such as a maximum number of polling attempts.