# isValidHL7

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

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | HL7 v2 `DTM` or `TS` string |

## Returns

boolean indicating validity

## Examples

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

isValidHL7("20240615103000-0500") // true
```

## Source

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