@astm-e1394/dictionary 0.0.0-stage → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -2
  3. package/astm-date.util.d.ts +13 -0
  4. package/astm-date.util.js +90 -0
  5. package/astm-dictionary.d.ts +36 -0
  6. package/astm-dictionary.js +69 -0
  7. package/astm-number.util.d.ts +4 -0
  8. package/astm-number.util.js +43 -0
  9. package/astm-records.d.ts +2 -0
  10. package/astm-records.js +164 -0
  11. package/astm-types.d.ts +2 -0
  12. package/astm-types.js +66 -0
  13. package/index.d.ts +9 -0
  14. package/index.js +9 -0
  15. package/package.json +22 -3
  16. package/record-fields/c-record.enum.d.ts +8 -0
  17. package/record-fields/c-record.enum.js +9 -0
  18. package/record-fields/h-record.enum.d.ts +17 -0
  19. package/record-fields/h-record.enum.js +18 -0
  20. package/record-fields/index.d.ts +9 -0
  21. package/record-fields/index.js +9 -0
  22. package/record-fields/l-record.enum.d.ts +6 -0
  23. package/record-fields/l-record.enum.js +7 -0
  24. package/record-fields/m-record.enum.d.ts +5 -0
  25. package/record-fields/m-record.enum.js +6 -0
  26. package/record-fields/o-record.enum.d.ts +34 -0
  27. package/record-fields/o-record.enum.js +35 -0
  28. package/record-fields/p-record.enum.d.ts +38 -0
  29. package/record-fields/p-record.enum.js +39 -0
  30. package/record-fields/q-record.enum.d.ts +16 -0
  31. package/record-fields/q-record.enum.js +17 -0
  32. package/record-fields/r-record.enum.d.ts +17 -0
  33. package/record-fields/r-record.enum.js +18 -0
  34. package/record-fields/s-record.enum.d.ts +24 -0
  35. package/record-fields/s-record.enum.js +25 -0
  36. package/tables/astm-tables.d.ts +2 -0
  37. package/tables/astm-tables.js +128 -0
  38. package/tables/codes.enum.d.ts +125 -0
  39. package/tables/codes.enum.js +141 -0
  40. package/tables/index.d.ts +2 -0
  41. package/tables/index.js +2 -0
  42. package/type-fields/ad-type.enum.d.ts +8 -0
  43. package/type-fields/ad-type.enum.js +9 -0
  44. package/type-fields/cn-type.enum.d.ts +9 -0
  45. package/type-fields/cn-type.enum.js +10 -0
  46. package/type-fields/cq-type.enum.d.ts +5 -0
  47. package/type-fields/cq-type.enum.js +6 -0
  48. package/type-fields/index.d.ts +6 -0
  49. package/type-fields/index.js +6 -0
  50. package/type-fields/pn-type.enum.d.ts +8 -0
  51. package/type-fields/pn-type.enum.js +9 -0
  52. package/type-fields/spd-type.enum.d.ts +5 -0
  53. package/type-fields/spd-type.enum.js +6 -0
  54. package/type-fields/uti-type.enum.d.ts +7 -0
  55. package/type-fields/uti-type.enum.js +8 -0
  56. package/types.d.ts +36 -0
  57. package/types.js +1 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Panates
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # @astm-e1394/dictionary
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Record and field definitions of ASTM E1394 (LIS2-A2).
4
+
5
+ [![NPM Version][npm-image]][npm-url]
6
+ [![NPM Downloads][downloads-image]][downloads-url]
7
+ [![CI Tests][ci-test-image]][ci-test-url]
8
+ [![Test Coverage][coveralls-image]][coveralls-url]
9
+
10
+ [npm-image]: https://img.shields.io/npm/v/@astm-e1394/dictionary
11
+ [npm-url]: https://npmjs.org/package/@astm-e1394/dictionary
12
+ [downloads-image]: https://img.shields.io/npm/dm/@astm-e1394/dictionary.svg
13
+ [downloads-url]: https://npmjs.org/package/@astm-e1394/dictionary
14
+ [ci-test-image]: https://github.com/panates/astm-e1394/actions/workflows/test.yml/badge.svg
15
+ [ci-test-url]: https://github.com/panates/astm-e1394/actions/workflows/test.yml
16
+ [coveralls-image]: https://img.shields.io/coveralls/panates/astm-e1394/dev.svg
17
+ [coveralls-url]: https://coveralls.io/r/panates/astm-e1394
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install @astm-e1394/dictionary@beta
23
+ ```
24
+
25
+ `@astm-e1394/core` installs it and exports everything it has.
26
+
27
+ ## Contents
28
+
29
+ - Record definitions of ASTM E1394-97 / CLSI LIS2-A2: H, P, O, R, C, Q, M, S and L, with each field's data type, whether it repeats, and the table of its codes.
30
+ - Enums of field positions (`PRecord.PatientName` is 6) and component positions (`PNType.FirstName` is 2).
31
+ - Code tables and their enums (`Priority.Stat` is `S`).
32
+ - Date, date/time and number codecs.
33
+
34
+ An instrument's own fields and codes go into a dictionary made with `extend()`:
35
+
36
+ ```typescript
37
+ import { dictionary } from '@astm-e1394/dictionary';
38
+
39
+ const ours = dictionary.extend({
40
+ records: { M: { fields: { '3': { type: 'ST', desc: 'Reagent lot' } } } },
41
+ tables: { AbnormalFlag: { values: { '*': 'Instrument flag' } } },
42
+ });
43
+ ```
44
+
45
+ ## License
46
+
47
+ [MIT](https://github.com/panates/astm-e1394/blob/main/LICENSE)
@@ -0,0 +1,13 @@
1
+ /** A Date as an ASTM date and time, in local time: 20250102060405 */
2
+ export declare function formatAstmDateTime(date: Date): string;
3
+ /** A Date as an ASTM date, its local date: 20250102 */
4
+ export declare function formatAstmDate(date: Date): string;
5
+ /**
6
+ * An ASTM date, or date and time, as a Date in local time. Missing parts
7
+ * are their lowest: "202501021230" is 12:30:00.
8
+ */
9
+ export declare function parseAstmDateTime(value: string): Date;
10
+ /** Date and time: a value read is kept as written once checked; a Date is formatted */
11
+ export declare function toAstmDateTime(value: Date | string, read?: boolean): string;
12
+ /** Date: a value read is kept as written once checked; a Date is formatted */
13
+ export declare function toAstmDate(value: Date | string, read?: boolean): string;
@@ -0,0 +1,90 @@
1
+ /*
2
+ * ASTM E1394 date and time values: YYYYMMDD for a date, YYYYMMDDHHMMSS for
3
+ * a date and time, read with the trailing parts left out
4
+ * (YYYYMMDDHHMM). The standard has no time zone: a time is the sender's
5
+ * local time, taken to be ours.
6
+ *
7
+ * A value read from a message is kept as written - its precision is part of
8
+ * it - and only checked. A Date is written in local time.
9
+ */
10
+ const DT = /^(\d{4})(\d{2})(\d{2})$/;
11
+ const TS = /^(\d{4})(\d{2})(\d{2})(?:(\d{2})(\d{2})(\d{2})?)?$/;
12
+ const pad = (n, width = 2) => String(n).padStart(width, '0');
13
+ function checkParts(value, month, day, hour, minute, second, what = 'date/time') {
14
+ const bad = +month < 1 ||
15
+ +month > 12 ||
16
+ +day < 1 ||
17
+ +day > 31 ||
18
+ (hour && +hour > 23) ||
19
+ (minute && +minute > 59) ||
20
+ (second && +second > 59);
21
+ if (bad)
22
+ throw new TypeError(`Value "${value}" is not a valid ASTM ${what}`);
23
+ }
24
+ /**
25
+ * A Date, or an ISO 8601 string (2025-01-02T03:04:05Z) given in code, as a
26
+ * Date; undefined for an ASTM value - and ASTM text read is never taken as
27
+ * ISO
28
+ */
29
+ function asDate(value, read) {
30
+ if (value instanceof Date) {
31
+ if (isNaN(value.getTime()))
32
+ throw new TypeError('Invalid Date');
33
+ return value;
34
+ }
35
+ if (!read && /^\d{4}-\d{2}/.test(String(value).trim())) {
36
+ const d = new Date(String(value).trim());
37
+ if (isNaN(d.getTime())) {
38
+ throw new TypeError(`Value "${value}" is not a valid date`);
39
+ }
40
+ return d;
41
+ }
42
+ }
43
+ /** A Date as an ASTM date and time, in local time: 20250102060405 */
44
+ export function formatAstmDateTime(date) {
45
+ return (formatAstmDate(date) +
46
+ pad(date.getHours()) +
47
+ pad(date.getMinutes()) +
48
+ pad(date.getSeconds()));
49
+ }
50
+ /** A Date as an ASTM date, its local date: 20250102 */
51
+ export function formatAstmDate(date) {
52
+ return (pad(date.getFullYear(), 4) + pad(date.getMonth() + 1) + pad(date.getDate()));
53
+ }
54
+ /**
55
+ * An ASTM date, or date and time, as a Date in local time. Missing parts
56
+ * are their lowest: "202501021230" is 12:30:00.
57
+ */
58
+ export function parseAstmDateTime(value) {
59
+ const v = value.trim();
60
+ const m = TS.exec(v);
61
+ if (!m)
62
+ throw new TypeError(`Value "${value}" is not a valid ASTM date/time`);
63
+ const [, y, mo, d, h = '00', mi = '00', s = '00'] = m;
64
+ checkParts(v, mo, d, h, mi, s);
65
+ return new Date(+y, +mo - 1, +d, +h, +mi, +s);
66
+ }
67
+ /** Date and time: a value read is kept as written once checked; a Date is formatted */
68
+ export function toAstmDateTime(value, read) {
69
+ const date = asDate(value, read);
70
+ if (date)
71
+ return formatAstmDateTime(date);
72
+ const v = String(value).trim();
73
+ const m = TS.exec(v);
74
+ if (!m)
75
+ throw new TypeError(`Value "${value}" is not a valid ASTM date/time`);
76
+ checkParts(v, m[2], m[3], m[4], m[5], m[6]);
77
+ return v;
78
+ }
79
+ /** Date: a value read is kept as written once checked; a Date is formatted */
80
+ export function toAstmDate(value, read) {
81
+ const date = asDate(value, read);
82
+ if (date)
83
+ return formatAstmDate(date);
84
+ const v = String(value).trim();
85
+ const m = DT.exec(v);
86
+ if (!m)
87
+ throw new TypeError(`Value "${value}" is not a valid ASTM date`);
88
+ checkParts(v, m[2], m[3], undefined, undefined, undefined, 'date');
89
+ return v;
90
+ }
@@ -0,0 +1,36 @@
1
+ import type { AstmDataTypeDefinition, AstmRecordDefinition, AstmTableDefinition } from './types.js';
2
+ /** A definition with every part optional, for merging over one */
3
+ export type DeepPartial<T> = T extends (...args: any[]) => any ? T : T extends object ? {
4
+ [K in keyof T]?: DeepPartial<T[K]>;
5
+ } : T;
6
+ /**
7
+ * The definitions a message is read and written with: records, data types
8
+ * and tables. The default one (`dictionary`) is ASTM E1394 / LIS2-A2 as the
9
+ * standard defines it; an instrument's own fields and codes go into one made
10
+ * with extend().
11
+ */
12
+ export declare class AstmDictionary {
13
+ records: Record<string, AstmRecordDefinition>;
14
+ types: Record<string, AstmDataTypeDefinition>;
15
+ tables: Record<string, AstmTableDefinition>;
16
+ constructor(args?: {
17
+ records?: Record<string, AstmRecordDefinition>;
18
+ types?: Record<string, AstmDataTypeDefinition>;
19
+ tables?: Record<string, AstmTableDefinition>;
20
+ });
21
+ /** The text of a code in a table: tableValue('Sex', 'F') is "Female" */
22
+ tableValue(table: string, code: string): string | undefined;
23
+ /**
24
+ * Creates a dictionary with this one's definitions, the given ones merged
25
+ * over them - a manufacturer's fields of the M record, an instrument's own
26
+ * result flags. Only what is given is copied - every other definition is
27
+ * shared, unchanged, with this dictionary.
28
+ */
29
+ extend(args: {
30
+ records?: Record<string, DeepPartial<AstmRecordDefinition>>;
31
+ types?: Record<string, DeepPartial<AstmDataTypeDefinition>>;
32
+ tables?: Record<string, DeepPartial<AstmTableDefinition>>;
33
+ }): AstmDictionary;
34
+ }
35
+ /** ASTM E1394-97 / CLSI LIS2-A2 */
36
+ export declare const dictionary: AstmDictionary;
@@ -0,0 +1,69 @@
1
+ import { ASTM_RECORDS } from './astm-records.js';
2
+ import { ASTM_TYPES } from './astm-types.js';
3
+ import { ASTM_TABLES } from './tables/astm-tables.js';
4
+ /**
5
+ * The definitions a message is read and written with: records, data types
6
+ * and tables. The default one (`dictionary`) is ASTM E1394 / LIS2-A2 as the
7
+ * standard defines it; an instrument's own fields and codes go into one made
8
+ * with extend().
9
+ */
10
+ export class AstmDictionary {
11
+ records;
12
+ types;
13
+ tables;
14
+ constructor(args) {
15
+ this.records = args?.records || {};
16
+ this.types = args?.types || {};
17
+ this.tables = args?.tables || {};
18
+ }
19
+ /** The text of a code in a table: tableValue('Sex', 'F') is "Female" */
20
+ tableValue(table, code) {
21
+ return this.tables[table]?.values[code];
22
+ }
23
+ /**
24
+ * Creates a dictionary with this one's definitions, the given ones merged
25
+ * over them - a manufacturer's fields of the M record, an instrument's own
26
+ * result flags. Only what is given is copied - every other definition is
27
+ * shared, unchanged, with this dictionary.
28
+ */
29
+ extend(args) {
30
+ const dict = new AstmDictionary({
31
+ records: { ...this.records },
32
+ types: { ...this.types },
33
+ tables: { ...this.tables },
34
+ });
35
+ if (args.records)
36
+ overwrite(dict.records, args.records);
37
+ if (args.types)
38
+ overwrite(dict.types, args.types);
39
+ if (args.tables)
40
+ overwrite(dict.tables, args.tables);
41
+ return dict;
42
+ }
43
+ }
44
+ /**
45
+ * Copy-on-write: a definition may be shared, frozen, by several
46
+ * dictionaries, so the merge goes into a copy that then replaces it in this
47
+ * dictionary alone.
48
+ */
49
+ function overwrite(target, defs) {
50
+ for (const [name, def] of Object.entries(defs)) {
51
+ target[name] = merge(target[name], def);
52
+ }
53
+ }
54
+ const isPlainObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
55
+ function merge(base, over) {
56
+ if (!isPlainObject(over))
57
+ return over;
58
+ const out = isPlainObject(base) ? { ...base } : {};
59
+ for (const [key, value] of Object.entries(over)) {
60
+ out[key] = merge(out[key], value);
61
+ }
62
+ return out;
63
+ }
64
+ /** ASTM E1394-97 / CLSI LIS2-A2 */
65
+ export const dictionary = new AstmDictionary({
66
+ records: { ...ASTM_RECORDS },
67
+ types: { ...ASTM_TYPES },
68
+ tables: { ...ASTM_TABLES },
69
+ });
@@ -0,0 +1,4 @@
1
+ /** NM: a number, or text in NM's form; anything else is refused */
2
+ export declare function toAstmNumber(value: unknown): number | string;
3
+ /** SI: a non-negative integer, a record's sequence number */
4
+ export declare function toAstmSequenceNumber(value: unknown): number | string;
@@ -0,0 +1,43 @@
1
+ /*
2
+ * Numbers: an optional sign, digits and an optional decimal point - "12.5",
3
+ * "-3", ".5" - with no exponent, no thousands separator and no decimal comma.
4
+ * A sequence number is a positive integer.
5
+ */
6
+ const NM = /^[+-]?(\d+(\.\d*)?|\.\d+)$/;
7
+ const SI = /^\d+$/;
8
+ /**
9
+ * The number a value holds, when a JavaScript number holds it exactly;
10
+ * otherwise the text, as written - "12345678901234567890" is not rounded
11
+ */
12
+ function asNumber(text) {
13
+ const n = Number(text);
14
+ const digits = text.replace(/^[+-]/, '').replace('.', '').replace(/^0+/, '');
15
+ return digits.length <= 15 ? n : text;
16
+ }
17
+ /** NM: a number, or text in NM's form; anything else is refused */
18
+ export function toAstmNumber(value) {
19
+ if (typeof value === 'number') {
20
+ if (!Number.isFinite(value))
21
+ throw new TypeError(`Value "${value}" is not a number`);
22
+ return value;
23
+ }
24
+ const text = String(value ?? '').trim();
25
+ if (!NM.test(text)) {
26
+ throw new TypeError(`Value "${value}" is not a valid ASTM number`);
27
+ }
28
+ return asNumber(text);
29
+ }
30
+ /** SI: a non-negative integer, a record's sequence number */
31
+ export function toAstmSequenceNumber(value) {
32
+ if (typeof value === 'number') {
33
+ if (!Number.isInteger(value) || value < 0) {
34
+ throw new TypeError(`Value "${value}" is not a valid sequence number`);
35
+ }
36
+ return value;
37
+ }
38
+ const text = String(value ?? '').trim();
39
+ if (!SI.test(text)) {
40
+ throw new TypeError(`Value "${value}" is not a valid sequence number`);
41
+ }
42
+ return asNumber(text);
43
+ }
@@ -0,0 +1,2 @@
1
+ import type { AstmRecordDefinition } from './types.js';
2
+ export declare const ASTM_RECORDS: Readonly<Record<string, AstmRecordDefinition>>;
@@ -0,0 +1,164 @@
1
+ function record(desc, fields) {
2
+ const out = {};
3
+ fields.forEach(([type, fieldDesc, options], i) => {
4
+ out[String(i + 1)] = Object.freeze({ type, desc: fieldDesc, ...options });
5
+ });
6
+ return Object.freeze({ desc, fields: Object.freeze(out) });
7
+ }
8
+ const RECORD_TYPE = ['ST', 'Record Type ID'];
9
+ const SEQUENCE = ['SI', 'Sequence Number'];
10
+ export const ASTM_RECORDS = Object.freeze({
11
+ H: record('Message Header', [
12
+ RECORD_TYPE,
13
+ ['ST', 'Delimiter Definition'],
14
+ ['ST', 'Message Control ID'],
15
+ ['ST', 'Access Password'],
16
+ ['ST', 'Sender Name or ID'],
17
+ ['AD', 'Sender Street Address'],
18
+ ['ST', 'Reserved Field'],
19
+ ['ST', 'Sender Telephone Number', { rep: true }],
20
+ ['ST', 'Characteristics of Sender'],
21
+ ['ST', 'Receiver ID'],
22
+ ['ST', 'Comment or Special Instructions'],
23
+ ['ID', 'Processing ID', { table: 'ProcessingID' }],
24
+ ['ST', 'Version Number'],
25
+ ['TS', 'Date and Time of Message'],
26
+ ]),
27
+ P: record('Patient Information', [
28
+ RECORD_TYPE,
29
+ SEQUENCE,
30
+ ['ST', 'Practice Assigned Patient ID'],
31
+ ['ST', 'Laboratory Assigned Patient ID'],
32
+ ['ST', 'Patient ID No. 3'],
33
+ ['PN', 'Patient Name'],
34
+ ['ST', "Mother's Maiden Name"],
35
+ ['TS', 'Birthdate'],
36
+ ['ID', 'Patient Sex', { table: 'Sex' }],
37
+ ['ST', 'Patient Race-Ethnic Origin'],
38
+ ['AD', 'Patient Address'],
39
+ ['ST', 'Reserved Field'],
40
+ ['ST', 'Patient Telephone Number', { rep: true }],
41
+ ['CN', 'Attending Physician ID', { rep: true }],
42
+ ['ST', 'Special Field 1'],
43
+ ['ST', 'Special Field 2'],
44
+ ['CQ', 'Patient Height'],
45
+ ['CQ', 'Patient Weight'],
46
+ ['ST', "Patient's Known or Suspected Diagnosis", { rep: true }],
47
+ ['ST', 'Patient Active Medications', { rep: true }],
48
+ ['ST', "Patient's Diet"],
49
+ ['ST', 'Practice Field No. 1'],
50
+ ['ST', 'Practice Field No. 2'],
51
+ ['TS', 'Admission and Discharge Dates', { rep: true }],
52
+ ['ID', 'Admission Status', { table: 'AdmissionStatus' }],
53
+ ['ST', 'Location'],
54
+ ['ST', 'Nature of Alternative Diagnostic Code and Classifiers'],
55
+ ['ST', 'Alternative Diagnostic Code and Classification', { rep: true }],
56
+ ['ST', 'Patient Religion'],
57
+ ['ID', 'Marital Status', { table: 'MaritalStatus' }],
58
+ ['ST', 'Isolation Status', { rep: true }],
59
+ ['ST', 'Language'],
60
+ ['ST', 'Hospital Service'],
61
+ ['ST', 'Hospital Institution'],
62
+ ['ST', 'Dosage Category'],
63
+ ]),
64
+ O: record('Test Order', [
65
+ RECORD_TYPE,
66
+ SEQUENCE,
67
+ ['ST', 'Specimen ID'],
68
+ ['ST', 'Instrument Specimen ID'],
69
+ ['UTI', 'Universal Test ID', { rep: true }],
70
+ ['ID', 'Priority', { table: 'Priority' }],
71
+ ['TS', 'Requested/Ordered Date and Time'],
72
+ ['TS', 'Specimen Collection Date and Time'],
73
+ ['TS', 'Collection End Time'],
74
+ ['CQ', 'Collection Volume'],
75
+ ['ST', 'Collector ID'],
76
+ ['ID', 'Action Code', { table: 'ActionCode' }],
77
+ ['ST', 'Danger Code'],
78
+ ['ST', 'Relevant Clinical Information'],
79
+ ['TS', 'Date/Time Specimen Received'],
80
+ ['SPD', 'Specimen Descriptor'],
81
+ ['CN', 'Ordering Physician'],
82
+ ['ST', "Physician's Telephone Number"],
83
+ ['ST', 'User Field No. 1'],
84
+ ['ST', 'User Field No. 2'],
85
+ ['ST', 'Laboratory Field No. 1'],
86
+ ['ST', 'Laboratory Field No. 2'],
87
+ ['TS', 'Date/Time Results Reported or Last Modified'],
88
+ ['ST', 'Instrument Charge to Computer System'],
89
+ ['ST', 'Instrument Section ID'],
90
+ ['ID', 'Report Types', { table: 'ReportType' }],
91
+ ['ST', 'Reserved Field'],
92
+ ['ST', 'Location or Ward of Specimen Collection'],
93
+ ['ST', 'Nosocomial Infection Flag'],
94
+ ['ST', 'Specimen Service'],
95
+ ['ST', 'Specimen Institution'],
96
+ ]),
97
+ R: record('Result', [
98
+ RECORD_TYPE,
99
+ SEQUENCE,
100
+ ['UTI', 'Universal Test ID'],
101
+ ['ST', 'Data or Measurement Value'],
102
+ ['ST', 'Units'],
103
+ ['ST', 'Reference Ranges'],
104
+ ['ID', 'Result Abnormal Flags', { table: 'AbnormalFlag' }],
105
+ ['ST', 'Nature of Abnormality Testing'],
106
+ ['ID', 'Result Status', { table: 'ResultStatus' }],
107
+ ['TS', 'Date of Change in Instrument Normative Values or Units'],
108
+ ['ST', 'Operator Identification'],
109
+ ['TS', 'Date/Time Test Started'],
110
+ ['TS', 'Date/Time Test Completed'],
111
+ ['ST', 'Instrument Identification'],
112
+ ]),
113
+ C: record('Comment', [
114
+ RECORD_TYPE,
115
+ SEQUENCE,
116
+ ['ID', 'Comment Source', { table: 'CommentSource' }],
117
+ ['ST', 'Comment Text', { rep: true }],
118
+ ['ID', 'Comment Type', { table: 'CommentType' }],
119
+ ]),
120
+ Q: record('Request Information', [
121
+ RECORD_TYPE,
122
+ SEQUENCE,
123
+ ['ST', 'Starting Range ID Number'],
124
+ ['ST', 'Ending Range ID Number'],
125
+ ['UTI', 'Universal Test ID', { rep: true }],
126
+ ['ID', 'Nature of Request Time Limits', { table: 'RequestTimeLimits' }],
127
+ ['TS', 'Beginning Request Results Date and Time'],
128
+ ['TS', 'Ending Request Results Date and Time'],
129
+ ['ST', 'Requesting Physician Name'],
130
+ ['ST', 'Requesting Physician Telephone Number'],
131
+ ['ST', 'User Field No. 1'],
132
+ ['ST', 'User Field No. 2'],
133
+ ['ID', 'Request Information Status Codes', { table: 'RequestStatus' }],
134
+ ]),
135
+ M: record('Manufacturer Information', [RECORD_TYPE, SEQUENCE]),
136
+ S: record('Scientific', [
137
+ RECORD_TYPE,
138
+ SEQUENCE,
139
+ ['ST', 'Analytical Method'],
140
+ ['ST', 'Instrumentation'],
141
+ ['ST', 'Reagents'],
142
+ ['ST', 'Units of Measure'],
143
+ ['ST', 'Quality Control'],
144
+ ['ST', 'Specimen Descriptor'],
145
+ ['ST', 'Reserved Field'],
146
+ ['ST', 'Container'],
147
+ ['ST', 'Specimen ID'],
148
+ ['ST', 'Analyte'],
149
+ ['ST', 'Result'],
150
+ ['ST', 'Result Units'],
151
+ ['TS', 'Collection Date and Time'],
152
+ ['TS', 'Result Date and Time'],
153
+ ['ST', 'Analytical Preprocessing Steps'],
154
+ ['ST', 'Patient Diagnosis'],
155
+ ['TS', 'Patient Birthdate'],
156
+ ['ID', 'Patient Sex', { table: 'Sex' }],
157
+ ['ST', 'Patient Race'],
158
+ ]),
159
+ L: record('Message Terminator', [
160
+ RECORD_TYPE,
161
+ SEQUENCE,
162
+ ['ID', 'Termination Code', { table: 'TerminationCode' }],
163
+ ]),
164
+ });
@@ -0,0 +1,2 @@
1
+ import type { AstmDataTypeDefinition } from './types.js';
2
+ export declare const ASTM_TYPES: Readonly<Record<string, AstmDataTypeDefinition>>;
package/astm-types.js ADDED
@@ -0,0 +1,66 @@
1
+ import { toAstmDate, toAstmDateTime } from './astm-date.util.js';
2
+ import { toAstmNumber, toAstmSequenceNumber } from './astm-number.util.js';
3
+ /*
4
+ * The data types. ASTM E1394 describes each field's value in words; these
5
+ * names give those descriptions a type each, so a field reads and writes
6
+ * its value the same way everywhere. Composite types name their components,
7
+ * which the enums in type-fields/ name too.
8
+ */
9
+ function components(desc, names) {
10
+ const fields = {};
11
+ names.forEach(([type, fieldDesc], i) => {
12
+ fields[String(i + 1)] = Object.freeze({ type, desc: fieldDesc });
13
+ });
14
+ return Object.freeze({ desc, fields: Object.freeze(fields) });
15
+ }
16
+ export const ASTM_TYPES = Object.freeze({
17
+ ST: Object.freeze({ desc: 'Text' }),
18
+ ID: Object.freeze({ desc: 'Coded value' }),
19
+ NM: Object.freeze({ desc: 'Number', decode: toAstmNumber }),
20
+ SI: Object.freeze({
21
+ desc: 'Sequence number',
22
+ decode: toAstmSequenceNumber,
23
+ }),
24
+ DT: Object.freeze({ desc: 'Date', decode: toAstmDate, encode: toAstmDate }),
25
+ TS: Object.freeze({
26
+ desc: 'Date and time',
27
+ decode: toAstmDateTime,
28
+ encode: toAstmDateTime,
29
+ }),
30
+ PN: components('Person name', [
31
+ ['ST', 'Last Name'],
32
+ ['ST', 'First Name'],
33
+ ['ST', 'Middle Name'],
34
+ ['ST', 'Suffix'],
35
+ ['ST', 'Title'],
36
+ ]),
37
+ CN: components('Physician', [
38
+ ['ST', 'ID'],
39
+ ['ST', 'Last Name'],
40
+ ['ST', 'First Name'],
41
+ ['ST', 'Middle Name'],
42
+ ['ST', 'Suffix'],
43
+ ['ST', 'Title'],
44
+ ]),
45
+ AD: components('Address', [
46
+ ['ST', 'Street Address'],
47
+ ['ST', 'City'],
48
+ ['ST', 'State'],
49
+ ['ST', 'Zip Code'],
50
+ ['ST', 'Country Code'],
51
+ ]),
52
+ UTI: components('Universal test ID', [
53
+ ['ST', 'Universal Test ID'],
54
+ ['ST', 'Universal Test ID Name'],
55
+ ['ST', 'Universal Test ID Type'],
56
+ ['ST', 'Manufacturer Local Code'],
57
+ ]),
58
+ SPD: components('Specimen descriptor', [
59
+ ['ST', 'Specimen Type'],
60
+ ['ST', 'Specimen Source'],
61
+ ]),
62
+ CQ: components('Quantity', [
63
+ ['NM', 'Value'],
64
+ ['ST', 'Units'],
65
+ ]),
66
+ });
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from './astm-date.util.js';
2
+ export * from './astm-dictionary.js';
3
+ export * from './astm-number.util.js';
4
+ export * from './astm-records.js';
5
+ export * from './astm-types.js';
6
+ export * from './record-fields/index.js';
7
+ export * from './tables/index.js';
8
+ export * from './type-fields/index.js';
9
+ export * from './types.js';
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from './astm-date.util.js';
2
+ export * from './astm-dictionary.js';
3
+ export * from './astm-number.util.js';
4
+ export * from './astm-records.js';
5
+ export * from './astm-types.js';
6
+ export * from './record-fields/index.js';
7
+ export * from './tables/index.js';
8
+ export * from './type-fields/index.js';
9
+ export * from './types.js';
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "@astm-e1394/dictionary",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "description": "Record and field definitions of ASTM E1394 (LIS2-A2).",
4
+ "version": "1.0.0-beta.0",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./index.d.ts",
10
+ "default": "./index.js"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "engines": {
15
+ "node": ">=22"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/panates/astm-e1394.git",
20
+ "directory": "packages/core/dictionary"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ }
6
25
  }
@@ -0,0 +1,8 @@
1
+ /** Field positions of the Comment record (C) */
2
+ export declare enum CRecord {
3
+ RecordTypeID = 1,
4
+ SequenceNumber = 2,
5
+ CommentSource = 3,
6
+ CommentText = 4,
7
+ CommentType = 5
8
+ }
@@ -0,0 +1,9 @@
1
+ /** Field positions of the Comment record (C) */
2
+ export var CRecord;
3
+ (function (CRecord) {
4
+ CRecord[CRecord["RecordTypeID"] = 1] = "RecordTypeID";
5
+ CRecord[CRecord["SequenceNumber"] = 2] = "SequenceNumber";
6
+ CRecord[CRecord["CommentSource"] = 3] = "CommentSource";
7
+ CRecord[CRecord["CommentText"] = 4] = "CommentText";
8
+ CRecord[CRecord["CommentType"] = 5] = "CommentType";
9
+ })(CRecord || (CRecord = {}));
@@ -0,0 +1,17 @@
1
+ /** Field positions of the Message Header record (H) */
2
+ export declare enum HRecord {
3
+ RecordTypeID = 1,
4
+ DelimiterDefinition = 2,
5
+ MessageControlID = 3,
6
+ AccessPassword = 4,
7
+ SenderNameOrID = 5,
8
+ SenderStreetAddress = 6,
9
+ ReservedField = 7,
10
+ SenderTelephoneNumber = 8,
11
+ CharacteristicsOfSender = 9,
12
+ ReceiverID = 10,
13
+ CommentOrSpecialInstructions = 11,
14
+ ProcessingID = 12,
15
+ VersionNumber = 13,
16
+ DateAndTimeOfMessage = 14
17
+ }