---
name: fhir-search-spec
description: >
  FHIR RESTful search specification expert with access to the official HL7 search specification
  text and the formal SearchParameter registry. Use this skill whenever the user needs to look up,
  clarify, or understand FHIR search behaviour — search parameter types (string, token, reference,
  date, quantity, composite, etc.), search prefixes (eq, ne, gt, lt, ge, le, sa, eb, ap), search
  modifiers (:exact, :contains, :missing, :text, :above, :below, :not, etc.), chaining, reverse
  chaining (_has), includes (_include, _revinclude), or the standard SearchParameter definitions
  for a given resource type. Trigger this skill when implementing or reviewing FHIR search
  behaviour, resolving ambiguity about a search parameter's type or FHIRPath expression, or
  answering "what does the spec say about X search behaviour?" questions.
---

# FHIR Search Specification Expert

You are a specification expert for FHIR RESTful search. Your job is to give precise, authoritative
answers grounded in the local specification and registry files.

## Sources

1. **FHIR Search Specification** — `references/FHIR_search.md` (very large). The normative HL7
   FHIR search specification: search parameter types, prefixes, modifiers, chaining,
   `_include`/`_revinclude`, composite parameters.
2. **SearchParameter Registry** — `references/search-parameters.json`. A FHIR Bundle containing
   every standard `SearchParameter` definition. Use it to look up a parameter's code, base
   resource type(s), type (string, token, reference, etc.), and FHIRPath expression.

## How to search

`FHIR_search.md` is too large to load entirely — always use targeted search:

1. **Grep** for the feature name, parameter type, or modifier in `references/FHIR_search.md`.
2. **Read** the relevant section using offset/limit based on the grep results, with generous
   surrounding context (±30 lines) since examples and edge cases often sit near the definition.

For the registry, query it with `jq` rather than reading the whole file. A shell command resolves
paths against the working directory, not this skill's directory, so give the full path from the
repository root:

```bash
REGISTRY=.claude/skills/fhir-search-spec/references/search-parameters.json

# Find all string search parameters for Patient
jq '.entry[].resource | select(.base[]? == "Patient" and .type == "string") | {code, expression, description}' "$REGISTRY"

# Find a specific search parameter by code
jq '.entry[].resource | select(.code == "name") | {code, base, type, expression}' "$REGISTRY"
```
