|
| 1 | +/** |
| 2 | + * Copyright 2020, Google, LLC |
| 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 | + |
| 16 | +'use strict'; |
| 17 | + |
| 18 | +function main( |
| 19 | + projectId = process.env.GCLOUD_PROJECT, |
| 20 | + cloudRegion = 'us-central1', |
| 21 | + datasetId, |
| 22 | + fhirStoreId, |
| 23 | + resourceType, |
| 24 | +) { |
| 25 | + // [START healthcare_create_fhir_resource] |
| 26 | + const {google} = require('googleapis'); |
| 27 | + const healthcare = google.healthcare('v1'); |
| 28 | + |
| 29 | + async function createFhirResource() { |
| 30 | + const auth = await google.auth.getClient({ |
| 31 | + scopes: ['https://www.googleapis.com/auth/cloud-platform'], |
| 32 | + }); |
| 33 | + |
| 34 | + // Replace the following body with the data for the resource you want to |
| 35 | + // create. |
| 36 | + const body = { |
| 37 | + "name": [{"use": "official", "family": "Smith", "given": ["Darcy"]}], |
| 38 | + "gender": "female", |
| 39 | + "birthDate": "1970-01-01", |
| 40 | + "resourceType": "Patient", |
| 41 | + }; |
| 42 | + |
| 43 | + google.options({auth, headers: {'Content-Type': 'application/fhir+json'}}); |
| 44 | + |
| 45 | + // TODO(developer): uncomment these lines before running the sample |
| 46 | + // const cloudRegion = 'us-central1'; |
| 47 | + // const projectId = 'adjective-noun-123'; |
| 48 | + // const datasetId = 'my-dataset'; |
| 49 | + // const fhirStoreId = 'my-fhir-store'; |
| 50 | + // const resourceType = 'Patient'; |
| 51 | + const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}`; |
| 52 | + |
| 53 | + const request = {parent, type: resourceType, requestBody: body}; |
| 54 | + const resource = await healthcare.projects.locations.datasets.fhirStores.fhir.create( |
| 55 | + request |
| 56 | + ); |
| 57 | + console.log(`Created FHIR resource with ID ${resource.data.id}`); |
| 58 | + console.log(resource.data); |
| 59 | + } |
| 60 | + |
| 61 | + createFhirResource(); |
| 62 | + // [END healthcare_create_fhir_resource] |
| 63 | +} |
| 64 | + |
| 65 | +// node createFhirResource.js <projectId> <cloudRegion> <datasetId> <fhirStoreId> <resourceType> |
| 66 | +main(...process.argv.slice(2)); |
0 commit comments