isValidFHIR
Signature
Section titled “Signature”isValidFHIR(value: string, type: FhirDateType): booleanisValidFHIR(value: void | {} | null | undefined, type: FhirDateType): booleanisValidFHIR(value: unknown, type: FhirDateType): value is stringReturn 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
parseFHIRuses, soisValidFHIR(v, "dateTime")is true exactly whenparseFHIR(v)returns a value. - The type adds a precision rule to one grammar:
datetakes a day or coarser,instanttakes a second or finer, anddateTimetakes all five precisions. - The R4 regexes (
fhirDate,fhirDateTime,fhirInstant) are shape only. They accept 30 February, a second of60on any day and a fraction of any length; this validator refuses all three. A second of60is 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:00and an offset past±14:00are invalid. - A type name is case-sensitive; an unknown
typereturns false. - A value that is not a string, a
Stringobject included, returns false. Never throws. A true result narrows anunknownvalue tostring.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | any value; a string is checked as a FHIR date type |
type | FhirDateType | "date", "dateTime" or "instant" |
Returns
Section titled “Returns”boolean indicating validity
Related types
Section titled “Related types”Examples
Section titled “Examples”import { isValidFHIR } from "@northguild/gmt/healthcare/validate";
isValidFHIR("2024-06", "date") // trueSource
Section titled “Source”© 2026 NorthGuild · Licences
Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.