Generate ASTM messages
The @cosyte/synth/astm subpath builds ASTM laboratory messages through @cosyte/astm's own
builders: buildAstmMessage for the E1394 record layer and composeAstmFrames for the E1381 frame
layer. Install @cosyte/astm alongside it (Installation).
- Records (E1394).
generateAstmResultreturns a result report (H,P,O,Rrecords,C, andL);generateAstmOrderreturns the order side (H,P,O, andL). TheH|\^&delimiter declaration, the record type letters, the sequence numbers, and theLterminator come from the builder. Both return a string. - Framing (E1381).
generateAstmResultFramedwraps the same records in frames, with the modulo-256 checksum and the frame numbers (0to7) computed by@cosyte/astm. It returns the bytes as aUint8Array.
Generate a result report and check it reads back clean
astmRoundTrip parses the records with @cosyte/astm and serializes them again:
import { astmRoundTrip, generateAstmResult } from "@cosyte/synth/astm";
// The same seed gives the same record stream, on any machine and any run.
const result = astmRoundTrip(generateAstmResult({ seed: 12345 }));
result.warnings; // => []
result.byteStable; // => true
result.specClean; // => true
Generate a framed message
astmFramedRoundTrip decodes the frames and the records inside them, so a wrong checksum or frame
number shows up as a warning:
import { astmFramedRoundTrip, generateAstmResultFramed } from "@cosyte/synth/astm";
const framed = astmFramedRoundTrip(generateAstmResultFramed({ seed: 12345 }));
framed.warnings; // => []
framed.specClean; // => true
Build a corpus
astmCorpus generates a result report and an order by default:
import { astmCorpus } from "@cosyte/synth/astm";
const corpus = astmCorpus({ seed: 42 });
corpus.artifacts.map((a) => a.kind); // => ["Result", "Order"]
corpus.artifacts.every((a) => a.warnings.length === 0); // => true
What a message carries
The P (patient) record carries the name, the birth date, and the practice-assigned and
laboratory-assigned patient IDs. The name comes from the invented-name pool, the birth date from
the seeded generator, and the two IDs are minted separately under a synthetic assigning authority,
so they differ, as @cosyte/astm keeps them apart when it parses. A result pairs a test code and a
value with no claim that they make clinical sense.
Generate an off-spec message
Quirk fixtures ship for ASTM: a non-standard &Z& escape that raises
ASTM_UNKNOWN_ESCAPE_SEQUENCE, and a site-defined record type that raises
ASTM_RECORD_UNKNOWN_TYPE. See Generate vendor-quirk fixtures.
Frame-layer faults (a wrong checksum, framing dropped over TCP) raise diagnostics that no parser
profile tolerates, so they are not generated.
Related
- Reference:
generateAstmResult,generateAstmOrder,generateAstmResultFramed,astmRoundTrip, andastmCorpus.