# Apply an ActivityDefinition

Canonical page: https://docs.ovok.com/primitives/apply-activity-definition

Apply a stored `ActivityDefinition` to a subject. The resource created by the operation depends on the ActivityDefinition's `kind` and content.

| Method | Path |
| --- | --- |
| `POST` | `/fhir/R4/ActivityDefinition/:id/$apply` |

## Request [#request]

```bash
curl --request POST \
  --url "https://api.sandbox.ovok.com/fhir/R4/ActivityDefinition/${ACTIVITY_DEFINITION_ID}/\$apply" \
  --header "Authorization: Bearer ${OVOK_TOKEN}" \
  --header 'Content-Type: application/fhir+json' \
  --data "{\"resourceType\":\"Parameters\",\"parameter\":[{\"name\":\"subject\",\"valueReference\":{\"reference\":\"Patient/${PATIENT_ID}\"}}]}"
```

| Parameter | Type | Description |
| --- | --- | --- |
| `subject` | Reference | Subject for whom to apply the definition. |
| `encounter` | Reference | Optional encounter context. |
| `practitioner` | Reference | Optional practitioner context. |
| `organization` | Reference | Optional organization context. |

Provide the parameters required by the selected ActivityDefinition and the server's implementation.

## Response [#response]

The response resource type is determined by `ActivityDefinition.kind`; consult the definition and the operation response for the resulting resource. The server may return an `OperationOutcome` when the definition cannot be applied.

See the [FHIR R4 ActivityDefinition `$apply` operation](https://hl7.org/fhir/R4/activitydefinition-operation-apply.html) for the standard definition.
