This document captures clarifications and interpretations of ambiguous or unclear aspects of the FHIR specification as implemented in Pathling.
FHIR Spec Reference: Search - Quantity
The FHIR specification defines the quantity search format as [prefix][number]|[system]|[code] but does not clearly specify:
- Which combinations of empty/present system and code are valid
- The semantics of an empty system component (e.g.,
5.4||kg)
Based on analysis of the token search parameter specification and practical considerations, Pathling implements the following interpretation:
| Format | Example | System | Code | Description |
|---|---|---|---|---|
[number] |
5.4 |
any | any | Value-only search |
[number]|[system]|[code] |
5.4|http://unitsofmeasure.org|kg |
exact | exact | Full match with system and code |
[number]||[code] |
5.4||kg |
any | exact | Match code in any system |
| Format | Example | Reason |
|---|---|---|
[number]|[system]| |
5.4|http://unitsofmeasure.org| |
Empty code with non-empty system is not supported |
An empty or omitted system component is interpreted as "match any system" (no constraint). This differs from token search where |[code] specifically matches resources where the system is not present (null).
Rationale: The quantity search format [number]|[system]|[code] is structurally different from token search [system]|[code]. Requiring users to match null-system quantities would be an unusual use case, and the simpler "any system" interpretation is more practical.
QuantitySearchValue.java- Parses and validates the formatQuantityMatcher.java- Implements the matching logic
FHIR Spec Reference: Search - Quantity
The FHIR specification mentions that quantity searches "should" support UCUM unit conversion but does not specify the exact implementation details:
- When should normalization be applied?
- How should failures in normalization be handled?
- Should range semantics (eq/ne) apply to canonicalized values?
Pathling implements UCUM normalization with the following behavior:
UCUM normalization is applied when all of the following conditions are met:
- The search specifies a system component
- The system is the UCUM system (
http://unitsofmeasure.org) - The search specifies a code component
- The UCUM library successfully canonicalizes the search value and code
If any of these conditions is not met, the matcher falls back to standard value comparison.
When UCUM normalization applies:
- The search value and code are canonicalized using the UCUM library
- Comparison is performed against pre-computed canonical values in the resource's Quantity struct
- This enables matching across equivalent unit representations (e.g.,
1000|http://unitsofmeasure.org|mgmatches a resource with value1 g)
For eq and ne prefixes with canonical values, Pathling uses exact equality comparison rather than range-based semantics. This is because:
- Canonicalization already normalizes values to a consistent form
- Range semantics based on significant figures are less meaningful after unit conversion
- Exact comparison provides more predictable behavior
Rationale: If a user searches for 1000|http://unitsofmeasure.org|mg, this canonicalizes to approximately 0.001 g. An exact match against the resource's canonical value is more intuitive than applying range semantics to the original "1000" value.
If canonicalization fails (e.g., unknown unit, invalid code), the matcher:
- Does not throw an error
- Falls back to standard value comparison with exact system/code matching
- This ensures searches remain functional even for non-standard units
QuantityMatcher.java- ContainstryMatchWithUcumNormalization()method- Uses
Ucum.getCanonical()for value/unit canonicalization - Compares against
_value_canonicalizedand_code_canonicalizedfields in Quantity struct