How the validator talks to a terminology server
This page describes the requests that the validator sends to an external terminology server, at startup and during a
validation. It helps to understand what a terminology server has to support to be used with Matchbox, what data leaves
Matchbox, and how the terminology cache works. The observations come from an investigation of the HL7 validator with
Matchbox 3.4.5 and the ch-elm implementation guide, configured with the terminology server
http://host.docker.internal:18002/eprik-cara/camel/tx/r4/; details may differ in newer versions.
For the role of the terminology server in validation, see Terminology in validation.
At startup
At startup, Matchbox makes two HTTP requests to the terminology server:
which returns a CapabilityStatement that contains supported operations; and: which returns a TerminologyCapabilities that seems to contain the list of supported code systems, and expansion parameters.The code responsible for this is SimpleWorkerContext.connectToTSServer(), both resources are put in the txCache.
During validation
During validation, the library makes a number of requests to the terminology server. The first type is to check the membership of a code in a value set:
{
"resourceType": "Parameters",
"parameter": [
{
"name": "coding",
"valueCoding": {
"system": "http://loinc.org",
"code": "697-3"
}
},
{
"name": "valueSetMode",
"valueString": "CHECK_MEMERSHIP_ONLY"
},
{
"name": "default-to-latest-version",
"valueBoolean": true
},
{
"name": "valueSet",
"resource": {
"resourceType": "ValueSet",
"url": "http://hl7.org/fhir/uv/ips/ValueSet/results-laboratory-observations-uv-ips--0",
"version": "current",
"status": "active",
"compose": {
"include": [
{
"system": "http://loinc.org",
"filter": [
{
"property": "STATUS",
"op": "=",
"value": "ACTIVE"
},
{
"property": "CLASSTYPE",
"op": "=",
"value": "1"
}
]
}
]
}
}
},
{
"name": "cache-id",
"valueId": "5a375c37-d208-4381-b8f7-409926dcf760"
},
{
"name": "profile",
"resource": {
"resourceType": "Parameters",
"parameter": [
{
"name": "profile-url",
"valueString": "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}
]
}
},
{
"name": "mode",
"valueString": "lenient-display-validation"
}
]
}
valueSetMode is sometimes set to NO_MEMBERSHIP_CHECK, other times to CHECK_MEMERSHIP_ONLY. It is linked to
enum ValidationOptions.ValueSetMode: ALL_CHECKS, CHECK_MEMERSHIP_ONLY, NO_MEMBERSHIP_CHECK.
The response contains the code if it is valid, and an OperationOutcome otherwise:
{
"resourceType": "Parameters",
"parameter": [
{
"name": "result",
"valueBoolean": true
},
{
"name": "system",
"valueUri": "http://snomed.info/sct"
},
{
"name": "code",
"valueCode": "10828004"
},
{
"name": "version",
"valueString": "http://snomed.info/sct/900000000000207008/version/20230901"
},
{
"name": "display",
"valueString": "Positive"
}
]
}
{
"resourceType": "Parameters",
"parameter": [
{
"name": "version",
"valueString": "2.74"
},
{
"name": "result",
"valueBoolean": false
},
{
"name": "message",
"valueString": "The provided code 'http://loinc.org#697-3' is not in the value set 'http://fhir.ch/ig/ch-elm/ValueSet/ch-elm-expecting-specimen-specification--0|1.0.0'"
},
{
"name": "issues",
"resource": {
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"code": "code-invalid",
"details": {
"text": "The provided code 'http://loinc.org#697-3' is not in the value set 'http://fhir.ch/ig/ch-elm/ValueSet/ch-elm-expecting-specimen-specification--0|1.0.0'"
},
"location": [
"Coding"
]
}
]
}
}
]
}
The request contains both the code to be checked, and the value set to check it against, as well as some parameters.
The second type is to check the validity of a code in a code system:
{
"resourceType": "Parameters",
"parameter": [
{
"name": "coding",
"valueCoding": {
"system": "http://loinc.org",
"code": "697-3"
}
},
{
"name": "default-to-latest-version",
"valueBoolean": true
},
{
"name": "cache-id",
"valueId": "5a375c37-d208-4381-b8f7-409926dcf760"
},
{
"name": "profile",
"resource": {
"resourceType": "Parameters",
"parameter": [
{
"name": "profile-url",
"valueString": "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}
]
}
},
{
"name": "mode",
"valueString": "lenient-display-validation"
}
]
}
The response is similar to the previous one.
The responsible code for these parts is BaseWorkerContext.validateOnServer().
A cache is also implemented with the parameter cache-id: within the same cache, the TX client does not need to
send a resource (ValueSet) again if it has already been sent.
E.g.
{
"resourceType": "Parameters",
"parameter": [
{
"name": "coding",
"valueCoding": {
"system": "http://loinc.org",
"code": "697-3"
}
},
{
"name": "default-to-latest-version",
"valueBoolean": true
},
{
"name": "url",
"valueUri": "http://fhir.ch/ig/ch-elm/ValueSet/ch-elm-expecting-specimen-specification--0|1.0.0"
},
{
"name": "cache-id",
"valueId": "a5ca9e93-2834-485b-9640-378503755211"
},
{
"name": "profile",
"resource": {
"resourceType": "Parameters",
"parameter": [
{
"name": "profile-url",
"valueString": "http://hl7.org/fhir/ExpansionProfile/dc8fd4bc-091a-424a-8a3b-6198ef146891"
}
]
}
}
]
}
url points to a ValueSet that has been sent in a previous request, with the same cache-id.
Caching
Code validation results are cached in a TerminologyCache. Since org.hl7.fhir.core 7.0.1, the cache of a context is
in memory only until initTxCache(folder) is called. matchbox-server writes it to a folder per terminology server when
the validation parameter txServerCache is true (the default), and disables the caching when it is false. With
matchbox-engine, engine.useTxCacheFolder(folder) stores the cache in a folder, engine.disableTxCache() disables it
(engine.initTxCache(folder) is deprecated).