> For the complete documentation index, see [llms.txt](https://php-fhir-tools.ardenexal.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://php-fhir-tools.ardenexal.net/fhirpath/functions/types.md).

# Type Conversion & Checking

## Conversion

Each `toX()` function converts a single-item input to the target type (returning empty when conversion is not possible). Each `convertsToX()` companion returns a Boolean reporting whether the conversion would succeed, without performing it.

| Function                                            | Description                                   | Example                              |
| --------------------------------------------------- | --------------------------------------------- | ------------------------------------ |
| `toBoolean()` / `convertsToBoolean()`               | Convert to / test convertibility to Boolean.  | `'true'.toBoolean()` → `true`        |
| `toInteger()` / `convertsToInteger()`               | Convert to / test convertibility to Integer.  | `'42'.toInteger()` → `42`            |
| `toDecimal()` / `convertsToDecimal()`               | Convert to / test convertibility to Decimal.  | `'3.14'.toDecimal()`                 |
| `toDate()` / `convertsToDate()`                     | Convert to / test convertibility to Date.     | `'2024-01-15'.toDate()`              |
| `toDateTime()` / `convertsToDateTime()`             | Convert to / test convertibility to DateTime. | `'2024-01-15T10:00:00'.toDateTime()` |
| `toTime()` / `convertsToTime()`                     | Convert to / test convertibility to Time.     | `'10:30:00'.toTime()`                |
| `toQuantity([unit])` / `convertsToQuantity([unit])` | Convert to / test convertibility to Quantity. | `'5 mg'.toQuantity()`                |
| `toString()` / `convertsToString()`                 | Convert to / test convertibility to String.   | `(42).toString()` → `'42'`           |

## Checking

| Function       | Description                                                | Example                                 |
| -------------- | ---------------------------------------------------------- | --------------------------------------- |
| `ofType(type)` | Filters the collection to items of the given type.         | `Bundle.entry.resource.ofType(Patient)` |
| `type()`       | Returns type information (namespace + name) for each item. | `Patient.active.type()`                 |

{% hint style="info" %}
Type specifiers accept both the `System.` namespace (e.g. `System.Boolean`) and the `FHIR.` namespace (e.g. `FHIR.Patient`). For runtime type testing with the `is` and `as` operators, see [Expressions & Operators](/fhirpath/expressions.md).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://php-fhir-tools.ardenexal.net/fhirpath/functions/types.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
