# Validate a CodeSystem code

Canonical page: https://docs.ovok.com/primitives/validate-codesystem-code

`$validate-code` checks whether a code belongs to a CodeSystem. It can also validate a supplied display and return the preferred display for the code.

| Method | Path |
| --- | --- |
| `GET` or `POST` | `/fhir/R4/CodeSystem/$validate-code` |

At the type-level route, identify the CodeSystem with `url` (or provide a `CodeSystem` resource using `codeSystem`). Supply exactly one code input: a `code`, a `Coding`, or a `CodeableConcept`.

## GET request [#get-request]

```bash
curl --get 'https://api.sandbox.ovok.com/fhir/R4/CodeSystem/$validate-code' \
  --header "Authorization: Bearer ${OVOK_TOKEN}" \
  --data-urlencode 'url=http://loinc.org' \
  --data-urlencode 'code=8867-4' \
  --data-urlencode 'display=Heart rate'
```

## POST request [#post-request]

Send the CodeSystem canonical URL and code together in a FHIR `Parameters` resource:

```bash
curl --request POST \
  --url 'https://api.sandbox.ovok.com/fhir/R4/CodeSystem/$validate-code' \
  --header "Authorization: Bearer ${OVOK_TOKEN}" \
  --header 'Content-Type: application/fhir+json' \
  --data @validate-codesystem-parameters.json
```

Example `validate-codesystem-parameters.json`:

```json
{
  "resourceType": "Parameters",
  "parameter": [
    { "name": "url", "valueUri": "http://loinc.org" },
    {
      "name": "coding",
      "valueCoding": {
        "system": "http://loinc.org",
        "code": "8867-4",
        "display": "Heart rate"
      }
    }
  ]
}
```

## Successful response [#successful-response]

The operation returns a FHIR `Parameters` resource.

| Response path | Example | Meaning |
| --- | --- | --- |
| `resourceType` | `Parameters` | FHIR wrapper for the operation output. |
| `parameter[name=result].valueBoolean` | `true` | Whether the code is valid in the CodeSystem. |
| `parameter[name=display].valueString` | `Heart rate` | Canonical display for the code, when available. A supplied display can be checked according to the CodeSystem's case-sensitivity rules. |
| `parameter[name=message].valueString` | Optional | Validation failure details or a hint, when present. |

Errors are returned as a FHIR `OperationOutcome`. The server may reject unknown systems, malformed inputs, or codes it cannot validate.

Reference: [HL7 FHIR R4 CodeSystem `$validate-code`](https://hl7.org/fhir/R4/codesystem-operation-validate-code.html).
