From bf0f9595357bd6f1552eb0bfd5fee4932fc448cd Mon Sep 17 00:00:00 2001 From: Noah Schatz Date: Sun, 29 Nov 2026 13:57:03 -0500 Subject: [PATCH] build(deps): move to @cosyte/hl7, fhir and x12 0.2 Bump the three parsers to 0.2, update every comparison to their prefixed codes, move transforms, examples, guides and tests from setField to withField, give the v2 XML example its own ORU_R01 groups now that the library ships none, and record the moved outputs in the equivalence files. C-CDA stays on 0.1. --- .changeset/format-libraries-0-2.md | 11 + README.md | 14 + bench/engine.mjs | 6 +- bench/profile.mjs | 5 +- docs-content/api/README.md | 14 +- docs-content/example-file-to-sftp.md | 4 +- docs-content/example-filter-and-route.md | 4 +- docs-content/example-mllp-to-http.md | 4 +- docs-content/example-replay-after-failure.md | 4 +- docs-content/example-vet-lab-to-fhir.md | 2 +- docs-content/example-vet-lab-to-v2-xml.md | 67 +++-- docs-content/logs-and-codes.md | 4 +- docs-content/quickstart.md | 3 +- docs-content/read-batch-files.md | 6 +- docs-content/send-a-lab-result-as-v2-xml.md | 18 +- docs-content/transform-and-filter-messages.md | 13 +- docs-content/use-the-message-context.md | 6 +- docs-content/work-with-formats.md | 6 +- docs-content/write-a-channel.md | 3 +- docs-content/write-custom-connectors.md | 3 +- .../channels/adt-to-lab/transform.ts | 3 +- .../channels/orders-to-lab/transform.ts | 4 +- .../channels/results-out/transform.ts | 4 +- .../channels/adt-to-http/transform.ts | 4 +- .../channels/adt-to-registry/transform.ts | 4 +- examples/vet-lab-to-fhir/package.json | 2 +- .../tests/oru-1.expected.hl7 | 18 +- .../tests/oru-2.expected.hl7 | 18 +- .../tests/oru-3.expected.hl7 | 22 +- .../tests/oru-4.expected.hl7 | 26 +- .../channels/vet-results-to-xml/transform.ts | 35 ++- examples/vet-lab-to-v2-xml/package.json | 2 +- examples/vet-lab-to-v2-xml/scripts/lab.ts | 10 +- package.json | 6 +- pnpm-lock.yaml | 54 ++-- scripts/bench.ts | 2 +- src/connectors/ack.ts | 5 +- src/connectors/batch.ts | 14 +- src/connectors/mllp.ts | 2 +- src/connectors/types.ts | 2 +- src/engine/worker-entry.ts | 19 +- src/extensions/events.ts | 2 +- src/transform.ts | 3 +- .../starter/channels/adt-to-lab/transform.ts | 3 +- test/ack-load.test.ts | 2 +- test/batch-engine.test.ts | 12 +- test/batch.test.ts | 25 +- test/channel-control.test.ts | 15 +- test/content-none.test.ts | 2 +- test/control.test.ts | 8 +- test/engine-http.test.ts | 2 +- test/engine.test.ts | 9 +- test/equivalence/digests.json | 284 +++++++++--------- test/equivalence/pathways-test.json | 26 +- test/examples.test.ts | 2 +- test/format-equivalence.test.ts | 6 +- test/helpers.ts | 5 +- test/hl7v2-charset.test.ts | 8 +- test/http-source-options.test.ts | 4 +- test/mllp-engine.test.ts | 4 +- test/mllp-source.test.ts | 4 +- test/output-equivalence.test.ts | 12 +- test/run-tests.test.ts | 12 +- test/store.test.ts | 6 +- test/transform-types.test.ts | 3 +- test/verify.test.ts | 18 +- test/worker-entry.test.ts | 49 ++- test/worker-memory.test.ts | 6 +- 68 files changed, 498 insertions(+), 487 deletions(-) create mode 100644 .changeset/format-libraries-0-2.md diff --git a/.changeset/format-libraries-0-2.md b/.changeset/format-libraries-0-2.md new file mode 100644 index 00000000..667c3070 --- /dev/null +++ b/.changeset/format-libraries-0-2.md @@ -0,0 +1,11 @@ +--- +"@cosyte/pathways": patch +--- + +Pathways now parses with `@cosyte/hl7` 0.2, `@cosyte/fhir` 0.2 and `@cosyte/x12` 0.2, so a parse or write code from HL7 v2 or FHIR carries its library's prefix in logs, stored errors, ACK problems and `pathways test` output: `HL7_NO_MSH_SEGMENT` where it was `NO_MSH_SEGMENT`, `FHIR_MALFORMED_JSON` where it was `MALFORMED_JSON`. + +An HL7 batch's envelope warnings are `HL7_BATCH_COUNT_MISMATCH` and `HL7_BATCH_MISSING_TRAILER`, where they were `BATCH_COUNT_MISMATCH` and `BATCH_MISSING_TRAILER`, and an HL7 v2 output refused for a character its set cannot hold fails with `HL7_ENCODE_UNENCODABLE_CHARACTER`. The default ACK's ERR-3.2 for condition 207 now reads "Application error", the text of HL7 table 0357, where it read "Application internal error". C-CDA and `xml` channels still read with `@cosyte/ccda` 0.1. + +A transform receives the 0.2 models. In an HL7 v2 dot-path a field repetition now counts from 1: `PID.3[1]` is the first identifier, and `PID.3[0]` is refused; a segment occurrence such as `OBX[0]` still counts from 0. `setField` still changes the message in place but is deprecated: `withField` returns a new message, which the transform returns. `XML_GROUP_TABLES` is empty, so `toHl7Xml` takes every structure's groups in `groups`. A FHIR resource is deep-frozen, so an assignment to it throws, and it carries the reader's `warnings`. The starter's transform, the examples and the guides now use `withField`. + +What a caller must change: compare against the prefixed codes; add 1 to every field repetition index in a dot-path your transforms use; build a FHIR resource with `complex`, `list` and `primitive` rather than editing the one a transform receives; pass `groups` to `toHl7Xml` where you read `XML_GROUP_TABLES`; and install `@cosyte/hl7` 0.2 and `@cosyte/fhir` 0.2 where a project imports them beside Pathways. diff --git a/README.md b/README.md index 34f6f7f8..b4b893d2 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ version is 0.0.x, and a release may still change a key or an API, which its chan - [Quickstart](#quickstart) - [Why this exists](#why-this-exists) - [What the latest release ships](#what-the-latest-release-ships) +- [In the next release](#in-the-next-release) - [Status](#status) - [Build from source](#build-from-source) - [Layout](#layout) @@ -229,6 +230,19 @@ What follows is in 0.0.6, the version on npm: --- +## In the next release + +These are on `main` and land in the next release, not in 0.0.6: + +- **The 0.2 parsers for HL7 v2, FHIR and X12.** Pathways parses with `@cosyte/hl7`, `@cosyte/fhir` + and `@cosyte/x12` 0.2. Their codes carry a prefix wherever Pathways reports one + (`HL7_NO_MSH_SEGMENT`, `FHIR_MALFORMED_JSON`, `HL7_BATCH_COUNT_MISMATCH`), and a transform + receives the 0.2 models: an HL7 v2 dot-path counts a field repetition from 1, `withField` + replaces `setField`, and a FHIR resource is frozen. C-CDA stays on `@cosyte/ccda` 0.1. + + +--- + ## Status Early, and released: 0.0.6 is on npm. Each release is published with provenance from this diff --git a/bench/engine.mjs b/bench/engine.mjs index 2c64441d..a812a17d 100644 --- a/bench/engine.mjs +++ b/bench/engine.mjs @@ -32,10 +32,8 @@ import { fileURLToPath } from "node:url"; export const TRANSFORMS = { // The starter's kind of edit: address each message to the lab, and send it on. hl7Address: [ - "export default (msg: { setField(path: string, value: string): void }) => {", - ' msg.setField("MSH.5", "LAB");', - " return msg;", - "};", + "export default (msg: { withField(path: string, value: string): unknown }) =>", + ' msg.withField("MSH.5", "LAB");', "", ].join("\n"), }; diff --git a/bench/profile.mjs b/bench/profile.mjs index ffa7f676..cfc89e17 100644 --- a/bench/profile.mjs +++ b/bench/profile.mjs @@ -269,10 +269,7 @@ function engineSection(bin, quick) { /** The channel's transform as the worker would load it from the TypeScript in bench/engine.mjs. */ function transformOf(channel) { if (channel.transform === TRANSFORMS.hl7Address) { - return (msg) => { - msg.setField("MSH.5", "LAB"); - return msg; - }; + return (msg) => msg.withField("MSH.5", "LAB"); } return (message) => [message]; } diff --git a/docs-content/api/README.md b/docs-content/api/README.md index aa902605..bf265740 100644 --- a/docs-content/api/README.md +++ b/docs-content/api/README.md @@ -376,7 +376,7 @@ nothing, the message's pass id, which no command can look up. > `readonly` **problem**: `string` \| `undefined` For an `unreadable` message, what was wrong, as a stable code: one of `@cosyte/hl7`'s parse -codes (such as `NO_MSH_SEGMENT`), `NO_CONTROL_ID`, `MULTIPLE_MESSAGES` or +codes (such as `HL7_NO_MSH_SEGMENT`), `NO_CONTROL_ID`, `MULTIPLE_MESSAGES` or `MLLP_TRAILING_BYTES`. ##### reason @@ -949,7 +949,7 @@ The pieces stored as new messages that are not failed. > `readonly` **warnings**: readonly `string`[] -The envelope's warning codes, such as `BATCH_COUNT_MISMATCH`, each once. +The envelope's warning codes, such as `HL7_BATCH_COUNT_MISMATCH`, each once. *** @@ -5290,7 +5290,7 @@ What a source can tell the engine about a message it hands over. Every field is ```ts await sink.receive(body, { duplicateKey: `${sender}|${controlId}` }); -await sink.receive(body, { failure: "inbound: NO_MSH_SEGMENT" }); +await sink.receive(body, { failure: "inbound: HL7_NO_MSH_SEGMENT" }); await sink.receive(body, { idempotencyKey: `queue|${deliveryTag}` }); await sink.receive(body, { idempotencyKey: `queue|${deliveryTag}`, resumed: true }); await sink.receive(body, { source: { queue: "inbound", deliveryTag } }); @@ -7096,7 +7096,7 @@ The channel's name. > `readonly` **code**: `string` \| `undefined` -The error's code, when it has one, such as a parser's `NO_MSH_SEGMENT`. +The error's code, when it has one, such as a parser's `HL7_NO_MSH_SEGMENT`. ##### kind @@ -7219,8 +7219,7 @@ import { defaultAckBuilder, type AckBuilder } from "@cosyte/pathways"; import { parseHL7 } from "@cosyte/hl7"; export default ((request) => { - const ack = parseHL7(Buffer.from(defaultAckBuilder(request))); - ack.setField("MSH.3", "PATHWAYS"); + const ack = parseHL7(Buffer.from(defaultAckBuilder(request))).withField("MSH.3", "PATHWAYS"); return Buffer.from(ack.toString()); }) satisfies AckBuilder; ``` @@ -8637,8 +8636,7 @@ import type { Transform } from "@cosyte/pathways"; export default ((msg) => { if (!msg.is("ADT^A01")) return null; - msg.setField("MSH.5", "LAB"); - return msg; + return msg.withField("MSH.5", "LAB"); }) satisfies Transform; ``` diff --git a/docs-content/example-file-to-sftp.md b/docs-content/example-file-to-sftp.md index 57ea5921..64fd59a8 100644 --- a/docs-content/example-file-to-sftp.md +++ b/docs-content/example-file-to-sftp.md @@ -144,9 +144,7 @@ import type { Transform } from "@cosyte/pathways"; export default ((msg) => { if (!msg.is("ORM^O01")) return null; // MSH-5 and MSH-6 are the receiving application and facility. - msg.setField("MSH.5", "LAB"); - msg.setField("MSH.6", "REFLAB"); - return msg; + return msg.withField("MSH.5", "LAB").withField("MSH.6", "REFLAB"); }) satisfies Transform; ``` diff --git a/docs-content/example-filter-and-route.md b/docs-content/example-filter-and-route.md index 1ff9213e..362fa147 100644 --- a/docs-content/example-filter-and-route.md +++ b/docs-content/example-filter-and-route.md @@ -140,9 +140,7 @@ export default ((msg) => { if (msg.get(`OBX[${String(i)}].11`) !== "F") return null; } // MSH-5 and MSH-6 are the receiving application and facility. - msg.setField("MSH.5", "EHR"); - msg.setField("MSH.6", "HOSPITAL"); - return msg; + return msg.withField("MSH.5", "EHR").withField("MSH.6", "HOSPITAL"); }) satisfies Transform; ``` diff --git a/docs-content/example-mllp-to-http.md b/docs-content/example-mllp-to-http.md index ae1e8899..e2128381 100644 --- a/docs-content/example-mllp-to-http.md +++ b/docs-content/example-mllp-to-http.md @@ -159,9 +159,7 @@ import type { Transform } from "@cosyte/pathways"; export default ((msg) => { if (!msg.is("ADT^A01") && !msg.is("ADT^A04") && !msg.is("ADT^A08")) return null; // MSH-5 and MSH-6 are the receiving application and facility. - msg.setField("MSH.5", "EHR"); - msg.setField("MSH.6", "HOSPITAL"); - return msg; + return msg.withField("MSH.5", "EHR").withField("MSH.6", "HOSPITAL"); }) satisfies Transform; ``` diff --git a/docs-content/example-replay-after-failure.md b/docs-content/example-replay-after-failure.md index 2ce8dae7..23818e69 100644 --- a/docs-content/example-replay-after-failure.md +++ b/docs-content/example-replay-after-failure.md @@ -184,9 +184,7 @@ export default (async (msg) => { // MSH-9.2 is the trigger event, such as A01. const code = codes[msg.get("MSH.9.2") ?? ""]; if (code === undefined) throw new Error("MSH-9.2 is not in event-codes.json"); - msg.setField("EVN.4", code); - msg.setField("MSH.5", "REGISTRY"); - return msg; + return msg.withField("EVN.4", code).withField("MSH.5", "REGISTRY"); }) satisfies Transform; ``` diff --git a/docs-content/example-vet-lab-to-fhir.md b/docs-content/example-vet-lab-to-fhir.md index 876107db..5c6fb64d 100644 --- a/docs-content/example-vet-lab-to-fhir.md +++ b/docs-content/example-vet-lab-to-fhir.md @@ -144,7 +144,7 @@ Its messages are synthetic, made by `@cosyte/synth`, and are on GitHub with the "test": "pathways test" }, "dependencies": { - "@cosyte/fhir": "^0.1.12", + "@cosyte/fhir": "^0.2.0", "@cosyte/transform": "^0.2.4" }, "devDependencies": { diff --git a/docs-content/example-vet-lab-to-v2-xml.md b/docs-content/example-vet-lab-to-v2-xml.md index e9551e68..0d5e0e33 100644 --- a/docs-content/example-vet-lab-to-v2-xml.md +++ b/docs-content/example-vet-lab-to-v2-xml.md @@ -21,8 +21,8 @@ about a real results service, and what it does not. - An [MLLP source](./send-and-receive-mllp.md) that stores each message before it sends the ACK. - A transform that writes each lab result with `toHl7Xml` from `@cosyte/hl7`: the segments placed in - the `ORU_R01` groups `@cosyte/hl7` ships for HL7 v2.5, and each field's components named for its - data type from a table in the transform. Every other message is filtered out. + `ORU_R01` groups from a table in the transform, made up for this example, and each field's + components named for its data type from another table there. Every other message is filtered out. - An [HTTP destination](./send-and-receive-http.md#settle-by-an-hl7-v2-xml-acknowledgement) with `ack: xml` that POSTs the document as `application/xml` over TLS, presents a client certificate, and settles each delivery by the acknowledgement's `MSA.1`: `AA` delivered, `AE` retried, `AR` @@ -30,8 +30,8 @@ about a real results service, and what it does not. - Three small scripts to try it with no other system: `scripts/dev-certs.ts` makes a development CA, server certificate and client certificate with `openssl`; `scripts/lab.ts` stands in for the results service, requires the client certificate, reads each POST with `parseHL7Xml` and answers - with an acknowledgement written by `toHl7Xml`, passing the `ACK` structure `@cosyte/hl7` ships no - table for; and `scripts/send.ts` sends files over MLLP. + with an acknowledgement written by `toHl7Xml`, passing the `ACK` structure, since `@cosyte/hl7` + ships no group table; and `scripts/send.ts` sends files over MLLP. The MLLP source runs plain TCP on the loopback (`plaintext: true`), for this example only. A lab system on another machine connects over TLS: see [Secure endpoints](./secure-endpoints.md). @@ -88,12 +88,12 @@ The destination sends them in order, one at a time, and the stand-in prints each its answer, never the content: ```text -POST /results: 2205 bytes to data/lab/1.xml, answered AA -POST /results: 2205 bytes to data/lab/2.xml, answered AE -POST /results: 2205 bytes to data/lab/3.xml, answered AA -POST /results: 2513 bytes to data/lab/4.xml, answered AR -POST /results: 2849 bytes to data/lab/5.xml, answered AA to another control id -POST /results: 2849 bytes to data/lab/6.xml, answered AA +POST /results: 2106 bytes to data/lab/1.xml, answered AA +POST /results: 2106 bytes to data/lab/2.xml, answered AE +POST /results: 2106 bytes to data/lab/3.xml, answered AA +POST /results: 2404 bytes to data/lab/4.xml, answered AR +POST /results: 2730 bytes to data/lab/5.xml, answered AA to another control id +POST /results: 2730 bytes to data/lab/6.xml, answered AA ``` - The first result is accepted and delivered. @@ -146,7 +146,7 @@ Its messages are synthetic, made by `@cosyte/synth`, and are on GitHub with the "test": "pathways test" }, "dependencies": { - "@cosyte/hl7": "^0.1.14" + "@cosyte/hl7": "^0.2.0" }, "devDependencies": { "@cosyte/pathways": "^0.0.6" @@ -207,7 +207,7 @@ destinations: // Writes each veterinary lab result (ORU^R01) in the HL7 v2 XML encoding with @cosyte/hl7's // writer, and filters every other message out. The HTTP destination POSTs the document and settles // the delivery by the XML acknowledgement the service answers with. -import { toHl7Xml, XML_GROUP_TABLES } from "@cosyte/hl7"; +import { toHl7Xml, type XmlMessageStructure } from "@cosyte/hl7"; import type { Transform } from "@cosyte/pathways"; /** @@ -251,19 +251,36 @@ const DATA_TYPES: Readonly> = { "OBX.14": "TS", }; +/** + * The groups the XML encoding places these results' segments in (ORU_R01.REPORT and the rest). The + * names and their order come from the receiver's schema, and @cosyte/hl7 ships none, so the writer + * is given them here. These are this example's own, made up for it and not a copy of any published + * structure: write yours from your receiver's schema. A segment with no place in them is refused. + */ +const GROUPS: XmlMessageStructure = { + structure: "ORU_R01", + items: [ + "MSH", + { + group: "REPORT+", + items: [ + "PID", + "NK1*", + { group: "ORDER+", items: ["OBR", { group: "RESULT*", items: ["OBX"] }] }, + ], + }, + ], +}; + export default ((msg) => { if (!msg.is("ORU^R01")) return null; - // The XML encoding places the segments in the message structure's groups - // (ORU_R01.PATIENT_RESULT and the rest), whose names come from each version's published schema. - // @cosyte/hl7 ships them for ORU_R01 in v2.5, which these results are. For another version or - // structure, pass the table your receiver's schema gives as groups, the way scripts/lab.ts passes - // the ACK's: this transform fails such a result rather than guess its groups. - const groups = XML_GROUP_TABLES[msg.version ?? ""]?.["ORU_R01"]; - if (groups === undefined) { + // The groups above are for the v2.5 results this example sends. For another version, pass the + // table your receiver's schema gives for it: this transform fails such a result rather than guess. + if (msg.version !== "2.5") { throw new Error("no ORU_R01 group table for this result's HL7 version (MSH-12)"); } - return toHl7Xml(msg, { dataTypes: DATA_TYPES, groups }); + return toHl7Xml(msg, { dataTypes: DATA_TYPES, groups: GROUPS }); }) satisfies Transform; ``` @@ -459,9 +476,9 @@ const ANSWERS = ["AA", "AE", "AR", "other-id"] as const; type Answer = (typeof ANSWERS)[number]; /** - * The ACK message structure, as the HL7 v2.5 standard gives it. @cosyte/hl7 ships group tables for - * ORU_R01 only, so the writer is given this one: an ACK has no groups, and the table also makes the - * writer refuse a segment that has no place in it. + * The ACK message structure, as the HL7 v2.5 standard gives it. @cosyte/hl7 ships no group table, + * so the writer is given this one: an ACK has no groups, and the table also makes the writer refuse + * a segment that has no place in it. */ const ACK_STRUCTURE: XmlMessageStructure = { structure: "ACK", @@ -495,8 +512,8 @@ mkdirSync(OUT, { recursive: true }); /** The XML acknowledgement to the message in `body`, with the answer `answer`. */ function acknowledge(body: string, answer: Answer): string { const message = parseHL7Xml(body); - const ack = buildAck(message, { code: answer === "other-id" ? "AA" : answer }); - if (answer === "other-id") ack.setField("MSA.2", "SYN-OTHER-0001"); + const built = buildAck(message, { code: answer === "other-id" ? "AA" : answer }); + const ack = answer === "other-id" ? built.withField("MSA.2", "SYN-OTHER-0001") : built; return toHl7Xml(ack, { dataTypes: ACK_DATA_TYPES, groups: ACK_STRUCTURE }); } diff --git a/docs-content/logs-and-codes.md b/docs-content/logs-and-codes.md index 59813510..e6cef4cb 100644 --- a/docs-content/logs-and-codes.md +++ b/docs-content/logs-and-codes.md @@ -217,7 +217,7 @@ a tcp destination's framing cannot carry. ## MLLP problem codes When an MLLP source stores a message as failed, the reason is one of `@cosyte/hl7`'s parse codes (such -as `NO_MSH_SEGMENT`), `NO_CONTROL_ID`, `MULTIPLE_MESSAGES` or `MLLP_TRAILING_BYTES`. An ACK builder +as `HL7_NO_MSH_SEGMENT`), `NO_CONTROL_ID`, `MULTIPLE_MESSAGES` or `MLLP_TRAILING_BYTES`. An ACK builder receives it as `problem`. `MULTIPLE_MESSAGES` means the frame held a second message header (`MSH`, `FHS` or `BHS`, in any case, behind or inside the id any bytes that are not printable ASCII, or a whole header such as `MSH|^~\&|` anywhere on a line): a frame is one message. On an `hl7v2` channel the engine stores a body from any other source that holds @@ -240,7 +240,7 @@ Besides the operating system's codes (`EACCES`, `EEXIST` and the like), a `sourc A file source with `batch:` sets a file aside with the `reason` `batch-too-large`, `batch-empty` or `batch-incomplete`, and stores it as a failed message with the error `batch: BATCH_FILE_TOO_LARGE`, `batch: BATCH_EMPTY` or `batch: BATCH_INCOMPLETE`. A piece of an HL7 batch that cannot be read is -stored as failed with `batch: ` and the parser's code, such as `batch: NO_MSH_SEGMENT`. An HTTP +stored as failed with `batch: ` and the parser's code, such as `batch: HL7_NO_MSH_SEGMENT`. An HTTP source with `batch:` answers 422 with `BATCH_EMPTY`, `BATCH_INCOMPLETE`, or `BATCH_KEY_REUSED` for an `Idempotency-Key` used before for another body, and stores nothing. diff --git a/docs-content/quickstart.md b/docs-content/quickstart.md index 4cf0d47d..5a402701 100644 --- a/docs-content/quickstart.md +++ b/docs-content/quickstart.md @@ -68,8 +68,7 @@ export default ((msg) => { // Only admissions go to the lab. Every other message is filtered out. if (!msg.is("ADT^A01")) return null; // MSH-5 is the receiving application. - msg.setField("MSH.5", "LAB"); - return msg; + return msg.withField("MSH.5", "LAB"); }) satisfies Transform; ``` diff --git a/docs-content/read-batch-files.md b/docs-content/read-batch-files.md index 1f3f4fbf..56e43c86 100644 --- a/docs-content/read-batch-files.md +++ b/docs-content/read-batch-files.md @@ -67,7 +67,7 @@ import type { Hl7Message, TransformContext } from "@cosyte/pathways"; export default (msg: Hl7Message, ctx: TransformContext): Hl7Message => { if (ctx.source?.kind === "file" && ctx.source.batch !== undefined) { - msg.setField("MSH.10", `${ctx.source.batch.hash}-${String(ctx.source.batch.piece)}`); + return msg.withField("MSH.10", `${ctx.source.batch.hash}-${String(ctx.source.batch.piece)}`); } return msg; }; @@ -92,7 +92,7 @@ with the code `BATCH_FILE_TOO_LARGE`. The file source's own `maxSize` still appl ## Pieces and files that cannot be read - With `split: hl7`, a piece `@cosyte/hl7` cannot read (text before the first `MSH`, a header too - short) is stored as a failed message, with an error such as `batch: NO_MSH_SEGMENT` and no + short) is stored as a failed message, with an error such as `batch: HL7_NO_MSH_SEGMENT` and no content. The pieces after it are stored as usual. - A file with no piece at all, such as one of blank lines, is failed whole with `BATCH_EMPTY`. @@ -159,7 +159,7 @@ one message with one ACK. Each batch read to the end is recorded in the [audit log](./read-the-audit-log.md) as a `batch` entry with counts only: `pieces`, `stored`, `failed` (stored as failed), and `duplicates` (stored before, by an earlier run or an earlier request). A file failed whole is recorded `refused`, with its -`reason`. An envelope warning, such as `BATCH_COUNT_MISMATCH` on a batch taken with `accept`, is +`reason`. An envelope warning, such as `HL7_BATCH_COUNT_MISMATCH` on a batch taken with `accept`, is in `warnings`. No entry, log line or error names a file or holds message text. ## Related diff --git a/docs-content/send-a-lab-result-as-v2-xml.md b/docs-content/send-a-lab-result-as-v2-xml.md index 9154c5e2..fe531217 100644 --- a/docs-content/send-a-lab-result-as-v2-xml.md +++ b/docs-content/send-a-lab-result-as-v2-xml.md @@ -30,17 +30,17 @@ The example's channel, `vet-results-to-xml`, does four things. Its files are on an `XPN`, so the family name is `XPN.1`), and a pipe-delimited message does not carry its types. The transform holds a table of the HL7 v2.5 type of each field the example's results fill that has components. A field with more than one component and no type in the table is refused with - `DATA_TYPE_UNKNOWN`, so the message fails rather than go out in a shape the receiver cannot + `HL7_XML_DATA_TYPE_UNKNOWN`, so the message fails rather than go out in a shape the receiver cannot read. A field with one value and no type in the table is written as text; check the table against your receiver's schema, or read the types from a sample document with `xmlDataTypes`. - **The groups.** The encoding places the segments in the message structure's groups - (`ORU_R01.PATIENT_RESULT`, `ORU_R01.ORDER_OBSERVATION` and the rest), and their names come from - each version's published schema. `@cosyte/hl7` ships the table for `ORU_R01` in v2.5, the - example's results, in `XML_GROUP_TABLES`. For a structure or version it has no table for, pass - the table your receiver's schema gives as `groups`, the way the example's stand-in passes the - `ACK` structure it writes its answers in. The transform fails a result of a version with no - table rather than guess. + (`ORU_R01.REPORT`, `ORU_R01.ORDER` and the rest), and their names come from your receiver's + schema. `@cosyte/hl7` ships no group table, so the transform holds one for `ORU_R01` and + passes it as `groups`, the way the example's stand-in passes the `ACK` structure it writes its + answers in. The example's groups are made up for it, not a copy of any published structure: + write yours from your receiver's schema. The transform fails a result of a version other + than v2.5 rather than guess. The document goes in the `urn:hl7-org:v2xml` namespace. A receiver that asks for none gets it with `namespace: null`. @@ -101,8 +101,8 @@ CI runs these on every change to Pathways, on synthetic messages only: - **Not the network's own message.** The network's public documents describe its results message as `OPU_R25` in the HL7 v2.6 XML encoding, answered by `ACK_R25` (see [For the animal diagnostic lab network](./send-and-receive-http.md#for-the-animal-diagnostic-lab-network)). - This example writes `ORU_R01` in v2.5, the structure `@cosyte/hl7` ships groups for. Building an - `OPU_R25`, its groups and its data types is for your transform, from the network's own schema. + This example writes `ORU_R01` in v2.5, in groups made up for it. Building an `OPU_R25`, its + groups and its data types is for your transform, from the network's own schema. - **No schema validation.** Nothing checks the document against a published XML schema. The data types in the transform's table are the v2.5 types of the fields these synthetic results fill, and a real lab's results will fill others. diff --git a/docs-content/transform-and-filter-messages.md b/docs-content/transform-and-filter-messages.md index 474ffea2..1237e329 100644 --- a/docs-content/transform-and-filter-messages.md +++ b/docs-content/transform-and-filter-messages.md @@ -28,9 +28,7 @@ import type { Transform } from "@cosyte/pathways"; export default ((msg) => { // Admissions and registrations go on; everything else is filtered out. if (!msg.is("ADT^A01") && !msg.is("ADT^A04")) return null; - msg.setField("MSH.5", "LAB"); - msg.setField("MSH.6", "SYNTHHOSP"); - return msg; + return msg.withField("MSH.5", "LAB").withField("MSH.6", "SYNTHHOSP"); }) satisfies Transform; ``` @@ -165,15 +163,15 @@ async function loinc(): Promise> { export default (async (msg) => { table ??= loinc(); const codes = await table; + let out = msg; for (let i = 0; i < msg.parts("OBX").length; i += 1) { const local = msg.get(`OBX[${i}].3.1`); const code = local === undefined ? undefined : codes[local]; // An unknown code fails the message rather than sending a result the EHR cannot file. if (code === undefined) throw new Error("an OBX-3 code is not in codes.json"); - msg.setField(`OBX[${i}].3.1`, code); - msg.setField(`OBX[${i}].3.3`, "LN"); + out = out.withField(`OBX[${i}].3.1`, code).withField(`OBX[${i}].3.3`, "LN"); } - return msg; + return out; }) satisfies Transform; ``` @@ -213,8 +211,7 @@ export const onStop: OnStop = () => { export default ((msg) => { const local = msg.get("OBX.3.1"); const code = local === undefined ? undefined : codes[local]; - if (code !== undefined) msg.setField("OBX.3.1", code); - return msg; + return code === undefined ? msg : msg.withField("OBX.3.1", code); }) satisfies Transform; ``` diff --git a/docs-content/use-the-message-context.md b/docs-content/use-the-message-context.md index 6f2181e7..21c22e74 100644 --- a/docs-content/use-the-message-context.md +++ b/docs-content/use-the-message-context.md @@ -100,12 +100,12 @@ import type { Transform } from "@cosyte/pathways"; export default ((msg, ctx) => { if (ctx === undefined) return msg; - msg.setField("MSH.6", ctx.config.facility); + const out = msg.withField("MSH.6", ctx.config.facility); if (ctx.source?.kind === "http") { const sender = ctx.source.headers["x-sending-facility"]; - if (sender !== undefined) msg.setField("MSH.4", sender); + if (sender !== undefined) return out.withField("MSH.4", sender); } - return msg; + return out; }) satisfies Transform; ``` diff --git a/docs-content/work-with-formats.md b/docs-content/work-with-formats.md index 97bce1b8..db96483c 100644 --- a/docs-content/work-with-formats.md +++ b/docs-content/work-with-formats.md @@ -15,7 +15,7 @@ message is now written in the character set its MSH-18 declares, and a blank MSH message that arrives with non-ASCII bytes and a blank MSH-18 (Latin-1 from a sender that does not declare it, say) still leaves byte for byte when nothing changes it. But when the transform edits any field in a segment that holds such a byte, even with ASCII text, the output now fails with -`UNENCODABLE_CHARACTER`, where 0.0.3 sent it re-encoded as UTF-8. Such a channel fails every such +`HL7_ENCODE_UNENCODABLE_CHARACTER`, where 0.0.3 sent it re-encoded as UTF-8. Such a channel fails every such message until the sender declares MSH-18, or the channel names the set to assume with [`hl7v2: { assumeCharset }`](#character-sets-in-hl7-v2). Setting MSH-18 inside the transform does not help: a message read this way holds the bytes as they arrived and cannot be moved to another set. @@ -37,7 +37,7 @@ number that a JavaScript number cannot hold exactly (a long id, say) fails with rather than being rounded; use `text` to pass it through untouched. A message that does not parse is marked failed with the parser's stable code, such as -`NO_MSH_SEGMENT` or `X12_NO_ISA_HEADER`, and the transform never sees it. +`HL7_NO_MSH_SEGMENT` or `X12_NO_ISA_HEADER`, and the transform never sees it. An HL7 v2 body is one message. A body that holds a second message (a later `MSH`, `FHS` or `BHS` segment, in any case, after any line ending, behind or inside its id any bytes that are not @@ -83,7 +83,7 @@ as it arrived. Pathways never guesses a set from the bytes. Pathways 0.0.3 and e `Hl7Message` as UTF-8, whatever MSH-18 said. A character the set has no byte for is never sent with a substitute: the output fails with -`UNENCODABLE_CHARACTER`, and the error names the segment, the field and the set, never the field's +`HL7_ENCODE_UNENCODABLE_CHARACTER`, and the error names the segment, the field and the set, never the field's text. That happens in two cases: - the transform writes a character the declared set cannot hold, such as a euro sign in a message diff --git a/docs-content/write-a-channel.md b/docs-content/write-a-channel.md index 3dc58860..4ee47c8c 100644 --- a/docs-content/write-a-channel.md +++ b/docs-content/write-a-channel.md @@ -54,8 +54,7 @@ export default ((msg) => { // OBR-25 is the result status. F is final; a preliminary result waits for its final one. if (msg.get("OBR.25") !== "F") return null; // MSH-5 is the receiving application. - msg.setField("MSH.5", "EHR"); - return msg; + return msg.withField("MSH.5", "EHR"); }) satisfies Transform; ``` diff --git a/docs-content/write-custom-connectors.md b/docs-content/write-custom-connectors.md index 613daf01..959b6970 100644 --- a/docs-content/write-custom-connectors.md +++ b/docs-content/write-custom-connectors.md @@ -214,8 +214,7 @@ import { parseHL7 } from "@cosyte/hl7"; import { defaultAckBuilder, type AckBuilder } from "@cosyte/pathways"; export default ((request) => { - const ack = parseHL7(Buffer.from(defaultAckBuilder(request))); - ack.setField("MSH.3", "PATHWAYS"); + const ack = parseHL7(Buffer.from(defaultAckBuilder(request))).withField("MSH.3", "PATHWAYS"); return Buffer.from(ack.toString()); }) satisfies AckBuilder; ``` diff --git a/examples/docker-compose/channels/adt-to-lab/transform.ts b/examples/docker-compose/channels/adt-to-lab/transform.ts index 9e234db4..f0a8e6bf 100644 --- a/examples/docker-compose/channels/adt-to-lab/transform.ts +++ b/examples/docker-compose/channels/adt-to-lab/transform.ts @@ -12,6 +12,5 @@ export default ((msg) => { // Only admissions go to the lab. Every other message is filtered out. if (!msg.is("ADT^A01")) return null; // MSH-5 is the receiving application. - msg.setField("MSH.5", "LAB"); - return msg; + return msg.withField("MSH.5", "LAB"); }) satisfies Transform; diff --git a/examples/file-to-sftp/channels/orders-to-lab/transform.ts b/examples/file-to-sftp/channels/orders-to-lab/transform.ts index 0f12cfcc..21d687c9 100644 --- a/examples/file-to-sftp/channels/orders-to-lab/transform.ts +++ b/examples/file-to-sftp/channels/orders-to-lab/transform.ts @@ -5,7 +5,5 @@ import type { Transform } from "@cosyte/pathways"; export default ((msg) => { if (!msg.is("ORM^O01")) return null; // MSH-5 and MSH-6 are the receiving application and facility. - msg.setField("MSH.5", "LAB"); - msg.setField("MSH.6", "REFLAB"); - return msg; + return msg.withField("MSH.5", "LAB").withField("MSH.6", "REFLAB"); }) satisfies Transform; diff --git a/examples/filter-and-route/channels/results-out/transform.ts b/examples/filter-and-route/channels/results-out/transform.ts index ca651474..a8b3a555 100644 --- a/examples/filter-and-route/channels/results-out/transform.ts +++ b/examples/filter-and-route/channels/results-out/transform.ts @@ -10,7 +10,5 @@ export default ((msg) => { if (msg.get(`OBX[${String(i)}].11`) !== "F") return null; } // MSH-5 and MSH-6 are the receiving application and facility. - msg.setField("MSH.5", "EHR"); - msg.setField("MSH.6", "HOSPITAL"); - return msg; + return msg.withField("MSH.5", "EHR").withField("MSH.6", "HOSPITAL"); }) satisfies Transform; diff --git a/examples/mllp-to-http/channels/adt-to-http/transform.ts b/examples/mllp-to-http/channels/adt-to-http/transform.ts index a0f57211..6813af48 100644 --- a/examples/mllp-to-http/channels/adt-to-http/transform.ts +++ b/examples/mllp-to-http/channels/adt-to-http/transform.ts @@ -5,7 +5,5 @@ import type { Transform } from "@cosyte/pathways"; export default ((msg) => { if (!msg.is("ADT^A01") && !msg.is("ADT^A04") && !msg.is("ADT^A08")) return null; // MSH-5 and MSH-6 are the receiving application and facility. - msg.setField("MSH.5", "EHR"); - msg.setField("MSH.6", "HOSPITAL"); - return msg; + return msg.withField("MSH.5", "EHR").withField("MSH.6", "HOSPITAL"); }) satisfies Transform; diff --git a/examples/replay-after-failure/channels/adt-to-registry/transform.ts b/examples/replay-after-failure/channels/adt-to-registry/transform.ts index 2cd80520..2d2aa6c8 100644 --- a/examples/replay-after-failure/channels/adt-to-registry/transform.ts +++ b/examples/replay-after-failure/channels/adt-to-registry/transform.ts @@ -21,7 +21,5 @@ export default (async (msg) => { // MSH-9.2 is the trigger event, such as A01. const code = codes[msg.get("MSH.9.2") ?? ""]; if (code === undefined) throw new Error("MSH-9.2 is not in event-codes.json"); - msg.setField("EVN.4", code); - msg.setField("MSH.5", "REGISTRY"); - return msg; + return msg.withField("EVN.4", code).withField("MSH.5", "REGISTRY"); }) satisfies Transform; diff --git a/examples/vet-lab-to-fhir/package.json b/examples/vet-lab-to-fhir/package.json index 7cbafa53..e9612000 100644 --- a/examples/vet-lab-to-fhir/package.json +++ b/examples/vet-lab-to-fhir/package.json @@ -12,7 +12,7 @@ "test": "pathways test" }, "dependencies": { - "@cosyte/fhir": "^0.1.12", + "@cosyte/fhir": "^0.2.0", "@cosyte/transform": "^0.2.4" }, "devDependencies": { diff --git a/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-1.expected.hl7 b/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-1.expected.hl7 index 2fdf8bba..1594363e 100644 --- a/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-1.expected.hl7 +++ b/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-1.expected.hl7 @@ -1,16 +1,14 @@ |^~\&COSYTE-SYNTHSYNTH-FACRECEIVERRECV-FAC20251031223518ORUR01SYNTH8308350075T2.5 - - - 190158063COSYTE-SYNTHMR999740221020013COSYTE-SYNTHMCNNonesuchTestbiscuit20070630M2512 Sample StreetFixturetonFL00000(693) 555-0154CATTLECattle99COSYTECTL-HOLHolstein99COSYTE - 1NonesuchSampletonOWNOwnerHL700632512 Sample StreetFixturetonFL00000(693) 555-0154 - - + + 190158063COSYTE-SYNTHMR999740221020013COSYTE-SYNTHMCNNonesuchTestbiscuit20070630M2512 Sample StreetFixturetonFL00000(693) 555-0154CATTLECattle99COSYTECTL-HOLHolstein99COSYTE + 1NonesuchSampletonOWNOwnerHL700632512 Sample StreetFixturetonFL00000(693) 555-0154 + 1332880744023864424356-8Urinalysis panelLN20221014025756 - + 1NM718-7HemoglobinLN96.9g/dLNF20200119092128 - - - + + + diff --git a/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-2.expected.hl7 b/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-2.expected.hl7 index ae2c80db..f539c7d5 100644 --- a/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-2.expected.hl7 +++ b/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-2.expected.hl7 @@ -1,16 +1,14 @@ |^~\&COSYTE-SYNTHSYNTH-FACRECEIVERRECV-FAC20230504040524ORUR01SYNTH1049414248T2.5 - - - 119189187COSYTE-SYNTHMR999773370184489COSYTE-SYNTHMCNPlaceholtSamplesnout20130720M2272 Testing TerraceFixturetonOH00000(785) 555-0169CATCat99COSYTECAT-DSHDomestic Shorthair99COSYTE - 1PlaceholtTestryOWNOwnerHL700632272 Testing TerraceFixturetonOH00000(785) 555-0169 - - + + 119189187COSYTE-SYNTHMR999773370184489COSYTE-SYNTHMCNPlaceholtSamplesnout20130720M2272 Testing TerraceFixturetonOH00000(785) 555-0169CATCat99COSYTECAT-DSHDomestic Shorthair99COSYTE + 1PlaceholtTestryOWNOwnerHL700632272 Testing TerraceFixturetonOH00000(785) 555-0169 + 1776605464907501858410-2CBC panelLN20200120010707 - + 1NM2951-2SodiumLN254.4mmol/LNF20201029034104 - - - + + + diff --git a/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-3.expected.hl7 b/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-3.expected.hl7 index f262ccb0..39c32e27 100644 --- a/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-3.expected.hl7 +++ b/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-3.expected.hl7 @@ -1,19 +1,17 @@ |^~\&COSYTE-SYNTHSYNTH-FACRECEIVERRECV-FAC20230111000944ORUR01SYNTH3084941386T2.5 - - - 184910503COSYTE-SYNTHMR999135338116760COSYTE-SYNTHMCNCorpusworthMockwhisker20170808M1982 Prototype CourtExampleburgVA00000(853) 555-0160CATCat99COSYTECAT-SIASiamese99COSYTE - 1CorpusworthQuilliamOWNOwnerHL700631982 Prototype CourtExampleburgVA00000(853) 555-0160 - - + + 184910503COSYTE-SYNTHMR999135338116760COSYTE-SYNTHMCNCorpusworthMockwhisker20170808M1982 Prototype CourtExampleburgVA00000(853) 555-0160CATCat99COSYTECAT-SIASiamese99COSYTE + 1CorpusworthQuilliamOWNOwnerHL700631982 Prototype CourtExampleburgVA00000(853) 555-0160 + 1151658700050343658410-2CBC panelLN20210624233916 - + 1NM2345-7GlucoseLN267.0mg/dLNF20210326070025 - - + + 2NM718-7HemoglobinLN104.8g/dLNF20250901060137 - - - + + + diff --git a/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-4.expected.hl7 b/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-4.expected.hl7 index 20bd7569..3ed3d34f 100644 --- a/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-4.expected.hl7 +++ b/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/tests/oru-4.expected.hl7 @@ -1,22 +1,20 @@ |^~\&COSYTE-SYNTHSYNTH-FACRECEIVERRECV-FAC20240910003013ORUR01SYNTH0968310697T2.5 - - - 120040387COSYTE-SYNTHMR999862338928059COSYTE-SYNTHMCNQuillfeatherFixturepaw20050810M146 Placeholder AvenueFixturetonSD00000(231) 555-0127CATTLECattle99COSYTECTL-ANGAngus99COSYTE - 1QuillfeatherFabricaOWNOwnerHL70063146 Placeholder AvenueFixturetonSD00000(231) 555-0127 - - + + 120040387COSYTE-SYNTHMR999862338928059COSYTE-SYNTHMCNQuillfeatherFixturepaw20050810M146 Placeholder AvenueFixturetonSD00000(231) 555-0127CATTLECattle99COSYTECTL-ANGAngus99COSYTE + 1QuillfeatherFabricaOWNOwnerHL70063146 Placeholder AvenueFixturetonSD00000(231) 555-0127 + 1847658305272143724356-8Urinalysis panelLN20240922154219 - + 1NM789-8ErythrocytesLN99.510*6/uLNF20210126042803 - - + + 2NM2823-3PotassiumLN130.2mmol/LNF20210810222856 - - + + 3NM789-8ErythrocytesLN153.810*6/uLNF20241026102344 - - - + + + diff --git a/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/transform.ts b/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/transform.ts index 4b98933d..7f00b02d 100644 --- a/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/transform.ts +++ b/examples/vet-lab-to-v2-xml/channels/vet-results-to-xml/transform.ts @@ -1,7 +1,7 @@ // Writes each veterinary lab result (ORU^R01) in the HL7 v2 XML encoding with @cosyte/hl7's // writer, and filters every other message out. The HTTP destination POSTs the document and settles // the delivery by the XML acknowledgement the service answers with. -import { toHl7Xml, XML_GROUP_TABLES } from "@cosyte/hl7"; +import { toHl7Xml, type XmlMessageStructure } from "@cosyte/hl7"; import type { Transform } from "@cosyte/pathways"; /** @@ -45,17 +45,34 @@ const DATA_TYPES: Readonly> = { "OBX.14": "TS", }; +/** + * The groups the XML encoding places these results' segments in (ORU_R01.REPORT and the rest). The + * names and their order come from the receiver's schema, and @cosyte/hl7 ships none, so the writer + * is given them here. These are this example's own, made up for it and not a copy of any published + * structure: write yours from your receiver's schema. A segment with no place in them is refused. + */ +const GROUPS: XmlMessageStructure = { + structure: "ORU_R01", + items: [ + "MSH", + { + group: "REPORT+", + items: [ + "PID", + "NK1*", + { group: "ORDER+", items: ["OBR", { group: "RESULT*", items: ["OBX"] }] }, + ], + }, + ], +}; + export default ((msg) => { if (!msg.is("ORU^R01")) return null; - // The XML encoding places the segments in the message structure's groups - // (ORU_R01.PATIENT_RESULT and the rest), whose names come from each version's published schema. - // @cosyte/hl7 ships them for ORU_R01 in v2.5, which these results are. For another version or - // structure, pass the table your receiver's schema gives as groups, the way scripts/lab.ts passes - // the ACK's: this transform fails such a result rather than guess its groups. - const groups = XML_GROUP_TABLES[msg.version ?? ""]?.["ORU_R01"]; - if (groups === undefined) { + // The groups above are for the v2.5 results this example sends. For another version, pass the + // table your receiver's schema gives for it: this transform fails such a result rather than guess. + if (msg.version !== "2.5") { throw new Error("no ORU_R01 group table for this result's HL7 version (MSH-12)"); } - return toHl7Xml(msg, { dataTypes: DATA_TYPES, groups }); + return toHl7Xml(msg, { dataTypes: DATA_TYPES, groups: GROUPS }); }) satisfies Transform; diff --git a/examples/vet-lab-to-v2-xml/package.json b/examples/vet-lab-to-v2-xml/package.json index 1c7703e5..2733d4ac 100644 --- a/examples/vet-lab-to-v2-xml/package.json +++ b/examples/vet-lab-to-v2-xml/package.json @@ -13,7 +13,7 @@ "test": "pathways test" }, "dependencies": { - "@cosyte/hl7": "^0.1.14" + "@cosyte/hl7": "^0.2.0" }, "devDependencies": { "@cosyte/pathways": "^0.0.6" diff --git a/examples/vet-lab-to-v2-xml/scripts/lab.ts b/examples/vet-lab-to-v2-xml/scripts/lab.ts index 097e3bee..f9040e8d 100644 --- a/examples/vet-lab-to-v2-xml/scripts/lab.ts +++ b/examples/vet-lab-to-v2-xml/scripts/lab.ts @@ -24,9 +24,9 @@ const ANSWERS = ["AA", "AE", "AR", "other-id"] as const; type Answer = (typeof ANSWERS)[number]; /** - * The ACK message structure, as the HL7 v2.5 standard gives it. @cosyte/hl7 ships group tables for - * ORU_R01 only, so the writer is given this one: an ACK has no groups, and the table also makes the - * writer refuse a segment that has no place in it. + * The ACK message structure, as the HL7 v2.5 standard gives it. @cosyte/hl7 ships no group table, + * so the writer is given this one: an ACK has no groups, and the table also makes the writer refuse + * a segment that has no place in it. */ const ACK_STRUCTURE: XmlMessageStructure = { structure: "ACK", @@ -60,8 +60,8 @@ mkdirSync(OUT, { recursive: true }); /** The XML acknowledgement to the message in `body`, with the answer `answer`. */ function acknowledge(body: string, answer: Answer): string { const message = parseHL7Xml(body); - const ack = buildAck(message, { code: answer === "other-id" ? "AA" : answer }); - if (answer === "other-id") ack.setField("MSA.2", "SYN-OTHER-0001"); + const built = buildAck(message, { code: answer === "other-id" ? "AA" : answer }); + const ack = answer === "other-id" ? built.withField("MSA.2", "SYN-OTHER-0001") : built; return toHl7Xml(ack, { dataTypes: ACK_DATA_TYPES, groups: ACK_STRUCTURE }); } diff --git a/package.json b/package.json index d102a91b..437359b9 100644 --- a/package.json +++ b/package.json @@ -136,10 +136,10 @@ }, "dependencies": { "@cosyte/ccda": "^0.1.6", - "@cosyte/fhir": "^0.1.9", - "@cosyte/hl7": "^0.1.14", + "@cosyte/fhir": "^0.2.0", + "@cosyte/hl7": "^0.2.0", "@cosyte/mllp": "^0.1.12", - "@cosyte/x12": "^0.1.11", + "@cosyte/x12": "^0.2.0", "better-sqlite3": "^13.0.3", "croner": "^11.0.0", "kysely": "^0.29.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a2dfd5b9..5fbe284d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,17 +17,17 @@ importers: specifier: ^0.1.6 version: 0.1.12(fast-check@4.10.2) '@cosyte/fhir': - specifier: ^0.1.9 - version: 0.1.16(fast-check@4.10.2) + specifier: ^0.2.0 + version: 0.2.0(fast-check@4.10.2) '@cosyte/hl7': - specifier: ^0.1.14 - version: 0.1.14(fast-check@4.10.2) + specifier: ^0.2.0 + version: 0.2.0(fast-check@4.10.2) '@cosyte/mllp': specifier: ^0.1.12 - version: 0.1.14(@cosyte/hl7@0.1.14(fast-check@4.10.2))(fast-check@4.10.2) + version: 0.1.14(@cosyte/hl7@0.2.0(fast-check@4.10.2))(fast-check@4.10.2) '@cosyte/x12': - specifier: ^0.1.11 - version: 0.1.11(fast-check@4.10.2) + specifier: ^0.2.0 + version: 0.2.0(fast-check@4.10.2) better-sqlite3: specifier: ^13.0.3 version: 13.0.3 @@ -82,13 +82,13 @@ importers: version: 0.1.16 '@cosyte/synth': specifier: ^0.1.10 - version: 0.1.10(@cosyte/ccda@0.1.12(fast-check@4.10.2))(@cosyte/fhir@0.1.16(fast-check@4.10.2))(@cosyte/hl7@0.1.14(fast-check@4.10.2))(@cosyte/x12@0.1.11(fast-check@4.10.2)) + version: 0.1.10(@cosyte/ccda@0.1.12(fast-check@4.10.2))(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2)) '@cosyte/test-utils': specifier: ^0.1.4 version: 0.1.4(fast-check@4.10.2) '@cosyte/transform': specifier: ^0.2.4 - version: 0.2.4(@cosyte/fhir@0.1.16(fast-check@4.10.2))(@cosyte/hl7@0.1.14(fast-check@4.10.2)) + version: 0.2.4(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2)) '@cosyte/tsconfig': specifier: ^0.1.2 version: 0.1.2 @@ -440,8 +440,8 @@ packages: eslint: ^9.0.0 || ^10.0.0 typescript: '>=5.0.0' - '@cosyte/fhir@0.1.16': - resolution: {integrity: sha512-EmqWqCyNgWgSji8Y3cmUKwjY7ZIlmk2psfIYSCKYrxufznyzYCgjl9NiFVjBe7NzgwaunvOyd4Uq7LiymHsNVw==} + '@cosyte/fhir@0.2.0': + resolution: {integrity: sha512-OuVgo307h2zg+xY3hqU87PMTattsE2AEfY/MG5op0Co/5Q5RdxM7Opr3I++WJsP90piGNGAY3LcOXspZVXppQg==} engines: {node: '>=22.0.0'} peerDependencies: fast-check: ^4.0.0 @@ -449,8 +449,8 @@ packages: fast-check: optional: true - '@cosyte/hl7@0.1.14': - resolution: {integrity: sha512-MSaHNjfjA1mmv4B2KKxeqbMs09P2m+BAlDtG8S7eZVrOc87gWoEHe6cdw1Fsazb+a1KZDNFtVjhxcvCM3xrhVQ==} + '@cosyte/hl7@0.2.0': + resolution: {integrity: sha512-KVvLj8EthFE7m4mVkw3ER+TiNGzDJEUzGFG57SDvGQpOkYoqIUh8wHtmexYlLQxLMY1pUPHTQ6d1N0ocEFTQQQ==} engines: {node: '>=22.0.0'} peerDependencies: fast-check: ^4.0.0 @@ -538,8 +538,8 @@ packages: vite: ^6.0.0 || ^7.0.0 || ^8.0.0 vitest: ^4.0.0 || ^5.0.0 - '@cosyte/x12@0.1.11': - resolution: {integrity: sha512-V6se6OFnKSi/vcJoNxDcwAJhNvFay5ixZ5tZR5GhkhjaEfnaLjvHwB6i3TAPYk1nrVEuihJS91f+gls0/goTcQ==} + '@cosyte/x12@0.2.0': + resolution: {integrity: sha512-umpeM3W1W0TyNHih3bFGxYIYpEnGavmD/Zuijt9p4rWf7CiCZrxouRitl9ju3sGVNkimzUDqkE7bR6gMdbRAoQ==} engines: {node: '>=22.0.0'} peerDependencies: fast-check: ^4.0.0 @@ -3428,17 +3428,17 @@ snapshots: transitivePeerDependencies: - supports-color - '@cosyte/fhir@0.1.16(fast-check@4.10.2)': + '@cosyte/fhir@0.2.0(fast-check@4.10.2)': optionalDependencies: fast-check: 4.10.2 - '@cosyte/hl7@0.1.14(fast-check@4.10.2)': + '@cosyte/hl7@0.2.0(fast-check@4.10.2)': optionalDependencies: fast-check: 4.10.2 - '@cosyte/mllp@0.1.14(@cosyte/hl7@0.1.14(fast-check@4.10.2))(fast-check@4.10.2)': + '@cosyte/mllp@0.1.14(@cosyte/hl7@0.2.0(fast-check@4.10.2))(fast-check@4.10.2)': optionalDependencies: - '@cosyte/hl7': 0.1.14(fast-check@4.10.2) + '@cosyte/hl7': 0.2.0(fast-check@4.10.2) fast-check: 4.10.2 '@cosyte/prettier-config@0.1.2': {} @@ -3477,21 +3477,21 @@ snapshots: '@cosyte/script-utils@0.1.16': {} - '@cosyte/synth@0.1.10(@cosyte/ccda@0.1.12(fast-check@4.10.2))(@cosyte/fhir@0.1.16(fast-check@4.10.2))(@cosyte/hl7@0.1.14(fast-check@4.10.2))(@cosyte/x12@0.1.11(fast-check@4.10.2))': + '@cosyte/synth@0.1.10(@cosyte/ccda@0.1.12(fast-check@4.10.2))(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2))(@cosyte/x12@0.2.0(fast-check@4.10.2))': optionalDependencies: '@cosyte/ccda': 0.1.12(fast-check@4.10.2) - '@cosyte/fhir': 0.1.16(fast-check@4.10.2) - '@cosyte/hl7': 0.1.14(fast-check@4.10.2) - '@cosyte/x12': 0.1.11(fast-check@4.10.2) + '@cosyte/fhir': 0.2.0(fast-check@4.10.2) + '@cosyte/hl7': 0.2.0(fast-check@4.10.2) + '@cosyte/x12': 0.2.0(fast-check@4.10.2) '@cosyte/test-utils@0.1.4(fast-check@4.10.2)': dependencies: fast-check: 4.10.2 - '@cosyte/transform@0.2.4(@cosyte/fhir@0.1.16(fast-check@4.10.2))(@cosyte/hl7@0.1.14(fast-check@4.10.2))': + '@cosyte/transform@0.2.4(@cosyte/fhir@0.2.0(fast-check@4.10.2))(@cosyte/hl7@0.2.0(fast-check@4.10.2))': dependencies: - '@cosyte/fhir': 0.1.16(fast-check@4.10.2) - '@cosyte/hl7': 0.1.14(fast-check@4.10.2) + '@cosyte/fhir': 0.2.0(fast-check@4.10.2) + '@cosyte/hl7': 0.2.0(fast-check@4.10.2) '@cosyte/tsconfig@0.1.2': {} @@ -3505,7 +3505,7 @@ snapshots: vite: 8.3.6(@types/node@24.19.2)(esbuild@0.28.2)(tsx@4.23.15)(yaml@2.9.1) vitest: 5.1.0(@types/node@24.19.2)(@vitest/coverage-v8@5.1.0)(vite@8.3.6(@types/node@24.19.2)(esbuild@0.28.2)(tsx@4.23.15)(yaml@2.9.1)) - '@cosyte/x12@0.1.11(fast-check@4.10.2)': + '@cosyte/x12@0.2.0(fast-check@4.10.2)': optionalDependencies: fast-check: 4.10.2 diff --git a/scripts/bench.ts b/scripts/bench.ts index 5dcfdc99..3dddc001 100644 --- a/scripts/bench.ts +++ b/scripts/bench.ts @@ -61,7 +61,7 @@ async function measure(encrypted: boolean): Promise { ); await writeFile( join(root, "channels/adt/transform.ts"), - "export default (msg: { setField(p: string, v: string): void }) => { msg.setField('MSH.5', 'LAB'); return msg; };\n", + "export default (msg: { withField(p: string, v: string): unknown }) => msg.withField('MSH.5', 'LAB');\n", ); await mkdir(join(root, "data/in"), { recursive: true }); for (let n = 0; n < count; n += 1) diff --git a/src/connectors/ack.ts b/src/connectors/ack.ts index 876e21f9..bc57d762 100644 --- a/src/connectors/ack.ts +++ b/src/connectors/ack.ts @@ -54,7 +54,7 @@ export interface AckRequest { readonly reason: AckReason; /** * For an `unreadable` message, what was wrong, as a stable code: one of `@cosyte/hl7`'s parse - * codes (such as `NO_MSH_SEGMENT`), `NO_CONTROL_ID`, `MULTIPLE_MESSAGES` or + * codes (such as `HL7_NO_MSH_SEGMENT`), `NO_CONTROL_ID`, `MULTIPLE_MESSAGES` or * `MLLP_TRAILING_BYTES`. */ readonly problem: string | undefined; @@ -85,8 +85,7 @@ export interface AckRequest { * import { parseHL7 } from "@cosyte/hl7"; * * export default ((request) => { - * const ack = parseHL7(Buffer.from(defaultAckBuilder(request))); - * ack.setField("MSH.3", "PATHWAYS"); + * const ack = parseHL7(Buffer.from(defaultAckBuilder(request))).withField("MSH.3", "PATHWAYS"); * return Buffer.from(ack.toString()); * }) satisfies AckBuilder; * ``` diff --git a/src/connectors/batch.ts b/src/connectors/batch.ts index 5828071d..7e251ea2 100644 --- a/src/connectors/batch.ts +++ b/src/connectors/batch.ts @@ -66,7 +66,7 @@ export const BATCH_CODES = { /** * One piece of a batch: its place in the batch, from 0, and its bytes, in a buffer of its own. A * piece that could not be read (an HL7 message `@cosyte/hl7` fails to parse) carries no bytes and - * the code it failed with, such as `NO_MSH_SEGMENT`. + * the code it failed with, such as `HL7_NO_MSH_SEGMENT`. */ export interface Piece { readonly index: number; @@ -93,7 +93,7 @@ export interface BatchResult { readonly failed: number; /** The pieces the store held already, from an earlier run or an earlier request with the key. */ readonly duplicates: number; - /** The envelope's warning codes, such as `BATCH_COUNT_MISMATCH`, each once. */ + /** The envelope's warning codes, such as `HL7_BATCH_COUNT_MISMATCH`, each once. */ readonly warnings: readonly string[]; } @@ -272,7 +272,7 @@ const ENVELOPE_HEAD = 256; * ```ts * const check = new EnvelopeCheck(); * for await (const chunk of chunks) check.push(chunk); - * check.end(); // [] when complete, or codes such as ["BATCH_MISSING_TRAILER"] + * check.end(); // [] when complete, or codes such as ["HL7_BATCH_MISSING_TRAILER"] * ``` */ export class EnvelopeCheck { @@ -362,12 +362,12 @@ export class EnvelopeCheck { if (count !== undefined) { if (this.pending > 0 || this.batchOpen) { if (typeof count === "number" && count !== this.pending) { - this.codes.add("BATCH_COUNT_MISMATCH"); + this.codes.add("HL7_BATCH_COUNT_MISMATCH"); } this.batches += 1; } } else if (this.batchOpen) { - this.codes.add("BATCH_MISSING_TRAILER"); + this.codes.add("HL7_BATCH_MISSING_TRAILER"); this.batches += 1; } this.pending = 0; @@ -379,10 +379,10 @@ export class EnvelopeCheck { this.finishBatch(undefined); if (count !== undefined) { if (typeof count === "number" && count !== this.batches) { - this.codes.add("BATCH_COUNT_MISMATCH"); + this.codes.add("HL7_BATCH_COUNT_MISMATCH"); } } else if (this.fileOpen) { - this.codes.add("BATCH_MISSING_TRAILER"); + this.codes.add("HL7_BATCH_MISSING_TRAILER"); } this.fileOpen = false; this.batches = 0; diff --git a/src/connectors/mllp.ts b/src/connectors/mllp.ts index 25128652..b110666d 100644 --- a/src/connectors/mllp.ts +++ b/src/connectors/mllp.ts @@ -61,7 +61,7 @@ export interface HeaderReading { readonly header: Hl7Message | undefined; /** * Why the header is not usable, as a stable code: a `@cosyte/hl7` parse code (such as - * `NO_MSH_SEGMENT`), `MULTIPLE_MESSAGES` or `NO_CONTROL_ID`. `undefined` when it is usable. + * `HL7_NO_MSH_SEGMENT`), `MULTIPLE_MESSAGES` or `NO_CONTROL_ID`. `undefined` when it is usable. */ readonly problem: string | undefined; /** MSH-10 as it arrived, when the header is usable. */ diff --git a/src/connectors/types.ts b/src/connectors/types.ts index 698b5a7e..c9fc01c7 100644 --- a/src/connectors/types.ts +++ b/src/connectors/types.ts @@ -27,7 +27,7 @@ export interface ReceivedPiece { * @example * ```ts * await sink.receive(body, { duplicateKey: `${sender}|${controlId}` }); - * await sink.receive(body, { failure: "inbound: NO_MSH_SEGMENT" }); + * await sink.receive(body, { failure: "inbound: HL7_NO_MSH_SEGMENT" }); * await sink.receive(body, { idempotencyKey: `queue|${deliveryTag}` }); * await sink.receive(body, { idempotencyKey: `queue|${deliveryTag}`, resumed: true }); * await sink.receive(body, { source: { queue: "inbound", deliveryTag } }); diff --git a/src/engine/worker-entry.ts b/src/engine/worker-entry.ts index 4a5854f3..2666da0c 100644 --- a/src/engine/worker-entry.ts +++ b/src/engine/worker-entry.ts @@ -572,8 +572,8 @@ export const FORMAT_REGISTRY = Object.freeze({ byShape: false, // Written in the charset MSH-18 declares, or the channel's assumed one when it is blank, so a // message nothing changed leaves as the bytes it arrived as. A character that set cannot hold - // is refused (`UNENCODABLE_CHARACTER`, naming the segment and field, never their text), never - // replaced. + // is refused (`HL7_ENCODE_UNENCODABLE_CHARACTER`, naming the segment and field, never their + // text), never replaced. write: async (value, settings) => { const library = await libraries.hl7(); return value instanceof library.Hl7Message @@ -586,8 +586,7 @@ export const FORMAT_REGISTRY = Object.freeze({ extension: "json", contentType: "application/fhir+json", load: libraries.fhir, - decode: async (body) => - (await libraries.fhir()).parseResource(strictUtf8.decode(body)).resource, + decode: async (body) => (await libraries.fhir()).parseResource(strictUtf8.decode(body)), model: { byShape: true, write: async (value) => @@ -691,8 +690,8 @@ function patientRepeated(library: typeof Hl7, message: Hl7.Hl7Message): boolean return findings.some( (finding) => finding.locus.segment === "PID" && - (finding.code === "STRUCTURE_SEGMENT_CARDINALITY" || - finding.code === "STRUCTURE_SEGMENT_OUT_OF_ORDER"), + (finding.code === "HL7_STRUCTURE_SEGMENT_CARDINALITY" || + finding.code === "HL7_STRUCTURE_SEGMENT_OUT_OF_ORDER"), ); } @@ -747,7 +746,7 @@ const B = 0x42; * never holds this: the field separator would end the field, so content carries it escaped. * * A body that opens with FHS or BHS is a batch, which is not one message either: the parser refuses - * it with its own code (`NO_MSH_SEGMENT`). One pass over the bytes, holding the last ten. + * it with its own code (`HL7_NO_MSH_SEGMENT`). One pass over the bytes, holding the last ten. * * Here, in the worker, which imports no module of its own, and imported by the MLLP and HTTP * sources and the engine, so every check reads a body the same way. @@ -932,7 +931,7 @@ function writeHl7( library: typeof Hl7, message: Hl7.Hl7Message, assumeCharset: string | undefined, -): Buffer { +): Uint8Array { const blank = msh18Blank(message); try { return blank && assumeCharset !== undefined @@ -943,7 +942,7 @@ function writeHl7( blank && assumeCharset === undefined && error instanceof library.Hl7EncodeError && - error.code === "UNENCODABLE_CHARACTER" + error.code === "HL7_ENCODE_UNENCODABLE_CHARACTER" ) { error.message += " MSH-18 is blank, so a segment the transform changed is written as ASCII: have the sender declare MSH-18, or set the channel's hl7v2.assumeCharset."; @@ -1015,7 +1014,7 @@ export async function loadFormat(format: WorkerFormat): Promise { * Parses a stored body into what the transform receives for `format`, with its registry entry (see * {@link FORMAT_REGISTRY} for what each gives). * - * A library's parse failure keeps its stable `code` (`NO_MSH_SEGMENT`, `MALFORMED_JSON`, + * A library's parse failure keeps its stable `code` (`HL7_NO_MSH_SEGMENT`, `FHIR_MALFORMED_JSON`, * `X12_NO_ISA_HEADER`, `NOT_WELL_FORMED_XML` and the rest). `json` refuses a body that is not JSON * (`MALFORMED_JSON`) and a number it cannot hold exactly (`INEXACT_JSON_NUMBER`), so a large id is * never rounded on its way through. diff --git a/src/extensions/events.ts b/src/extensions/events.ts index fb809c5a..867689ad 100644 --- a/src/extensions/events.ts +++ b/src/extensions/events.ts @@ -151,7 +151,7 @@ export interface TransformFailedEvent extends LifecycleEventBase { readonly kind: TransformFailureKind; /** The error's name, such as `TypeError`. */ readonly name: string; - /** The error's code, when it has one, such as a parser's `NO_MSH_SEGMENT`. */ + /** The error's code, when it has one, such as a parser's `HL7_NO_MSH_SEGMENT`. */ readonly code: string | undefined; /** Where in the transform it was thrown, as `file:line:column`, when it was. */ readonly where: string | undefined; diff --git a/src/transform.ts b/src/transform.ts index bac7ce0d..0250133a 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -347,8 +347,7 @@ export interface DestinationFacts { * * export default ((msg) => { * if (!msg.is("ADT^A01")) return null; - * msg.setField("MSH.5", "LAB"); - * return msg; + * return msg.withField("MSH.5", "LAB"); * }) satisfies Transform; * ``` */ diff --git a/templates/starter/channels/adt-to-lab/transform.ts b/templates/starter/channels/adt-to-lab/transform.ts index 9e234db4..f0a8e6bf 100644 --- a/templates/starter/channels/adt-to-lab/transform.ts +++ b/templates/starter/channels/adt-to-lab/transform.ts @@ -12,6 +12,5 @@ export default ((msg) => { // Only admissions go to the lab. Every other message is filtered out. if (!msg.is("ADT^A01")) return null; // MSH-5 is the receiving application. - msg.setField("MSH.5", "LAB"); - return msg; + return msg.withField("MSH.5", "LAB"); }) satisfies Transform; diff --git a/test/ack-load.test.ts b/test/ack-load.test.ts index e68ba72a..06b6146e 100644 --- a/test/ack-load.test.ts +++ b/test/ack-load.test.ts @@ -53,7 +53,7 @@ describe("loading the ACK builder", () => { 'const { parseHL7, Hl7Message } = await import("@cosyte/hl7");', 'const header = parseHL7("MSH|^~\\\\&|SYNTH|TESTFAC|LAB|TESTFAC|20261107120000||ADT^A01|MSG1|P|2.5.1\\r");', "const ack = Buffer.from(defaultAckBuilder({ code: 'AA', reason: 'stored', problem: undefined, header, messageId: 1 })).toString();", - "const placeholder = Buffer.from(defaultAckBuilder({ code: 'AR', reason: 'unreadable', problem: 'NO_MSH_SEGMENT', header: undefined, messageId: 1 })).toString();", + "const placeholder = Buffer.from(defaultAckBuilder({ code: 'AR', reason: 'unreadable', problem: 'HL7_NO_MSH_SEGMENT', header: undefined, messageId: 1 })).toString();", "process.stdout.write(JSON.stringify({ msa: ack.split('\\r')[1], placeholder: placeholder.split('\\r')[1], instance: header instanceof Hl7Message }));", ].join("\n"), ); diff --git a/test/batch-engine.test.ts b/test/batch-engine.test.ts index 59dc1780..6d44aefb 100644 --- a/test/batch-engine.test.ts +++ b/test/batch-engine.test.ts @@ -131,7 +131,7 @@ describe("A channel whose file source reads batches", () => { const errors = await Promise.all( failed.items.map(async (summary) => (await store.message(summary.id))?.error), ); - expect(errors.sort()).toEqual(["batch: BATCH_EMPTY", "batch: NO_MSH_SEGMENT"]); + expect(errors.sort()).toEqual(["batch: BATCH_EMPTY", "batch: HL7_NO_MSH_SEGMENT"]); for (const message of failed.items) expect(message.size).toBe(0); const audit = await store.auditEntries({ action: "batch", limit: 10 }); expect(audit.items.map((entry) => [entry.outcome, entry.detail])).toEqual( @@ -164,7 +164,11 @@ describe("A batch whose audit entry cannot be written", () => { const events = lines.map((line) => JSON.parse(line) as Record); expect(events).toEqual( expect.arrayContaining([ - expect.objectContaining({ event: "batch", warnings: "BATCH_COUNT_MISMATCH", pieces: 1 }), + expect.objectContaining({ + event: "batch", + warnings: "HL7_BATCH_COUNT_MISMATCH", + pieces: 1, + }), expect.objectContaining({ event: "batch-audit-failed", channel: "adt" }), ]), ); @@ -334,7 +338,9 @@ destinations: out: (line) => out.push(line), }); expect(out).toEqual([ - expect.stringMatching(/^FAIL adt\/tests\/feed\.hl7: piece 2 could not be read \([A-Z_]+\)$/), + expect.stringMatching( + /^FAIL adt\/tests\/feed\.hl7: piece 2 could not be read \(HL7_[A-Z0-9_]+\)$/, + ), ]); }); }); diff --git a/test/batch.test.ts b/test/batch.test.ts index 82efb965..b5832be8 100644 --- a/test/batch.test.ts +++ b/test/batch.test.ts @@ -93,13 +93,13 @@ describe("splitPieces", () => { it("yields a piece HL7 cannot read with its code and no bytes, and goes on", async () => { const { bodies, failures } = await cut(`PID|1||TEST000009\r${adt(3)}`, { split: "hl7" }); - expect(failures).toEqual(["NO_MSH_SEGMENT", undefined]); + expect(failures).toEqual(["HL7_NO_MSH_SEGMENT", undefined]); expect(bodies).toEqual(["", adt(3)]); }); it("says when the last HL7 message is cut off", async () => { const { warnings } = await cut(adt(4).slice(0, -1), { split: "hl7" }); - expect(warnings).toEqual(["UNTERMINATED_STREAM_MESSAGE"]); + expect(warnings).toEqual(["HL7_UNTERMINATED_STREAM_MESSAGE"]); }); }); @@ -121,8 +121,10 @@ describe("EnvelopeCheck", () => { }); it("finds a missing trailer", () => { - expect(envelope(`BHS|^~\\&\r${adt(1)}`)).toEqual(["BATCH_MISSING_TRAILER"]); - expect(envelope(`FHS|^~\\&\rBHS|^~\\&\r${adt(1)}BTS|1\r`)).toEqual(["BATCH_MISSING_TRAILER"]); + expect(envelope(`BHS|^~\\&\r${adt(1)}`)).toEqual(["HL7_BATCH_MISSING_TRAILER"]); + expect(envelope(`FHS|^~\\&\rBHS|^~\\&\r${adt(1)}BTS|1\r`)).toEqual([ + "HL7_BATCH_MISSING_TRAILER", + ]); }); it("passes over what it cannot check: a lone trailer, one with no field, a count too large", () => { @@ -135,13 +137,13 @@ describe("EnvelopeCheck", () => { const framed = `BHS|^~\\&\r\u000b${adt(1).slice(0, -1)}\u001c\rBTS|1\r`; expect(envelope(framed)).toEqual([]); const long = `BHS|^~\\&\r${adt(1)}OBX|1|TX|||${"x".repeat(400)}\rBTS|2\r`; - expect(envelope(long)).toEqual(["BATCH_COUNT_MISMATCH"]); + expect(envelope(long)).toEqual(["HL7_BATCH_COUNT_MISMATCH"]); }); it("finds a count that does not match", () => { - expect(envelope(`BHS|^~\\&\r${adt(1)}BTS|2\r`)).toEqual(["BATCH_COUNT_MISMATCH"]); + expect(envelope(`BHS|^~\\&\r${adt(1)}BTS|2\r`)).toEqual(["HL7_BATCH_COUNT_MISMATCH"]); expect(envelope(`FHS|^~\\&\rBHS|^~\\&\r${adt(1)}BTS|1\rFTS|2\r`)).toEqual([ - "BATCH_COUNT_MISMATCH", + "HL7_BATCH_COUNT_MISMATCH", ]); }); }); @@ -318,7 +320,7 @@ describe("A file source with batch", () => { const { sink, handed, results } = batchSink(); await new FileSource({ dir, channel, minAgeMs: 0, batch: { split: "hl7" } }).poll(sink); expect(handed.map((piece) => [piece.body, piece.failure])).toEqual([ - ["", "batch: NO_MSH_SEGMENT"], + ["", "batch: HL7_NO_MSH_SEGMENT"], [adt(5), undefined], ]); expect(handed[0]?.source).toBeUndefined(); @@ -391,7 +393,10 @@ describe("A file source with batch", () => { await source.poll(sink); expect(handed.map((piece) => piece.failure)).toEqual(["batch: BATCH_INCOMPLETE"]); expect(results[0]).toEqual( - expect.objectContaining({ code: "BATCH_INCOMPLETE", warnings: ["BATCH_MISSING_TRAILER"] }), + expect.objectContaining({ + code: "BATCH_INCOMPLETE", + warnings: ["HL7_BATCH_MISSING_TRAILER"], + }), ); }); @@ -406,7 +411,7 @@ describe("A file source with batch", () => { batch: { split: "hl7", onIncomplete: "accept" }, }).poll(sink); expect(handed.map((piece) => piece.body)).toEqual([adt(1)]); - expect(results[0]?.warnings).toEqual(["BATCH_COUNT_MISMATCH"]); + expect(results[0]?.warnings).toEqual(["HL7_BATCH_COUNT_MISMATCH"]); }); it("fails an incomplete HL7 batch at once with fail", async () => { diff --git a/test/channel-control.test.ts b/test/channel-control.test.ts index ebe0bc5f..3a03b98e 100644 --- a/test/channel-control.test.ts +++ b/test/channel-control.test.ts @@ -47,20 +47,15 @@ destinations: /** A transform that marks each output with `tag` in MSH.5. */ const tagging = (tag: string): string => ` -interface Msg { setField(path: string, value: string): void } -export default (msg: Msg): Msg => { - msg.setField("MSH.5", "${tag}"); - return msg; -}; +interface Msg { withField(path: string, value: string): Msg } +export default (msg: Msg): Msg => msg.withField("MSH.5", "${tag}"); `; /** A transform that writes its configuration's `facility` and `site` into MSH.5. */ const CONFIGURED = ` -interface Msg { setField(path: string, value: string): void } -export default (msg: Msg, ctx: { config: Record }): Msg => { - msg.setField("MSH.5", String(ctx.config["facility"]) + "-" + String(ctx.config["site"])); - return msg; -}; +interface Msg { withField(path: string, value: string): Msg } +export default (msg: Msg, ctx: { config: Record }): Msg => + msg.withField("MSH.5", String(ctx.config["facility"]) + "-" + String(ctx.config["site"])); `; /** A channel whose one destination takes its token from a secret reference. */ diff --git a/test/content-none.test.ts b/test/content-none.test.ts index a4742545..58f16bbe 100644 --- a/test/content-none.test.ts +++ b/test/content-none.test.ts @@ -265,7 +265,7 @@ describe("a channel that stores nothing", () => { const dropped = await sink.receive(text("drop")); expect(dropped).toBeGreaterThan(id); expect( - await sink.receive(text("unread"), { failure: "inbound: NO_MSH_SEGMENT" }), + await sink.receive(text("unread"), { failure: "inbound: HL7_NO_MSH_SEGMENT" }), ).toBeGreaterThan(dropped); // Nothing of any message is stored. diff --git a/test/control.test.ts b/test/control.test.ts index 3b2f0025..0a54ed64 100644 --- a/test/control.test.ts +++ b/test/control.test.ts @@ -534,11 +534,9 @@ destinations: const settings = (facility: string): string => `${KEYS}defaults:\n pollInterval: 20ms\nconfig: { facility: ${facility} }\n`; const FACILITY = ` -interface Msg { setField(path: string, value: string): void } -export default (msg: Msg, ctx: { config: Record }): Msg => { - msg.setField("MSH.5", String(ctx.config["facility"])); - return msg; -}; +interface Msg { withField(path: string, value: string): Msg } +export default (msg: Msg, ctx: { config: Record }): Msg => + msg.withField("MSH.5", String(ctx.config["facility"])); `; async function project(transform = LAB_TRANSFORM): Promise { diff --git a/test/engine-http.test.ts b/test/engine-http.test.ts index 5e622258..9b4cc0ee 100644 --- a/test/engine-http.test.ts +++ b/test/engine-http.test.ts @@ -220,7 +220,7 @@ describe("an HTTP channel in the engine", () => { event: "http-unreadable", channel: "adt", message: 2, - problem: "NO_MSH_SEGMENT", + problem: "HL7_NO_MSH_SEGMENT", }), ); expect(lines.join("")).not.toContain("TEST000001"); diff --git a/test/engine.test.ts b/test/engine.test.ts index 7a6ea71e..e3d481ef 100644 --- a/test/engine.test.ts +++ b/test/engine.test.ts @@ -501,8 +501,13 @@ describe("retryDelay and storedFailure", () => { it("keeps stage, name, code and location ahead of the error's own text", () => { expect( - storedFailure({ kind: "parse", name: "Hl7ParseError", code: "NO_MSH_SEGMENT", detail: "x" }), - ).toBe("parse: Hl7ParseError NO_MSH_SEGMENT: x"); + storedFailure({ + kind: "parse", + name: "Hl7ParseError", + code: "HL7_NO_MSH_SEGMENT", + detail: "x", + }), + ).toBe("parse: Hl7ParseError HL7_NO_MSH_SEGMENT: x"); expect( storedFailure({ kind: "transform", diff --git a/test/equivalence/digests.json b/test/equivalence/digests.json index 6301f170..8a4a289d 100644 --- a/test/equivalence/digests.json +++ b/test/equivalence/digests.json @@ -101,8 +101,8 @@ "hl7v2 bench oru 8 KiB": "1c18e2ceedfc35722647fbdcb18e5360", "hl7v2 bench oru 64 KiB": "ddaf61ab74688e66cec9fa973911ca8c", "hl7v2 bench oru document 8 KiB": "0057aa872619e6efffeecbf83191b6d4", - "hl7v2 hand empty": "03829121b5e24841396904894413f99d", - "hl7v2 hand no MSH": "dbd58e1282efcc1bbca084ddf89d7a68", + "hl7v2 hand empty": "28c0db40474544b074e1c3d37e16fdfe", + "hl7v2 hand no MSH": "d9c73c4b40c5cabbd6fc70cb234aeda1", "hl7v2 hand MSH only": "436f9bff530ea14986918fa1a62d9ba4", "hl7v2 hand no control id": "74b990909b5e3098751b902afe95cd46", "hl7v2 hand LF endings": "67704d9cda10028d30e2f38e2d3bda15", @@ -114,14 +114,14 @@ "hl7v2 hand repetitions": "73a61fdef0524a9fa53be8bcf9d49e27", "hl7v2 hand trailing garbage": "ca7f74a904de8420df617ba9be274f64", "hl7v2 hand two messages": "4e81a99ab83b0fad2762da8ceb41c551", - "hl7v2 hand short MSH": "b95fa81e134e29b5104ac5fd213dd843", - "hl7v2 hand bad encoding characters": "b95fa81e134e29b5104ac5fd213dd843", + "hl7v2 hand short MSH": "859b2b14c093e4d636ea161f3ab55064", + "hl7v2 hand bad encoding characters": "859b2b14c093e4d636ea161f3ab55064", "hl7v2 hand control id with components": "ffd604d7ca80a42976171d969003240a", "hl7v2 hand hex escape in control id": "4bfd87b69bc00a2207b699a848b813f9", "hl7v2 hand UTF-8 name": "4a44ba1c15690e17005b20640557a5db", "hl7v2 hand Latin-1 name, MSH-18 8859/1": "04a10b0e4f25f74970ed248df9d64bb0", "hl7v2 hand Latin-1 bytes, no MSH-18": "ca8a671a06c64c666fc468c1be379e3b", - "hl7v2 hand invalid UTF-8": "0fed3fb7f846a7f0188689103a195449", + "hl7v2 hand invalid UTF-8": "e9c8966ea89d1c88365c63a171474564", "hl7v2 hand segment of one field": "3e484e29bc18aab86bd33847385f246e", "hl7v2 hand Z segment": "d3c362c26759f81a2e66b016e7c32039", "hl7v2 hand subcomponents": "0da9aa7429f56999c0faeea99a721cdc", @@ -174,9 +174,9 @@ "fhir bench patient 2": "881e34108ef430e1a09ae285d5863c21", "fhir bench patient 3": "4d5e72fa3f9674421be8b772d5ad4b71", "fhir bench bundle 16 KiB": "f2de9f05d2c5ba7dbc520d5c0d6c4496", - "fhir hand empty": "9c6b9b6d2acb05e9b9af7affbf712983", - "fhir hand not JSON": "297e5b62765fc607fb8f9d78c40b3a7b", - "fhir hand array": "d55f9752c7e092c45e274b47783431b2", + "fhir hand empty": "4cc862ef546c0fa179fd45d2e1ced35d", + "fhir hand not JSON": "2292792efa52eae6ae84bb0dc22d0d40", + "fhir hand array": "f59073f0d88e09de5b16b911a4111689", "fhir hand no resourceType": "74196aa534e4f0af73099e3d8a649fcc", "fhir hand unknown resourceType": "fba776835b4692c3fcef1381d0a836e8", "fhir hand large integer": "7ceced52e7d5d750b123de58f688635c", @@ -185,7 +185,7 @@ "fhir hand pretty printed": "fd3aec5c74df0244e18ce97fa501482b", "fhir hand BOM": "fd3aec5c74df0244e18ce97fa501482b", "fhir hand invalid UTF-8": "85250303dfd88432738c784bea3eeb44", - "fhir hand duplicate key": "374700c03fb9e65ba82d99bba7b2560d", + "fhir hand duplicate key": "32c0c4dc0a2cfedfe75a4f8a82f3eea0", "fhir hand unknown property": "979c38369dba07d4d18e1ea5c9b22fbb", "fhir hand wrong type": "a611bfa0873cf1a71bdb6909671f0825", "fhir hand null value": "7ca8611e2acc8037d8f3c3511e11337c", @@ -707,145 +707,145 @@ "text random bytes 7": "f65e283ca7526ddfb6eecc03d4f20cb7" }, "ack": { - "hl7v2 synth ADT^A01 1": "eba751605971f53af896bb0206f0bc7d", - "hl7v2 synth ADT^A01 2": "12048fd28d58fdb2ca4e63f7c4025ec0", - "hl7v2 synth ADT^A01 3": "79462ea676c86c564a3b68ed30b1e72e", - "hl7v2 synth ADT^A01 4": "b0c039423edf2c3a547bce2ef19e528c", - "hl7v2 synth ADT^A01 5": "5528087b293ab14d6d3631fcbfeb35b1", - "hl7v2 synth ADT^A01 6": "22090ec6f09380a0fd067889f2b0552a", - "hl7v2 synth ADT^A01 7": "bcf6361b2d1f3d19474942556a6d4b74", - "hl7v2 synth ADT^A01 8": "ecff976b858237be21b5dbb48c16c601", - "hl7v2 synth ADT^A01 9": "beb8b9994d07bf5d3236e65bac0639d5", - "hl7v2 synth ADT^A01 10": "e0d28e73a4732826f0b4121811da1fa9", - "hl7v2 synth ADT^A01 11": "54393e678a35c3003fffccbd3727dcc6", - "hl7v2 synth ADT^A01 12": "4818f09d13b6686bac2e0741f81ae1f9", - "hl7v2 synth ADT^A04 1": "a0eb9073e6b2f20af1bbaf719ad959e5", - "hl7v2 synth ADT^A04 2": "123728fba3bd2b73d09c616cd0c2ed3e", - "hl7v2 synth ADT^A04 3": "db6ff4b619ca425a95b8766c9fda5b9c", - "hl7v2 synth ADT^A04 4": "14189d3ed2096bf1ded0c4c7ce067383", - "hl7v2 synth ADT^A04 5": "c78357f71bbf9dd4f4003620a728a26a", - "hl7v2 synth ADT^A04 6": "694fd771a07a4ab53d34575907b98a79", - "hl7v2 synth ADT^A04 7": "754055f8eb11975abc9c3b8ec471746e", - "hl7v2 synth ADT^A04 8": "615c668b4f79f2e7f4d5f3a0d52a1bf7", - "hl7v2 synth ADT^A04 9": "ddab844daa2c3bc1518a8f1055fa5f56", - "hl7v2 synth ADT^A04 10": "c089353ee8aec44034571230a4ee22e6", - "hl7v2 synth ADT^A04 11": "31f4a24aab798162df655881ef099d4c", - "hl7v2 synth ADT^A04 12": "1176e43dd4d063dce857dfbac197e911", - "hl7v2 synth ADT^A08 1": "0a2806132e153d8a399413d3c57e417d", - "hl7v2 synth ADT^A08 2": "6e6a2d4976c4ed657f6d4f672f260375", - "hl7v2 synth ADT^A08 3": "6a69676cea3b90becda6df663f7fed8a", - "hl7v2 synth ADT^A08 4": "f0d39c4285377c2247e1a55b4f4968ac", - "hl7v2 synth ADT^A08 5": "3fc8318456b984fafe31ed131bfac73d", - "hl7v2 synth ADT^A08 6": "f092a7934f484c7834d2107ee89d8643", - "hl7v2 synth ADT^A08 7": "7ad19351233b213468183cd14fc5178f", - "hl7v2 synth ADT^A08 8": "35a13041140d474a5adb52a52e6cc1b9", - "hl7v2 synth ADT^A08 9": "73769f86132a40127bf0f90428d19855", - "hl7v2 synth ADT^A08 10": "6d382440b1a1239efa862b2cfc444f06", - "hl7v2 synth ADT^A08 11": "73fc36ce29bdf773afe91405a8fc1df4", - "hl7v2 synth ADT^A08 12": "fe72480af9d7bf5767e7986470d05956", - "hl7v2 synth ORU^R01 1": "2834d74c1c540f0bbc6d865ece353391", - "hl7v2 synth ORU^R01 2": "8f3be893a330a503518cb99fc17b7e7c", - "hl7v2 synth ORU^R01 3": "56e9b780acd7b856c094de450b32c267", - "hl7v2 synth ORU^R01 4": "94448fc7bfee66aad621ee6770025e25", - "hl7v2 synth ORU^R01 5": "84e7a9e3feadbdba7bc5f207745d0e61", - "hl7v2 synth ORU^R01 6": "f77b4bc52c06fcce657e9276a8d04a2a", - "hl7v2 synth ORU^R01 7": "e4baf9656c8495d7de75f54290b2bd54", - "hl7v2 synth ORU^R01 8": "3b9ad8ec476f52f291d459c71718cdf9", - "hl7v2 synth ORU^R01 9": "16ae88ee76ad278e1635b50dbe279cc9", - "hl7v2 synth ORU^R01 10": "c97c55f8466dd4c8785dbaeb002060e1", - "hl7v2 synth ORU^R01 11": "b26a8407795e0b8b0ddd7b956db632e4", - "hl7v2 synth ORU^R01 12": "4f8eedf824d99dcffc68531b2b850f74", - "hl7v2 synth ORM^O01 1": "44a5ed463e489fe055a968630e414943", - "hl7v2 synth ORM^O01 2": "41896833f0078d70cb9674793c9f2c16", - "hl7v2 synth ORM^O01 3": "77a03b8f4694ac84f40ff8284d48d993", - "hl7v2 synth ORM^O01 4": "d70d6fd4c297add0a10249365988fc7a", - "hl7v2 synth ORM^O01 5": "690f004fe090b5e7300292a495468f68", - "hl7v2 synth ORM^O01 6": "58bf3b37bd995fa014200ceca2bfd9e3", - "hl7v2 synth ORM^O01 7": "9130ff4a70796739a35492ec92173a19", - "hl7v2 synth ORM^O01 8": "aa3c0007c06bb4df462bae0f90d881c5", - "hl7v2 synth ORM^O01 9": "17bfccf719eb815426613a98f870fd5e", - "hl7v2 synth ORM^O01 10": "8ada8f28f63849f8313d5192a80b888e", - "hl7v2 synth ORM^O01 11": "5d8d845c4464ec1db4cf151f18036b7b", - "hl7v2 synth ORM^O01 12": "7c84d4d71c5a22e9281de971c190da3f", - "hl7v2 synth SIU^S12 1": "2d87f50052664f59438bfd57237d3613", - "hl7v2 synth SIU^S12 2": "0950f5cfe4f4cf10cedbe5c23f3180af", - "hl7v2 synth SIU^S12 3": "cce650338d371ab04871007029e53982", - "hl7v2 synth SIU^S12 4": "b5a3807c2bb2b3b35ae573ea413fed88", - "hl7v2 synth SIU^S12 5": "f4ecfcf95a7a2948d456c4397a62bb14", - "hl7v2 synth SIU^S12 6": "82ebf698ee8fd0f8f94444c19588d63a", - "hl7v2 synth SIU^S12 7": "3e7773d79ef2eeeed1e3224dfdb4908c", - "hl7v2 synth SIU^S12 8": "a6ef13bcc13bff428f9ec2f2d2c93e72", - "hl7v2 synth SIU^S12 9": "6eed66fb35d645e7809460d4bd34d0e8", - "hl7v2 synth SIU^S12 10": "412374714e3326649fcd060ebe0081ab", - "hl7v2 synth SIU^S12 11": "e6dfb8924b198447b3617b05f767ff05", - "hl7v2 synth SIU^S12 12": "4203a103e690674ebf257286b4e07fbb", - "hl7v2 synth VXU^V04 1": "2a708c6d3565397c0d2a8314c61e4929", - "hl7v2 synth VXU^V04 2": "d466a98cbaa3eff0c4d0ddf491b274f3", - "hl7v2 synth VXU^V04 3": "87dc980a8ab9bb814e7c261168887921", - "hl7v2 synth VXU^V04 4": "0a2f0fb13f0d369d5e63bc9835796922", - "hl7v2 synth VXU^V04 5": "96c7756e2a2e55fe2fe95525c3484d53", - "hl7v2 synth VXU^V04 6": "5bc9146b7992575223654bbd6793aaf8", - "hl7v2 synth VXU^V04 7": "b3965713d044ed36ae42a5d43cce9322", - "hl7v2 synth VXU^V04 8": "8baacedef978d3f26a64842cd3e5eeb0", - "hl7v2 synth VXU^V04 9": "ce8419586f1f2ca5736c5c581f7c0265", - "hl7v2 synth VXU^V04 10": "4d04df91ebae4fda014e24d515805663", - "hl7v2 synth VXU^V04 11": "39d2da2215f53f283f0f31c52558b668", - "hl7v2 synth VXU^V04 12": "db802754a3c2cc602750587f06a9ff59", - "hl7v2 synth quirk unknown-zsegment 1": "2834d74c1c540f0bbc6d865ece353391", - "hl7v2 synth quirk unknown-zsegment 2": "8f3be893a330a503518cb99fc17b7e7c", - "hl7v2 synth quirk unknown-zsegment 3": "56e9b780acd7b856c094de450b32c267", - "hl7v2 synth quirk unknown-zsegment 4": "94448fc7bfee66aad621ee6770025e25", - "hl7v2 synth quirk unknown-escape 1": "2834d74c1c540f0bbc6d865ece353391", - "hl7v2 synth quirk unknown-escape 2": "8f3be893a330a503518cb99fc17b7e7c", - "hl7v2 synth quirk unknown-escape 3": "56e9b780acd7b856c094de450b32c267", - "hl7v2 synth quirk unknown-escape 4": "94448fc7bfee66aad621ee6770025e25", - "hl7v2 bench adt 0": "ea32d83e41566e8616f61feb4597f419", - "hl7v2 bench adt 1": "b0ddc5def17b164c38039145f6965f49", - "hl7v2 bench adt 2": "984176f0ddb075581a45148bf395be93", - "hl7v2 bench adt 3": "4348bc4b2b8df757ceb4a6dc41e5359a", - "hl7v2 bench adt 4": "cc7db9c7d8155fbf78af271cc70ff0ba", - "hl7v2 bench adt 5": "90efb435feff30f6c23be048dda25393", - "hl7v2 bench oru 8 KiB": "c3ccca020e8045332177bb525e83fb86", - "hl7v2 bench oru 64 KiB": "5754ad595b4349b233b4e414729cf4af", - "hl7v2 bench oru document 8 KiB": "c3ccca020e8045332177bb525e83fb86", - "hl7v2 hand empty": "9d0a1701bbdbd5e12f4893fcc8ff85e0", - "hl7v2 hand no MSH": "dd02b60258a3a58d1ca8e747b81a6043", - "hl7v2 hand MSH only": "6bd207c6806db46c6dd3d450bb15b4c0", - "hl7v2 hand no control id": "2f4af0c5341a7fdd0136374172b1aec4", - "hl7v2 hand LF endings": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand CRLF endings": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand no final CR": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand blank lines": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand other delimiters": "23ad9175bfc23cddbef51235ea9ddc3c", - "hl7v2 hand escapes": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand repetitions": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand trailing garbage": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand two messages": "a635a8c60cdf0c423ce24972146bda76", - "hl7v2 hand short MSH": "98cc75eafae8b7d5e7c81e16641c2bea", - "hl7v2 hand bad encoding characters": "98cc75eafae8b7d5e7c81e16641c2bea", - "hl7v2 hand control id with components": "6f7649d96214adfc838e2d4db3eb5daf", - "hl7v2 hand hex escape in control id": "291c6bcdf1a41d2199681acb58a9f509", - "hl7v2 hand UTF-8 name": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand Latin-1 name, MSH-18 8859/1": "d7b008bccf356fac3159324517ef35a0", - "hl7v2 hand Latin-1 bytes, no MSH-18": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand invalid UTF-8": "62d85af40c6903d2a207faf5b7f62e73", - "hl7v2 hand segment of one field": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand Z segment": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand subcomponents": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand very long field": "cf1639ba5e39885a07c4884c09f49358", - "hl7v2 hand version 2.3": "5deca9921624bf411b9a96776b7b97f1", - "hl7v2 hand MSH-9 one component": "d78bbee6a9a50e236a6c3d139a75d57e", - "hl7v2 hand NUL byte": "3baa7ef485a9b9966453cc47174ea26f", + "hl7v2 synth ADT^A01 1": "eb5a0249c191dc938db2ec3853f8fbc2", + "hl7v2 synth ADT^A01 2": "c28966c1b1725ee12b6c42d5e4c7190d", + "hl7v2 synth ADT^A01 3": "df03f82b9635e42bc7e18ef3eb788a01", + "hl7v2 synth ADT^A01 4": "3dcc98388120f49c4f8933ce10244a5d", + "hl7v2 synth ADT^A01 5": "8583d45f1e968c09a923ad973db5c4a1", + "hl7v2 synth ADT^A01 6": "75777daf757d27dac00338ca94300455", + "hl7v2 synth ADT^A01 7": "906ccae27497bb20721f1e8088ea97de", + "hl7v2 synth ADT^A01 8": "571862f3c01e835bc75ed92cec98774b", + "hl7v2 synth ADT^A01 9": "969c57a38b140372b2c7822f3682cf1e", + "hl7v2 synth ADT^A01 10": "8421cbe38917183edefdd6794b829fbc", + "hl7v2 synth ADT^A01 11": "b8f230d8f4970d29759d8dcd4eca9f20", + "hl7v2 synth ADT^A01 12": "97160f15a8069bbbd209c0966c73dc78", + "hl7v2 synth ADT^A04 1": "3a39eb3828564ad3540d76df6dd63728", + "hl7v2 synth ADT^A04 2": "85a2200d533ce70b29cbd661e91a81f3", + "hl7v2 synth ADT^A04 3": "f0963ddd343dfca960b349ea98e57405", + "hl7v2 synth ADT^A04 4": "09ccdb92bb5b6e8b75e79143a625e028", + "hl7v2 synth ADT^A04 5": "843a33fb2ae2cea018a7c1740ea6f024", + "hl7v2 synth ADT^A04 6": "c0f7d1154ed1d98e8964ad13f45f3695", + "hl7v2 synth ADT^A04 7": "2aafff435d945c376950e85efbae97ec", + "hl7v2 synth ADT^A04 8": "9265997a32c2a16692c858f347057ea4", + "hl7v2 synth ADT^A04 9": "71a001cdd947d867e2081a64d767870b", + "hl7v2 synth ADT^A04 10": "af7b2da9d9e0d9e026a0793135ecfd50", + "hl7v2 synth ADT^A04 11": "34413f15aa4b5c004ad926378da61892", + "hl7v2 synth ADT^A04 12": "e38b9879cd47a3857f767bc55d8471e0", + "hl7v2 synth ADT^A08 1": "0826f3f908afbf1cc5fb95934bfb6544", + "hl7v2 synth ADT^A08 2": "1681500b72b902f2f183d9bfeefb492b", + "hl7v2 synth ADT^A08 3": "3c47ba214cdb6920dd6413e3b09698ff", + "hl7v2 synth ADT^A08 4": "1f7ccd17076f76b6f131b9dbc69aa130", + "hl7v2 synth ADT^A08 5": "4e87544a922130a329f477b0cd9ea473", + "hl7v2 synth ADT^A08 6": "ebf4db5872d8c2b770ffc4591b2f1ed5", + "hl7v2 synth ADT^A08 7": "69e132e96353bcd3871740f9613f0e38", + "hl7v2 synth ADT^A08 8": "faa8cc9c5537e79fc02d09a4af619b4b", + "hl7v2 synth ADT^A08 9": "e9784d98cb4824e8268c7d457f656619", + "hl7v2 synth ADT^A08 10": "26c437e0f68e0c68b8b06c5520a9d2fb", + "hl7v2 synth ADT^A08 11": "058756153d65fed2049267f5b74f2d13", + "hl7v2 synth ADT^A08 12": "09c04a76cfb71025c4c08a4de29a9613", + "hl7v2 synth ORU^R01 1": "6212906b767fc46956b056fa9097d866", + "hl7v2 synth ORU^R01 2": "5f539661db28f15903c713656c5b7b42", + "hl7v2 synth ORU^R01 3": "680829b85699512eee5f35c493cf4481", + "hl7v2 synth ORU^R01 4": "30280174c5b92d92514b7989d36aa4c5", + "hl7v2 synth ORU^R01 5": "721619ee7dcef4658b49bbd6268443a0", + "hl7v2 synth ORU^R01 6": "78eddba85e4955b7f15baf0d0f6b8ad8", + "hl7v2 synth ORU^R01 7": "2a253cfbea227b68bce09491e1024da4", + "hl7v2 synth ORU^R01 8": "9dff48ae5cbf7969ef0c409c1527673a", + "hl7v2 synth ORU^R01 9": "6854e44c6cc872de2ee91c0e170d579b", + "hl7v2 synth ORU^R01 10": "592b44d39dcd87effc4cc64293480e35", + "hl7v2 synth ORU^R01 11": "8cff33cf1cc8d143f26cb0aeb4c5e22a", + "hl7v2 synth ORU^R01 12": "277c1b36ce6543f83dd280bcd4785ff4", + "hl7v2 synth ORM^O01 1": "c93e258a7614f5bdc3122b79ef7cb5a0", + "hl7v2 synth ORM^O01 2": "2956d8e3853bbca1ede91844facd2715", + "hl7v2 synth ORM^O01 3": "2b50c616ee053eaad2874900321fae84", + "hl7v2 synth ORM^O01 4": "c4b9a2ccce820bbd6858a831d957a72b", + "hl7v2 synth ORM^O01 5": "9470ed4806d96c82072dd5873b1be490", + "hl7v2 synth ORM^O01 6": "99bce87251cb4da167b550bb5a31fae9", + "hl7v2 synth ORM^O01 7": "dd305f9f3c8907421bfbff3976ed0464", + "hl7v2 synth ORM^O01 8": "f2a3be700e4c51d228d19a0ff6165299", + "hl7v2 synth ORM^O01 9": "2227e3543d003e383a9924c090835475", + "hl7v2 synth ORM^O01 10": "336790c250aaeba66a88920371e81838", + "hl7v2 synth ORM^O01 11": "d3f1d1577c6000837b74db0180763873", + "hl7v2 synth ORM^O01 12": "54df26a0021757d9d847ffd5fb26b650", + "hl7v2 synth SIU^S12 1": "6c1af5fcb3c5996b5aafbb2b6ed87093", + "hl7v2 synth SIU^S12 2": "4b6602120beafaf2ff7effb6f6085f53", + "hl7v2 synth SIU^S12 3": "64f3732e9ac899b89c7464e82bb11100", + "hl7v2 synth SIU^S12 4": "0e1b2a0379e5f6dc2fc76231017df65d", + "hl7v2 synth SIU^S12 5": "e4eb3d2f18b79622ec1466774e657ab2", + "hl7v2 synth SIU^S12 6": "b8846d53ab164f5ded5c50027653b13a", + "hl7v2 synth SIU^S12 7": "e8106f6117b172e8ee820f037a5ca9a2", + "hl7v2 synth SIU^S12 8": "b7519adfe8dd1f5e3ef52117784dbd50", + "hl7v2 synth SIU^S12 9": "b668d24183ac8ed3cce97aa18dd5b199", + "hl7v2 synth SIU^S12 10": "1d744c1fb2db81d1f2a3065adb5d2f8c", + "hl7v2 synth SIU^S12 11": "942fafd9e770abea813c5a0bcd0eac42", + "hl7v2 synth SIU^S12 12": "48b61aaba4bc662422b7466ce54fe0ec", + "hl7v2 synth VXU^V04 1": "3e77df1c95ba1a780a6d9307c36ccda5", + "hl7v2 synth VXU^V04 2": "fe4eb8837c3d978fe173a77609f3a0b9", + "hl7v2 synth VXU^V04 3": "fcd6e54261e7849eedba26f08d21c883", + "hl7v2 synth VXU^V04 4": "ef65439ec4b71d9c0edfcd64b834bf0f", + "hl7v2 synth VXU^V04 5": "c9ff562e3dddb6a87965a953e0301417", + "hl7v2 synth VXU^V04 6": "135e6fb28d9d81caf978a300972017d9", + "hl7v2 synth VXU^V04 7": "eb26a7a44499329684268bf84e16381a", + "hl7v2 synth VXU^V04 8": "5e44bd3558c81e7ba8a50abcf39023d3", + "hl7v2 synth VXU^V04 9": "9f2cee211081f88e033a72ee2d772b2c", + "hl7v2 synth VXU^V04 10": "b1f593d83779c1b5111b48b3330ff7fe", + "hl7v2 synth VXU^V04 11": "14fda5f2fb817622c44d9a10e3e70c63", + "hl7v2 synth VXU^V04 12": "5558608a40caea8bb92191c562de3779", + "hl7v2 synth quirk unknown-zsegment 1": "6212906b767fc46956b056fa9097d866", + "hl7v2 synth quirk unknown-zsegment 2": "5f539661db28f15903c713656c5b7b42", + "hl7v2 synth quirk unknown-zsegment 3": "680829b85699512eee5f35c493cf4481", + "hl7v2 synth quirk unknown-zsegment 4": "30280174c5b92d92514b7989d36aa4c5", + "hl7v2 synth quirk unknown-escape 1": "6212906b767fc46956b056fa9097d866", + "hl7v2 synth quirk unknown-escape 2": "5f539661db28f15903c713656c5b7b42", + "hl7v2 synth quirk unknown-escape 3": "680829b85699512eee5f35c493cf4481", + "hl7v2 synth quirk unknown-escape 4": "30280174c5b92d92514b7989d36aa4c5", + "hl7v2 bench adt 0": "790315133a0ca11456a46f7739a19656", + "hl7v2 bench adt 1": "cdd1ad63b578b0416bf04211df46c54b", + "hl7v2 bench adt 2": "0437bc8535bd708951f9aaf3cb862c1b", + "hl7v2 bench adt 3": "187cb327d227e3ea764cbcd22a4715ac", + "hl7v2 bench adt 4": "f32c79e6e3b7d3a32c7fbc528bba70b0", + "hl7v2 bench adt 5": "1c9002f704ae52de2ae000cd8771d1af", + "hl7v2 bench oru 8 KiB": "873a0aaf96ed2976db10d91d90c482a5", + "hl7v2 bench oru 64 KiB": "ed1969c25d2e9f473773687c7c206fba", + "hl7v2 bench oru document 8 KiB": "873a0aaf96ed2976db10d91d90c482a5", + "hl7v2 hand empty": "e778d57bcfe917033b766d5dd08049b1", + "hl7v2 hand no MSH": "0b8799531c7c2bffdb26f6fe3c7c45df", + "hl7v2 hand MSH only": "5f88c314d86be5ef5ac75cabaed7dd4f", + "hl7v2 hand no control id": "151ed9acc90baa2c2c200b419b1ae02c", + "hl7v2 hand LF endings": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand CRLF endings": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand no final CR": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand blank lines": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand other delimiters": "938891300951b64c98c107b6d654af48", + "hl7v2 hand escapes": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand repetitions": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand trailing garbage": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand two messages": "592a8ee1a5a93c142521e8bbe9490249", + "hl7v2 hand short MSH": "a8d36849257cb7818d70d4a48e262adc", + "hl7v2 hand bad encoding characters": "a8d36849257cb7818d70d4a48e262adc", + "hl7v2 hand control id with components": "4e0fdb73814d0840da6ae9c48bb06e07", + "hl7v2 hand hex escape in control id": "35ad17c515636efd74a01903075f47d0", + "hl7v2 hand UTF-8 name": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand Latin-1 name, MSH-18 8859/1": "cf69e11dac72dea48e47af931ec0e058", + "hl7v2 hand Latin-1 bytes, no MSH-18": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand invalid UTF-8": "f0b51327a7a744ad41e0e7132e101a9a", + "hl7v2 hand segment of one field": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand Z segment": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand subcomponents": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand very long field": "9447a6b4c8db8f10dafac6ac35416ed1", + "hl7v2 hand version 2.3": "3a563d4b8573a43c45534e0e6b111aa2", + "hl7v2 hand MSH-9 one component": "132b3d096f3a0a05ab732138008624ca", + "hl7v2 hand NUL byte": "e98a8e0d7a78c785ea94c5f18d10e8ef", "no header AA": "743945f9b88ffb0b65843f92f9955dd0", - "no header AE store-failed": "ff40ec4f1f1dcb8a801134c3c3ebddbb", - "no header AR store-failed": "b764bee739dc1e9696961b92a75b12f6", + "no header AE store-failed": "815bc3d5ca2506af075e2a1cb2843584", + "no header AR store-failed": "5272e98430b24928f64124ff1c871b5c", "no header AR no control id": "1e53c86d03987dbfbd63d68e7ba5774b", "no header AR other": "03a76794f537107d4b2e5d96e30d66c0" }, "engine": { "ccda": "076f93e0618d340a15c4ceb58903e3bd", - "fhir": "85fdaeb27e37d878b912a447238a61d0", - "hl7v2": "b8e1df5aad394d7c9be7fed38c92f1d4", + "fhir": "1ccee10a2518fe645a9b9eb10490a225", + "hl7v2": "f39b09f54423f663144b0bc8efcfd58f", "json": "0c96b9ba2bb0e29aaa5954a02e58bd8a", "text": "aee577b132b6b4fb384632f0e0598e10", "x12": "3d91f2f6177c5e01470e0d3b11640870" diff --git a/test/equivalence/pathways-test.json b/test/equivalence/pathways-test.json index 95133a82..d92f87be 100644 --- a/test/equivalence/pathways-test.json +++ b/test/equivalence/pathways-test.json @@ -962,9 +962,9 @@ "PASS eq-fhir/tests/0042.msg", "PASS eq-fhir/tests/0043.msg", "PASS eq-fhir/tests/0044.msg", - "FAIL eq-fhir/tests/0045.msg: the input could not be parsed as fhir (MALFORMED_JSON)", - "FAIL eq-fhir/tests/0046.msg: the input could not be parsed as fhir (MALFORMED_JSON)", - "FAIL eq-fhir/tests/0047.msg: the input could not be parsed as fhir (MALFORMED_JSON)", + "FAIL eq-fhir/tests/0045.msg: the input could not be parsed as fhir (FHIR_MALFORMED_JSON)", + "FAIL eq-fhir/tests/0046.msg: the input could not be parsed as fhir (FHIR_MALFORMED_JSON)", + "FAIL eq-fhir/tests/0047.msg: the input could not be parsed as fhir (FHIR_MALFORMED_JSON)", "PASS eq-fhir/tests/0048.msg", "PASS eq-fhir/tests/0049.msg", "PASS eq-fhir/tests/0050.msg", @@ -973,7 +973,7 @@ "PASS eq-fhir/tests/0053.msg", "PASS eq-fhir/tests/0054.msg", "FAIL eq-fhir/tests/0055.msg: the input could not be parsed as fhir (ERR_ENCODING_INVALID_ENCODED_DATA)", - "FAIL eq-fhir/tests/0056.msg: the transform's output could not be serialized (UNSERIALIZABLE_SHADOWED_PROPERTY)", + "FAIL eq-fhir/tests/0056.msg: the transform's output could not be serialized (FHIR_UNSERIALIZABLE_SHADOWED_PROPERTY)", "PASS eq-fhir/tests/0057.msg", "PASS eq-fhir/tests/0058.msg", "PASS eq-fhir/tests/0059.msg", @@ -1080,8 +1080,8 @@ "PASS eq-hl7v2/tests/0098.msg", "PASS eq-hl7v2/tests/0099.msg", "PASS eq-hl7v2/tests/0100.msg", - "FAIL eq-hl7v2/tests/0101.msg: the input could not be parsed as hl7v2 (EMPTY_INPUT)", - "FAIL eq-hl7v2/tests/0102.msg: the input could not be parsed as hl7v2 (NO_MSH_SEGMENT)", + "FAIL eq-hl7v2/tests/0101.msg: the input could not be parsed as hl7v2 (HL7_EMPTY_INPUT)", + "FAIL eq-hl7v2/tests/0102.msg: the input could not be parsed as hl7v2 (HL7_NO_MSH_SEGMENT)", "PASS eq-hl7v2/tests/0103.msg", "PASS eq-hl7v2/tests/0104.msg", "PASS eq-hl7v2/tests/0105.msg", @@ -1093,8 +1093,8 @@ "PASS eq-hl7v2/tests/0111.msg", "PASS eq-hl7v2/tests/0112.msg", "FAIL eq-hl7v2/tests/0113.msg: the input could not be parsed as hl7v2 (MULTIPLE_MESSAGES)", - "FAIL eq-hl7v2/tests/0114.msg: the input could not be parsed as hl7v2 (MSH_TOO_SHORT)", - "FAIL eq-hl7v2/tests/0115.msg: the input could not be parsed as hl7v2 (MSH_TOO_SHORT)", + "FAIL eq-hl7v2/tests/0114.msg: the input could not be parsed as hl7v2 (HL7_MSH_TOO_SHORT)", + "FAIL eq-hl7v2/tests/0115.msg: the input could not be parsed as hl7v2 (HL7_MSH_TOO_SHORT)", "PASS eq-hl7v2/tests/0116.msg", "PASS eq-hl7v2/tests/0117.msg", "PASS eq-hl7v2/tests/0118.msg", @@ -1209,8 +1209,8 @@ "PASS eq-hl7v2-edit/tests/0098.msg", "PASS eq-hl7v2-edit/tests/0099.msg", "PASS eq-hl7v2-edit/tests/0100.msg", - "FAIL eq-hl7v2-edit/tests/0101.msg: the input could not be parsed as hl7v2 (EMPTY_INPUT)", - "FAIL eq-hl7v2-edit/tests/0102.msg: the input could not be parsed as hl7v2 (NO_MSH_SEGMENT)", + "FAIL eq-hl7v2-edit/tests/0101.msg: the input could not be parsed as hl7v2 (HL7_EMPTY_INPUT)", + "FAIL eq-hl7v2-edit/tests/0102.msg: the input could not be parsed as hl7v2 (HL7_NO_MSH_SEGMENT)", "PASS eq-hl7v2-edit/tests/0103.msg", "PASS eq-hl7v2-edit/tests/0104.msg", "PASS eq-hl7v2-edit/tests/0105.msg", @@ -1222,14 +1222,14 @@ "PASS eq-hl7v2-edit/tests/0111.msg", "PASS eq-hl7v2-edit/tests/0112.msg", "FAIL eq-hl7v2-edit/tests/0113.msg: the input could not be parsed as hl7v2 (MULTIPLE_MESSAGES)", - "FAIL eq-hl7v2-edit/tests/0114.msg: the input could not be parsed as hl7v2 (MSH_TOO_SHORT)", - "FAIL eq-hl7v2-edit/tests/0115.msg: the input could not be parsed as hl7v2 (MSH_TOO_SHORT)", + "FAIL eq-hl7v2-edit/tests/0114.msg: the input could not be parsed as hl7v2 (HL7_MSH_TOO_SHORT)", + "FAIL eq-hl7v2-edit/tests/0115.msg: the input could not be parsed as hl7v2 (HL7_MSH_TOO_SHORT)", "PASS eq-hl7v2-edit/tests/0116.msg", "PASS eq-hl7v2-edit/tests/0117.msg", "PASS eq-hl7v2-edit/tests/0118.msg", "PASS eq-hl7v2-edit/tests/0119.msg", "PASS eq-hl7v2-edit/tests/0120.msg", - "FAIL eq-hl7v2-edit/tests/0121.msg: the transform's output could not be serialized (UNENCODABLE_CHARACTER)", + "FAIL eq-hl7v2-edit/tests/0121.msg: the transform's output could not be serialized (HL7_ENCODE_UNENCODABLE_CHARACTER)", "PASS eq-hl7v2-edit/tests/0122.msg", "PASS eq-hl7v2-edit/tests/0123.msg", "PASS eq-hl7v2-edit/tests/0124.msg", diff --git a/test/examples.test.ts b/test/examples.test.ts index 5154c4da..ad39dcbf 100644 --- a/test/examples.test.ts +++ b/test/examples.test.ts @@ -1085,6 +1085,6 @@ describe("the v2 XML example's messages and transform", () => { thrown = error; } expect(thrown).toBeInstanceOf(Hl7XmlError); - expect((thrown as Hl7XmlError).code).toBe("DATA_TYPE_UNKNOWN"); + expect((thrown as Hl7XmlError).code).toBe("HL7_XML_DATA_TYPE_UNKNOWN"); }); }); diff --git a/test/format-equivalence.test.ts b/test/format-equivalence.test.ts index 2937aaee..03f54952 100644 --- a/test/format-equivalence.test.ts +++ b/test/format-equivalence.test.ts @@ -46,10 +46,8 @@ afterAll(cleanUp); /** The starter's kind of edit, on HL7 v2: address the message to another facility. */ const EDIT_HL7 = [ - "export default (msg: { setField(path: string, value: string): void }) => {", - ' msg.setField("MSH.5", "LAB");', - " return msg;", - "};", + "export default (msg: { withField(path: string, value: string): unknown }) =>", + ' msg.withField("MSH.5", "LAB");', "", ].join("\n"); diff --git a/test/helpers.ts b/test/helpers.ts index 0dd0b9b5..2282d5c0 100644 --- a/test/helpers.ts +++ b/test/helpers.ts @@ -143,11 +143,10 @@ export const CCDA_DOCUMENT = ` /** A transform that routes A01s to the lab and filters everything else out. */ export const LAB_TRANSFORM = ` -interface Msg { is(type: string): boolean; setField(path: string, value: string): void } +interface Msg { is(type: string): boolean; withField(path: string, value: string): Msg } export default (msg: Msg): Msg | null => { if (!msg.is("ADT^A01")) return null; - msg.setField("MSH.5", "LAB2"); - return msg; + return msg.withField("MSH.5", "LAB2"); }; `; diff --git a/test/hl7v2-charset.test.ts b/test/hl7v2-charset.test.ts index 4bd8de5e..e56f5baf 100644 --- a/test/hl7v2-charset.test.ts +++ b/test/hl7v2-charset.test.ts @@ -16,9 +16,9 @@ afterEach(cleanUp); * byte (0xc5): a sender that sends Latin-1 and does not declare it. */ function undeclaredLatin1Adt(): Buffer { - const message = generateAdt({ seed: 24, trigger: "A01" }); - message.setField("MSH.18", ""); - message.setField("PID.5.2", "ÅLPHA"); + const message = generateAdt({ seed: 24, trigger: "A01" }) + .withField("MSH.18", "") + .withField("PID.5.2", "ÅLPHA"); return Buffer.from(message.toString(), "latin1"); } @@ -30,7 +30,7 @@ async function project(extra: string): Promise { "source:\n file: { dir: ../../data/inbox, minAge: 0 }\ntransform: ./transform.ts\n" + "destinations:\n - file: { dir: ../../data/out }\n", "channels/adt/transform.ts": - 'export default (message) => {\n message.setField("PID.3.1", "TEST2");\n return message;\n};\n', + 'export default (message) => message.withField("PID.3.1", "TEST2");\n', }); } diff --git a/test/http-source-options.test.ts b/test/http-source-options.test.ts index 6d8dc805..f30cc6d2 100644 --- a/test/http-source-options.test.ts +++ b/test/http-source-options.test.ts @@ -195,11 +195,11 @@ describe("an HTTP source answering with an HL7 ACK", () => { expect(noControlId.body).toContain("101"); expect(sink.received.map((r) => r.options)).toEqual([ - { failure: "inbound: NO_MSH_SEGMENT" }, + { failure: "inbound: HL7_NO_MSH_SEGMENT" }, { failure: "inbound: NO_CONTROL_ID" }, ]); expect(unreadable).toEqual([ - [1, "NO_MSH_SEGMENT"], + [1, "HL7_NO_MSH_SEGMENT"], [2, "NO_CONTROL_ID"], ]); }); diff --git a/test/mllp-engine.test.ts b/test/mllp-engine.test.ts index 5a682282..c83ca773 100644 --- a/test/mllp-engine.test.ts +++ b/test/mllp-engine.test.ts @@ -217,7 +217,7 @@ describe("an MLLP channel", () => { channel: "adt", status: "failed", state: "failed", - error: "inbound: NO_MSH_SEGMENT", + error: "inbound: HL7_NO_MSH_SEGMENT", duplicateOf: null, }); expect(receiver.received).toEqual([]); @@ -228,7 +228,7 @@ describe("an MLLP channel", () => { expect.objectContaining({ event: "mllp-unreadable", channel: "adt", - problem: "NO_MSH_SEGMENT", + problem: "HL7_NO_MSH_SEGMENT", }), ); }); diff --git a/test/mllp-source.test.ts b/test/mllp-source.test.ts index f134a718..a56f7991 100644 --- a/test/mllp-source.test.ts +++ b/test/mllp-source.test.ts @@ -180,7 +180,7 @@ describe("MllpSource", () => { ); it.each([ - ["not an HL7 message", "NO_MSH_SEGMENT", "", "100"], + ["not an HL7 message", "HL7_NO_MSH_SEGMENT", "", "100"], [ "MSH|^~\\&|SYNTH|TESTFAC|LAB|TESTFAC|20261107120000||ADT^A01||P|2.5.1\rPID|1\r", "NO_CONTROL_ID", @@ -188,7 +188,7 @@ describe("MllpSource", () => { "101", ], [ADT_A01 + ADT_A08, "MULTIPLE_MESSAGES", "MSG00001", "100"], - [`FHS|^~\\&\rBHS|^~\\&\r${ADT_A01}`, "NO_MSH_SEGMENT", "", "100"], + [`FHS|^~\\&\rBHS|^~\\&\r${ADT_A01}`, "HL7_NO_MSH_SEGMENT", "", "100"], ])( "stores a message with no usable header as failed and answers AR (%#: %s)", async (message, problem, controlId, condition) => { diff --git a/test/output-equivalence.test.ts b/test/output-equivalence.test.ts index 53f8abd9..c66a43f2 100644 --- a/test/output-equivalence.test.ts +++ b/test/output-equivalence.test.ts @@ -119,10 +119,8 @@ function describeMessage(format: WorkerFormat, message: unknown): unknown { } const passThrough: TransformFunction = (message) => [message]; -const addressToLab: TransformFunction = (message) => { - (message as { setField(path: string, value: string): void }).setField("MSH.5", "LAB"); - return message; -}; +const addressToLab: TransformFunction = (message) => + (message as { withField(path: string, value: string): unknown }).withField("MSH.5", "LAB"); describe("output equivalence", () => { it("has a corpus of a few hundred inputs, in every format", () => { @@ -211,10 +209,8 @@ describe("output equivalence", () => { const records = new Map(); const formats = [...new Set(CORPUS.map((entry) => entry.format))].sort(); const transform = [ - "export default (msg: { setField(path: string, value: string): void }) => {", - ' msg.setField("MSH.5", "LAB");', - " return msg;", - "};", + "export default (msg: { withField(path: string, value: string): unknown }) =>", + ' msg.withField("MSH.5", "LAB");', "", ].join("\n"); for (const format of formats) { diff --git a/test/run-tests.test.ts b/test/run-tests.test.ts index 18f97496..691c421e 100644 --- a/test/run-tests.test.ts +++ b/test/run-tests.test.ts @@ -102,7 +102,7 @@ describe("runChannelTests", () => { }); expect(summary).toEqual({ passed: 0, failed: 2, updated: 0 }); expect(lines[0]).toBe( - "FAIL adt/tests/a.hl7: the input could not be parsed as hl7v2 (NO_MSH_SEGMENT)", + "FAIL adt/tests/a.hl7: the input could not be parsed as hl7v2 (HL7_NO_MSH_SEGMENT)", ); expect(lines[1]).toMatch( /^FAIL adt\/tests\/b\.hl7: the transform threw TypeError at transform\.ts:2:\d+$/, @@ -154,7 +154,7 @@ export default (resource: Resource): Resource => ({ expect(lines).toEqual([ "PASS fhir/tests/a.json", "PASS fhir/tests/b.json", - "FAIL fhir/tests/c.json: the input could not be parsed as fhir (MALFORMED_JSON)", + "FAIL fhir/tests/c.json: the input could not be parsed as fhir (FHIR_MALFORMED_JSON)", ]); expect(summary).toEqual({ passed: 2, failed: 1, updated: 0 }); }); @@ -247,7 +247,7 @@ export default (document: { sections: readonly unknown[] }) => [document, String "channels/fhir/tests/a.json": '{"resourceType":"Patient","active":true,"active":false}', }); expect(lines).toEqual([ - "FAIL fhir/tests/a.json: the transform's output could not be serialized (UNSERIALIZABLE_SHADOWED_PROPERTY)", + "FAIL fhir/tests/a.json: the transform's output could not be serialized (FHIR_UNSERIALIZABLE_SHADOWED_PROPERTY)", ]); }); }); @@ -296,8 +296,10 @@ describe("expectedName, firstDifference and describeFailure", () => { expect(describe_({ ...base, kind: "output" })).toBe( "the transform returned something that is neither a message nor a string", ); - expect(describe_({ ...base, kind: "output", code: "UNSERIALIZABLE_SHADOWED_PROPERTY" })).toBe( - "the transform's output could not be serialized (UNSERIALIZABLE_SHADOWED_PROPERTY)", + expect( + describe_({ ...base, kind: "output", code: "FHIR_UNSERIALIZABLE_SHADOWED_PROPERTY" }), + ).toBe( + "the transform's output could not be serialized (FHIR_UNSERIALIZABLE_SHADOWED_PROPERTY)", ); expect(describe_({ ...base, kind: "timeout" })).toBe("the transform ran longer than 5000 ms"); expect(describe_({ ...base, kind: "memory" })).toBe( diff --git a/test/store.test.ts b/test/store.test.ts index 59c50894..2b78fc5a 100644 --- a/test/store.test.ts +++ b/test/store.test.ts @@ -273,13 +273,15 @@ for (const database of TEST_DATABASES) { it("stores a message as failed, with its reason, when told to, and never hands it to the transform", async () => { const { store } = await openStore(database); - const { id } = await store.receive("a", bytes("x"), { failure: "inbound: NO_MSH_SEGMENT" }); + const { id } = await store.receive("a", bytes("x"), { + failure: "inbound: HL7_NO_MSH_SEGMENT", + }); expect(await store.message(id)).toEqual({ id, channel: "a", status: "failed", state: "failed", - error: "inbound: NO_MSH_SEGMENT", + error: "inbound: HL7_NO_MSH_SEGMENT", receivedAt: "2026-11-07T12:00:00.000Z", updatedAt: "2026-11-07T12:00:00.000Z", size: 1, diff --git a/test/transform-types.test.ts b/test/transform-types.test.ts index 8545a6de..38926eaa 100644 --- a/test/transform-types.test.ts +++ b/test/transform-types.test.ts @@ -36,8 +36,7 @@ async function run( /** A plain HL7 v2 route, unchanged: `Transform` still means HL7 v2. */ const routeA01 = ((msg) => { if (!msg.is("ADT^A01")) return null; - msg.setField("MSH.5", "LAB"); - return msg; + return msg.withField("MSH.5", "LAB"); }) satisfies Transform; /** A FHIR transform, typed from the format name. The model is immutable, so it returns a new one. */ diff --git a/test/verify.test.ts b/test/verify.test.ts index ef7b9f7e..b59c8b38 100644 --- a/test/verify.test.ts +++ b/test/verify.test.ts @@ -28,17 +28,16 @@ const KEYS = "encryption:\n keys: [{ id: test, file: ./test.key }]\n current: /** Sets the receiving application, as a lab feed might. */ const TRANSFORM = ` -interface Msg { setField(path: string, value: string): void } +interface Msg { withField(path: string, value: string): Msg } export default (msg: Msg): Msg => { - msg.setField("MSH.5", "LAB2"); - return msg; + return msg.withField("MSH.5", "LAB2"); }; `; /** The same, and also the patient's administrative sex: one field more, so a different output. */ const CHANGED = TRANSFORM.replace( - 'msg.setField("MSH.5", "LAB2");', - 'msg.setField("MSH.5", "LAB2");\n msg.setField("PID.8", "F");', + 'msg.withField("MSH.5", "LAB2");', + 'msg.withField("MSH.5", "LAB2").withField("PID.8", "F");', ); const THROWS = `export default () => { throw new TypeError("TESTPATIENT in the error text"); };\n`; @@ -305,12 +304,9 @@ describe("pathways verify, on stored messages", () => { it("runs each stored message with the context the engine gave it: its id and the configuration", async () => { // Stamps the configured facility into MSH-6 and the message's id into MSH-10. const contextual = ` -interface Msg { setField(path: string, value: string): void } -export default (msg: Msg, ctx: { messageId: number; config: { facility: string } }): Msg => { - msg.setField("MSH.6", ctx.config.facility); - msg.setField("MSH.10", \`SYNTH\${ctx.messageId}\`); - return msg; -}; +interface Msg { withField(path: string, value: string): Msg } +export default (msg: Msg, ctx: { messageId: number; config: { facility: string } }): Msg => + msg.withField("MSH.6", ctx.config.facility).withField("MSH.10", \`SYNTH\${ctx.messageId}\`); `; const root = await makeProject({ "test.key": `${generateKey()}\n`, diff --git a/test/worker-entry.test.ts b/test/worker-entry.test.ts index af4c2a08..8e7458b4 100644 --- a/test/worker-entry.test.ts +++ b/test/worker-entry.test.ts @@ -63,9 +63,9 @@ const identity: TransformFunction = (message) => message; * letter, as the Latin-1 bytes a sender would send. */ function latin1Adt(): Uint8Array { - const message = generateAdt({ seed: 21, trigger: "A01" }); - message.setField("MSH.18", "8859/1"); - message.setField("PID.5.1", "TESTPATIENTÉ"); + const message = generateAdt({ seed: 21, trigger: "A01" }) + .withField("MSH.18", "8859/1") + .withField("PID.5.1", "TESTPATIENTÉ"); return new Uint8Array(Buffer.from(message.toString(), "latin1")); } @@ -74,9 +74,9 @@ function latin1Adt(): Uint8Array { * byte (0xc5): a sender that sends Latin-1 and does not declare it. */ function undeclaredLatin1Adt(): Uint8Array { - const message = generateAdt({ seed: 23, trigger: "A01" }); - message.setField("MSH.18", ""); - message.setField("PID.5.2", "ÅLPHA"); + const message = generateAdt({ seed: 23, trigger: "A01" }) + .withField("MSH.18", "") + .withField("PID.5.2", "ÅLPHA"); return new Uint8Array(Buffer.from(message.toString(), "latin1")); } @@ -155,9 +155,9 @@ describe("decode and encode", () => { it("keeps each library's error code when a body will not parse", async () => { const cases: [WorkerFormat, string, string][] = [ - ["hl7v2", "not hl7", "NO_MSH_SEGMENT"], - ["fhir", "[]", "MALFORMED_JSON"], - ["fhir", "{", "MALFORMED_JSON"], + ["hl7v2", "not hl7", "HL7_NO_MSH_SEGMENT"], + ["fhir", "[]", "FHIR_MALFORMED_JSON"], + ["fhir", "{", "FHIR_MALFORMED_JSON"], ["x12", "", "X12_EMPTY_INPUT"], ["x12", "ISA*", "X12_ISA_TOO_SHORT"], [ @@ -287,8 +287,7 @@ describe("decode and encode", () => { expect(Buffer.from(out ?? []).equals(Buffer.from(body))).toBe(true); // A message the transform changed is written in the declared set too. const edit: TransformFunction = (message) => { - (message as Hl7Message).setField("MSH.5", "LAB2"); - return message; + return (message as Hl7Message).withField("MSH.5", "LAB2"); }; const [edited] = await runTransform(edit, "hl7v2", body); expect(Buffer.from(edited ?? []).toString("latin1")).toContain("|LAB2|"); @@ -298,22 +297,20 @@ describe("decode and encode", () => { it("fails the output on a character the declared set cannot hold, naming no field text", async () => { const edit: TransformFunction = (message) => { - (message as Hl7Message).setField("PID.5.2", "EURO€NAME"); - return message; + return (message as Hl7Message).withField("PID.5.2", "EURO€NAME"); }; const failure = await failureOf(runTransform(edit, "hl7v2", latin1Adt())); expect(failure).toMatchObject({ kind: "output", name: "Hl7EncodeError", - code: "UNENCODABLE_CHARACTER", + code: "HL7_ENCODE_UNENCODABLE_CHARACTER", }); expect(failure.detail).not.toMatch(/EURO|NAME|€|TESTPAT/); }); describe("a message with MSH-18 blank and non-ASCII bytes", () => { const setPid3: TransformFunction = (message) => { - (message as Hl7Message).setField("PID.3.1", "TEST2"); - return message; + return (message as Hl7Message).withField("PID.3.1", "TEST2"); }; const assumeLatin1 = { hl7v2: { assumeCharset: "8859/1" } } as const; /** The segment of `body` that starts with `name`, as bytes. */ @@ -326,7 +323,7 @@ describe("decode and encode", () => { it("fails an edit to a segment holding such a byte without the setting, naming it", async () => { const failure = await failureOf(runTransform(setPid3, "hl7v2", undeclaredLatin1Adt())); - expect(failure).toMatchObject({ kind: "output", code: "UNENCODABLE_CHARACTER" }); + expect(failure).toMatchObject({ kind: "output", code: "HL7_ENCODE_UNENCODABLE_CHARACTER" }); expect(failure.detail).toContain("MSH-18 is blank"); expect(failure.detail).toContain("hl7v2.assumeCharset"); expect(failure.detail).not.toMatch(/LPHA|TESTPAT|TEST2/); @@ -351,21 +348,20 @@ describe("decode and encode", () => { it("with hl7v2.assumeCharset 8859/1, still refuses a character Latin-1 has no byte for", async () => { const euro: TransformFunction = (message) => { - (message as Hl7Message).setField("PID.5.2", "EURO€NAME"); - return message; + return (message as Hl7Message).withField("PID.5.2", "EURO€NAME"); }; const failure = await failureOf( runTransform(euro, "hl7v2", undeclaredLatin1Adt(), undefined, assumeLatin1), ); - expect(failure).toMatchObject({ kind: "output", code: "UNENCODABLE_CHARACTER" }); + expect(failure).toMatchObject({ kind: "output", code: "HL7_ENCODE_UNENCODABLE_CHARACTER" }); expect(failure.detail).toContain('"8859/1"'); expect(failure.detail).not.toMatch(/EURO|NAME|€|LPHA|assumeCharset/); }); it("with the setting, still reads and writes a declared MSH-18 in its own set", async () => { - const message = generateAdt({ seed: 22, trigger: "A01" }); - message.setField("MSH.18", "UNICODE UTF-8"); - message.setField("PID.5.1", "TESTPATIENTÉ"); + const message = generateAdt({ seed: 22, trigger: "A01" }) + .withField("MSH.18", "UNICODE UTF-8") + .withField("PID.5.1", "TESTPATIENTÉ"); const body = bytes(message.toString()); const [edited] = await runTransform(setPid3, "hl7v2", body, undefined, assumeLatin1); // E-acute stays two UTF-8 bytes: the assumed set applies to a blank MSH-18 only. @@ -378,7 +374,7 @@ describe("decode and encode", () => { const shadowed = '{"resourceType":"Patient","active":true,"active":false}'; expect(await failureOf(runTransform(identity, "fhir", bytes(shadowed)))).toMatchObject({ kind: "output", - code: "UNSERIALIZABLE_SHADOWED_PROPERTY", + code: "FHIR_UNSERIALIZABLE_SHADOWED_PROPERTY", }); }); }); @@ -386,8 +382,7 @@ describe("decode and encode", () => { describe("runTransform", () => { it("runs a message through and serializes what comes back", async () => { const edit: TransformFunction = (message) => { - (message as Hl7Message).setField("MSH.5", "LAB2"); - return message; + return (message as Hl7Message).withField("MSH.5", "LAB2"); }; const [out] = await runTransform(edit, "hl7v2", bytes(ADT_A01)); expect(text(out)).toContain("|LAB2|"); @@ -413,7 +408,7 @@ describe("runTransform", () => { it("names the stage that failed", async () => { expect(await failureOf(runTransform(identity, "hl7v2", bytes("not hl7")))).toMatchObject({ kind: "parse", - code: "NO_MSH_SEGMENT", + code: "HL7_NO_MSH_SEGMENT", }); const thrown = await failureOf( runTransform( diff --git a/test/worker-memory.test.ts b/test/worker-memory.test.ts index c3fe1561..1fd151b9 100644 --- a/test/worker-memory.test.ts +++ b/test/worker-memory.test.ts @@ -26,10 +26,8 @@ afterEach(async () => { /** The starter's kind of edit: address the message to the lab, and send it on. */ const ADDRESS_TO_LAB = [ - "export default (msg: { setField(path: string, value: string): void }) => {", - ' msg.setField("MSH.5", "LAB");', - " return msg;", - "};", + "export default (msg: { withField(path: string, value: string): unknown }) =>", + ' msg.withField("MSH.5", "LAB");', "", ].join("\n");