Skip to content

Commit 461a131

Browse files
authored
Merge branch 'main' into main
2 parents f65a0e0 + f9b8d86 commit 461a131

6 files changed

Lines changed: 156 additions & 31 deletions

File tree

healthcare/fhir/getFhirResource.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const main = (
2929
auth: new google.auth.GoogleAuth({
3030
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
3131
}),
32+
responseType: 'json',
3233
});
3334

3435
const getFhirResource = async () => {
@@ -42,11 +43,18 @@ const main = (
4243
const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}`;
4344
const request = {name};
4445

45-
const resource =
46-
await healthcare.projects.locations.datasets.fhirStores.fhir.read(
47-
request
46+
try {
47+
const resource =
48+
await healthcare.projects.locations.datasets.fhirStores.fhir.read(
49+
request
50+
);
51+
console.log(`Got ${resourceType} resource:\n`, resource.data);
52+
} catch (error) {
53+
console.error(
54+
`Error getting ${resourceType} resource:`,
55+
error.message || error
4856
);
49-
console.log(`Got ${resourceType} resource:\n`, resource.data);
57+
}
5058
};
5159

5260
getFhirResource();

healthcare/fhir/importFhirResources.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const main = (
2828
auth: new google.auth.GoogleAuth({
2929
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
3030
}),
31+
responseType: 'json',
3132
});
3233
const sleep = ms => {
3334
return new Promise(resolve => setTimeout(resolve, ms));
@@ -50,32 +51,48 @@ const main = (
5051
},
5152
},
5253
};
54+
try {
55+
const operation =
56+
await healthcare.projects.locations.datasets.fhirStores.import(request);
57+
const operationName = operation.data.name;
5358

54-
const operation =
55-
await healthcare.projects.locations.datasets.fhirStores.import(request);
56-
const operationName = operation.data.name;
59+
console.log(`Import operation started: ${operationName}`);
5760

58-
const operationRequest = {name: operationName};
61+
let done = false;
62+
let operationStatus;
63+
let attempts = 0;
5964

60-
// Wait twenty seconds for the LRO to finish.
61-
await sleep(20000);
65+
while (!done && attempts < 100) {
66+
console.log('Waiting for import operation to complete...');
67+
attempts++;
68+
await sleep(5000); // Wait 5 seconds between polls
6269

63-
// Check the LRO's status
64-
const operationStatus =
65-
await healthcare.projects.locations.datasets.operations.get(
66-
operationRequest
67-
);
70+
operationStatus =
71+
await healthcare.projects.locations.datasets.operations.get({
72+
name: operationName,
73+
});
6874

69-
const success = operationStatus.data.metadata.counter.success;
75+
done = operationStatus.data.done;
76+
}
7077

71-
if (typeof success !== 'undefined') {
72-
console.log(
73-
`Import FHIR resources succeeded. ${success} resources imported.`
74-
);
75-
} else {
76-
console.log(
77-
'Imported FHIR resources failed. Details available in Cloud Logging at the following URL:\n',
78-
operationStatus.data.metadata.logsUrl
78+
if (operationStatus.data.error) {
79+
console.error(
80+
'Import FHIR resources failed:',
81+
operationStatus.data.error
82+
);
83+
} else if (done) {
84+
const successCount =
85+
operationStatus.data.metadata?.counter?.success || 0;
86+
console.log(
87+
`Import FHIR resources succeeded. ${successCount} resources imported.`
88+
);
89+
} else {
90+
console.error('Import operation timed out in the sample.');
91+
}
92+
} catch (error) {
93+
console.error(
94+
'An error occurred during the import process:',
95+
error.message || error
7996
);
8097
}
8198
};

healthcare/fhir/listFhirStores.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const main = (
2626
auth: new google.auth.GoogleAuth({
2727
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
2828
}),
29+
responseType: 'json',
2930
});
3031

3132
const listFhirStores = async () => {
@@ -36,9 +37,13 @@ const main = (
3637
const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
3738
const request = {parent};
3839

39-
const fhirStores =
40-
await healthcare.projects.locations.datasets.fhirStores.list(request);
41-
console.log(JSON.stringify(fhirStores.data));
40+
try {
41+
const fhirStores =
42+
await healthcare.projects.locations.datasets.fhirStores.list(request);
43+
console.log(JSON.stringify(fhirStores.data));
44+
} catch (error) {
45+
console.error('Error listing FHIR stores:', error.message || error);
46+
}
4247
};
4348

4449
listFhirStores();

healthcare/fhir/updateFhirResource.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const main = (
3030
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
3131
}),
3232
headers: {'Content-Type': 'application/fhir+json'},
33+
responseType: 'json',
3334
});
3435

3536
const updateFhirResource = async () => {
@@ -47,11 +48,18 @@ const main = (
4748
const body = {resourceType: resourceType, id: resourceId, active: true};
4849
const request = {name, requestBody: body};
4950

50-
const resource =
51-
await healthcare.projects.locations.datasets.fhirStores.fhir.update(
52-
request
51+
try {
52+
const resource =
53+
await healthcare.projects.locations.datasets.fhirStores.fhir.update(
54+
request
55+
);
56+
console.log(`Updated ${resourceType} resource:\n`, resource.data);
57+
} catch (error) {
58+
console.error(
59+
`Error updating ${resourceType} resource:`,
60+
error.message || error
5361
);
54-
console.log(`Updated ${resourceType} resource:\n`, resource.data);
62+
}
5563
};
5664

5765
updateFhirResource();

storage/quickstart.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
function main(bucketName = 'my-new-bucket') {
18+
// [START storage_quickstart]
19+
// Imports the Google Cloud client library
20+
const {Storage} = require('@google-cloud/storage');
21+
22+
// For more information on ways to initialize Storage, please see
23+
// https://googleapis.dev/nodejs/storage/latest/Storage.html
24+
25+
// Creates a client using Application Default Credentials
26+
const storage = new Storage();
27+
28+
// Creates a client from a Google service account key
29+
// const storage = new Storage({keyFilename: 'key.json'});
30+
31+
/**
32+
* TODO(developer): Uncomment these variables before running the sample.
33+
*/
34+
// The ID of your GCS bucket
35+
// const bucketName = 'your-unique-bucket-name';
36+
37+
async function createBucket() {
38+
try {
39+
// Creates the new bucket
40+
await storage.createBucket(bucketName);
41+
console.log(`Bucket ${bucketName} created.`);
42+
} catch (error) {
43+
console.error('Error executing create bucket:', error.message || error);
44+
}
45+
}
46+
47+
createBucket();
48+
// [END storage_quickstart]
49+
}
50+
51+
main(...process.argv.slice(2));
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {after, it} = require('mocha');
19+
const cp = require('child_process');
20+
const uuid = require('uuid');
21+
const {Storage} = require('@google-cloud/storage');
22+
23+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24+
25+
const storage = new Storage();
26+
const bucketName = `nodejs-storage-samples-${uuid.v4()}`;
27+
28+
after(async () => {
29+
const bucket = storage.bucket(bucketName);
30+
await bucket.delete({force: true}).catch(console.error);
31+
});
32+
33+
it('should run the quickstart', async () => {
34+
const stdout = execSync(`node quickstart ${bucketName}`);
35+
assert.match(stdout, /Bucket .* created./);
36+
});

0 commit comments

Comments
 (0)