@rethinkhealth/hl7v2-lint-message-version 0.2.22
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/LICENSE +21 -0
- package/README.md +80 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Rethink Health
|
|
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
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
## @rethinkhealth/hl7v2-lint-message-version
|
|
2
|
+
|
|
3
|
+
> Lint rule that checks an HL7v2 message version (MSH-12) satisfies a version expression.
|
|
4
|
+
|
|
5
|
+
### Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @rethinkhealth/hl7v2-lint-message-version
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { unified } from "unified";
|
|
15
|
+
import { hl7v2Parser } from "@rethinkhealth/hl7v2-parser";
|
|
16
|
+
import hl7v2LintMessageVersion from "@rethinkhealth/hl7v2-lint-message-version";
|
|
17
|
+
|
|
18
|
+
const message = `MSH|^~\\&|SENDER|FAC|RCVR|FAC|20250101010101||ADT^A01^ADT_A01|MSG00001|P|2.5`;
|
|
19
|
+
|
|
20
|
+
const processor = unified()
|
|
21
|
+
.use(hl7v2Parser)
|
|
22
|
+
// default expression is "<3.0.0 >=2.3"
|
|
23
|
+
.use(hl7v2LintMessageVersion, { expression: "<3.0.0 >=2.3" });
|
|
24
|
+
|
|
25
|
+
await processor.process(message);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Options
|
|
29
|
+
|
|
30
|
+
- **expression**: string (optional)
|
|
31
|
+
- A semver-like range expression evaluated against `MSH-12`.
|
|
32
|
+
- Defaults to `"<3.0.0 >=2.3"`.
|
|
33
|
+
|
|
34
|
+
Expressions are parsed and evaluated by `@rethinkhealth/hl7v2-util-semver`.
|
|
35
|
+
|
|
36
|
+
### Examples
|
|
37
|
+
|
|
38
|
+
- **✅ Valid within default range** (default `"<3.0.0 >=2.3"`)
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
MSH|^~\&|SENDER|FAC|RCVR|FAC|20250101010101||ADT^A01^ADT_A01|MSG00001|P|2.5
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- **❌ Invalid: below minimum (2.3)**
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
MSH|^~\&|SENDER|FAC|RCVR|FAC|20250101010101||ADT^A01^ADT_A01|MSG00001|P|2.2
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- **✅ Custom expression allowing 2.2**
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
unified()
|
|
54
|
+
.use(hl7v2Parser)
|
|
55
|
+
.use(hl7v2LintMessageVersion, { expression: "<3.0.0 >=2.2" });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Contributing
|
|
59
|
+
|
|
60
|
+
We welcome contributions! Please see our [Contributing Guide][github-contributing] for more details.
|
|
61
|
+
|
|
62
|
+
1. Fork the repository
|
|
63
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
64
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
65
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
66
|
+
5. Open a Pull Request
|
|
67
|
+
|
|
68
|
+
## Code of Conduct
|
|
69
|
+
|
|
70
|
+
To ensure a welcoming and positive environment, we have a [Code of Conduct][github-code-of-conduct] that all contributors and participants are expected to adhere to.
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
Copyright 2025 Rethink Health, SUARL. All rights reserved.
|
|
75
|
+
|
|
76
|
+
This program is licensed to you under the terms of the [MIT License](https://opensource.org/licenses/MIT). This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [LICENSE][github-license] file for details.
|
|
77
|
+
|
|
78
|
+
[github-code-of-conduct]: https://github.com/rethinkhealth/hl7v2/blob/main/CODE_OF_CONDUCT.md
|
|
79
|
+
[github-license]: https://github.com/rethinkhealth/hl7v2/blob/main/LICENSE
|
|
80
|
+
[github-contributing]: https://github.com/rethinkhealth/hl7v2/blob/main/CONTRIBUTING.md
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Node } from "@rethinkhealth/hl7v2-ast";
|
|
2
|
+
export type MessageVersionLintOptions = {
|
|
3
|
+
expression: string;
|
|
4
|
+
};
|
|
5
|
+
declare const hl7v2LintMessageVersion: import("unified-lint-rule").Plugin<Node, MessageVersionLintOptions>;
|
|
6
|
+
export default hl7v2LintMessageVersion;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAQ,MAAM,0BAA0B,CAAC;AAK3D,MAAM,MAAM,yBAAyB,GAAG;IACtC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAMF,QAAA,MAAM,uBAAuB,qEA6D5B,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { find, value } from "@rethinkhealth/hl7v2-util-query";
|
|
3
|
+
import { parse, satisfies } from "@rethinkhealth/hl7v2-util-semver";
|
|
4
|
+
import { lintRule } from "unified-lint-rule";
|
|
5
|
+
var defaultOptions = {
|
|
6
|
+
expression: "<3.0.0 >=2.3"
|
|
7
|
+
};
|
|
8
|
+
var hl7v2LintMessageVersion = lintRule(
|
|
9
|
+
{
|
|
10
|
+
origin: "hl7v2-lint:message-version",
|
|
11
|
+
url: "https://github.com/rethinkhealth/hl7v2/tree/main/packages/hl7v2-lint-message-version#readme"
|
|
12
|
+
},
|
|
13
|
+
(tree, file, opts) => {
|
|
14
|
+
const options = { ...defaultOptions, ...opts };
|
|
15
|
+
if (tree.type !== "root") {
|
|
16
|
+
file.fail(
|
|
17
|
+
`The root node is expected to be a message. Received ${tree.type} instead.`,
|
|
18
|
+
{
|
|
19
|
+
ancestors: [tree],
|
|
20
|
+
place: tree.position
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const msh12 = find(tree, "MSH-12");
|
|
26
|
+
const place = msh12?.position ?? tree.position;
|
|
27
|
+
if (!msh12) {
|
|
28
|
+
file.fail("Message version (MSH.12) is not present.", {
|
|
29
|
+
ancestors: [tree],
|
|
30
|
+
place
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const versionStr = value(tree, "MSH-12");
|
|
35
|
+
if (!versionStr) {
|
|
36
|
+
file.fail(
|
|
37
|
+
"Unexpected value `undefined` for `MSH-12`, expected `string`",
|
|
38
|
+
{
|
|
39
|
+
ancestors: [tree, msh12],
|
|
40
|
+
place
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const version = parse(versionStr);
|
|
46
|
+
if (!version) {
|
|
47
|
+
file.fail("The message version is not valid.", {
|
|
48
|
+
ancestors: [tree, msh12],
|
|
49
|
+
place
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!satisfies(versionStr, options.expression)) {
|
|
54
|
+
file.fail("Message version is not supported.", {
|
|
55
|
+
ancestors: [tree, msh12],
|
|
56
|
+
place
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
var index_default = hl7v2LintMessageVersion;
|
|
63
|
+
export {
|
|
64
|
+
index_default as default
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Node, Root } from \"@rethinkhealth/hl7v2-ast\";\nimport { find, value } from \"@rethinkhealth/hl7v2-util-query\";\nimport { parse, satisfies } from \"@rethinkhealth/hl7v2-util-semver\";\nimport { lintRule } from \"unified-lint-rule\";\n\nexport type MessageVersionLintOptions = {\n expression: string;\n};\n\nconst defaultOptions: Required<MessageVersionLintOptions> = {\n expression: \"<3.0.0 >=2.3\",\n};\n\nconst hl7v2LintMessageVersion = lintRule<Node, MessageVersionLintOptions>(\n {\n origin: \"hl7v2-lint:message-version\",\n url: \"https://github.com/rethinkhealth/hl7v2/tree/main/packages/hl7v2-lint-message-version#readme\",\n },\n (tree, file, opts) => {\n const options = { ...defaultOptions, ...opts };\n\n if (tree.type !== \"root\") {\n file.fail(\n `The root node is expected to be a message. Received ${tree.type} instead.`,\n {\n ancestors: [tree],\n place: tree.position,\n }\n );\n return;\n }\n\n const msh12 = find(tree as Root, \"MSH-12\");\n const place = msh12?.position ?? tree.position;\n\n if (!msh12) {\n file.fail(\"Message version (MSH.12) is not present.\", {\n ancestors: [tree],\n place,\n });\n return;\n }\n\n const versionStr = value(tree as Root, \"MSH-12\");\n\n if (!versionStr) {\n file.fail(\n \"Unexpected value `undefined` for `MSH-12`, expected `string`\",\n {\n ancestors: [tree, msh12],\n place,\n }\n );\n return;\n }\n\n const version = parse(versionStr);\n\n if (!version) {\n file.fail(\"The message version is not valid.\", {\n ancestors: [tree, msh12],\n place,\n });\n return;\n }\n\n if (!satisfies(versionStr, options.expression)) {\n file.fail(\"Message version is not supported.\", {\n ancestors: [tree, msh12],\n place,\n });\n return;\n }\n }\n);\n\nexport default hl7v2LintMessageVersion;\n"],"mappings":";AACA,SAAS,MAAM,aAAa;AAC5B,SAAS,OAAO,iBAAiB;AACjC,SAAS,gBAAgB;AAMzB,IAAM,iBAAsD;AAAA,EAC1D,YAAY;AACd;AAEA,IAAM,0BAA0B;AAAA,EAC9B;AAAA,IACE,QAAQ;AAAA,IACR,KAAK;AAAA,EACP;AAAA,EACA,CAAC,MAAM,MAAM,SAAS;AACpB,UAAM,UAAU,EAAE,GAAG,gBAAgB,GAAG,KAAK;AAE7C,QAAI,KAAK,SAAS,QAAQ;AACxB,WAAK;AAAA,QACH,uDAAuD,KAAK,IAAI;AAAA,QAChE;AAAA,UACE,WAAW,CAAC,IAAI;AAAA,UAChB,OAAO,KAAK;AAAA,QACd;AAAA,MACF;AACA;AAAA,IACF;AAEA,UAAM,QAAQ,KAAK,MAAc,QAAQ;AACzC,UAAM,QAAQ,OAAO,YAAY,KAAK;AAEtC,QAAI,CAAC,OAAO;AACV,WAAK,KAAK,4CAA4C;AAAA,QACpD,WAAW,CAAC,IAAI;AAAA,QAChB;AAAA,MACF,CAAC;AACD;AAAA,IACF;AAEA,UAAM,aAAa,MAAM,MAAc,QAAQ;AAE/C,QAAI,CAAC,YAAY;AACf,WAAK;AAAA,QACH;AAAA,QACA;AAAA,UACE,WAAW,CAAC,MAAM,KAAK;AAAA,UACvB;AAAA,QACF;AAAA,MACF;AACA;AAAA,IACF;AAEA,UAAM,UAAU,MAAM,UAAU;AAEhC,QAAI,CAAC,SAAS;AACZ,WAAK,KAAK,qCAAqC;AAAA,QAC7C,WAAW,CAAC,MAAM,KAAK;AAAA,QACvB;AAAA,MACF,CAAC;AACD;AAAA,IACF;AAEA,QAAI,CAAC,UAAU,YAAY,QAAQ,UAAU,GAAG;AAC9C,WAAK,KAAK,qCAAqC;AAAA,QAC7C,WAAW,CAAC,MAAM,KAAK;AAAA,QACvB;AAAA,MACF,CAAC;AACD;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rethinkhealth/hl7v2-lint-message-version",
|
|
3
|
+
"description": "hl7v2-lint rule to warn when message version is not supported",
|
|
4
|
+
"version": "0.2.22",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Melek Somai",
|
|
8
|
+
"email": "melek@rethinkhealth.io"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"unified-lint-rule": "3.0.1",
|
|
20
|
+
"@rethinkhealth/hl7v2-util-semver": "0.2.22",
|
|
21
|
+
"@rethinkhealth/hl7v2-util-query": "0.2.22"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "24.8.1",
|
|
25
|
+
"@types/unist": "^3.0.3",
|
|
26
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
27
|
+
"tsup": "8.5.0",
|
|
28
|
+
"typescript": "^5.9.3",
|
|
29
|
+
"unified": "^11.0.5",
|
|
30
|
+
"vfile": "^6.0.3",
|
|
31
|
+
"vfile-reporter": "^8.1.1",
|
|
32
|
+
"vitest": "^3.2.4",
|
|
33
|
+
"@rethinkhealth/hl7v2-builder": "0.2.22",
|
|
34
|
+
"@rethinkhealth/hl7v2-ast": "0.2.22",
|
|
35
|
+
"@rethinkhealth/testing": "0.0.1",
|
|
36
|
+
"@rethinkhealth/tsconfig": "0.0.1"
|
|
37
|
+
},
|
|
38
|
+
"repository": "rethinkhealth/hl7v2.git",
|
|
39
|
+
"homepage": "https://www.rethinkhealth.io/hl7v2/docs",
|
|
40
|
+
"keywords": [
|
|
41
|
+
"definition",
|
|
42
|
+
"hl7",
|
|
43
|
+
"hl7v2",
|
|
44
|
+
"hl7v2-lint",
|
|
45
|
+
"hl7v2-lint-rule",
|
|
46
|
+
"lint",
|
|
47
|
+
"nodejs",
|
|
48
|
+
"rule",
|
|
49
|
+
"typescript",
|
|
50
|
+
"version"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup && tsc --emitDeclarationOnly",
|
|
57
|
+
"check-types": "tsc --noEmit",
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"test:coverage": "vitest run --coverage",
|
|
60
|
+
"test:watch": "vitest"
|
|
61
|
+
}
|
|
62
|
+
}
|