Patch Resource
The FHIR patch operation allows you to partially update an existing resource on the FHIR server. This is done using an HTTP PATCH request to the endpoint corresponding to the resource type and ID. FHIR supports both JSON Patch and FHIRPath Patch formats.
- CLI
- TypeScript
- cURL
Patch a Patient resource using the Haste Health CLI:
haste-health api patch Patient 12345 --file patch.json
Where patch.json contains JSON Patch operations:
[
{
"op": "add",
"path": "/telecom",
"value": [
{
"system": "phone",
"value": "555-1234"
}
]
}
]
Patch a Patient resource using the TypeScript client:
import { AsynchronousClient } from '@haste-health/client';
import { R4 } from '@haste-health/fhir-types/versions';
// Assuming you have a configured client
const client: AsynchronousClient<{}> = /* ... */;
const patches = [
{
op: "add",
path: "/telecom",
value: [
{
system: "phone",
value: "555-1234"
}
]
}
];
const patchedPatient = await client.patch(
{},
R4,
'Patient',
'12345',
patches
);
console.log('Patched Patient:', patchedPatient);
Patch a Patient resource using cURL with JSON Patch:
curl -X PATCH "https://api.haste.health/w/[tenant]/[project]/api/v1/fhir/r4/Patient/12345" \
-H "Content-Type: application/json-patch+json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '[
{
"op": "add",
"path": "/telecom",
"value": [{"system": "phone", "value": "555-1234"}]
}
]'
Replace [tenant] with your tenant name and [project] with your project ID.
Error Handling
If there are any issues with the request (e.g., resource not found, invalid patch operation), the server will respond with an appropriate error status code and include an OperationOutcome resource in the response body.
HTTP/1.1 400 Bad Request
Content-Type: application/fhir+json
{
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"code": "invalid",
"diagnostics": "Invalid patch operation: path not found"
}
]
}