# isValidFHIR

Industry: Healthcare

:::caution[Unreleased]
Not in `@northguild/gmt` 1.21.0 on npm yet. It is on `main` and ships in the next release.
:::

## Signature

```ts
isValidFHIR(value: string, type: FhirDateType): boolean
isValidFHIR(value: void | {} | null | undefined, type: FhirDateType): boolean
isValidFHIR(value: unknown, type: FhirDateType): value is string
```

Return true when `value` is a real FHIR R4 `date`, `dateTime` or `instant`, as `type` names.

- FHIR R4 (v4.0.1) Datatypes §2.24.0.1 defines the three types. The check reads the value with the reader `parseFHIR` uses, so `isValidFHIR(v, "dateTime")` is true exactly when `parseFHIR(v)` returns a value.
- The type adds a precision rule to one grammar: `date` takes a day or coarser, `instant` takes a second or finer, and `dateTime` takes all five precisions.
- The R4 regexes (`fhirDate`, `fhirDateTime`, `fhirInstant`) are shape only. They accept 30 February, a second of `60` on any day and a fraction of any length; this validator refuses all three. A second of `60` is valid only on an inserted leap second, and a fraction holds at most nine digits (**GMT rules**).
- A time with no zone is invalid as every type, unlike HL7 v2. `24:00` and an offset past `±14:00` are invalid.
- A type name is case-sensitive; an unknown `type` returns false.
- A value that is not a string, a `String` object included, returns false. Never throws. A true result narrows an `unknown` value to `string`.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | any value; a string is checked as a FHIR date type |
| `type` | `FhirDateType` | `"date"`, `"dateTime"` or `"instant"` |

## Returns

boolean indicating validity

## Related types

- [`FhirDateType`](/gmt/reference/types/FhirDateType/)

## Examples

```ts
import { isValidFHIR } from "@northguild/gmt/healthcare/validate";

isValidFHIR("2024-06", "date") // true
```

## Source

[healthcare/validate/isValidFHIR.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/healthcare/validate/isValidFHIR.ts)
