Invoke Type Operation
The FHIR type-level operation invocation allows you to invoke a custom or standard operation on a specific resource type. This is done using an HTTP POST or GET request to the operation endpoint for the resource type.
- CLI
- TypeScript Client
- cURL
Invoke the $validate operation on the Patient resource type using the Haste Health CLI:
haste-health api invoke-type Patient validate --file params.json
Where params.json contains:
{
"resourceType": "Parameters",
"parameter": [
{
"name": "resource",
"resource": {
"resourceType": "Patient",
"name": [{"family": "Doe", "given": ["John"]}]
}
}
]
}
Invoke a type-level operation using the TypeScript client:
import { AsynchronousClient } from '@haste-health/client';
import { R4 } from '@haste-health/fhir-types/versions';
import { Parameters, Patient } from '@haste-health/fhir-types/r4/types';
// Assuming you have a configured client
const client: AsynchronousClient<{}> = /* ... */;
const patientToValidate: Patient = {
resourceType: "Patient",
name: [{family: "Doe", given: ["John"]}]
};
const params: Parameters = {
resourceType: "Parameters",
parameter: [
{
name: "resource",
resource: patientToValidate
}
]
};
const result = await client.invoke_type(
{},
R4,
'Patient',
'validate',
params
);
console.log('Validation result:', result);
Invoke the $validate operation on the Patient resource type using cURL:
curl -X POST "https://api.haste.health/w/[tenant]/[project]/api/v1/fhir/r4/Patient/\$validate" \
-H "Content-Type: application/fhir+json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"resourceType": "Parameters",
"parameter": [
{
"name": "resource",
"resource": {
"resourceType": "Patient",
"name": [{"family": "Doe", "given": ["John"]}]
}
}
]
}'
Replace [tenant] with your tenant name and [project] with your project ID.
Error Handling
If there are any issues with the request (e.g., invalid parameters, operation not supported), 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 resource: missing required field"
}
]
}