Patch a FHIR resource
Stay organized with collections
Save and categorize content based on your preferences.
Patch a FHIR resource.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis content demonstrates how to patch a FHIR resource using Node.js and the Google Cloud Healthcare API.\u003c/p\u003e\n"],["\u003cp\u003eThe code sample utilizes the \u003ccode\u003e@googleapis/healthcare\u003c/code\u003e library to interact with the API, including setting authentication and defining the request header.\u003c/p\u003e\n"],["\u003cp\u003eThe sample highlights the use of JSON patch operations to modify a FHIR resource by replacing specific attributes, in this case the "active" attribute.\u003c/p\u003e\n"],["\u003cp\u003eTo run the sample, users must configure the project ID, cloud region, dataset ID, FHIR store ID, resource type, and resource ID and it also requires the right scope and authentication, detailed in the documentation links.\u003c/p\u003e\n"]]],[],null,["# Patch a FHIR resource.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Creating and managing FHIR resources](/healthcare-api/docs/how-tos/fhir-resources)\n\nCode sample\n-----------\n\n### Node.js\n\n\nBefore trying this sample, follow the Node.js setup instructions in the\n[Cloud Healthcare API quickstart using\nclient libraries](https://cloud.google.com/healthcare-api/docs/store-healthcare-data-client-library).\n\n\nFor more information, see the\n[Cloud Healthcare API Node.js API\nreference documentation](https://github.com/googleapis/google-api-nodejs-client/blob/main/src/apis/healthcare/README.md).\n\n\nTo authenticate to Cloud Healthcare API, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const google = require('@googleapis/healthcare');\n const healthcare = google.healthcare({\n version: 'v1',\n auth: new google.auth.GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n }),\n headers: {'Content-Type': 'application/json-patch+json'},\n });\n\n async function patchFhirResource() {\n // TODO(developer): replace patchOptions with your desired JSON patch body\n const patchOptions = [{op: 'replace', path: '/active', value: false}];\n\n // TODO(developer): uncomment these lines before running the sample\n // const cloudRegion = 'us-central1';\n // const projectId = 'adjective-noun-123';\n // const datasetId = 'my-dataset';\n // const fhirStoreId = 'my-fhir-store';\n // const resourceType = 'Patient';\n // const resourceId = '16e8a860-33b3-49be-9b03-de979feed14a';\n const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/${resourceType}/${resourceId}`;\n const request = {\n name,\n requestBody: patchOptions,\n };\n\n await healthcare.projects.locations.datasets.fhirStores.fhir.patch(request);\n console.log(`Patched ${resourceType} resource`);\n }\n\n patchFhirResource();\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=healthcare)."]]