@rethinkhealth/hl7v2-builder 0.4.2 → 0.5.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.
- package/README.md +9 -7
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +19 -19
package/README.md
CHANGED
|
@@ -38,18 +38,18 @@ pnpm add @rethinkhealth/hl7v2-builder
|
|
|
38
38
|
## Usage
|
|
39
39
|
|
|
40
40
|
```typescript
|
|
41
|
-
import { c, f, m, s } from
|
|
41
|
+
import { c, f, m, s } from "@rethinkhealth/hl7v2-builder";
|
|
42
42
|
|
|
43
43
|
const tree = m(
|
|
44
44
|
s(
|
|
45
|
-
f(
|
|
46
|
-
f(
|
|
45
|
+
f("MSH"), // include the segment header explicitly
|
|
46
|
+
f("^~\\&")
|
|
47
47
|
),
|
|
48
48
|
s(
|
|
49
|
-
f(
|
|
49
|
+
f("PID"),
|
|
50
50
|
f(), // empty field
|
|
51
51
|
f([
|
|
52
|
-
c([
|
|
52
|
+
c(["123456", "DOE", "JOHN"]), // accept arrays or individual args interchangeably
|
|
53
53
|
])
|
|
54
54
|
)
|
|
55
55
|
);
|
|
@@ -62,14 +62,16 @@ const tree = m(
|
|
|
62
62
|
The builder respects the `emptyMode` experimental setting from `@rethinkhealth/hl7v2-config`. When `emptyMode: "empty"` is configured in your `.hl7v2rc.json`, empty fields, repetitions, and components will have empty children arrays instead of the legacy full structure.
|
|
63
63
|
|
|
64
64
|
**Legacy mode (default):**
|
|
65
|
+
|
|
65
66
|
```typescript
|
|
66
|
-
f()
|
|
67
|
+
f(); // → Field → Rep → Comp → Sub("")
|
|
67
68
|
```
|
|
68
69
|
|
|
69
70
|
**Empty mode (via config):**
|
|
71
|
+
|
|
70
72
|
```typescript
|
|
71
73
|
// With .hl7v2rc.json: { "settings": { "experimental": { "emptyMode": "empty" } } }
|
|
72
|
-
f()
|
|
74
|
+
f(); // → Field with children: []
|
|
73
75
|
```
|
|
74
76
|
|
|
75
77
|
See [`@rethinkhealth/hl7v2-config`](../hl7v2-config/) for configuration details.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/** biome-ignore-all lint/style/useUnifiedTypeSignatures: fine */
|
|
2
1
|
import type { Component, Field, FieldRepetition, Group, Root, RootContent, Segment } from "@rethinkhealth/hl7v2-ast";
|
|
3
2
|
export declare function m(...children: RootContent[]): Root;
|
|
4
|
-
export declare function g(name: string, ...children:
|
|
3
|
+
export declare function g(name: string, ...children: (Segment | Group)[]): Group;
|
|
5
4
|
export declare function s(name: string, ...fields: Field[]): Segment;
|
|
6
5
|
type FieldValue = FieldRepetition | Component | string;
|
|
7
6
|
type Flattenable<T> = T | T[];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,SAAS,EACT,KAAK,EACL,eAAe,EACf,KAAK,EACL,IAAI,EACJ,WAAW,EACX,OAAO,EACR,MAAM,0BAA0B,CAAC;AAalC,wBAAgB,CAAC,CAAC,GAAG,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAElD;AAED,wBAAgB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC,OAAO,GAAG,KAAK,CAAC,EAAE,GAAG,KAAK,CAIvE;AAKD,wBAAgB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAI3D;AAED,KAAK,UAAU,GAAG,eAAe,GAAG,SAAS,GAAG,MAAM,CAAC;AACvD,KAAK,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAoB9B,kBAAkB;AAClB,wBAAgB,CAAC,IAAI,KAAK,CAAC;AAC3B,wBAAgB,CAAC,CAAC,GAAG,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC,EAAE,GAAG,KAAK,CAAC;AAqD/D,wBAAgB,CAAC,IAAI,eAAe,CAAC;AACrC,wBAAgB,CAAC,CACf,GAAG,UAAU,EAAE,WAAW,CAAC,SAAS,GAAG,MAAM,CAAC,EAAE,GAC/C,eAAe,CAAC;AA6BnB,wBAAgB,CAAC,IAAI,SAAS,CAAC;AAC/B,wBAAgB,CAAC,CAAC,GAAG,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,8 +14,8 @@ function g(name, ...children) {
|
|
|
14
14
|
return group;
|
|
15
15
|
}
|
|
16
16
|
function s(name, ...fields) {
|
|
17
|
-
const
|
|
18
|
-
|
|
17
|
+
const segment = u("segment", fields);
|
|
18
|
+
segment.name = name;
|
|
19
19
|
return segment;
|
|
20
20
|
}
|
|
21
21
|
function flatten(values) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// oxlint-disable typescript/unified-signatures\nimport type {\n Component,\n Field,\n FieldRepetition,\n Group,\n Root,\n RootContent,\n Segment,\n} from \"@rethinkhealth/hl7v2-ast\";\nimport { loadConfig } from \"@rethinkhealth/hl7v2-config\";\nimport { u } from \"unist-builder\";\n\n/**\n * Get the emptyMode setting from the configuration.\n * Falls back to 'legacy' if no config is found or if the setting is not defined.\n */\nfunction getEmptyMode() {\n const config = loadConfig();\n return config.settings.experimental.emptyMode;\n}\n\nexport function m(...children: RootContent[]): Root {\n return u(\"root\", children);\n}\n\nexport function g(name: string, ...children: (Segment | Group)[]): Group {\n const group = u(\"group\", children) as Group;\n group.name = name;\n return group;\n}\n\n// TODO: Add support for string[]\n// export function s(name: string, ...fields: string[]): Segment;\n// export function s(name: string, ...fields: string[] | Field[]): Segment {\nexport function s(name: string, ...fields: Field[]): Segment {\n const segment = u(\"segment\", fields) as Segment;\n segment.name = name;\n return segment;\n}\n\ntype FieldValue = FieldRepetition | Component | string;\ntype Flattenable<T> = T | T[];\n\nfunction flatten<T>(values: Flattenable<T>[]): T[] {\n return values.flatMap((value) => (Array.isArray(value) ? value : [value]));\n}\n\nfunction isFieldRepetition(value: FieldValue): value is FieldRepetition {\n return (\n typeof value === \"object\" &&\n value !== null &&\n value.type === \"field-repetition\"\n );\n}\n\nfunction isComponent(value: FieldValue): value is Component {\n return (\n typeof value === \"object\" && value !== null && value.type === \"component\"\n );\n}\n\n/** Empty field */\nexport function f(): Field;\nexport function f(...values: Flattenable<FieldValue>[]): Field;\nexport function f(...values: Flattenable<FieldValue>[]): Field {\n if (values.length === 0) {\n // Empty field - check emptyMode from config\n const emptyMode = getEmptyMode();\n if (emptyMode === \"empty\") {\n return u(\"field\", []);\n }\n return u(\"field\", [r()]);\n }\n\n const flat = flatten<FieldValue>(values);\n if (flat.length === 0) {\n // Empty field - check emptyMode from config\n const emptyMode = getEmptyMode();\n if (emptyMode === \"empty\") {\n return u(\"field\", []);\n }\n return u(\"field\", [r()]);\n }\n\n const repetitions: FieldRepetition[] = [];\n let pendingComponents: (Component | string)[] = [];\n\n const flushPending = () => {\n if (pendingComponents.length === 0) {\n return;\n }\n repetitions.push(r(...pendingComponents));\n pendingComponents = [];\n };\n\n for (const value of flat) {\n if (isFieldRepetition(value)) {\n flushPending();\n repetitions.push(value);\n continue;\n }\n\n if (isComponent(value) || typeof value === \"string\") {\n pendingComponents.push(value);\n }\n }\n\n flushPending();\n\n if (repetitions.length === 0) {\n return u(\"field\", [r()]);\n }\n\n return u(\"field\", repetitions);\n}\n\nexport function r(): FieldRepetition;\nexport function r(\n ...components: Flattenable<Component | string>[]\n): FieldRepetition;\nexport function r(\n ...components: Flattenable<Component | string>[]\n): FieldRepetition {\n if (components.length === 0) {\n // Empty repetition - check emptyMode from config\n const emptyMode = getEmptyMode();\n if (emptyMode === \"empty\") {\n return u(\"field-repetition\", []);\n }\n return u(\"field-repetition\", [c()]);\n }\n\n const flat = flatten<Component | string>(components);\n if (flat.length === 0) {\n // Empty repetition - check emptyMode from config\n const emptyMode = getEmptyMode();\n if (emptyMode === \"empty\") {\n return u(\"field-repetition\", []);\n }\n return u(\"field-repetition\", [c()]);\n }\n\n return u(\n \"field-repetition\",\n flat.map((value) => (typeof value === \"string\" ? c(value) : value))\n );\n}\n\nexport function c(): Component;\nexport function c(...values: Flattenable<string>[]): Component;\nexport function c(...values: Flattenable<string>[]): Component {\n if (values.length === 0) {\n // Empty component - check emptyMode from config\n const emptyMode = getEmptyMode();\n if (emptyMode === \"empty\") {\n return u(\"component\", []);\n }\n return u(\"component\", [u(\"subcomponent\", \"\")]);\n }\n\n const flat = flatten<string>(values);\n if (flat.length === 0) {\n // Empty component - check emptyMode from config\n const emptyMode = getEmptyMode();\n if (emptyMode === \"empty\") {\n return u(\"component\", []);\n }\n return u(\"component\", [u(\"subcomponent\", \"\")]);\n }\n\n return u(\n \"component\",\n flat.map((subcomponent) => u(\"subcomponent\", subcomponent))\n );\n}\n"],"mappings":";AAUA,SAAS,kBAAkB;AAC3B,SAAS,SAAS;AAMlB,SAAS,eAAe;AACtB,QAAM,SAAS,WAAW;AAC1B,SAAO,OAAO,SAAS,aAAa;AACtC;AAEO,SAAS,KAAK,UAA+B;AAClD,SAAO,EAAE,QAAQ,QAAQ;AAC3B;AAEO,SAAS,EAAE,SAAiB,UAAsC;AACvE,QAAM,QAAQ,EAAE,SAAS,QAAQ;AACjC,QAAM,OAAO;AACb,SAAO;AACT;AAKO,SAAS,EAAE,SAAiB,QAA0B;AAC3D,QAAM,UAAU,EAAE,WAAW,MAAM;AACnC,UAAQ,OAAO;AACf,SAAO;AACT;AAKA,SAAS,QAAW,QAA+B;AACjD,SA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7v2-builder",
|
|
3
|
+
"version": "0.5.0",
|
|
3
4
|
"description": "Build HL7v2 AST nodes",
|
|
4
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"health",
|
|
7
|
+
"healthcare",
|
|
8
|
+
"hl7",
|
|
9
|
+
"hl7v2",
|
|
10
|
+
"nodejs",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://www.rethinkhealth.io/hl7v2/docs",
|
|
5
14
|
"license": "MIT",
|
|
6
15
|
"author": {
|
|
7
16
|
"name": "Melek Somai",
|
|
8
17
|
"email": "melek@rethinkhealth.io"
|
|
9
18
|
},
|
|
10
|
-
"
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
19
|
+
"repository": "rethinkhealth/hl7v2.git",
|
|
12
20
|
"files": [
|
|
13
21
|
"dist"
|
|
14
22
|
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
15
25
|
"exports": {
|
|
16
26
|
".": "./dist/index.js"
|
|
17
27
|
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
18
31
|
"dependencies": {
|
|
19
32
|
"unist-builder": "4.0.0",
|
|
20
|
-
"@rethinkhealth/hl7v2-ast": "0.
|
|
21
|
-
"@rethinkhealth/hl7v2-config": "0.
|
|
33
|
+
"@rethinkhealth/hl7v2-ast": "0.5.0",
|
|
34
|
+
"@rethinkhealth/hl7v2-config": "0.5.0"
|
|
22
35
|
},
|
|
23
36
|
"devDependencies": {
|
|
24
37
|
"@types/node": "24.10.1",
|
|
25
38
|
"@types/unist": "^3.0.3",
|
|
26
|
-
"@vitest/coverage-v8": "4.0.
|
|
39
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
27
40
|
"tsup": "8.5.1",
|
|
28
41
|
"typescript": "^5.9.3",
|
|
29
42
|
"unified": "^11.0.5",
|
|
@@ -34,20 +47,7 @@
|
|
|
34
47
|
"engines": {
|
|
35
48
|
"node": ">=18"
|
|
36
49
|
},
|
|
37
|
-
"repository": "rethinkhealth/hl7v2.git",
|
|
38
|
-
"homepage": "https://www.rethinkhealth.io/hl7v2/docs",
|
|
39
|
-
"keywords": [
|
|
40
|
-
"health",
|
|
41
|
-
"healthcare",
|
|
42
|
-
"hl7",
|
|
43
|
-
"hl7v2",
|
|
44
|
-
"nodejs",
|
|
45
|
-
"typescript"
|
|
46
|
-
],
|
|
47
50
|
"packageManager": "pnpm@10.14.0",
|
|
48
|
-
"publishConfig": {
|
|
49
|
-
"access": "public"
|
|
50
|
-
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsup && tsc --emitDeclarationOnly",
|
|
53
53
|
"check-types": "tsc --noEmit",
|