Create Resource
The FHIR create operation allows you to create a new resource of a specified type on the FHIR server. This is done using an HTTP POST request to the endpoint corresponding to the resource type.
- CLI
- TypeScript
- cURL
Create a Patient resource using the Haste Health CLI:
haste-health api create --file patient.json
Where patient.json contains:
{
"resourceType": "Patient",
"name": [
{
"use": "official",
"family": "Doe",
"given": ["John"]
}
],
"gender": "male",
"birthDate": "1980-01-01"
}
Or pass the data inline:
echo '{
"resourceType": "Patient",
"name": [{"use": "official", "family": "Doe", "given": ["John"]}],
"gender": "male",
"birthDate": "1980-01-01"
}' | haste-health api create r4 --data -
Create 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 newPatient: Patient = {
resourceType: "Patient",
name: [
{
use: "official",
family: "Doe",
given: ["John"]
}
],
gender: "male",
birthDate: "1980-01-01"
};
const createdPatient = await client.create(
{},
R4,
newPatient
);
console.log('Created Patient:', createdPatient);
Create a Patient resource using cURL:
curl -X POST "https://api.haste.health/w/[tenant]/[project]/api/v1/fhir/r4/Patient" \
-H "Content-Type: application/fhir+json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"resourceType": "Patient",
"name": [
{
"use": "official",
"family": "Doe",
"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., missing required fields, invalid data), the server will respond with an appropriate error status code (e.g., 400 Bad Request) and include an OperationOutcome resource in the response body detailing the errors.
HTTP/1.1 400 Bad Request Content-Type: application/fhir+json
{
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"code": "invalid",
"diagnostics": "Missing required field: name"
}
]
}