Skip to content

isValidHL7

  • 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.
isValidHL7(value: string): boolean

Return true when value is an HL7 v2 DTM, or a TS with a degree of precision the digits carry, that parseHL7 reads.

  • HL7 v2.5.1 2.A.22 (headed 2.A.1.22 in the hl7.eu v2.5.1 copy) defines the DTM YYYY[MM[DD[HH[MM[SS[.S[S[S[S]]]]]]]]][+/-ZZZZ]; 2.A.77 the TS.
  • True exactly when parseHL7 returns a reading: the validator calls the parser, so the two cannot disagree.
  • The null value '""' (two double quote marks) is valid, because ch. 2 §2.5.3 makes it a value that clears the stored one; '' is not.
  • A valid value is not necessarily an instant: parseHL7 reads a value at a minute or finer with no offset as "local", one at year to hour precision as "partial" (with or without an offset), and '""' as "null".
  • Components are read as parseHL7 reads them: ^ separates them (ch. 2 §2.5.4). GMT reads TS.1 as exactly a DTM and TS.2 as one code, so 2024&X is not valid (GMT’s strict-kind rule). Components after TS.2 are ignored (§2.6.2), so 20240615^D^X is valid unless one holds |, ~ or a C0 control character.
  • No public regex exists: a DTM is valid only as a whole (calendar, clock, offset and degree of precision together), which a pattern alone cannot check.
  • False for a value that is not a string. Never throws.
ParameterTypeDescription
valuestringHL7 v2 DTM or TS string

boolean indicating validity

import { isValidHL7 } from "@northguild/gmt/healthcare/validate";
isValidHL7("20240615103000-0500") // true
output 

healthcare/validate/isValidHL7.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.