> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ferrum.thalamiq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Type-Level Operations

> Execute operations on a resource type

## Type-Level Operations

Execute FHIR operations on all resources of a specific type.

<ParamField path="resource_type" type="string" required>
  The FHIR resource type (e.g., `Patient`, `Observation`, `Encounter`)
</ParamField>

<ParamField path="operation" type="string" required>
  The operation name (e.g., `$validate`, `$everything`, `$export`)
</ParamField>

## Endpoint

```
GET /fhir/:resource_type/$:operation
POST /fhir/:resource_type/$:operation
```

Use `GET` for operations that only read data, or `POST` for operations that require input parameters.

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
       -H "Content-Type: application/fhir+json" \
       -d '{"resourceType":"Parameters"}' \
       https://your-server.com/fhir/Patient/$validate
  ```

  ```bash HTTP theme={null}
  POST /fhir/Patient/$validate HTTP/1.1
  Host: your-server.com
  Content-Type: application/fhir+json

  {
    "resourceType": "Parameters",
    ...
  }
  ```
</CodeGroup>

## Common Type Operations

### \$validate

Validate a resource of this type:

```json theme={null}
POST /fhir/Patient/$validate
Content-Type: application/fhir+json

{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "resource",
      "resource": {
        "resourceType": "Patient",
        "name": [{"family": "Doe"}]
      }
    }
  ]
}
```

### \$everything

Get all resources of this type and related resources:

```bash theme={null}
GET /fhir/Patient/$everything
```

Or with parameters:

```json theme={null}
POST /fhir/Patient/$everything
Content-Type: application/fhir+json

{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "_since",
      "valueDateTime": "2024-01-01T00:00:00Z"
    }
  ]
}
```

### \$export

Export all resources of this type:

```json theme={null}
POST /fhir/Patient/$export
Content-Type: application/fhir+json

{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "_outputFormat",
      "valueString": "application/fhir+ndjson"
    }
  ]
}
```

## Request Format

Operations use a `Parameters` resource for input:

```json theme={null}
{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "parameter-name",
      "valueString": "parameter-value"
    },
    {
      "name": "resource",
      "resource": {
        "resourceType": "Patient",
        ...
      }
    }
  ]
}
```

## Response

### Success (200 OK)

Returns operation results, typically as a `Parameters` resource or a `Bundle`:

```json theme={null}
{
  "resourceType": "Bundle",
  "type": "searchset",
  "entry": [
    {
      "resource": {
        "resourceType": "Patient",
        ...
      }
    }
  ]
}
```

### Error (400 Bad Request)

Returns an `OperationOutcome` if the operation fails:

```json theme={null}
{
  "resourceType": "OperationOutcome",
  "issue": [
    {
      "severity": "error",
      "code": "invalid",
      "details": {
        "text": "Operation $unknown not supported for Patient"
      }
    }
  ]
}
```

## Available Operations

The available type-level operations depend on server configuration and resource type. Check the capability statement (`/fhir/metadata`) to see which operations are supported for each resource type:

```json theme={null}
{
  "rest": [
    {
      "resource": [
        {
          "type": "Patient",
          "operation": [
            {
              "name": "$validate",
              "definition": "http://hl7.org/fhir/OperationDefinition/Resource-validate"
            },
            {
              "name": "$everything",
              "definition": "http://hl7.org/fhir/OperationDefinition/Patient-everything"
            }
          ]
        }
      ]
    }
  ]
}
```

## Notes

* Type operations apply to all resources of the specified type
* Available operations vary by resource type
* Operations may require specific permissions
* Use POST when operations require input parameters
* Operation names are case-sensitive and start with `$`
