Update Resource
The FHIR update operation allows you to update an existing resource on the FHIR server. This is done using an HTTP PUT request to the endpoint corresponding to the resource type and ID.
Examples
- CLI
- TypeScript
- cURL
Update a Patient resource using the Haste Health CLI:
haste-health api update Patient 12345 --file updated-patient.json
Where updated-patient.json contains:
{
"resourceType": "Patient",
"id": "12345",
"name": [
{
"use": "official",
"family": "Smith",
"given": ["John"]
}
],
"gender": "male",
"birthDate": "1980-01-01",
"telecom": [
{
"system": "phone",
"value": "555-1234"
}
]
}
Update a Patient resource using the TypeScript client:
import { AsynchronousClient } from '@haste-health/client';
import { R4 } from '@haste-health/fhir-types/versions';
import { Patient } from '@haste-health/fhir-types/r4/types';
// Assuming you have a configured client
const client: AsynchronousClient<{}> = /* ... */;
const updatedPatient: Patient = {
resourceType: "Patient",
id: "12345",
name: [
{
use: "official",
family: "Smith",
given: ["John"]
}
],
gender: "male",
birthDate: "1980-01-01",
telecom: [
{
system: "phone",
value: "555-1234"
}
]
};
const result = await client.update(
{},
R4,
'Patient',
'12345',
updatedPatient
);
console.log('Updated Patient:', result);
Update a Patient resource using cURL:
curl -X PUT "https://api.haste.health/w/[tenant]/[project]/api/v1/fhir/r4/Patient/12345" \
-H "Content-Type: application/fhir+json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"resourceType": "Patient",
"id": "12345",
"name": [
{
"use": "official",
"family": "Smith",
"given": ["John"]
}
],
"gender": "male",
"birthDate": "1980-01-01"
}'
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 data), 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 phone number format"
}
]
}