Skip to content

isValidFHIR

  • Timestamps in HL7 and FHIR clinical data: a precision set by what is sent, and a time with no offset, which HL7 reads as local time and FHIR refuses.
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.
ParameterTypeDescription
valuestringany value; a string is checked as a FHIR date type
typeFhirDateType"date", "dateTime" or "instant"

boolean indicating validity

import { isValidFHIR } from "@northguild/gmt/healthcare/validate";
isValidFHIR("2024-06", "date") // true
output 

healthcare/validate/isValidFHIR.ts

© 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.