Repository navigation
feat(domination): read and write HL7 v2 timestamps (HLTH-93, #401) - #494
Conversation
Add the healthcare namespace with parseHL7, formatHL7 and isValidHL7. An HL7 time with no offset is the sender's local time, not UTC. parseHL7 returns it as a local kind with no instant, so the caller supplies the sender's zone to resolveLocal. A value coarser than a minute is partial and has no instant. A TS degree of precision only lowers the precision, so 199904011200^L is April 1999, not 12:00. formatHL7 writes a DTM, cut to the precision and never rounded. On the Dox site, add the HL7 Timestamp Reader tool, a clinical timestamps guide, two scenarios, a mistakes page and the Healthcare industry. Add the gmt-healthcare agent skill.
…l7-v2-timestamps # Conflicts: # README.md # apps/dox/src/data/gmt-stats.json # apps/dox/src/lib/dox-tools.ts # packages/gmt/README.md # scripts/bundle-size.budgets.json
|
/craig-review |
There was a problem hiding this comment.
code-reviewer: minor issues
This adds the healthcare namespace (parseHL7, formatHL7, isValidHL7), its types, subpaths, a changeset and an agent skill. On the Dox side it adds the HL7 Timestamp Reader, a guide, scenarios, a mistakes page, and an optional reference mark on the shared timeline kit. The library code is careful: every field goes through Temporal with overflow: "reject", the code never throws, a degree of precision only lowers, and the tables check the edge cases well. I found no defects in the library. The three findings are a factual error on the tool page, an "As sent" ladder column in the Reader that drops fraction digits that were sent, and a scoped exception in the coding standards that does not describe the second regex the formatter relies on.
Reviewed c3f1cfb for craig-o-curtis · claude-opus-5-5 · 81 files · $0.94
The writer ladder built its source from fromOffsetInstant, which drops trailing zeros from a fraction, so 20240615103000.1000+0000 wrote .1 in the fraction row and .0000 wrote no result. A value sent to the minute also got a seconds row the sender never sent. The ladder now writes from parseHL7's local at the precision sent, with the offset for an instant. The UTC column and zone 1's column put the sent fraction back and cut a minute value to the minute. New tests cover .1000, .0000, a minute value and a local value in zone 1. Review wording fixes: - The Reader page's four kinds now match the guide's table. - The coding-standards exception names isoHl7Form and what it may read, and no longer says formatHL7 uses fromOffsetInstant. The same claim is corrected in decisions.md and the hl7DateTime.ts header.
|
Answers to the four open questions:
|
Answers the four owner questions settled in review of #494. A sender writes ^ only before another populated component (ch. 2 2.6.1.1), and a recipient treats a component not sent as not present (2.6.2). splitHl7Ts now drops every trailing ^ before it splits, so 20240615^D^ reads as 20240615^D and the null value followed by an empty degree reads as kind null. A third component that is not empty (20240615^D^X) still returns null, and so does a degree after the null value. New rows cover both sides in the parse, validate and split tables. The HL7 Timestamp Reader drops the same empty components before it picks the reason under NO SIGNAL, so a third component that is not empty now gets the picture reason, not the degree reason. The hub text and the guide intro now give HL7 International's own claim for version 2, from the HL7 TSC product list, in place of the unsourced most of their records. decisions.md moves the four questions to the settled list, records the approved 581300 B root budget and the rule for #493, and opens one new question: 2.6.2 also says to ignore a component that was not expected, which would read 20240615^D^X as 20240615^D.
|
Thanks. All four are in 8e3daea.
I made one change you did not ask for. The HL7 Timestamp Reader chooses the sentence it shows under NO SIGNAL by parsing the text before the first One new question, recorded as open question (e) in
Read that way, a recipient would read |
|
/craig-review |
There was a problem hiding this comment.
code-reviewer follow-up: minor issues
Since c3f1cfb, the branch settles the open TS questions. Empty trailing ^ components are now dropped before a TS is split, so 20240615^D^ reads as 20240615^D and '""^' reads as the null value, while a third component that is not empty still returns null. The Reader's writer ladder now keeps the digits as sent (no made-up seconds, trailing fraction zeros kept), and the hub text and guide intro cite HL7 International instead of the unsourced claim. The new splitting, null-value handling, NO SIGNAL reason and ladder logic check out against the updated tests and docs. My one note is that the new loops are while loops, which the coding standards ask new code to avoid.
Reviewed 8e3daea (changes since c3f1cfb) for craig-o-curtis · claude-opus-5-5 · 16 files · $0.32
The coding standards ask new code to avoid while loops (Loop Style). This branch added three: the trailing ^ trim in splitHl7Ts, the trailing empty component trim in the Reader's sentinelText, and the fraction digit scan in the Reader's inSentForm. The first two are now bounded for loops over one pass of the input. The scan is an anchored regex for a dot and its digits, which cannot backtrack. No change in behaviour; the existing rows cover all three.
craig-o-curtis
left a comment
There was a problem hiding this comment.
Approving. parseHL7, formatHL7 and isValidHL7 read the DTM and TS rules correctly, and the for loops in ccf40ac give the same results as the while loops did. Please make these changes before you merge.
1. The open question: 20240615^D^X reads as 20240615^D. HL7 v2.5.1 chapter 2, §2.6.2, rule 1, tells a recipient to ignore segments, fields, components, subcomponents, and extra repetitions of a field that are present but were not expected. §2.8.1 and §2.8.2 say new components are added at the end of a data type, so a reader that refuses them breaks on a later version. The PR already uses rule 3 of the same section to drop empty trailing components.
splitHl7Ts(internal/hl7DateTime.ts:211-213) keeps the first two components and ignores the rest.20240615^D^X,20240615^^Dand20240615^D^X^move from the null rows to the read rows.^^Dand""^Dstay null.- The JSDoc of
splitHl7Ts,parseHL7andisValidHL7,decisions.mdand the skill cite §2.6.2 instead of a GMT rule.
2. Subcomponents are ignored by the same rule. Read each component only up to its first &, so 2024&X reads as 2024, and 2024^D&X and 2024&X^D read as 2024 with degree D. An empty part before the & means the component is not present, so &X stays null. A lone field carries no MSH-2, so the JSDoc should say the reader assumes the separators Figure 2-1 recommends, ^ and & (§2.5.4). The code already assumes ^. Add rows for each case, and keep isValidHL7 equal to parseHL7 !== null.
3. Narrow the precision types (types/hl7.ts:53, :66, :85). Each kind accepts all seven precisions, but parseHL7 returns only 10 of the 21 pairs. For example, { kind: "partial", precision: "fraction" } type-checks but can never come back. Suggest Hl7MomentPrecision = "minute" | "second" | "fraction" for instant and local, and Hl7PartialPrecision = "year" | "month" | "day" | "hour" for partial, with Hl7Precision as their union for Hl7FormatOptions.
4. Smaller fixes:
context/coding-standards.md:176says the extracted fields go toTemporal.PlainYearMonth.from.formatHL7passes it a string (formatHL7.ts:190), and it reads the day withisValidDateand thenPlainDate.from(:198). Please describe what the code does.context/domination/issues/HLTH-93.md:178still says four open owner questions.decisions.md:23gives the root as 575497 B. It measures 575594 B at ccf40ac, and the formula gives 581400. Whichever PR merges second sets the figure, so please record the current measurement.
|
@baldurpan #493 is merged, so this branch now conflicts with This PR now merges second, so after the merge please measure the root again. Set I'll approve again once CI is green on the merged branch. The notes in my approval are still wanted before you merge. |
|
The notes from your approval come next, in one push. |
Review of #494 asked for four changes. A TS read on its own carries no MSH-2, so ^ separates its components and & their subcomponents, as Figure 2-1 recommends (ch. 2 2.5.4). A receiver ignores what is present but not expected (2.6.2), and a later version adds components at the end (2.8.1, 2.8.2). splitHl7Ts now reads two components, each up to its first &: 20240615^D^X reads as 20240615^D and 2024&X as 2024. An empty DTM, as in ^D and &X, still returns null. isValidHL7 stays parseHL7 !== null. Hl7DateTime narrows its precision by kind: Hl7PartialPrecision (year to hour) for partial values, Hl7MomentPrecision (minute to fraction) for instant and local ones. Hl7Precision is their union. The HL7 Timestamp Reader draws ignored parts as their own dashed box and probes the first component cut at & for its NO SIGNAL reason. The guide, the skill, decisions.md, coding-standards.md and built.md say the new rule; the open owner question is settled. The root bundle measures 578210 B, inside the 584000 budget.
|
All four are in affd826. 1. What is not expected is ignored (§2.6.2, §2.8.1, §2.8.2). 2. Subcomponents. Each component is read up to its first One difference from your list: 3. Narrower types. 4. Smaller fixes.
Run locally: the HL7 tests (418), the gmt |
Closes #405 (AV-97). ## Summary This adds an `aviation` namespace that reads, writes and checks the date in IATA SSIM airline schedule files. An SSIM date is `DDMMMYY`, such as `01JAN26`. It is not ISO 8601, and no `Temporal.*.from` reads it. Two mistakes are common with it. Code that reads the month through the platform's language breaks on a machine that is not set to English. Code that picks the century itself is wrong for either an archive or a forward schedule. Here the month letters are a fixed code, and the caller states the century. The Dox site gains the SSIM Date Reader and an aviation guide. ## What Changed ### 1. Library: `@northguild/gmt/aviation` - `parseSsimDate(value, options)` reads an SSIM date and returns an ISO date. - `formatSsimDate(value, options)` writes an ISO date as an SSIM date. It returns `""` for a year outside the window, because written as two digits that year would read back as another century. It takes only an ISO calendar date. - `isValidSsimDate(value, options)` calls the parser, so the two cannot disagree. - **The month is a fixed English code.** The letters `JAN` to `DEC` are a constant table, never read through `Intl` and never case-folded. `01jan26`, `01ENE26` and `01JANV26` are refused, and the answer is the same under every locale in the matrix. - **The century is the caller's.** `options.yearWindow` is required, with no default (INT-15's `TwoDigitYearOptions`). Without it the parser and formatter return `""` and the validator returns `false`. - **A day that does not exist is refused** by Temporal with `overflow: "reject"`. Examples are `29FEB25` and `31APR26`. - Subpaths `/parse`, `/format` and `/validate`. Sentinels are `""` and `false`. Nothing throws. - The grammar is one regex in `internal/ssimDate.ts`, and `context/coding-standards.md` gains a scoped exception for it. Nothing is added to `regex/`: a value is a date only once its century is known, so no pattern can say whether it is valid. ### 2. Dox - The SSIM Date Reader at `/tools/ssim-date-reader/`, with the chat tool `showSsimDateReader`, a starter and the permalink `ssim`. It reads a date with the window you state, beside `parseDateWithPattern` under a locale you pick, so the reader sees why a locale parser gets the month wrong. It also writes an ISO date back. It opens on a French-locale preset so the difference shows straight away. - The guide Aviation: Message Times, `/mistakes/aviation/`, and the scenario An SSIM Month Read in the Wrong Language. - The Aviation industry: hub text, a control tower glyph and an example area. - The gate scripts (contrast, grow, HTML diff, readout-still, visual snapshot) list the new tool page. ### 3. Agent skill - A `gmt-aviation` TanStack Intent skill. It is in `skill_tree.yaml` and `domain_map.yaml`, in the skills install command, and in the worker vocabulary. ### 4. Merge with main - main gained HLTH-93 (#494) while this branch was open. Both industries, namespaces, skills and chat tools are kept, with main's first: `showHl7TimestampReader` is `DOX_TOOL_DOCS[45]` and `showSsimDateReader` is `DOX_TOOL_DOCS[46]`. - On the merged tree, the gmt build and `pnpm dox:generate` were run again, and the corpus holds both stories' functions. Stats and both READMEs were regenerated with `pnpm stats:sync`, and `stats check` and `api-surface check` pass. The root bundle is 579,106 bytes, under its 584,000 budget. ## Why - Airlines exchange schedules in SSIM files. Their dates are a code, not a sentence in a language, and their two-digit years say nothing about the century. - Both mistakes are silent: nothing fails, and the date comes out wrong. ## Sources - IATA does not publish SSIM openly, and the Chapter 7 text was not reached. The JSDoc says so in one line. - EUROCONTROL's CSST Users Guide (§3.2, Figure 1) shows the seven-character form. ACL (UK) shows the day and the month letters, and Avinor shows the two-digit year. The owner accepted these sources as meeting the story's bar. The full table is in `context/domination/issues/AV-97.md`. ## Validation All on the tree after the merge with main: - `pnpm validate` ran all 23 checks. 21 passed before it stopped at `test:dox`, which failed one test: `head-tags.test.ts` found no `dateModified` on the HL7 guide `healthcare-clinical-timestamps`. That date comes from `git log`, and the merge was not yet committed, so no commit that HEAD could reach had the HL7 guide. - After the merge commit, `node scripts/affected.mjs run --only dox-pages,build:dox,test:dox,test:gmt` rebuilt the site and ran both suites. All 4 checks passed: `test:dox` 19,053 of 19,053 tests and `test:gmt` 73,261 of 73,261. - `node scripts/stats.mjs check` and `node scripts/api-surface.mjs check` pass on the merged tree. ## Risk / Impact Low. The namespace is new, and nothing existing changes behaviour. The Dox changes add one tool, one guide and one industry. ## Release `.changeset/aviation-ssim-dates.md`: `@northguild/gmt` minor, for the new namespace. Merging publishes nothing.
Closes #401 (HLTH-93).
Summary
This adds a
healthcarenamespace that reads and writes HL7 v2 date-times (DTM, and the olderTS). HL7 says a time with no offset is the sender's local time. A parser that reads it as UTC moves every event by the sender's offset. Here that value comes back askind: 'local'with no instant, so the caller supplies the sender's zone toresolveLocal. The Dox site gains the HL7 Timestamp Reader and a clinical timestamps guide.What Changed
1. Library:
@northguild/gmt/healthcareparseHL7(value)returns an instant, a local time, a partial value or the HL7 null value. A value coarser than a minute is partial and has no instant. ATSdegree of precision only lowers the precision, so199904011200^Lis April 1999, not 12:00.formatHL7(isoString, { precision })writes aDTM, cut to the precision and never rounded. It never writesTS, which HL7 withdrew in v2.6.isValidHL7(value)is true exactly whenparseHL7reads the value./parse,/formatand/validate. TypesHl7DateTime,Hl7PrecisionandHl7FormatOptions. Sentinels arenull, an empty string andfalse. Nothing throws.context/coding-standards.mdgains a scoped exception for the HL7 grammar regex ininternal/hl7DateTime.ts. Its fields are always handed to Temporal.2. Dox
/tools/hl7-timestamp-reader/, with a chat tool and a starter./mistakes/healthcare/.referencemark. The DTM Decoder and X12 Time Reader pass none, and their visual diffs are 0.000% against main.namespace-summary.tsgained a healthcare line. The spec did not name it.3. Agent skill
gmt-healthcareTanStack Intent skill, inskill_tree.yamlanddomain_map.yaml, listed in the skills and install docs and in the worker vocabulary.4. Merge with main
showTerrestrialTimeStackisDOX_TOOL_DOCS[43]andshowHl7TimestampReaderisDOX_TOOL_DOCS[44].pnpm stats:syncon the merged tree. They now count 745 functions.Why
DTMorTS. Reading a time with no offset as UTC is a silent error: nothing fails, and the event moves by the sender's offset.Temporal.*.fromreads aDTMor aTS.Validation
All on the tree after the merge with main:
pnpm validateran all 23 checks. 21 passed.test:doxfailed on one timeout:billing-deadlines-mount.test.tsx, orders dates across year 9999, ran past 20 s while that file took 113 s under full-suite load. That file passes alone (62 of 62 in 18.7 s), and this branch does not touch it or what it imports.test:doxandtest:gmt(the step that had not run yet) were run again withnode scripts/affected.mjs run --only test:dox,test:gmt. Both passed.node scripts/bundle-size.mjs checkpasses with the root budget at 581300.Risk / Impact
Low. The new namespace adds subpaths and changes no existing function. The Dox timeline kit change is opt-in, and the two tools that use the kit render the same as before.
Release
One changeset,
.changeset/hl7-v2-timestamps.md, minor for@northguild/gmt. No changeset for the Dox part. Merging publishes nothing.For the reviewer: four open questions
These are not decided. They are recorded in
context/domination/issues/HLTH-93/decisions.md.20240615^D^returnsnullbecause a thirdTScomponent is refused. Chapter 2 §2.6.2 suggests it could read as20240615^D. Should it?'""^'returnsnull, not the HL7 null value. Should it read as the null value?scripts/bundle-size.budgets.jsonrises from 570400 (main after SPA-47) to 581300 B. That is the 575497 B measured with both stories in, plus 1%, rounded up to the next 100 asbundle-size.mjs --updatedoes. Is the raise approved?INDUSTRY_OVERVIEWS.healthcare.aboutand the guide intro has no source. Keep, source or cut?Checklist