# Terminology

Clinical terminology is the backbone of interoperable healthcare data. The [FHIR Terminology module](http://hl7.org/fhir/terminologies.html) defines how coded values, the codes and systems used to describe clinical concepts, are represented, validated, and exchanged in FHIR resources. Smile CDR provides a comprehensive set of terminology services built on the HAPI FHIR JPA server's terminology engine.

Terminology can be loaded into Smile CDR in three ways: [uploading CodeSystems](/content/docs/terminology/uploading.html), installing [IG packages](/content/docs/validation_and_conformance/packages_and_igs.html), or delegating to a [Remote Terminology Service](/content/docs/validation_and_conformance/remote_terminology_services.html).

# FHIR Terminology Resources

The FHIR specification defines three core resource types for managing terminology:

- A [**CodeSystem**](https://hl7.org/fhir/codesystem.html) defines a collection of codes and their meanings. Examples include [LOINC](https://loinc.org/), [SNOMED CT](https://www.snomed.org/), [ICD-10](https://www.who.int/standards/classifications/classification-of-diseases), and organization-specific local code systems.

- A [**ValueSet**](https://hl7.org/fhir/valueset.html) selects a subset of codes from one or more CodeSystems for a specific purpose. ValueSets are used extensively in FHIR profiles to constrain which codes are valid for a given element.

- A [**ConceptMap**](https://hl7.org/fhir/conceptmap.html) defines mappings between concepts in different CodeSystems. For example, mapping a proprietary local code to its LOINC equivalent.

For a detailed explanation of how codes are used in FHIR resources, see [Using Codes in Resources](http://hl7.org/fhir/terminologies.html) in the FHIR specification.

# Terminology Features in Smile CDR

## Loading Terminology

Smile CDR bundles all FHIR-specification CodeSystems, ValueSets, and ConceptMaps out of the box, and these can be seeded into the repository at startup. For standard vocabularies such as LOINC, SNOMED CT, and ICD-10, as well as for custom organization-specific code systems, Smile CDR provides upload operations and a command-line tool (`smileutil`) that handle large files without loading them fully into memory. See [Uploading CodeSystems](/content/docs/terminology/uploading.html) for details.

## ValueSet Expansion

ValueSets are defined by composition rules, which Smile CDR pre-calculates into a flat expansion and stores in dedicated database tables. This enables fast `$expand` and `$validate-code` responses, membership testing during resource validation, and paginated expansion of very large ValueSets. See [ValueSet Expansion](/content/docs/terminology/valueset_expansion.html) for details.

## Terminology Mapping

Smile CDR supports mapping codes between different CodeSystems via [ConceptMap](https://hl7.org/fhir/conceptmap.html) resources and the [`$translate`](https://hl7.org/fhir/conceptmap-operation-translate.html) operation. This is commonly used to translate between standard vocabularies (e.g. local codes to LOINC) or between institution-specific and standardized code sets. See [Terminology Mapping](/content/docs/terminology/terminology_mapping.html) for details.

## In-Place Code Translation

Smile CDR can apply ConceptMap `$translate` mappings automatically as resources are stored, adding translated codings directly to the resource before it is persisted. This _mapping-on-the-way-in_ approach ensures that downstream consumers always see standardized codes. Currently this is limited to a single fixed mapping: `Observation.code` translated to LOINC. See [In-Place Code Translation](/content/docs/terminology/inplace_translation.html) for details.

## Response Terminology Enhancement

As an alternative to in-place translation, Smile CDR can apply terminology mappings to FHIR responses as they are served, without modifying the stored data. This _mapping-on-the-way-out_ approach centralizes mapping management: when mappings change, there is a single source of truth to update. See [FHIR Response Terminology Enhancement](/content/docs/terminology/response_terminology_enhancement.html) for details.

## Full-Text Indexing for Terminology

When full-text indexing is enabled, `$expand` gains additional filter support including display-name filtering, hierarchy filters (`parent`, `child`, `ancestor`, `descendant`), regex filtering, and LOINC-specific filters. This is especially useful for large hierarchical terminologies e.g. LOINC, SNOMED, RxNorm. See [Terminology and Full-Text Indexing](/content/docs/terminology/terminology_and_fulltext_indexing.html) for details.

# Supported Terminology Operations

## Standard FHIR Operations

Smile CDR supports the following [FHIR terminology operations](https://hl7.org/fhir/terminology-module.html):

| Operation | Resource | Description |
| --- | --- | --- |
| [`$lookup`](https://hl7.org/fhir/codesystem-operation-lookup.html) | CodeSystem | Look up a code and return its display name, properties, and designations |
| [`$validate-code`](https://hl7.org/fhir/codesystem-operation-validate-code.html) | CodeSystem, ValueSet | Validate whether a code is valid in a CodeSystem or is a member of a ValueSet |
| [`$expand`](https://hl7.org/fhir/valueset-operation-expand.html) | ValueSet | Expand a ValueSet into its full flat list of codes; supports pagination and display filters |
| [`$translate`](https://hl7.org/fhir/conceptmap-operation-translate.html) | ConceptMap | Translate a code from one CodeSystem to another using a ConceptMap |
| [`$subsumes`](https://hl7.org/fhir/codesystem-operation-subsumes.html) | CodeSystem | Test whether one concept subsumes another (hierarchy / is-a testing) |

## HAPI FHIR Extended Operations

In addition to the standard FHIR operations, Smile CDR exposes the following HAPI FHIR-specific operations:

| Operation | Resource | Description |
| --- | --- | --- |
| `$invalidate-expansion` | ValueSet | Invalidate the pre-calculated expansion for a ValueSet and trigger a fresh background recalculation. See [ValueSet Expansion](/content/docs/terminology/valueset_expansion.html#invalidating-pre-calculated-expansion/index.html). |
| `$hapi.fhir.expansion-status` | ValueSet | List ValueSets filtered by their pre-expansion status (e.g. `EXPANDED`, `FAILED_TO_EXPAND`) without requiring database access. See [Checking Expansion Status](/content/docs/terminology/valueset_expansion.html#checking-expansion-status/index.html). |
| `$reindex-terminology` | System | Recreate the free-text indexes for terminology resources. See the [smileutil reindex-terminology](/content/docs/smileutil/reindex_terminology.html) command for an automated alternative. |
| `$hapi.fhir.add-mapping` | ConceptMap | Add a single concept mapping to an existing ConceptMap resource. See [Terminology Mapping](/content/docs/terminology/terminology_mapping.html#add-mapping/index.html). |
| `$hapi.fhir.remove-mapping` | ConceptMap | Remove a single concept mapping from an existing ConceptMap resource. See [Terminology Mapping](/content/docs/terminology/terminology_mapping.html#remove-mapping/index.html). |

**Upload Terminology Workflow**

Uploading a large external CodeSystem is not a single operation but a sequence of four `CodeSystem`-level operations invoked in order. Each step feeds the job created in step 1, and the final step polls the resulting background batch job to completion. See  [Upload Terminology Operations](/content/docs/terminology/uploading.html#upload-terminology-operations/index.html) for full details.

1. [`$hapi.fhir.upload-terminology.create-job`](/content/docs/terminology/uploading.html#hapi.fhir.upload-terminology.create-job/index.html) creates an upload job and returns a job ID.
2. [`$hapi.fhir.upload-terminology.attach-file`](/content/docs/terminology/uploading.html#hapi.fhir.upload-terminology.attach-file/index.html) attaches a terminology distribution file to the job.
3. [`$hapi.fhir.upload-terminology.start-job`](/content/docs/terminology/uploading.html#hapi.fhir.upload-terminology.start-job/index.html) starts processing the attached files as a background batch job.
4. [`$hapi.fhir.upload-terminology.poll-for-status`](/content/docs/terminology/uploading.html#hapi.fhir.upload-terminology.poll-for-status/index.html) polls the status of the running job until it completes.

# Unsupported Operations

Smile CDR does **not** currently support the following [terminology operations](https://hl7.org/fhir/terminology-module.html):

- [**$find-matches**](https://hl7.org/fhir/codesystem-operation-find-matches.html) (CodeSystem)
- [**$closure**](https://hl7.org/fhir/conceptmap-operation-closure.html) (ConceptMap)

Terminology Introduction

Terminology

[Terminology Introduction](/content/docs/terminology/introduction.html)
[Uploading Codes](/content/docs/terminology/uploading.html)
[Terminology and Full-Text Indexing](/content/docs/terminology/terminology_and_fulltext_indexing.html)
[ValueSet Expansion](/content/docs/terminology/valueset_expansion.html)
[Terminology Mapping](/content/docs/terminology/terminology_mapping.html)
[FHIR Response Terminology Mapping](/content/docs/terminology/response_terminology_enhancement.html)
[In-Place Code Translation](/content/docs/terminology/inplace_translation.html)

[Uploading Codes](/content/docs/terminology/uploading.html)
