@medplum/core 2.0.18 → 2.0.19
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/dist/cjs/index.cjs +806 -665
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/esm/client.mjs +27 -3
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/filter/parse.mjs +54 -1
- package/dist/esm/filter/parse.mjs.map +1 -1
- package/dist/esm/filter/types.mjs.map +1 -1
- package/dist/esm/hl7.mjs +23 -1
- package/dist/esm/hl7.mjs.map +1 -1
- package/dist/esm/index.min.mjs +1 -1
- package/dist/esm/index.mjs +3 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/search/details.mjs +11 -5
- package/dist/esm/search/details.mjs.map +1 -1
- package/dist/esm/sftp.mjs +25 -0
- package/dist/esm/sftp.mjs.map +1 -0
- package/dist/esm/utils.mjs +13 -1
- package/dist/esm/utils.mjs.map +1 -1
- package/dist/types/client.d.ts +10 -1
- package/dist/types/filter/types.d.ts +3 -2
- package/dist/types/hl7.d.ts +12 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/search/details.d.ts +1 -0
- package/dist/types/sftp.d.ts +9 -0
- package/dist/types/utils.d.ts +16 -0
- package/package.json +1 -1
|
@@ -1,9 +1,62 @@
|
|
|
1
1
|
import '../types.mjs';
|
|
2
2
|
import '../utils.mjs';
|
|
3
3
|
import { initFhirPathParserBuilder } from '../fhirpath/parse.mjs';
|
|
4
|
+
import { OperationOutcomeError, badRequest } from '../outcomes.mjs';
|
|
5
|
+
import { Operator } from '../search/search.mjs';
|
|
4
6
|
import { tokenize } from './tokenize.mjs';
|
|
5
7
|
import { FhirFilterNegation, FhirFilterComparison, FhirFilterConnective } from './types.mjs';
|
|
6
8
|
|
|
9
|
+
/**
|
|
10
|
+
* The operatorMap maps FHIR _filter operators to Medplum search operators.
|
|
11
|
+
* See _filter operators: https://www.hl7.org/fhir/search_filter.html#ops
|
|
12
|
+
*/
|
|
13
|
+
const operatorMap = {
|
|
14
|
+
// eq - an item in the set has an equal value
|
|
15
|
+
eq: Operator.EQUALS,
|
|
16
|
+
// ne - An item in the set has an unequal value
|
|
17
|
+
ne: Operator.NOT_EQUALS,
|
|
18
|
+
// co - An item in the set contains this value
|
|
19
|
+
co: Operator.CONTAINS,
|
|
20
|
+
// sw - An item in the set starts with this value
|
|
21
|
+
sw: undefined,
|
|
22
|
+
// ew - An item in the set ends with this value
|
|
23
|
+
ew: undefined,
|
|
24
|
+
// gt / lt / ge / le - A value in the set is (greater than, less than, greater or equal, less or equal) the given value
|
|
25
|
+
gt: Operator.GREATER_THAN,
|
|
26
|
+
lt: Operator.LESS_THAN,
|
|
27
|
+
ge: Operator.GREATER_THAN_OR_EQUALS,
|
|
28
|
+
le: Operator.LESS_THAN_OR_EQUALS,
|
|
29
|
+
// ap - A value in the set is approximately the same as this value.
|
|
30
|
+
// Note that the recommended value for the approximation is 10% of the stated value (or for a date, 10% of the gap between now and the date), but systems may choose other values where appropriate
|
|
31
|
+
ap: Operator.APPROXIMATELY,
|
|
32
|
+
// sa - The value starts after the specified value
|
|
33
|
+
sa: Operator.STARTS_AFTER,
|
|
34
|
+
// eb - The value ends before the specified value
|
|
35
|
+
eb: Operator.ENDS_BEFORE,
|
|
36
|
+
// pr - The set is empty or not (value is false or true)
|
|
37
|
+
pr: Operator.MISSING,
|
|
38
|
+
// po - True if a (implied) date period in the set overlaps with the implied period in the value
|
|
39
|
+
po: undefined,
|
|
40
|
+
// ss - True if the value subsumes a concept in the set
|
|
41
|
+
ss: undefined,
|
|
42
|
+
// sb - True if the value is subsumed by a concept in the set
|
|
43
|
+
sb: undefined,
|
|
44
|
+
// in - True if one of the concepts is in the nominated value set by URI, either a relative, literal or logical vs
|
|
45
|
+
in: Operator.IN,
|
|
46
|
+
// ni - True if none of the concepts are in the nominated value set by URI, either a relative, literal or logical vs
|
|
47
|
+
ni: Operator.NOT_IN,
|
|
48
|
+
// re - True if one of the references in set points to the given URL
|
|
49
|
+
re: undefined,
|
|
50
|
+
// identifier - True if the identifier is in the identifier set (Medplum extension)
|
|
51
|
+
identifier: Operator.IDENTIFIER,
|
|
52
|
+
};
|
|
53
|
+
function getOperator(value) {
|
|
54
|
+
const operator = operatorMap[value];
|
|
55
|
+
if (!operator) {
|
|
56
|
+
throw new OperationOutcomeError(badRequest('Invalid operator: ' + value));
|
|
57
|
+
}
|
|
58
|
+
return operator;
|
|
59
|
+
}
|
|
7
60
|
class FilterParameterParser {
|
|
8
61
|
constructor(parser) {
|
|
9
62
|
this.parser = parser;
|
|
@@ -22,7 +75,7 @@ class FilterParameterParser {
|
|
|
22
75
|
this.parser.consume(')');
|
|
23
76
|
}
|
|
24
77
|
else {
|
|
25
|
-
result = new FhirFilterComparison(this.parser.consume('Symbol').value, this.parser.consume('Symbol').value, this.parser.consume().value);
|
|
78
|
+
result = new FhirFilterComparison(this.parser.consume('Symbol').value, getOperator(this.parser.consume('Symbol').value), this.parser.consume().value);
|
|
26
79
|
}
|
|
27
80
|
const next = this.parser.peek()?.value;
|
|
28
81
|
if (next === 'and' || next === 'or') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.mjs","sources":["../../../src/filter/parse.ts"],"sourcesContent":["import { Parser } from '../fhirlexer';\nimport { initFhirPathParserBuilder } from '../fhirpath';\nimport { tokenize } from './tokenize';\nimport { FhirFilterComparison, FhirFilterConnective, FhirFilterExpression, FhirFilterNegation } from './types';\n\nclass FilterParameterParser {\n constructor(readonly parser: Parser) {}\n\n parse(): FhirFilterExpression {\n let result: FhirFilterExpression;\n\n if (this.parser.peek()?.value === '(') {\n this.parser.consume('(');\n result = this.parse();\n this.parser.consume(')');\n } else if (this.parser.peek()?.value === 'not') {\n this.parser.consume('Symbol', 'not');\n this.parser.consume('(');\n result = new FhirFilterNegation(this.parse());\n this.parser.consume(')');\n } else {\n result = new FhirFilterComparison(\n this.parser.consume('Symbol').value,\n this.parser.consume('Symbol').value,\n this.parser.consume().value\n );\n }\n\n const next = this.parser.peek()?.value;\n if (next === 'and' || next === 'or') {\n this.parser.consume('Symbol', next);\n return new FhirFilterConnective(next, result, this.parse());\n }\n\n return result;\n }\n}\n\nconst fhirPathParserBuilder = initFhirPathParserBuilder();\n\n/**\n * Parses a FHIR _filter parameter expression into an AST.\n * @param input The FHIR _filter parameter expression.\n * @returns The AST representing the filters.\n */\nexport function parseFilterParameter(input: string): FhirFilterExpression {\n const parser = fhirPathParserBuilder.construct(tokenize(input));\n parser.removeComments();\n return new FilterParameterParser(parser).parse();\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse.mjs","sources":["../../../src/filter/parse.ts"],"sourcesContent":["import { Parser } from '../fhirlexer';\nimport { initFhirPathParserBuilder } from '../fhirpath';\nimport { OperationOutcomeError, badRequest } from '../outcomes';\nimport { Operator } from '../search/search';\nimport { tokenize } from './tokenize';\nimport { FhirFilterComparison, FhirFilterConnective, FhirFilterExpression, FhirFilterNegation } from './types';\n\n/**\n * The operatorMap maps FHIR _filter operators to Medplum search operators.\n * See _filter operators: https://www.hl7.org/fhir/search_filter.html#ops\n */\nconst operatorMap: Record<string, Operator | undefined> = {\n // eq - an item in the set has an equal value\n eq: Operator.EQUALS,\n // ne - An item in the set has an unequal value\n ne: Operator.NOT_EQUALS,\n // co - An item in the set contains this value\n co: Operator.CONTAINS,\n // sw - An item in the set starts with this value\n sw: undefined,\n // ew - An item in the set ends with this value\n ew: undefined,\n // gt / lt / ge / le - A value in the set is (greater than, less than, greater or equal, less or equal) the given value\n gt: Operator.GREATER_THAN,\n lt: Operator.LESS_THAN,\n ge: Operator.GREATER_THAN_OR_EQUALS,\n le: Operator.LESS_THAN_OR_EQUALS,\n // ap - A value in the set is approximately the same as this value.\n // Note that the recommended value for the approximation is 10% of the stated value (or for a date, 10% of the gap between now and the date), but systems may choose other values where appropriate\n ap: Operator.APPROXIMATELY,\n // sa - The value starts after the specified value\n sa: Operator.STARTS_AFTER,\n // eb - The value ends before the specified value\n eb: Operator.ENDS_BEFORE,\n // pr - The set is empty or not (value is false or true)\n pr: Operator.MISSING,\n // po - True if a (implied) date period in the set overlaps with the implied period in the value\n po: undefined,\n // ss - True if the value subsumes a concept in the set\n ss: undefined,\n // sb - True if the value is subsumed by a concept in the set\n sb: undefined,\n // in - True if one of the concepts is in the nominated value set by URI, either a relative, literal or logical vs\n in: Operator.IN,\n // ni - True if none of the concepts are in the nominated value set by URI, either a relative, literal or logical vs\n ni: Operator.NOT_IN,\n // re - True if one of the references in set points to the given URL\n re: undefined,\n // identifier - True if the identifier is in the identifier set (Medplum extension)\n identifier: Operator.IDENTIFIER,\n};\n\nfunction getOperator(value: string): Operator {\n const operator = operatorMap[value];\n if (!operator) {\n throw new OperationOutcomeError(badRequest('Invalid operator: ' + value));\n }\n return operator;\n}\n\nclass FilterParameterParser {\n constructor(readonly parser: Parser) {}\n\n parse(): FhirFilterExpression {\n let result: FhirFilterExpression;\n\n if (this.parser.peek()?.value === '(') {\n this.parser.consume('(');\n result = this.parse();\n this.parser.consume(')');\n } else if (this.parser.peek()?.value === 'not') {\n this.parser.consume('Symbol', 'not');\n this.parser.consume('(');\n result = new FhirFilterNegation(this.parse());\n this.parser.consume(')');\n } else {\n result = new FhirFilterComparison(\n this.parser.consume('Symbol').value,\n getOperator(this.parser.consume('Symbol').value),\n this.parser.consume().value\n );\n }\n\n const next = this.parser.peek()?.value;\n if (next === 'and' || next === 'or') {\n this.parser.consume('Symbol', next);\n return new FhirFilterConnective(next, result, this.parse());\n }\n\n return result;\n }\n}\n\nconst fhirPathParserBuilder = initFhirPathParserBuilder();\n\n/**\n * Parses a FHIR _filter parameter expression into an AST.\n * @param input The FHIR _filter parameter expression.\n * @returns The AST representing the filters.\n */\nexport function parseFilterParameter(input: string): FhirFilterExpression {\n const parser = fhirPathParserBuilder.construct(tokenize(input));\n parser.removeComments();\n return new FilterParameterParser(parser).parse();\n}\n"],"names":[],"mapp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E,CAAC,CAAC;AAC7D,SAAA;AAED,QAAA,OAAO,MAAM,CAAC;KACf;AACF,CAAA;AAED,MAAM,qBAAqB,GAAG,yBAAyB,EAAE,CAAC;AAE1D;;;;AAIG;AACG,SAAU,oBAAoB,CAAC,KAAa,EAAA;IAChD,MAAM,MAAM,GAAG,qBAAqB,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAChE,MAAM,CAAC,cAAc,EAAE,CAAC;IACxB,OAAO,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC;AACnD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sources":["../../../src/filter/types.ts"],"sourcesContent":["// See: https://hl7.org/fhir/search_filter.html\n\n/**\n * The FhirFilterExpression type is the base type of all filter expressions.\n */\nexport type FhirFilterExpression = FhirFilterComparison | FhirFilterNegation | FhirFilterConnective;\n\n/**\n * The FhirFilterComparison class represents a comparison expression.\n */\nexport class FhirFilterComparison {\n constructor(readonly path: string, readonly operator:
|
|
1
|
+
{"version":3,"file":"types.mjs","sources":["../../../src/filter/types.ts"],"sourcesContent":["// See: https://hl7.org/fhir/search_filter.html\n\nimport { Operator } from '../search/search';\n\n/**\n * The FhirFilterExpression type is the base type of all filter expressions.\n */\nexport type FhirFilterExpression = FhirFilterComparison | FhirFilterNegation | FhirFilterConnective;\n\n/**\n * The FhirFilterComparison class represents a comparison expression.\n */\nexport class FhirFilterComparison {\n constructor(readonly path: string, readonly operator: Operator, readonly value: string) {}\n}\n\n/**\n * The FhirFilterNegation class represents a negation expression.\n * It contains a single child expression.\n */\nexport class FhirFilterNegation {\n constructor(readonly child: FhirFilterExpression) {}\n}\n\n/**\n * The FhirFilterConnective class represents a connective expression.\n * It contains a list of child expressions.\n */\nexport class FhirFilterConnective {\n constructor(\n readonly keyword: 'and' | 'or',\n readonly left: FhirFilterExpression,\n readonly right: FhirFilterExpression\n ) {}\n}\n"],"names":[],"mappings":"AAAA;AASA;;AAEG;MACU,oBAAoB,CAAA;AAC/B,IAAA,WAAA,CAAqB,IAAY,EAAW,QAAkB,EAAW,KAAa,EAAA;QAAjE,IAAI,CAAA,IAAA,GAAJ,IAAI,CAAQ;QAAW,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAU;QAAW,IAAK,CAAA,KAAA,GAAL,KAAK,CAAQ;KAAI;AAC3F,CAAA;AAED;;;AAGG;MACU,kBAAkB,CAAA;AAC7B,IAAA,WAAA,CAAqB,KAA2B,EAAA;QAA3B,IAAK,CAAA,KAAA,GAAL,KAAK,CAAsB;KAAI;AACrD,CAAA;AAED;;;AAGG;MACU,oBAAoB,CAAA;AAC/B,IAAA,WAAA,CACW,OAAqB,EACrB,IAA0B,EAC1B,KAA2B,EAAA;QAF3B,IAAO,CAAA,OAAA,GAAP,OAAO,CAAc;QACrB,IAAI,CAAA,IAAA,GAAJ,IAAI,CAAsB;QAC1B,IAAK,CAAA,KAAA,GAAL,KAAK,CAAsB;KAClC;AACL;;;;"}
|
package/dist/esm/hl7.mjs
CHANGED
|
@@ -215,6 +215,28 @@ class Hl7Field {
|
|
|
215
215
|
return new Hl7Field(text.split(context.repetitionSeparator).map((r) => r.split(context.componentSeparator)), context);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Returns a formatted string representing the date in ISO-8601 format.
|
|
220
|
+
* @param hl7Date Date string.
|
|
221
|
+
* @param options Optional configuration Object
|
|
222
|
+
* @returns
|
|
223
|
+
*/
|
|
224
|
+
function parseHl7Date(hl7Date, options) {
|
|
225
|
+
if (!hl7Date) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
options = { ...{ seconds: true, tzOffset: 'Z' }, ...options };
|
|
229
|
+
const year = Number.parseInt(hl7Date.substring(0, 4));
|
|
230
|
+
const month = Number.parseInt(hl7Date.substring(4, 6));
|
|
231
|
+
const date = Number.parseInt(hl7Date.substring(6, 8));
|
|
232
|
+
const hours = Number.parseInt(hl7Date.substring(8, 10));
|
|
233
|
+
const minutes = Number.parseInt(hl7Date.substring(10, 12));
|
|
234
|
+
const seconds = options.seconds ? Number.parseInt(hl7Date.substring(12, 14)) : 0;
|
|
235
|
+
return `${pad2(year)}-${pad2(month)}-${pad2(date)}T${pad2(hours)}:${pad2(minutes)}:${pad2(seconds)}.000${options.tzOffset}`;
|
|
236
|
+
}
|
|
237
|
+
function pad2(n) {
|
|
238
|
+
return n.toString().padStart(2, '0');
|
|
239
|
+
}
|
|
218
240
|
|
|
219
|
-
export { Hl7Context, Hl7Field, Hl7Message, Hl7Segment };
|
|
241
|
+
export { Hl7Context, Hl7Field, Hl7Message, Hl7Segment, parseHl7Date };
|
|
220
242
|
//# sourceMappingURL=hl7.mjs.map
|
package/dist/esm/hl7.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hl7.mjs","sources":["../../src/hl7.ts"],"sourcesContent":["import { isStringArray } from './utils';\n\n/**\n * The Hl7Context class represents the parsing context for an HL7 message.\n *\n * MSH-1:\n * https://hl7-definition.caristix.com/v2/HL7v2.6/Fields/MSH.1\n *\n * MSH-2:\n * https://hl7-definition.caristix.com/v2/HL7v2.6/Fields/MSH.2\n *\n * See this tutorial on MSH, and why it's a bad idea to use anything other than the default values:\n * https://www.hl7soup.com/HL7TutorialMSH.html\n */\nexport class Hl7Context {\n constructor(\n public readonly segmentSeparator = '\\r',\n public readonly fieldSeparator = '|',\n public readonly componentSeparator = '^',\n public readonly repetitionSeparator = '~',\n public readonly escapeCharacter = '\\\\',\n public readonly subcomponentSeparator = '&'\n ) {}\n\n /**\n * Returns the MSH-2 field value based on the configured separators.\n * @returns The HL7 MSH-2 field value.\n */\n getMsh2(): string {\n return (\n this.fieldSeparator +\n this.componentSeparator +\n this.repetitionSeparator +\n this.escapeCharacter +\n this.subcomponentSeparator\n );\n }\n}\n\n/**\n * The Hl7Message class represents one HL7 message.\n * A message is a collection of segments.\n */\nexport class Hl7Message {\n readonly context: Hl7Context;\n readonly segments: Hl7Segment[];\n\n /**\n * Creates a new HL7 message.\n * @param segments The HL7 segments.\n * @param context Optional HL7 parsing context.\n */\n constructor(segments: Hl7Segment[], context = new Hl7Context()) {\n this.context = context;\n this.segments = segments;\n }\n\n /**\n * Returns an HL7 segment by index or by name.\n * @param index The HL7 segment index or name.\n * @returns The HL7 segment if found; otherwise, undefined.\n */\n get(index: number | string): Hl7Segment | undefined {\n if (typeof index === 'number') {\n return this.segments[index];\n }\n return this.segments.find((s) => s.name === index);\n }\n\n /**\n * Returns all HL7 segments of a given name.\n * @param name The HL7 segment name.\n * @returns An array of HL7 segments with the specified name.\n */\n getAll(name: string): Hl7Segment[] {\n return this.segments.filter((s) => s.name === name);\n }\n\n /**\n * Returns the HL7 message as a string.\n * @returns The HL7 message as a string.\n */\n toString(): string {\n return this.segments.map((s) => s.toString()).join(this.context.segmentSeparator);\n }\n\n /**\n * Returns an HL7 \"ACK\" (acknowledgement) message for this message.\n * @returns The HL7 \"ACK\" message.\n */\n buildAck(): Hl7Message {\n const now = new Date();\n const msh = this.get('MSH');\n const sendingApp = msh?.get(2)?.toString() || '';\n const sendingFacility = msh?.get(3)?.toString() || '';\n const receivingApp = msh?.get(4)?.toString() || '';\n const receivingFacility = msh?.get(5)?.toString() || '';\n const controlId = msh?.get(9)?.toString() || '';\n const versionId = msh?.get(12)?.toString() || '2.5.1';\n\n return new Hl7Message([\n new Hl7Segment(\n [\n 'MSH',\n this.context.getMsh2(),\n receivingApp,\n receivingFacility,\n sendingApp,\n sendingFacility,\n now.toISOString(),\n '',\n 'ACK',\n now.getTime().toString(),\n 'P',\n versionId,\n ],\n this.context\n ),\n new Hl7Segment(['MSA', 'AA', controlId, 'OK'], this.context),\n ]);\n }\n\n /**\n * Parses an HL7 message string into an Hl7Message object.\n * @param text The HL7 message text.\n * @returns The parsed HL7 message.\n */\n static parse(text: string): Hl7Message {\n if (!text.startsWith('MSH')) {\n const err = new Error('Invalid HL7 message');\n (err as any).type = 'entity.parse.failed';\n throw err;\n }\n const context = new Hl7Context(\n '\\r',\n text.charAt(3), // Field separator, recommended \"|\"\n text.charAt(4), // Component separator, recommended \"^\"\n text.charAt(5), // Repetition separator, recommended \"~\"\n text.charAt(6), // Escape character, recommended \"\\\"\n text.charAt(7) // Subcomponent separator, recommended \"&\"\n );\n return new Hl7Message(\n text.split(/[\\r\\n]+/).map((line) => Hl7Segment.parse(line, context)),\n context\n );\n }\n}\n\n/**\n * The Hl7Segment class represents one HL7 segment.\n * A segment is a collection of fields.\n * The name field is the first field.\n */\nexport class Hl7Segment {\n readonly context: Hl7Context;\n readonly name: string;\n readonly fields: Hl7Field[];\n\n /**\n * Creates a new HL7 segment.\n * @param fields The HL7 fields.\n * @param context Optional HL7 parsing context.\n */\n constructor(fields: Hl7Field[] | string[], context = new Hl7Context()) {\n this.context = context;\n if (isStringArray(fields)) {\n this.fields = fields.map((f) => Hl7Field.parse(f));\n } else {\n this.fields = fields;\n }\n this.name = this.fields[0].components[0][0];\n }\n\n /**\n * Returns an HL7 field by index.\n * @param index The HL7 field index.\n * @returns The HL7 field.\n */\n get(index: number): Hl7Field {\n return this.fields[index];\n }\n\n /**\n * Returns the HL7 segment as a string.\n * @returns The HL7 segment as a string.\n */\n toString(): string {\n return this.fields.map((f) => f.toString()).join(this.context.fieldSeparator);\n }\n\n /**\n * Parses an HL7 segment string into an Hl7Segment object.\n * @param text The HL7 segment text.\n * @param context Optional HL7 parsing context.\n * @returns The parsed HL7 segment.\n */\n static parse(text: string, context = new Hl7Context()): Hl7Segment {\n return new Hl7Segment(\n text.split(context.fieldSeparator).map((f) => Hl7Field.parse(f, context)),\n context\n );\n }\n}\n\n/**\n * The Hl7Field class represents one HL7 field.\n * A field is a collection of components.\n */\nexport class Hl7Field {\n readonly context: Hl7Context;\n readonly components: string[][];\n\n /**\n * Creates a new HL7 field.\n * @param components The HL7 components.\n * @param context Optional HL7 parsing context.\n */\n constructor(components: string[][], context = new Hl7Context()) {\n this.context = context;\n this.components = components;\n }\n\n /**\n * Returns an HL7 component by index.\n * @param component The component index.\n * @param subcomponent Optional subcomponent index.\n * @param repetition Optional repetition index.\n * @returns The string value of the specified component.\n */\n get(component: number, subcomponent?: number, repetition = 0): string {\n let value = this.components[repetition][component] || '';\n\n if (subcomponent !== undefined) {\n value = value.split(this.context.subcomponentSeparator)[subcomponent] || '';\n }\n\n return value;\n }\n\n /**\n * Returns the HL7 field as a string.\n * @returns The HL7 field as a string.\n */\n toString(): string {\n return this.components.map((r) => r.join(this.context.componentSeparator)).join(this.context.repetitionSeparator);\n }\n\n /**\n * Parses an HL7 field string into an Hl7Field object.\n * @param text The HL7 field text.\n * @param context Optional HL7 parsing context.\n * @returns The parsed HL7 field.\n */\n static parse(text: string, context = new Hl7Context()): Hl7Field {\n return new Hl7Field(\n text.split(context.repetitionSeparator).map((r) => r.split(context.componentSeparator)),\n context\n );\n }\n}\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;;AAWG;MACU,UAAU,CAAA;AACrB,IAAA,WAAA,CACkB,mBAAmB,IAAI,EACvB,cAAiB,GAAA,GAAG,EACpB,kBAAqB,GAAA,GAAG,EACxB,mBAAA,GAAsB,GAAG,EACzB,eAAA,GAAkB,IAAI,EACtB,wBAAwB,GAAG,EAAA;QAL3B,IAAgB,CAAA,gBAAA,GAAhB,gBAAgB,CAAO;QACvB,IAAc,CAAA,cAAA,GAAd,cAAc,CAAM;QACpB,IAAkB,CAAA,kBAAA,GAAlB,kBAAkB,CAAM;QACxB,IAAmB,CAAA,mBAAA,GAAnB,mBAAmB,CAAM;QACzB,IAAe,CAAA,eAAA,GAAf,eAAe,CAAO;QACtB,IAAqB,CAAA,qBAAA,GAArB,qBAAqB,CAAM;KACzC;AAEJ;;;AAGG;IACH,OAAO,GAAA;QACL,QACE,IAAI,CAAC,cAAc;AACnB,YAAA,IAAI,CAAC,kBAAkB;AACvB,YAAA,IAAI,CAAC,mBAAmB;AACxB,YAAA,IAAI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O,CAAC,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;KACnH;AAED;;;;;AAKG;IACH,OAAO,KAAK,CAAC,IAAY,EAAE,OAAO,GAAG,IAAI,UAAU,EAAE,EAAA;AACnD,QAAA,OAAO,IAAI,QAAQ,CACjB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,EACvF,OAAO,CACR,CAAC;KACH;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"hl7.mjs","sources":["../../src/hl7.ts"],"sourcesContent":["import { isStringArray } from './utils';\n\n/**\n * The Hl7Context class represents the parsing context for an HL7 message.\n *\n * MSH-1:\n * https://hl7-definition.caristix.com/v2/HL7v2.6/Fields/MSH.1\n *\n * MSH-2:\n * https://hl7-definition.caristix.com/v2/HL7v2.6/Fields/MSH.2\n *\n * See this tutorial on MSH, and why it's a bad idea to use anything other than the default values:\n * https://www.hl7soup.com/HL7TutorialMSH.html\n */\nexport class Hl7Context {\n constructor(\n public readonly segmentSeparator = '\\r',\n public readonly fieldSeparator = '|',\n public readonly componentSeparator = '^',\n public readonly repetitionSeparator = '~',\n public readonly escapeCharacter = '\\\\',\n public readonly subcomponentSeparator = '&'\n ) {}\n\n /**\n * Returns the MSH-2 field value based on the configured separators.\n * @returns The HL7 MSH-2 field value.\n */\n getMsh2(): string {\n return (\n this.fieldSeparator +\n this.componentSeparator +\n this.repetitionSeparator +\n this.escapeCharacter +\n this.subcomponentSeparator\n );\n }\n}\n\n/**\n * The Hl7Message class represents one HL7 message.\n * A message is a collection of segments.\n */\nexport class Hl7Message {\n readonly context: Hl7Context;\n readonly segments: Hl7Segment[];\n\n /**\n * Creates a new HL7 message.\n * @param segments The HL7 segments.\n * @param context Optional HL7 parsing context.\n */\n constructor(segments: Hl7Segment[], context = new Hl7Context()) {\n this.context = context;\n this.segments = segments;\n }\n\n /**\n * Returns an HL7 segment by index or by name.\n * @param index The HL7 segment index or name.\n * @returns The HL7 segment if found; otherwise, undefined.\n */\n get(index: number | string): Hl7Segment | undefined {\n if (typeof index === 'number') {\n return this.segments[index];\n }\n return this.segments.find((s) => s.name === index);\n }\n\n /**\n * Returns all HL7 segments of a given name.\n * @param name The HL7 segment name.\n * @returns An array of HL7 segments with the specified name.\n */\n getAll(name: string): Hl7Segment[] {\n return this.segments.filter((s) => s.name === name);\n }\n\n /**\n * Returns the HL7 message as a string.\n * @returns The HL7 message as a string.\n */\n toString(): string {\n return this.segments.map((s) => s.toString()).join(this.context.segmentSeparator);\n }\n\n /**\n * Returns an HL7 \"ACK\" (acknowledgement) message for this message.\n * @returns The HL7 \"ACK\" message.\n */\n buildAck(): Hl7Message {\n const now = new Date();\n const msh = this.get('MSH');\n const sendingApp = msh?.get(2)?.toString() || '';\n const sendingFacility = msh?.get(3)?.toString() || '';\n const receivingApp = msh?.get(4)?.toString() || '';\n const receivingFacility = msh?.get(5)?.toString() || '';\n const controlId = msh?.get(9)?.toString() || '';\n const versionId = msh?.get(12)?.toString() || '2.5.1';\n\n return new Hl7Message([\n new Hl7Segment(\n [\n 'MSH',\n this.context.getMsh2(),\n receivingApp,\n receivingFacility,\n sendingApp,\n sendingFacility,\n now.toISOString(),\n '',\n 'ACK',\n now.getTime().toString(),\n 'P',\n versionId,\n ],\n this.context\n ),\n new Hl7Segment(['MSA', 'AA', controlId, 'OK'], this.context),\n ]);\n }\n\n /**\n * Parses an HL7 message string into an Hl7Message object.\n * @param text The HL7 message text.\n * @returns The parsed HL7 message.\n */\n static parse(text: string): Hl7Message {\n if (!text.startsWith('MSH')) {\n const err = new Error('Invalid HL7 message');\n (err as any).type = 'entity.parse.failed';\n throw err;\n }\n const context = new Hl7Context(\n '\\r',\n text.charAt(3), // Field separator, recommended \"|\"\n text.charAt(4), // Component separator, recommended \"^\"\n text.charAt(5), // Repetition separator, recommended \"~\"\n text.charAt(6), // Escape character, recommended \"\\\"\n text.charAt(7) // Subcomponent separator, recommended \"&\"\n );\n return new Hl7Message(\n text.split(/[\\r\\n]+/).map((line) => Hl7Segment.parse(line, context)),\n context\n );\n }\n}\n\n/**\n * The Hl7Segment class represents one HL7 segment.\n * A segment is a collection of fields.\n * The name field is the first field.\n */\nexport class Hl7Segment {\n readonly context: Hl7Context;\n readonly name: string;\n readonly fields: Hl7Field[];\n\n /**\n * Creates a new HL7 segment.\n * @param fields The HL7 fields.\n * @param context Optional HL7 parsing context.\n */\n constructor(fields: Hl7Field[] | string[], context = new Hl7Context()) {\n this.context = context;\n if (isStringArray(fields)) {\n this.fields = fields.map((f) => Hl7Field.parse(f));\n } else {\n this.fields = fields;\n }\n this.name = this.fields[0].components[0][0];\n }\n\n /**\n * Returns an HL7 field by index.\n * @param index The HL7 field index.\n * @returns The HL7 field.\n */\n get(index: number): Hl7Field {\n return this.fields[index];\n }\n\n /**\n * Returns the HL7 segment as a string.\n * @returns The HL7 segment as a string.\n */\n toString(): string {\n return this.fields.map((f) => f.toString()).join(this.context.fieldSeparator);\n }\n\n /**\n * Parses an HL7 segment string into an Hl7Segment object.\n * @param text The HL7 segment text.\n * @param context Optional HL7 parsing context.\n * @returns The parsed HL7 segment.\n */\n static parse(text: string, context = new Hl7Context()): Hl7Segment {\n return new Hl7Segment(\n text.split(context.fieldSeparator).map((f) => Hl7Field.parse(f, context)),\n context\n );\n }\n}\n\n/**\n * The Hl7Field class represents one HL7 field.\n * A field is a collection of components.\n */\nexport class Hl7Field {\n readonly context: Hl7Context;\n readonly components: string[][];\n\n /**\n * Creates a new HL7 field.\n * @param components The HL7 components.\n * @param context Optional HL7 parsing context.\n */\n constructor(components: string[][], context = new Hl7Context()) {\n this.context = context;\n this.components = components;\n }\n\n /**\n * Returns an HL7 component by index.\n * @param component The component index.\n * @param subcomponent Optional subcomponent index.\n * @param repetition Optional repetition index.\n * @returns The string value of the specified component.\n */\n get(component: number, subcomponent?: number, repetition = 0): string {\n let value = this.components[repetition][component] || '';\n\n if (subcomponent !== undefined) {\n value = value.split(this.context.subcomponentSeparator)[subcomponent] || '';\n }\n\n return value;\n }\n\n /**\n * Returns the HL7 field as a string.\n * @returns The HL7 field as a string.\n */\n toString(): string {\n return this.components.map((r) => r.join(this.context.componentSeparator)).join(this.context.repetitionSeparator);\n }\n\n /**\n * Parses an HL7 field string into an Hl7Field object.\n * @param text The HL7 field text.\n * @param context Optional HL7 parsing context.\n * @returns The parsed HL7 field.\n */\n static parse(text: string, context = new Hl7Context()): Hl7Field {\n return new Hl7Field(\n text.split(context.repetitionSeparator).map((r) => r.split(context.componentSeparator)),\n context\n );\n }\n}\n\ninterface Hl7DateParseOptions {\n seconds?: boolean;\n tzOffset?: string;\n}\n\n/**\n * Returns a formatted string representing the date in ISO-8601 format.\n * @param hl7Date Date string.\n * @param options Optional configuration Object\n * @returns\n */\nexport function parseHl7Date(hl7Date: string | undefined, options?: Hl7DateParseOptions): string | undefined {\n if (!hl7Date) {\n return undefined;\n }\n\n options = { ...{ seconds: true, tzOffset: 'Z' }, ...options };\n\n const year = Number.parseInt(hl7Date.substring(0, 4));\n const month = Number.parseInt(hl7Date.substring(4, 6));\n const date = Number.parseInt(hl7Date.substring(6, 8));\n const hours = Number.parseInt(hl7Date.substring(8, 10));\n const minutes = Number.parseInt(hl7Date.substring(10, 12));\n\n const seconds = options.seconds ? Number.parseInt(hl7Date.substring(12, 14)) : 0;\n\n return `${pad2(year)}-${pad2(month)}-${pad2(date)}T${pad2(hours)}:${pad2(minutes)}:${pad2(seconds)}.000${\n options.tzOffset\n }`;\n}\n\nfunction pad2(n: number): string {\n return n.toString().padStart(2, '0');\n}\n"],"names":[],"mappings":";;AAEA;;;;;;;;;;;AAWG;MACU,UAAU,CAAA;AACrB,IAAA,WAAA,CACkB,mBAAmB,IAAI,EACvB,cAAiB,GAAA,GAAG,EACpB,kBAAqB,GAAA,GAAG,EACxB,mBAAA,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