Skip to content

Commit 7f13b79

Browse files
committed
refactor(fhir): improve API response handling and fix test failures
Configured fhirStore requests with responseType: 'json' for automatic parsing, resolving Node 20 ESM/Blob issues. Additionally, fixed the members array syntax in IAM policy payloads.
1 parent 474fd44 commit 7f13b79

5 files changed

Lines changed: 22 additions & 6 deletions

File tree

healthcare/fhir/createFhirResource.js

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

3536
async function createFhirResource() {

healthcare/fhir/getFhirResourceHistory.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const main = (
3030
auth: new google.auth.GoogleAuth({
3131
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
3232
}),
33+
responseType: 'json',
3334
});
3435

3536
const getFhirResourceHistory = async () => {

healthcare/fhir/listFhirResourceHistory.js

Lines changed: 1 addition & 0 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 listFhirResourceHistory = async () => {

healthcare/fhir/searchFhirResourcesPost.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,24 @@ const main = (
4444
// Patient with the last name "Smith", set resourceType to "Patient" and
4545
// specify the following params:
4646
// params = {'family:exact' : 'Smith'};
47-
const client = await auth.getClient();
48-
const response = await client.request({url, method: 'POST', params});
49-
const resources = response.data.entry;
50-
console.log(`Resources found: ${resources.length}`);
51-
console.log(JSON.stringify(resources, null, 2));
47+
48+
try {
49+
const client = await auth.getClient();
50+
const response = await client.request({
51+
url,
52+
method: 'POST',
53+
params,
54+
responseType: 'json',
55+
});
56+
const resources = response.data.entry;
57+
console.log(`Resources found: ${resources.length}`);
58+
console.log(JSON.stringify(resources, null, 2));
59+
} catch (error) {
60+
console.error(
61+
`Error searching ${resourceType} resources:`,
62+
error.response ? error.response.data : error.message
63+
);
64+
}
5265
};
5366

5467
searchFhirResourcesPost();

healthcare/fhir/setFhirStoreIamPolicy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const main = (
4646
policy: {
4747
bindings: [
4848
{
49-
members: member,
49+
members: [member],
5050
role: role,
5151
},
5252
],

0 commit comments

Comments
 (0)