# astm cheatsheet
Every export of @deckyard/astm. Guides are listed in the introduction .
jennifer import "@deckyard/astm/" as astm;
Every failure is Error{kind: "astm"}. An r argument is a Record, an m a Message, a d Delimiters, an l a Link, a p a Profile. Fields, repeats and components are numbered from 1, as LIS02 numbers them: field 1 is the record type.
# Constants
Constant Value Meaning DEFAULT_DELIMITERS'|\^&'field |, repeat \, component ^, escape &: what most instruments use DEFAULT_FRAME_SIZE240the most text bytes in a frame, as LIS01 sets it DEFAULT_REPLY_TIMEOUT_MS15000how long a sender waits for a reply DEFAULT_FRAME_TIMEOUT_MS30000how long a receiver waits for the next frame DEFAULT_MAX_BYTES131072the largest transmission read or sent: 128 KiB, over a thousand results MAX_FIELDS65536the most fields, repeats and components parse reads in one call MAX_RECORDS4096the most records parse reads in one call
# Records and messages
Function Returns Does astm.delimiters(definition)Delimitersthe delimiters of a four-character definition such as DEFAULT_DELIMITERS astm.parse(text)list of Messageevery message in record text, each from H to L, every record ended by CR; at most MAX_RECORDS records and MAX_FIELDS fields, repeats and components astm.message(records)Messagea message from records, checked: H first, L last, one set of delimiters, every record valid astm.encode(m)stringthe message as text, every record followed by CR astm.encodeRecord(r)stringone record as text, without its CR; an invalid record is an error astm.record(type, d)Recorda new record of a type (H gets its delimiters as field 2) astm.recordType(r)stringthe record's type, field 1
# Fields
Function Returns Does astm.field(r, n)stringfield n unescaped; a field with repeats or components is an error astm.raw(r, n)stringfield n as on the wire, still escaped astm.repeats(r, n)inthow many repeats field n has, 0 when empty astm.components(r, n, rep)list of stringthe components of one repeat, unescaped astm.component(r, n, rep, component)stringone component of one repeat, unescaped, "" when absent astm.values(r, n)list of stringthe first component of every repeat: a code field such as F\R astm.setField(r, n, value)Recordset field n to a value, escaping its delimiters astm.setComponent(r, n, rep, component, value)Recordset one component, escaping, adding empty repeats and components before it astm.setRaw(r, n, text)Recordset field n's wire text as given, checked
# Results, orders, queries
Function Returns Does astm.results(m)list of Resultevery result, with its patient, order and comments astm.order(sampleId, tests)Ordera routine new order for a specimen, to fill in further astm.orders(m)list of Orderevery order, with its patient astm.orderMessage(sender, orders, termination)Messagea message sending orders; the orders of one patient share a P record astm.queries(m)list of Queryevery request for information astm.queryMessage(sender, sampleIds, tests, status)Messagea message asking about specimens
# The link
Function Returns Does astm.profile()ProfileLIS01's values for the computer system (the LIS) astm.instrumentProfile()ProfileLIS01's values for an instrument, which wins contention astm.connect(address, p)Linkconnect over TCP as a client astm.listen(address)net.Listenerlisten over TCP as a server astm.accept(listener, p)Linkwait for the other side to connect astm.openSerial(path, options, p)Linkopen a serial port (Linux, default jennifer binary) astm.send(l, messages)nullsend messages in one transmission: ENQ, frames, EOT astm.receive(l, waitMs)list of Messagereceive the next transmission; empty when none began in time astm.close(l)nullclose the link
# Types
# Delimiters
Field Meaning field as stringbetween fields, usually | repetition as stringbetween repeats, usually \ component as stringbetween components, usually ^ escape as stringopens and closes an escape sequence, usually &
# Record
Field Meaning fields as list of stringthe fields as on the wire, field n at index n - 1 delimiters as Delimitersthe delimiters of its message
# Message
Field Meaning delimiters as Delimitersthe delimiters its header declares records as list of Recordevery record, H first and L last
# Result
Field Meaning patientId as stringP-3, "" without a P record sampleId as stringO-3, the specimen ID test as stringR-3 component 4, the manufacturer's test code value as stringR-4, the measurement units as stringR-5 flags as list of stringR-7, the abnormal flags status as list of stringR-9, the result status completed as stringR-13, YYYYMMDDHHMMSS instrument as stringR-14 record as Recordthe R record order as Recordits O record comments as list of Recordthe C records after it
# Order
Field Meaning patientId as stringP-3 patientName as stringP-6 component 1, the last name birthDate as stringP-8, YYYYMMDD sex as stringP-9 sampleId as stringO-3 tests as list of stringO-5 component 4, one repeat each priority as stringO-6: S, A or R collected as stringO-8, YYYYMMDDHHMMSS action as stringO-12: N, A, C, Q, ... specimen as stringO-16 component 1 reportType as stringO-26: O, Q, F, X, ...
# Query
Field Meaning patientIds as list of stringQ-3 component 1 of each repeat sampleIds as list of stringQ-3 component 2 of each repeat tests as list of stringQ-5 component 4 of each repeat, ALL for every test begin as stringQ-7 end as stringQ-8 status as stringQ-13 record as Recordthe Q record
# Profile
Field Meaning instrument as boolthis side is the instrument and wins contention encoding as stringthe character set: iso-8859-1, windows-1252, ascii, utf-8, ... frameSize as intthe most text bytes in a frame, both ways, 1 to 64000 retries as inthow often a refused frame is sent again, and busy NAKs waited out, 0 to 100 replyTimeoutMs as inthow long a sender waits for a reply frameTimeoutMs as inthow long a receiver waits for the next frame busyWaitMs as inthow long a sender waits after a busy NAK contentionWaitMs as inthow long the side that lost contention waits before its next ENQ maxBytes as intthe largest transmission, 1024 to 67108864 bytes
# Link
Field Meaning kind as stringtcp or serialconn as net.Connthe socket of a tcp link port as serial.Portthe port of a serial link input as channel of intthe bytes read output as channel of intunused outside the tests inbox as channel of stringtransmissions received while sending profile as Profilehow this side behaves