Conversion
FHIRPath defines both implicit and explicit conversion. Implicit conversions occur automatically, as opposed to explicit conversions that require a function in this section to be called explicitly.
ConvertsToBoolean
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath convertsToBoolean()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return True
if:
- the item is a Boolean
- the item is an Integer
that is equal to one of the possible integer representations of Boolean
values
- the item is a Decimal
that is equal to one of the possible decimal representations of Boolean
values
- the item is a String
that is equal to one of the possible string representations of Boolean
values
If the item is not one of the above types, or the item is a String
, Integer
, or Decimal
, but is not equal to one of the possible values convertible to a Boolean
, the result is false.
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 |
---|---|
int
|
bool |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ConvertsToDate
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath convertsToDate()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return True
if:
- the item is a Date
- the item is a DateTime
- the item is a String
and is convertible to a Date
If the item is not one of the above types, or is not convertible to a Date
(using the format YYYY-MM-DD
), the result is False
.
If the item contains a partial date (e.g. '2012-01'
), the result is a partial date.
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 |
---|---|
int
|
bool |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ConvertsToDateTime
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath convertsToDateTime()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return True
if:
- the item is a DateTime
- the item is a Date
, in which case the result is a DateTime
with the year, month, and day of the Date
, and the time components empty (not set to zero)
- the item is a String
and is convertible to a DateTime
If the item is a String
, but the string is not convertible to a DateTime
(using the format YYYY-MM-DDThh:mm:ss.fff(+|-)hh:mm
), the result is False
.
If the item contains a partial datetime (e.g. '2012-01-01T10:00'
), 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 |
---|---|
int
|
bool |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ConvertsToDecimal
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath convertsToDecimal()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return True
if:
- the item is an Integer
or Decimal
- the item is a String
and is convertible to a Decimal
- the item is a Boolean
, where True
results in a 1.0
and False
results in a 0.0
.
If the item is not one of the above types, or is not convertible to a Decimal
, the result is False
.
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 |
---|---|
int
|
bool |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ConvertsToInteger
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath convertsToInteger()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return True
if:
- the item is an Integer
- the item is a String
and is convertible to an integer
- the item is a Boolean
, where True
results in a 1 and False
results in a 0.
If the item is not one of the above types, or the item is a String
, but is not convertible to an Integer
, the result is false.
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 |
---|---|
int
|
bool |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ConvertsToQuantity
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath convertsToQuantity()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return True
if:
- the item is an Integer
, or Decimal
, where the resulting quantity will have the default unit ('1'
)
- the item is a Quantity
- the item is a String
and is convertible to a Quantity
- the item is a Boolean
, where true results in the quantity 1.0 '1'
, and false results in the quantity 0.0 '1'
If the item is not one of the above types, the result is False
.
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 |
---|---|
int
|
bool |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ConvertsToString
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath convertsToString()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return True
if:
- the item in the input collection is a String
- the item in the input collection is an Integer
, Decimal
, Date
, Time
, DateTime
, or Quantity
the output will contain its String
representation
- the item is a Boolean
, where true results in 'true'
and false in 'false'
.
If the item is not one of the above types, the result is False
.
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 |
---|---|
int
|
bool |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ConvertsToTime
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath convertsToTime()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return True
if:
- the item is a Time
- the item is a String
and is convertible to a Time
If the item is a String
, but the string is not convertible to a DateTime
(using the format hh:mm:ss.fff(+|-)hh:mm
), the result is False
.
If the item contains a partial datetime (e.g. '10:00'
), 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 |
---|---|
int
|
bool |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
FHIRTypeConversionFunction
Bases: FHIRPathFunction
Abstract class definition for the category of type conversion FHIRPath functions.
Source code in fhircraft/fhir/path/engine/conversion.py
validate_collection(collection, *args, **kwargs)
Validates the input collection of a FHIRPath type conversion 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. |
Source code in fhircraft/fhir/path/engine/conversion.py
Iif
Bases: FHIRPathFunction
A representation of the FHIRPath iif()
function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criterion |
FHIRPath
|
The criterion expression, is expected to evaluate to a |
required |
true_result |
Union[FHIRPath, Any]
|
Value to be returned if |
required |
otherwise_result |
Optional[Union[FHIRPath, Any]]
|
Value to be returned if |
None
|
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
Thif function acts as an immediate if, also known as a conditional operator.
If criterion
evaluates to True
, the function returns the value of the true_result
argument.
If true_result
is a FHIRPath expression it is evaluated.
If criterion
is False
or an empty collection, the function returns the otherwise_result
argument,
unless the optional otherwise_result
is not given, in which case the function returns an empty collection.
If otherwise_result
is a FHIRPath expression it is evaluated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
int
|
Converted value |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ToBoolean
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath toBoolean()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return a single Boolean
if:
- the item is a Boolean
- the item is an Integer
that is equal to one of the possible integer representations of Boolean
values
- the item is a Decimal
that is equal to one of the possible decimal representations of Boolean
values
- the item is a String
that is equal to one of the possible string representations of Boolean
values
If the item is not one of the above types, or the item is a String
, Integer
, or Decimal
, but is not equal to one of the possible values convertible to a Boolean
, the result is false.
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 |
---|---|---|
bool |
int
|
Converted value |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ToDate
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath toDate()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return a single date if:
- the item is a Date
- the item is a DateTime
- the item is a String
and is convertible to a Date
If the item is not one of the above types, or is not convertible to a Date
(using the format YYYY-MM-DD
), the result is empty.
If the item contains a partial date (e.g. '2012-01'
), the result is a partial date.
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 |
---|---|---|
str |
int
|
Converted value |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ToDateTime
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath toDateTime()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return a single datetime if:
- the item is a DateTime
- the item is a Date
, in which case the result is a DateTime
with the year, month, and day of the Date
, and the time components empty (not set to zero)
- the item is a String
and is convertible to a DateTime
If the item is a String
, but the string is not convertible to a DateTime
(using the format YYYY-MM-DDThh:mm:ss.fff(+|-)hh:mm
), the result is empty.
If the item contains a partial datetime (e.g. '2012-01-01T10:00'
), the result is a partial datetime.
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 |
---|---|---|
str |
int
|
Converted value |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ToDecimal
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath toDecimal()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return a single decimal if:
- the item is an Integer
or Decimal
- the item is a String
and is convertible to a Decimal
- the item is a Boolean
, where True
results in a 1.0
and False
results in a 0.0
.
If the item is not one of the above types, the result is empty ([]
).
If the item is a String
, but the string is not convertible to a Decimal
, the result is empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
int
|
Converted value |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ToInteger
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath toInteger()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return a single Integer
if:
- the item is an Integer
- the item is a String
and is convertible to an integer
- the item is a Boolean
, where True
results in a 1 and False
results in a 0.
If the item is not one the above types, the result is empty ([]
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
List[FHIRPathCollectionItem]
|
The input collection. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Converted value |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ToQuantity
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath toQuantity()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return a single quantity if:
- the item is an Integer
, or Decimal
, where the resulting quantity will have the default unit ('1'
)
- the item is a Quantity
- the item is a String
and is convertible to a Quantity
- the item is a Boolean
, where true results in the quantity 1.0 '1'
, and false results in the quantity 0.0 '1'
If the item is not one of the above types, the result is empty.
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 |
---|---|---|
Quantity |
int
|
Converted value |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ToString
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath toString()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return a single string if:
- the item in the input collection is a String
- the item in the input collection is an Integer
, Decimal
, Date
, Time
, DateTime
, or Quantity
the output will contain its String
representation
- the item is a Boolean
, where true results in 'true'
and false in 'false'
.
If the item is not one of the above types, the result is empty.
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 |
---|---|---|
str |
int
|
Converted value |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |
Source code in fhircraft/fhir/path/engine/conversion.py
ToTime
Bases: FHIRTypeConversionFunction
A representation of the FHIRPath toTime()
function.
Source code in fhircraft/fhir/path/engine/conversion.py
evaluate(collection, *args, **kwargs)
If the input collection contains a single item, this function will return a single time if:
- the item is a Time
- the item is a String
and is convertible to a Time
If the item is a String
, but the string is not convertible to a Time
(using the format hh:mm:ss.fff(+|-)hh:mm
), the result is empty.
If the item contains a partial datetime (e.g. '10:00'
), the result is a partial datetime.
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 |
---|---|---|
str |
int
|
Converted value |
Raises:
Type | Description |
---|---|
FHIRPathError
|
If input collection has more than one item. |