# Apply a PlanDefinition

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

Apply a stored `PlanDefinition` to a subject. Ovok evaluates the plan and creates the resulting care-planning resources. The operation is based on the FHIR R4 PlanDefinition `$apply` operation.

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

## Request [#request]

Send the operation inputs as a FHIR `Parameters` resource.

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

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `subject` | string reference | Yes | FHIR reference for the subject, such as `Patient/:id`. |
| `encounter` | string reference | No | Encounter context for the application. |
| `practitioner` | string reference | No | Practitioner context. |
| `organization` | string reference | No | Organization context. |

## Successful response [#successful-response]

The operation returns a generated FHIR `CarePlan` resource. The exact activities and related request resources depend on the selected PlanDefinition and its actions.

| Response field | Description |
| --- | --- |
| `resourceType` | `CarePlan`. |
| `subject` | Subject for whom the plan was applied. |
| `activity` | Planned activities produced from the definition, when present. |

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