Interface Mappings
- All Known Implementing Classes:
DefaultMappings, SpringMappings
Mappings, whatever format they were loaded from.
Compared to the older MappingService this interface is String-typed and
returns Optional rather than null, so call sites no longer cast. An unknown
mapping name is a programming error and raises IllegalArgumentException;
an unknown key within a known mapping yields an empty Optional.
Mappings instances can be built programmatically like this:
var mappings = Mappings.builder()
.function("oidUri", s -> !s.isEmpty() && Character.isDigit(s.charAt(0)) ? "urn:oid:" + s : s)
.load("classpath:/META-INF/map/atna2fhir.mapping.xml")
.build();
String uri = mappings.map("atnaCodingSystem", "DCM").orElseThrow();
- Since:
- 6.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classAssembles aMappingsinstance from mapping sources and named functions. -
Method Summary
Modifier and TypeMethodDescriptionstatic Mappings.Builderbuilder()The entries a mapping declares, whatever its kind: those of aSimpleMapping, and for aCompositeMappingthose of its parts, in part order.Looks up a key without applying the mapping'sunmatchedbehavior.lookupReverse(String mapping, String value) Looks up a value without applying the mapping'sreverse unmatchedbehavior.default StringmappingFor(String keySystem, String valueSystem) Where aCompositeMappingmatches together with some of its parts, the composite stands for them: it answers for all of them, so asking the whole of a ConceptMap by its source system finds the ConceptMap rather than failing on its groups.mappingsFor(String keySystem, String valueSystem) Finds mappings by the code systems they translate between, rather than by name.mapReverse(String mapping, String value) default StringmapReverse(String mapping, String value, String defaultKey) reverseUnmatched(String mapping, String value) Applies a mapping's reverse unmatched behavior to a value, without looking it up first.default Optional<Translation> Maps a key likemap(String, String), and says which code system the answer belongs to and how it is displayed - what a caller needs to build a coded value from it.default Optional<Translation> translateReverse(String mapping, String value) Maps a value back likemapReverse(String, String), and says which code system the answer belongs to and how it is displayed.Applies a mapping's unmatched behavior to a key, without looking the key up first.valueSystem(String mapping)
-
Method Details
-
mapping
-
mappingNames
-
mappingsFor
Finds mappings by the code systems they translate between, rather than by name.A caller holding a code to translate knows which code system it is in and which one it wants, not what the mapping happens to be called - which is the shape of FHIR's
ConceptMap/$translate, and the only way to reach a mapping read from a source that names itself, such as a ConceptMap resource. Either argument may benullfor "any", so passing only a key system finds every mapping that translates out of it.This is a scan over the registered mappings, not an index: resolve the mapping once and keep it, rather than calling this per message.
- Parameters:
keySystem- identifier of the key code system, ornullfor anyvalueSystem- identifier of the value code system, ornullfor any- Returns:
- the matching mappings, in registration order
-
mappingFor
Where aCompositeMappingmatches together with some of its parts, the composite stands for them: it answers for all of them, so asking the whole of a ConceptMap by its source system finds the ConceptMap rather than failing on its groups.- Parameters:
keySystem- identifier of the key code system, ornullfor anyvalueSystem- identifier of the value code system, ornullfor any- Returns:
- the single mapping translating between the two systems, empty if there is none
- Throws:
IllegalArgumentException- if several mappings translate between them, since picking one of them would be arbitrary - usemappingsFor(String, String)to see them all- See Also:
-
lookup
Looks up a key without applying the mapping'sunmatchedbehavior.- Parameters:
mapping- mapping namekey- left side of the mapping- Returns:
- the value declared for that key, empty if the mapping declares no entry for it
- Throws:
IllegalArgumentException- if the mapping name is not registered
-
lookupReverse
Looks up a value without applying the mapping'sreverse unmatchedbehavior.- Parameters:
mapping- mapping namevalue- right side of the mapping- Returns:
- the key declared for that value, empty if the mapping declares no invertible entry for it
- Throws:
IllegalArgumentException- if the mapping name is not registered
-
unmatched
Applies a mapping's unmatched behavior to a key, without looking the key up first.- Parameters:
mapping- mapping namekey- left side of the mapping- Returns:
- the fallback value, empty if the mapping declares no fallback
- Throws:
IllegalArgumentException- if the mapping name is not registered
-
reverseUnmatched
Applies a mapping's reverse unmatched behavior to a value, without looking it up first.- Parameters:
mapping- mapping namevalue- right side of the mapping- Returns:
- the fallback key, empty if the mapping declares no reverse fallback
- Throws:
IllegalArgumentException- if the mapping name is not registered
-
map
- Parameters:
mapping- mapping namekey- left side of the mapping- Returns:
- the mapped value, falling back to the mapping's unmatched behavior
- Throws:
IllegalArgumentException- if the mapping name is not registered
-
map
- Parameters:
mapping- mapping namekey- left side of the mappingdefaultValue- value to return if neither an entry nor a fallback yields one- Returns:
- the mapped value or
defaultValue - Throws:
IllegalArgumentException- if the mapping name is not registered
-
mapReverse
- Parameters:
mapping- mapping namevalue- right side of the mapping- Returns:
- the key mapping to that value, falling back to the mapping's reverse unmatched behavior
- Throws:
IllegalArgumentException- if the mapping name is not registered
-
mapReverse
- Parameters:
mapping- mapping namevalue- right side of the mappingdefaultKey- key to return if neither an entry nor a fallback yields one- Returns:
- the reverse-mapped key or
defaultKey - Throws:
IllegalArgumentException- if the mapping name is not registered
-
translate
Maps a key likemap(String, String), and says which code system the answer belongs to and how it is displayed - what a caller needs to build a coded value from it.The system is that of the mapping which actually answered: a
compositeanswers with the system of the part that had the answer, adelegatingfallback with that of the mapping delegated to. Anidentityfallback answers with the key itself, and so with the key system.The default implementation knows none of that and answers with the mapping's value system and no display;
DefaultMappingsoverrides it.- Parameters:
mapping- mapping namekey- left side of the mapping- Returns:
- the mapped value with its system and display, falling back to the mapping's unmatched behavior
- Throws:
IllegalArgumentException- if the mapping name is not registered
-
translateReverse
Maps a value back likemapReverse(String, String), and says which code system the answer belongs to and how it is displayed.- Parameters:
mapping- mapping namevalue- right side of the mapping- Returns:
- the key mapping to that value with its system and display, falling back to the mapping's reverse unmatched behavior
- Throws:
IllegalArgumentException- if the mapping name is not registered- See Also:
-
keySystem
- Parameters:
mapping- mapping name- Returns:
- formal identifier of the key code system, empty if the mapping declares none
- Throws:
IllegalArgumentException- if the mapping name is not registered
-
valueSystem
- Parameters:
mapping- mapping name- Returns:
- formal identifier of the value code system, empty if the mapping declares none
- Throws:
IllegalArgumentException- if the mapping name is not registered
-
keys
- Parameters:
mapping- mapping name- Returns:
- the keys this mapping translates, in declaration order. A key declared only by a
Equivalence.DISJOINTentry is not among them, because it does not translate. The keys of a mapping this one delegates to follow its own, since a lookup asks that mapping for every key this one does not declare; keys that only a fallback such as identity answers are not listed. For acompositethey are the keys of all its parts. Changes to the set do not change the mapping - Throws:
IllegalArgumentException- if the mapping name is not registered
-
values
- Parameters:
mapping- mapping name- Returns:
- the values this mapping translates to, in declaration order. Changes to the collection do not change the mapping
- Throws:
IllegalArgumentException- if the mapping name is not registered- See Also:
-
entries
The entries a mapping declares, whatever its kind: those of aSimpleMapping, and for aCompositeMappingthose of its parts, in part order. Unlikekeys(String), this is the declaration -disjointentries included, and a key declared by several parts listed once per part.- Parameters:
mapping- mapping name- Returns:
- the declared entries, in declaration order
- Throws:
IllegalArgumentException- if the mapping name is not registered
-
functions
MappingFunctions functions()- Returns:
- read access to the functions available to
Unmatched.Computedfallbacks. Functions are registered while building, withMappings.Builder.function(String, Function); a built instance cannot be changed through what this returns
-
builder
-