Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d89402c
fix(healthcare): set responseType to JSON instead of Buffer
angelcaamal Mar 3, 2026
c14a186
fix(healthcare): set responseType to JSON instead of Buffer
angelcaamal Mar 4, 2026
eb7bc5c
fix(healthcare): set responseType to JSON instead of Buffer
angelcaamal Mar 5, 2026
aedc47e
fix(healthcare): set responseType to JSON instead of Buffer
angelcaamal Mar 5, 2026
c876688
fix(healthcare): Fix test for delete resource
angelcaamal Mar 5, 2026
ae749ad
fix(healthcare): Fix response type
angelcaamal Mar 5, 2026
90c5a4e
fix(healthcare): set responseType to JSON instead of Buffer
angelcaamal Mar 9, 2026
22c430b
fix(healthcare): replace fixed sleep with polling for LRO and improve…
angelcaamal Mar 9, 2026
6af88bf
Merge branch 'main' into fix-fhir-export-resources
iennae Mar 30, 2026
c7b6c14
Merge branch 'main' into fix-fhir-patch-store
angelcaamal Apr 8, 2026
eddf329
Merge remote-tracking branch 'mi-fork/fix-fhir-export-resources' into…
angelcaamal Apr 29, 2026
6072032
Merge remote-tracking branch 'mi-fork/fix-fhir-delete-resource' into …
angelcaamal Apr 29, 2026
12ea87f
Merge remote-tracking branch 'mi-fork/fix-fhir-delete-resource-purge'…
angelcaamal Apr 29, 2026
ea95853
Merge remote-tracking branch 'mi-fork/fix-fhir-store-Iam-policy' into…
angelcaamal Apr 29, 2026
474fd44
Merge remote-tracking branch 'mi-fork/fix-fhir-patch-store' into feat…
angelcaamal Apr 29, 2026
7f13b79
refactor(fhir): improve API response handling and fix test failures
angelcaamal Apr 30, 2026
b1d7082
fix(fhir): add missing Content-Type header to POST request
angelcaamal Apr 30, 2026
7dca047
fix(healthcare): remove mocha parallel execution to prevent npm insta…
angelcaamal Apr 30, 2026
2d60e96
fix(healthcare): apply code review feedback
angelcaamal Apr 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions healthcare/fhir/createFhirResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function main(
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
}),
headers: {'Content-Type': 'application/fhir+json'},
responseType: 'json',
});

async function createFhirResource() {
Expand Down
13 changes: 9 additions & 4 deletions healthcare/fhir/deleteFhirResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const main = (
auth: new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
}),
responseType: 'json',
});

const deleteFhirResource = async () => {
Expand All @@ -46,10 +47,14 @@ const main = (
// fails, the server returns a 200 OK HTTP status code. To check that the
// resource was successfully deleted, search for or get the resource and
// see if it exists.
await healthcare.projects.locations.datasets.fhirStores.fhir.delete(
request
);
console.log('Deleted FHIR resource');
try {
await healthcare.projects.locations.datasets.fhirStores.fhir.delete(
request
);
console.log(`Deleted FHIR resource: ${resourceId}`);
} catch (error) {
console.error('Error deleting FHIR resource:', error.message || error);
}
};

deleteFhirResource();
Expand Down
13 changes: 9 additions & 4 deletions healthcare/fhir/deleteFhirResourcePurge.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const main = (
auth: new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
}),
responseType: 'json',
});

const deleteFhirResourcePurge = async () => {
Expand All @@ -42,10 +43,14 @@ const main = (
const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}`;
const request = {name};

await healthcare.projects.locations.datasets.fhirStores.fhir.ResourcePurge(
request
);
console.log('Deleted all historical versions of resource');
try {
await healthcare.projects.locations.datasets.fhirStores.fhir.ResourcePurge(
request
);
console.log(`Purged all historical versions of resource: ${resourceId}`);
} catch (error) {
console.error('Error purging FHIR resource:', error.message || error);
}
};

deleteFhirResourcePurge();
Expand Down
39 changes: 25 additions & 14 deletions healthcare/fhir/exportFhirResources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -51,23 +52,33 @@ const main = (
},
};

const operation =
await healthcare.projects.locations.datasets.fhirStores.export(request);
const operationName = operation.data.name;
try {
const operation =
await healthcare.projects.locations.datasets.fhirStores.export(request);
const operationName = operation.data.name;

// Wait ten seconds for the LRO to finish
await sleep(10000);
let done = false;
let operationStatus;

// Check the LRO's status
const operationStatus =
await healthcare.projects.locations.datasets.operations.get({
name: operationName,
});
while (!done) {
console.log('Waiting for operation to complete...');
await sleep(5000);

if (typeof operationStatus.data.metadata.counter !== 'undefined') {
console.log('Exported FHIR resources successfully');
} else {
console.log('Export failed');
operationStatus =
await healthcare.projects.locations.datasets.operations.get({
name: operationName,
});

done = operationStatus.data.done;
}

if (operationStatus.data.error) {
console.log('Export failed with error:', operationStatus.data.error);
} else {
console.log('Exported FHIR resources successfully');
}
} catch (error) {
console.error('Error exporting FHIR resources:', error.message || error);
}
};

Expand Down
1 change: 1 addition & 0 deletions healthcare/fhir/getFhirResourceHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const main = (
auth: new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
}),
responseType: 'json',
});

const getFhirResourceHistory = async () => {
Expand Down
22 changes: 15 additions & 7 deletions healthcare/fhir/getFhirStoreIamPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const main = (
auth: new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
}),
responseType: 'json',
});

const getFhirStoreIamPolicy = async () => {
Expand All @@ -38,14 +39,21 @@ const main = (
const resource_ = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}`;
const request = {resource_};

const fhirStore =
await healthcare.projects.locations.datasets.fhirStores.getIamPolicy(
request
try {
const fhirStore =
await healthcare.projects.locations.datasets.fhirStores.getIamPolicy(
request
);
console.log(
'Got FHIR store IAM policy:',
JSON.stringify(fhirStore.data, null, 2)
);
console.log(
'Got FHIR store IAM policy:',
JSON.stringify(fhirStore.data, null, 2)
);
} catch (error) {
console.error(
'Error getting FHIR store IAM policy:',
error.message || error
);
}
};

getFhirStoreIamPolicy();
Expand Down
1 change: 1 addition & 0 deletions healthcare/fhir/listFhirResourceHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const main = (
auth: new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
}),
responseType: 'json',
});

const listFhirResourceHistory = async () => {
Expand Down
2 changes: 1 addition & 1 deletion healthcare/fhir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"node": ">=12.0.0"
},
"scripts": {
"test": "c8 mocha -p -j 2 system-test/*.test.js --timeout=60000"
"test": "c8 mocha system-test/*.test.js --timeout=60000"
},
"devDependencies": {
"@google-cloud/pubsub": "^4.0.0",
Expand Down
15 changes: 11 additions & 4 deletions healthcare/fhir/patchFhirStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const main = (
auth: new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
}),
responseType: 'json',
});

const patchFhirStore = async () => {
Expand All @@ -50,10 +51,16 @@ const main = (
},
};

await healthcare.projects.locations.datasets.fhirStores.patch(request);
console.log(
`Patched FHIR store ${fhirStoreId} with Cloud Pub/Sub topic ${pubsubTopic}`
);
try {
const response =
await healthcare.projects.locations.datasets.fhirStores.patch(request);
console.log(
`Patched FHIR store ${fhirStoreId} with Cloud Pub/Sub topic ${pubsubTopic}`
);
console.log(JSON.stringify(response.data, null, 2));
} catch (error) {
console.error('Error patching FHIR store:', error.message || error);
}
};

patchFhirStore();
Expand Down
28 changes: 21 additions & 7 deletions healthcare/fhir/searchFhirResourcesPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const main = (
const searchFhirResourcesPost = async () => {
const auth = new GoogleAuth({
scopes: 'https://www.googleapis.com/auth/cloud-platform',
// Set application/fhir+json header because this is a POST request.
headers: {'Content-Type': 'application/fhir+json'},
});
// TODO(developer): uncomment these lines before running the sample
// const cloudRegion = 'us-central1';
Expand All @@ -44,11 +42,27 @@ const main = (
// Patient with the last name "Smith", set resourceType to "Patient" and
// specify the following params:
// params = {'family:exact' : 'Smith'};
const client = await auth.getClient();
const response = await client.request({url, method: 'POST', params});
const resources = response.data.entry;
console.log(`Resources found: ${resources.length}`);
console.log(JSON.stringify(resources, null, 2));

try {
const client = await auth.getClient();
const response = await client.request({
url,
method: 'POST',
headers: {
'Content-Type': 'application/fhir+json',
},
params,
responseType: 'json',
});
Comment thread
angelcaamal marked this conversation as resolved.
const resources = response.data.entry || [];
console.log('Resources found: ' + resources.length);
console.log(JSON.stringify(resources, null, 2));
} catch (error) {
console.error(
`Error searching ${resourceType} resources:`,
error.response ? error.response.data : error.message
);
}
};

searchFhirResourcesPost();
Expand Down
2 changes: 1 addition & 1 deletion healthcare/fhir/setFhirStoreIamPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const main = (
policy: {
bindings: [
{
members: member,
members: [member],
role: role,
},
],
Expand Down
9 changes: 7 additions & 2 deletions healthcare/fhir/system-test/fhir_resources.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ it('should purge all historical versions of a FHIR resource', () => {
{cwd}
);
assert.strictEqual(
new RegExp('Deleted all historical versions of resource').test(output),
new RegExp(
`Purged all historical versions of resource: ${resourceId}`
).test(output),
true
);
});
Expand All @@ -181,7 +183,10 @@ it('should delete a FHIR resource', () => {
`node deleteFhirResource.js ${projectId} ${cloudRegion} ${datasetId} ${fhirStoreId} ${resourceType} ${resourceId}`,
{cwd}
);
assert.strictEqual(new RegExp('Deleted FHIR resource').test(output), true);
assert.strictEqual(
new RegExp(`Deleted FHIR resource: ${resourceId}`).test(output),
true
);

// Clean up
execSync(
Expand Down
Loading