Class DefaultMappings
- All Implemented Interfaces:
Mappings
- Direct Known Subclasses:
SpringMappings
Mappings implementation, backed by one forward and one reverse index per
mapping. Both indices are built once, when the mapping is registered, and are never rebuilt
afterwards — which is what keeps loading a second mapping source from disturbing the
mappings loaded from the first.
Reads are lock-free against an immutable snapshot; registration is serialized, and validates each mapping against what is already registered - which is what lets a lookup follow delegations and composites without checking them again.
This is the extension point for wiring the mapping service into a container: a subclass may add
whatever way of naming a source that container prefers and calls load(URL). See
SpringMappings in ipf-commons-spring, which takes Spring Resources.
- Since:
- 6.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface Mappings
Mappings.Builder -
Constructor Summary
ConstructorsConstructorDescriptionApplies every discoveredMappingFunctionProvider, so that a mapping file shipped with the functions it names works without any configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Forgets every mapping.voidReads a mapping source and registers everything it contains.voidReads a mapping source in a format named explicitly, for a source whose name does not identify one - a ConceptMap fetched over HTTP, a file calledgender.xml- or where the file extension is not the loader the caller wants.voidload(URL url, MappingLoader loader) Reads a mapping source with an explicitly provided loader, which need not be one theServiceLoadercan see.Looks up a key without applying the mapping'sunmatchedbehavior.lookupReverse(String mapping, String value) Looks up a value without applying the mapping'sreverse unmatchedbehavior.mappingsFor(String keySystem, String valueSystem) Finds mappings by the code systems they translate between, rather than by name.voidRegisters a single mapping, validating it against the model's constraints.voidregisterFunction(String name, Function<String, String> function) Registers a function thatUnmatched.Computedfallbacks can name, replacing any registered before under that name.reverseUnmatched(String mapping, String value) Applies a mapping's reverse unmatched behavior to a value, without looking it up first.voidsetAllowOverride(boolean allowOverride) Whether an existing mapping may be overridden to a mapping definition registered latervoidsetAllowReverseCollisions(boolean allowReverseCollisions) Whether a mapping may register two invertible entries sharing a value, in which case the last one declared wins the reverse index.Maps a key likeMappings.map(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.translateReverse(String mapping, String value) Maps a value back likeMappings.mapReverse(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) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Mappings
entries, map, map, mappingFor, mapReverse, mapReverse
-
Constructor Details
-
DefaultMappings
public DefaultMappings()Applies every discoveredMappingFunctionProvider, so that a mapping file shipped with the functions it names works without any configuration.
-
-
Method Details
-
functions
- Specified by:
functionsin interfaceMappings- Returns:
- read access to the registered functions; register them with
registerFunction(String, java.util.function.Function)
-
registerFunction
Registers a function thatUnmatched.Computedfallbacks can name, replacing any registered before under that name. Register it before loading a source that names it: a source naming an unknown function is rejected as it is read.- Parameters:
name- function namefunction- the function; it must tolerate anullargument
-
load
Reads a mapping source and registers everything it contains.- Parameters:
url- location of the source; theMappingLoaderis selected by its file extension
-
load
Reads a mapping source in a format named explicitly, for a source whose name does not identify one - a ConceptMap fetched over HTTP, a file calledgender.xml- or where the file extension is not the loader the caller wants.- Parameters:
url- location of the sourceformat- aformat idsuch asxmlorconceptmap-r4-json, ornullto select the loader by file extension
-
load
Reads a mapping source with an explicitly provided loader, which need not be one theServiceLoadercan see. -
register
-
clear
public void clear()Forgets every mapping. Thefunctionsstay registered: they are configuration, which mapping sources loaded afterwards refer to just as before. -
mapping
-
mappingNames
- Specified by:
mappingNamesin interfaceMappings- Returns:
- the names of all registered mappings, in registration order
-
mappingsFor
Description copied from interface:MappingsFinds 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.
- Specified by:
mappingsForin interfaceMappings- 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
-
lookup
-
lookupReverse
Description copied from interface:MappingsLooks up a value without applying the mapping'sreverse unmatchedbehavior.- Specified by:
lookupReversein interfaceMappings- 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
-
unmatched
Description copied from interface:MappingsApplies a mapping's unmatched behavior to a key, without looking the key up first. -
reverseUnmatched
Description copied from interface:MappingsApplies a mapping's reverse unmatched behavior to a value, without looking it up first.- Specified by:
reverseUnmatchedin interfaceMappings- Parameters:
mapping- mapping namevalue- right side of the mapping- Returns:
- the fallback key, empty if the mapping declares no reverse fallback
-
translate
Description copied from interface:MappingsMaps a key likeMappings.map(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. -
translateReverse
Description copied from interface:MappingsMaps a value back likeMappings.mapReverse(String, String), and says which code system the answer belongs to and how it is displayed.- Specified by:
translateReversein interfaceMappings- 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
- See Also:
-
keySystem
-
valueSystem
- Specified by:
valueSystemin interfaceMappings- Parameters:
mapping- mapping name- Returns:
- formal identifier of the value code system, empty if the mapping declares none
-
keys
- Specified by:
keysin interfaceMappings- 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
-
values
-
setAllowOverride
public void setAllowOverride(boolean allowOverride) Whether an existing mapping may be overridden to a mapping definition registered later -
setAllowReverseCollisions
public void setAllowReverseCollisions(boolean allowReverseCollisions) Whether a mapping may register two invertible entries sharing a value, in which case the last one declared wins the reverse index. Off by default: a value with two inverses is a load-time error, since the alternative is a reverse lookup that silently answers whichever key happened to be written last.
-