Skip to main content

Terminology Service

The WSO2 Healthcare Accelerator includes a pre-built FHIR R4 Terminology Service that provides RESTful APIs for managing and querying FHIR ValueSets and CodeSystems. It is designed to be compatible with the HL7 FHIR Terminology Service specification and supports key terminology operations such as expansion, validation, lookup, and subsumption.

Features

  • ValueSet Operations -- Expand, validate codes, search, create, and retrieve ValueSets.
  • CodeSystem Operations -- Lookup, subsumption testing, search, create, and retrieve CodeSystems.
  • Batch Validation -- Validate multiple ValueSets in a single request.
  • Upload -- Upload terminology resources (CodeSystems and ValueSets) in bulk.
  • Find Code -- Search for codes across CodeSystems and ValueSets.
  • FHIR CapabilityStatement -- Exposes service metadata for FHIR clients.

Supported Terminology Types

The service supports loading and querying the following standard terminology systems:

TerminologyType
SNOMED CTClinical findings, procedures
LOINCLab observations, clinical measurements
ICD-10Diagnoses
RxNormMedications
FHIRBuilt-in FHIR code systems and value sets

API Endpoints

All endpoints are served under /fhir/r4:

OperationEndpointDescription
$expandGET/POST /ValueSet/$expandExpand a ValueSet
$validate-codeGET/POST /ValueSet/$validate-codeValidate a code against a ValueSet
$lookupGET/POST /CodeSystem/$lookupLook up a code in a CodeSystem
$subsumesGET/POST /CodeSystem/$subsumesTest subsumption relationships
Search ValueSetsGET /ValueSetSearch ValueSets
Search CodeSystemsGET /CodeSystemSearch CodeSystems
Get by IDGET /ValueSet/{id}, GET /CodeSystem/{id}Retrieve by ID
CreatePOST /ValueSet, POST /CodeSystemCreate new resources
Batch ValidatePOST /Batch validate ValueSets
UploadPOST /$uploadUpload terminology resources in bulk
Find CodeGET/POST /$find-codeSearch for codes
MetadataGET /metadataFHIR CapabilityStatement

Setting Up the Terminology Service

Prerequisites

Clone the WSO2 Healthcare Accelerator repository and navigate to the terminology service:

git clone https://github.com/wso2/open-healthcare-choreo-accelerators.git
cd open-healthcare-choreo-accelerators/miscellaneous/terminology-service

Database Configuration

The terminology service requires a database backend. Two database types are supported:

H2 (Embedded)

Suitable for development and testing. Configure in Config.toml:

[wso2.terminology_service]
db_type = "h2"

[wso2.terminology_service.store_h2]
url = "jdbc:h2:./resources/database/terminologyDB"
user = "sa"
password = ""

PostgreSQL

Recommended for production. Configure in Config.toml:

[wso2.terminology_service]
db_type = "postgresql"

[wso2.terminology_service.store_pg]
host = "localhost"
database = "terminology"
user = "dbuser"
password = "dbpassword"
port = 5432

Running the Service

Start the terminology service:

bal run

The service starts on port 9089 by default and is available at http://localhost:9089/fhir/r4.

Verifying the Service

Check the service metadata:

curl http://localhost:9089/fhir/r4/metadata

Quick Start

Validate a Code

curl 'http://localhost:9089/fhir/r4/ValueSet/$validate-code?url=http://hl7.org/fhir/ValueSet/observation-status&code=final&system=http://hl7.org/fhir/observation-status'

Response:

{
"resourceType": "Parameters",
"parameter": [
{"name": "result", "valueBoolean": true},
{"name": "display", "valueString": "Final"}
]
}

Expand a ValueSet

curl 'http://localhost:9089/fhir/r4/ValueSet/$expand?url=http://hl7.org/fhir/ValueSet/observation-status'

Look Up a Code

curl 'http://localhost:9089/fhir/r4/CodeSystem/$lookup?system=http://loinc.org&code=85354-9'

Integrating with Terminology Validation

The pre-built terminology service can be used as the backend for terminology validation in your integrations. Point your Config.toml terminology configuration to the running service:

[ballerinax.health.fhir.r4.parser.terminologyConfig]
isTerminologyValidationEnabled = true
terminologyServiceApi = "http://localhost:9089/fhir/r4"