Skip to content

healthcare API: FHIR resources cleanup and bug fixes #1850

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

Merged
merged 5 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 6 additions & 7 deletions healthcare/fhir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Run the following command to install the library dependencies for Node.js:
## FHIR resources

Commands:
createFhirResource.js <projectId> <cloudRegion> <datasetId> Creates a FHIR resource.
<fhirStoreId> <resourceType>
deleteFhirResource.js <projectId> <cloudRegion> <datasetId> Deletes a FHIR resource.
<fhirStoreId> <resourceType> <resourceId>
deleteFhirResourcePurge.js <projectId> <cloudRegion> <datasetId> Deletes all historical versions of a FHIR resource.
Expand All @@ -57,14 +59,11 @@ Run the following command to install the library dependencies for Node.js:
<fhirStoreId> <resourceType>
updateFhirResource.js <projectId> <cloudRegion> <datasetId> Updates the entire contents of a resource.
<fhirStoreId> <resourceType> <resourceId>
patchFhirResource.js <projectId> <cloudRegion> <datasetId> Updates part of a resource.
<fhirStoreId> <resourceType> <resourceId>
executeFhirBundle.js <projectId> <cloudRegion> <datasetId> Executes all the requests in the given Bundle.
<fhirStoreId> <bundleFile>

Commands:
fhir_resources.js createResource <datasetId> <fhirStoreId> Creates a new resource in a FHIR store.
<resourceType>
fhir_resources.js patchResource <datasetId> <fhirStoreId> Patches an existing resource in a FHIR store.
<resourceType> <resourceId>
fhir_resources.js executeBundle <datasetId> <fhirStoreId> Executes all the requests in the given Bundle.
<bundleFile>

Options:
--version Show version number [boolean]
Expand Down
66 changes: 66 additions & 0 deletions healthcare/fhir/createFhirResource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright 2020, Google, LLC
* Licensed under the Apache License, Version 2.0 (the `License`);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an `AS IS` BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(
projectId = process.env.GCLOUD_PROJECT,
cloudRegion = 'us-central1',
datasetId,
fhirStoreId,
resourceType,
) {
// [START healthcare_create_fhir_resource]
const {google} = require('googleapis');
const healthcare = google.healthcare('v1');

async function createFhirResource() {
const auth = await google.auth.getClient({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});

// Replace the following body with the data for the resource you want to
// create.
const body = {
"name": [{"use": "official", "family": "Smith", "given": ["Darcy"]}],
"gender": "female",
"birthDate": "1970-01-01",
"resourceType": "Patient",
};

google.options({auth, headers: {'Content-Type': 'application/fhir+json'}});

// TODO(developer): uncomment these lines before running the sample
// const cloudRegion = 'us-central1';
// const projectId = 'adjective-noun-123';
// const datasetId = 'my-dataset';
// const fhirStoreId = 'my-fhir-store';
// const resourceType = 'Patient';
const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}`;

const request = {parent, type: resourceType, requestBody: body};
const resource = await healthcare.projects.locations.datasets.fhirStores.fhir.create(
request
);
console.log(`Created FHIR resource with ID ${resource.data.id}`);
console.log(resource.data);
}

createFhirResource();
// [END healthcare_create_fhir_resource]
}

// node createFhirResource.js <projectId> <cloudRegion> <datasetId> <fhirStoreId> <resourceType>
main(...process.argv.slice(2));
2 changes: 1 addition & 1 deletion healthcare/fhir/deleteFhirResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const main = (
await healthcare.projects.locations.datasets.fhirStores.fhir.delete(
request
);
console.log(`Deleted FHIR resource ${resourceType}`);
console.log(`Deleted FHIR resource`);
};

deleteFhirResource();
Expand Down
2 changes: 1 addition & 1 deletion healthcare/fhir/deleteFhirResourcePurge.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const main = (
await healthcare.projects.locations.datasets.fhirStores.fhir.ResourcePurge(
request
);
console.log(`Deleted all historical versions of ${resourceType} resource`);
console.log(`Deleted all historical versions of resource`);
};

deleteFhirResourcePurge();
Expand Down
60 changes: 60 additions & 0 deletions healthcare/fhir/executeFhirBundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright 2020, Google, LLC
* Licensed under the Apache License, Version 2.0 (the `License`);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an `AS IS` BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

function main(
projectId = process.env.GCLOUD_PROJECT,
cloudRegion = 'us-central1',
datasetId,
fhirStoreId,
bundleFile
) {
// [START healthcare_fhir_execute_bundle]
const {google} = require('googleapis');
const healthcare = google.healthcare('v1');
const fs = require('fs');

async function executeFhirBundle() {
const auth = await google.auth.getClient({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});

google.options({auth, headers: {'Content-Type': 'application/fhir+json'}});

// TODO(developer): uncomment these lines before running the sample
// const cloudRegion = 'us-central1';
// const projectId = 'adjective-noun-123';
// const datasetId = 'my-dataset';
// const fhirStoreId = 'my-fhir-store';
// const bundleFile = 'bundle.json';
const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}`;

const bundle = JSON.parse(fs.readFileSync(bundleFile));

const request = {parent, requestBody: bundle};
const resource = await healthcare.projects.locations.datasets.fhirStores.fhir.executeBundle(
request
);
console.log(`FHIR bundle executed`);
console.log(resource.data);
}

executeFhirBundle();
// [END healthcare_fhir_execute_bundle]
}

// node executeFhirBundle.js <projectId> <cloudRegion> <datasetId> <fhirStoreId> <bundleFile>
main(...process.argv.slice(2));
Loading