Strings
The functions in this section operate on collections with a single item. If there is more than one item, or an item that is not a String, the evaluation of the expression will end and signal an error to the calling environment.
To use these functions over a collection with multiple items, one may use filters like where()
and select()
:
Patient.name.given.select(substring(0))
Concatenation
Bases: FHIRPath
A representation of the FHIRPath &
operator.
Attributes:
Name | Type | Description |
---|---|---|
left |
FHIRPath
|
Left operand. |
right |
FHIRPath
|
Right operand. |
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
For strings, will concatenate the strings, where an empty operand is taken to be the empty string. This differs from + on two strings, which will result in an empty collection when one of the operands is empty. This operator is specifically included to simplify treating an empty collection as an empty string, a common use case in string manipulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
result |
str
|
Concatenated string |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If either expression evaluates to a non-singleton collection. |
Source code in fhircraft/fhir/path/engine/strings.py
Contains
Bases: StringManipulationFunction
A representation of the FHIRPath contains()
function.
Attributes:
Name | Type | Description |
---|---|---|
substring |
str
|
Substring to query. |
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Returns true when the given substring is a substring of the input string.
If substring is the empty string (''
), the result is True
.
If the input collection is empty, the result is empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the string contains |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Note
Note: The FHIRPath .contains()
function described here is a string function that looks
for a substring in a string. This is different than the contains
FHIRPath operator, which
is a list operator that looks for an element in a list.
Source code in fhircraft/fhir/path/engine/strings.py
EndsWith
Bases: StringManipulationFunction
A representation of the FHIRPath endsWith()
function.
Attributes:
Name | Type | Description |
---|---|---|
suffix |
str
|
String suffix to query. |
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Returns true when the input string ends with the given suffix.
If suffix is the empty string (''
), the result is True
.
If the input collection is empty, the result is empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the string ends with |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Source code in fhircraft/fhir/path/engine/strings.py
IndexOf
Bases: StringManipulationFunction
A representation of the FHIRPath indexOf()
function.
Attributes:
Name | Type | Description |
---|---|---|
substring |
str
|
Subtring query. |
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Returns the 0-based index of the first position substring is found in the input string,
or -1
if it is not found.
If substring is an empty string (''
), the function returns 0
.
If the input or substring is empty ([]
), the result is empty ([]
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
index |
int
|
Index of the first position of |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Source code in fhircraft/fhir/path/engine/strings.py
Length
Bases: StringManipulationFunction
A representation of the FHIRPath length()
function.
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Returns the length of the input string. If the input collection is empty ([]
), the result is empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
length |
int
|
Length of the string |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Source code in fhircraft/fhir/path/engine/strings.py
Lower
Bases: StringManipulationFunction
A representation of the FHIRPath lower()
function.
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Returns the input string with all characters converted to lower case. If the input collection is empty, the result is empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
str
|
Lower case string. |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Source code in fhircraft/fhir/path/engine/strings.py
Matches
Bases: StringManipulationFunction
A representation of the FHIRPath matches()
function.
Attributes:
Name | Type | Description |
---|---|---|
regex |
str
|
Regular expression to match. |
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Returns True
when the value matches the given regular expression. Regular expressions
should function consistently, regardless of any culture- and locale-specific settings
in the environment, should be case-sensitive, use 'single line' mode and allow Unicode characters.
If the input collection or regex are empty, the result is empty ([]
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether string matches the regular expression |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Source code in fhircraft/fhir/path/engine/strings.py
Replace
Bases: StringManipulationFunction
A representation of the FHIRPath replace()
function.
Attributes:
Name | Type | Description |
---|---|---|
pattern |
str
|
Substring to substitute. |
substitution |
str
|
String to substitute |
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Returns the input string with all instances of pattern
replaced with substitution
.
If the substitution is the empty string (''
), instances of pattern are removed from the result.
If pattern is the empty string (''
), every character in the input string is surrounded by
the substitution, e.g. 'abc'.replace('','x')
becomes 'xaxbxcx'
.
If the input collection, pattern, or substitution are empty, the result is empty ({ }).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
str
|
Substituted string |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Source code in fhircraft/fhir/path/engine/strings.py
ReplaceMatches
Bases: StringManipulationFunction
A representation of the FHIRPath replaceMatches()
function.
Attributes:
Name | Type | Description |
---|---|---|
regex |
str
|
Regular expression to substitute. |
substitution |
str
|
String to substitute |
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Matches the input using the regular expression in regex and replaces each match with the
substitution string. The substitution may refer to identified match groups in the regular expression.
If the input collection, regex, or substitution are empty, the result is empty ([]
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
str
|
Substituted string |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Source code in fhircraft/fhir/path/engine/strings.py
StartsWith
Bases: StringManipulationFunction
A representation of the FHIRPath startsWith()
function.
Attributes:
Name | Type | Description |
---|---|---|
prefix |
str
|
String prefix to query. |
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Returns true when the input string starts with the given prefix.
If prefix is the empty string (''
), the result is True
.
If the input collection is empty, the result is empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the string starts with |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Source code in fhircraft/fhir/path/engine/strings.py
StringManipulationFunction
Bases: FHIRPathFunction
Abstract class definition for category of string manipulation FHIRPath functions.
Source code in fhircraft/fhir/path/engine/strings.py
validate_collection(collection, *args, **kwargs)
Validates the input collection of a FHIRPath string manipulation function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
Collection to be validated. |
required |
Returns:
Name | Type | Description |
---|---|---|
collection |
List[FHIRPathCollectionItem]
|
Validated collection. |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Source code in fhircraft/fhir/path/engine/strings.py
Substring
Bases: StringManipulationFunction
A representation of the FHIRPath substring()
function.
Attributes:
Name | Type | Description |
---|---|---|
start |
int
|
Start index of the substring. |
end |
Optional[int]
|
End index of the substring. |
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Returns the part of the string starting at position start (zero-based). If length is given, will
return at most length number of characters from the input string.
If start lies outside the length of the string, the function returns empty ([]
). If there are
less remaining characters in the string than indicated by length, the function returns just the
remaining characters.
If the input or start is empty, the result is empty.
If an empty length is provided, the behavior is the same as if length had not been provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
substring |
str
|
The substring indexed by the |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Source code in fhircraft/fhir/path/engine/strings.py
ToChars
Bases: StringManipulationFunction
A representation of the FHIRPath toChars()
function.
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Returns the list of characters in the input string. If the input collection is empty ([]
), the result is empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
characters |
List[FHIRPathCollectionItem])
|
Collection of characters in the string |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |
Source code in fhircraft/fhir/path/engine/strings.py
Upper
Bases: StringManipulationFunction
A representation of the FHIRPath upper()
function.
Source code in fhircraft/fhir/path/engine/strings.py
evaluate(collection, *args, **kwargs)
Returns the input string with all characters converted to upper case. If the input collection is empty, the result is empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
string |
str
|
Upper case string. |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
FHIRPathError
|
If the item in the input collection is not a string. |