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

# FHIR ValueSet/$validate-code membership check

> Check whether an OMOP code is a member of a specified FHIR ValueSet - validate Observations, Conditions, and Medications against expected sets.

## Overview

Validates whether a code is a member of an implicit ValueSet. EHRbase uses this during composition validation to check if a submitted code falls within the allowed set for a template field.

Supports the same ValueSet URL patterns as `$expand`.

<Note>
  FHIR clients typically call [ValueSet search](/api-reference/fhir-terminology/valueset-search) first as a preflight check to confirm the server supports the target ValueSet, then call `$validate-code` (or `$expand`) for the actual membership test. The two endpoints are independent - you can call `$validate-code` directly without the preflight if you already know the URL is supported.
</Note>

## Supported Patterns

### All codes in a code system

```bash theme={null}
curl "https://fhir.omophub.com/fhir/r4/ValueSet/\$validate-code?\
url=http://snomed.info/sct?fhir_vs&\
system=http://snomed.info/sct&code=44054006" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

Is SNOMED code 44054006 valid? (Yes, if it exists in the SNOMED vocabulary.)

### Descendants of a concept (is-a filter)

```bash theme={null}
curl "https://fhir.omophub.com/fhir/r4/ValueSet/\$validate-code?\
url=http://snomed.info/sct?fhir_vs=isa/73211009&\
system=http://snomed.info/sct&code=44054006" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

Is "Type 2 diabetes mellitus" (44054006) a descendant of "Diabetes mellitus" (73211009)? (Yes.)

## Parameters

| Parameter | Type   | Required | Description                                                                                                     |
| --------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------- |
| `url`     | uri    | Yes      | Implicit ValueSet URL (e.g., `http://snomed.info/sct?fhir_vs` or `http://snomed.info/sct?fhir_vs=isa/73211009`) |
| `system`  | uri    | No       | Code system URI of the code being validated (defaults to the ValueSet system)                                   |
| `code`    | code   | Yes      | The code to validate                                                                                            |
| `display` | string | No       | Expected display text to verify                                                                                 |

## Response (valid code)

```json theme={null}
{
  "resourceType": "Parameters",
  "parameter": [
    { "name": "result", "valueBoolean": true },
    { "name": "display", "valueString": "Type 2 diabetes mellitus" }
  ]
}
```

## Response (not a member)

```json theme={null}
{
  "resourceType": "Parameters",
  "parameter": [
    { "name": "result", "valueBoolean": false },
    { "name": "message", "valueString": "Code '22298006' is not a member of the ValueSet (not a descendant of '73211009')." }
  ]
}
```

## Response (display mismatch)

```json theme={null}
{
  "resourceType": "Parameters",
  "parameter": [
    { "name": "result", "valueBoolean": true },
    { "name": "display", "valueString": "Type 2 diabetes mellitus" },
    { "name": "message", "valueString": "Display mismatch: provided 'Diabetes type 2', actual 'Type 2 diabetes mellitus'." }
  ]
}
```

## Errors

| HTTP | Issue Code  | Cause                                                                           |
| ---- | ----------- | ------------------------------------------------------------------------------- |
| 400  | `invalid`   | Missing `url` or `code` parameter, invalid ValueSet URL, or unknown code system |
| 404  | `not-found` | ValueSet root concept not found                                                 |
