@rethinkhealth/hl7v2-ack 0.7.0 → 0.7.1
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/acknowledge.d.ts +14 -6
- package/dist/acknowledge.d.ts.map +1 -1
- package/dist/constants.d.ts +37 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/errors/application-internal-error.d.ts +12 -0
- package/dist/errors/application-internal-error.d.ts.map +1 -0
- package/dist/errors/commit-internal-error.d.ts +11 -0
- package/dist/errors/commit-internal-error.d.ts.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/unsupported-message-type-reject.d.ts +11 -0
- package/dist/errors/unsupported-message-type-reject.d.ts.map +1 -0
- package/dist/exception.d.ts +64 -0
- package/dist/exception.d.ts.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +122 -17
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/errors.d.ts +0 -21
- package/dist/errors.d.ts.map +0 -1
package/dist/acknowledge.d.ts
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import type { Root } from "@rethinkhealth/hl7v2-ast";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AckSuccessCode } from "./constants";
|
|
3
|
+
import type { AckException } from "./exception";
|
|
3
4
|
export interface SendingInfo {
|
|
4
5
|
application: string;
|
|
5
6
|
facility: string;
|
|
6
7
|
}
|
|
7
|
-
export
|
|
8
|
+
export type AcknowledgeOptions = {
|
|
8
9
|
/** Custom MSH-10 control ID. Auto-generated via `uid()` when omitted. */
|
|
9
10
|
id?: string;
|
|
10
11
|
/** MSH-3/MSH-4 of the ACK. Defaults to the original message's MSH-5/MSH-6. */
|
|
11
12
|
sending?: SendingInfo;
|
|
12
13
|
/** MSH-11 processing ID. Defaults to the original message's MSH-11. */
|
|
13
14
|
processingId?: string;
|
|
14
|
-
|
|
15
|
-
error
|
|
15
|
+
} & ({
|
|
16
|
+
/** Sets the ACK code (AE/AR/CE/CR) and populates MSA-3 with the error message. */
|
|
17
|
+
error: AckException;
|
|
16
18
|
/** Include ERR segment when an error is provided. Defaults to `true`. */
|
|
17
19
|
includeErrSegment?: boolean;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
successCode?: never;
|
|
21
|
+
} | {
|
|
22
|
+
error?: never;
|
|
23
|
+
includeErrSegment?: never;
|
|
24
|
+
/** MSA-1 code when no error is present. Defaults to `AckCode.ApplicationAccept`. */
|
|
25
|
+
successCode?: AckSuccessCode;
|
|
26
|
+
});
|
|
27
|
+
export declare function acknowledge(origin: Root, { id, processingId, sending, error, includeErrSegment, successCode, }?: AcknowledgeOptions): Root;
|
|
20
28
|
//# sourceMappingURL=acknowledge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acknowledge.d.ts","sourceRoot":"","sources":["../src/acknowledge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"acknowledge.d.ts","sourceRoot":"","sources":["../src/acknowledge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,0BAA0B,CAAC;AAM9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,yEAAyE;IACzE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,CACA;IACE,kFAAkF;IAClF,KAAK,EAAE,YAAY,CAAC;IACpB,yEAAyE;IACzE,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,WAAW,CAAC,EAAE,KAAK,CAAC;CACrB,GACD;IACE,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,iBAAiB,CAAC,EAAE,KAAK,CAAC;IAC1B,oFAAoF;IACpF,WAAW,CAAC,EAAE,cAAc,CAAC;CAC9B,CACJ,CAAC;AAmEF,wBAAgB,WAAW,CACzB,MAAM,EAAE,IAAI,EACZ,EACE,EAAE,EACF,YAAY,EACZ,OAAO,EACP,KAAK,EACL,iBAAwB,EACxB,WAAuC,GACxC,GAAE,kBAAuB,GACzB,IAAI,CAkBN"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** HL7v2 Table 0008 — Acknowledgment codes used in MSA-1. */
|
|
2
|
+
export declare const AckCode: {
|
|
3
|
+
readonly ApplicationAccept: "AA";
|
|
4
|
+
readonly ApplicationError: "AE";
|
|
5
|
+
readonly ApplicationReject: "AR";
|
|
6
|
+
readonly CommitAccept: "CA";
|
|
7
|
+
readonly CommitError: "CE";
|
|
8
|
+
readonly CommitReject: "CR";
|
|
9
|
+
};
|
|
10
|
+
export type AckCodeValue = (typeof AckCode)[keyof typeof AckCode];
|
|
11
|
+
/** Accept codes used as `successCode` in `acknowledge()`. */
|
|
12
|
+
export type AckSuccessCode = typeof AckCode.ApplicationAccept | typeof AckCode.CommitAccept;
|
|
13
|
+
/** HL7v2 Table 0357 — Message error condition codes used in ERR-3. Stable across all versions (v2.1–v2.9). */
|
|
14
|
+
export declare const Hl7ErrorCode: {
|
|
15
|
+
readonly MessageAccepted: "0";
|
|
16
|
+
readonly SegmentSequenceError: "100";
|
|
17
|
+
readonly RequiredFieldMissing: "101";
|
|
18
|
+
readonly DataTypeError: "102";
|
|
19
|
+
readonly TableValueNotFound: "103";
|
|
20
|
+
readonly UnsupportedMessageType: "200";
|
|
21
|
+
readonly UnsupportedEventCode: "201";
|
|
22
|
+
readonly UnsupportedProcessingId: "202";
|
|
23
|
+
readonly UnsupportedVersionId: "203";
|
|
24
|
+
readonly UnknownKeyIdentifier: "204";
|
|
25
|
+
readonly DuplicateKeyIdentifier: "205";
|
|
26
|
+
readonly ApplicationRecordLocked: "206";
|
|
27
|
+
readonly ApplicationInternalError: "207";
|
|
28
|
+
};
|
|
29
|
+
export type Hl7ErrorCodeValue = (typeof Hl7ErrorCode)[keyof typeof Hl7ErrorCode];
|
|
30
|
+
/** HL7v2 Table 0516 — Error severity codes used in ERR-4. */
|
|
31
|
+
export declare const Severity: {
|
|
32
|
+
readonly Info: "I";
|
|
33
|
+
readonly Warning: "W";
|
|
34
|
+
readonly Error: "E";
|
|
35
|
+
};
|
|
36
|
+
export type SeverityValue = (typeof Severity)[keyof typeof Severity];
|
|
37
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,eAAO,MAAM,OAAO;;;;;;;CAOV,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAElE,6DAA6D;AAC7D,MAAM,MAAM,cAAc,GACtB,OAAO,OAAO,CAAC,iBAAiB,GAChC,OAAO,OAAO,CAAC,YAAY,CAAC;AAEhC,8GAA8G;AAC9G,eAAO,MAAM,YAAY;;;;;;;;;;;;;;CAcf,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAEnD,6DAA6D;AAC7D,eAAO,MAAM,QAAQ;;;;CAIX,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AckApplicationError } from "../exception";
|
|
2
|
+
/**
|
|
3
|
+
* Application internal error (MSA-1 = `AE`, ERR-3 = `207`, ERR-4 = `E`).
|
|
4
|
+
*
|
|
5
|
+
* Used to wrap unexpected/unknown errors that don't map to a specific
|
|
6
|
+
* HL7v2 error condition. This is the default error produced by
|
|
7
|
+
* `ackMiddleware` when a handler throws an unrecognized exception.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ApplicationInternalError extends AckApplicationError {
|
|
10
|
+
constructor(message: string, cause?: Error);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=application-internal-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-internal-error.d.ts","sourceRoot":"","sources":["../../src/errors/application-internal-error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD;;;;;;GAMG;AACH,qBAAa,wBAAyB,SAAQ,mBAAmB;gBACnD,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAQ3C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AckCommitError } from "../exception";
|
|
2
|
+
/**
|
|
3
|
+
* Commit-level internal error (MSA-1 = `CE`, ERR-3 = `207`, ERR-4 = `E`).
|
|
4
|
+
*
|
|
5
|
+
* Used when the message could not be persisted due to an internal
|
|
6
|
+
* infrastructure failure (e.g. database unavailable).
|
|
7
|
+
*/
|
|
8
|
+
export declare class CommitInternalError extends AckCommitError {
|
|
9
|
+
constructor(message: string, cause?: Error);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=commit-internal-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-internal-error.d.ts","sourceRoot":"","sources":["../../src/errors/commit-internal-error.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAQ3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AckApplicationReject } from "../exception";
|
|
2
|
+
/**
|
|
3
|
+
* Unsupported message type reject (MSA-1 = `AR`, ERR-3 = `200`, ERR-4 = `E`).
|
|
4
|
+
*
|
|
5
|
+
* Throw when the receiving application does not handle the inbound
|
|
6
|
+
* message type (e.g. ADT^A01 sent to a system that only accepts ORU).
|
|
7
|
+
*/
|
|
8
|
+
export declare class UnsupportedMessageTypeReject extends AckApplicationReject {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=unsupported-message-type-reject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsupported-message-type-reject.d.ts","sourceRoot":"","sources":["../../src/errors/unsupported-message-type-reject.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;GAKG;AACH,qBAAa,4BAA6B,SAAQ,oBAAoB;gBACxD,OAAO,EAAE,MAAM;CAO5B"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Segment } from "@rethinkhealth/hl7v2-ast";
|
|
2
|
+
import type { AckCodeValue, Hl7ErrorCodeValue, SeverityValue } from "./constants";
|
|
3
|
+
export interface AckExceptionOptions extends ErrorOptions {
|
|
4
|
+
errorCode: Hl7ErrorCodeValue;
|
|
5
|
+
severity?: SeverityValue;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Abstract base class for all HL7v2 acknowledgment exceptions.
|
|
9
|
+
*
|
|
10
|
+
* Subclasses map to specific MSA-1 acknowledgment codes (Table 0008).
|
|
11
|
+
* Each exception carries an error code (Table 0357), optional severity
|
|
12
|
+
* (Table 0516), and can build its own ERR segment AST via {@link toErrSegment}.
|
|
13
|
+
*
|
|
14
|
+
* Use `instanceof AckException` to detect any ACK-level error in middleware.
|
|
15
|
+
*/
|
|
16
|
+
export declare abstract class AckException extends Error {
|
|
17
|
+
abstract readonly code: AckCodeValue;
|
|
18
|
+
readonly errorCode: Hl7ErrorCodeValue;
|
|
19
|
+
readonly severity: SeverityValue | undefined;
|
|
20
|
+
constructor(message: string, options: AckExceptionOptions);
|
|
21
|
+
/** Build an ERR segment AST node from this exception's error code and severity. */
|
|
22
|
+
toErrSegment(): Segment;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Application-level error (MSA-1 = `AE`).
|
|
26
|
+
*
|
|
27
|
+
* Throw when the message was understood but could not be processed
|
|
28
|
+
* due to an application-level problem (e.g. validation failure, unknown key).
|
|
29
|
+
*/
|
|
30
|
+
export declare class AckApplicationError extends AckException {
|
|
31
|
+
readonly code: "AE";
|
|
32
|
+
constructor(message: string, options: AckExceptionOptions);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Application-level reject (MSA-1 = `AR`).
|
|
36
|
+
*
|
|
37
|
+
* Throw when the message is rejected outright at the application level
|
|
38
|
+
* (e.g. unsupported message type, unsupported version).
|
|
39
|
+
*/
|
|
40
|
+
export declare class AckApplicationReject extends AckException {
|
|
41
|
+
readonly code: "AR";
|
|
42
|
+
constructor(message: string, options: AckExceptionOptions);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Commit-level error (MSA-1 = `CE`).
|
|
46
|
+
*
|
|
47
|
+
* Throw when the message could not be safely persisted/committed
|
|
48
|
+
* (e.g. storage failure). Used in enhanced acknowledgment mode.
|
|
49
|
+
*/
|
|
50
|
+
export declare class AckCommitError extends AckException {
|
|
51
|
+
readonly code: "CE";
|
|
52
|
+
constructor(message: string, options: AckExceptionOptions);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Commit-level reject (MSA-1 = `CR`).
|
|
56
|
+
*
|
|
57
|
+
* Throw when the message is rejected at the commit level
|
|
58
|
+
* (e.g. message cannot be stored). Used in enhanced acknowledgment mode.
|
|
59
|
+
*/
|
|
60
|
+
export declare class AckCommitReject extends AckException {
|
|
61
|
+
readonly code: "CR";
|
|
62
|
+
constructor(message: string, options: AckExceptionOptions);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=exception.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAIxD,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACd,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD,SAAS,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED;;;;;;;;GAQG;AACH,8BAAsB,YAAa,SAAQ,KAAK;IAC9C,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;gBAEjC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB;IAMzD,mFAAmF;IACnF,YAAY,IAAI,OAAO;CASxB;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,QAAQ,CAAC,IAAI,OAA4B;gBAE7B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB;CAI1D;AAED;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,YAAY;IACpD,QAAQ,CAAC,IAAI,OAA6B;gBAE9B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB;CAI1D;AAED;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,QAAQ,CAAC,IAAI,OAAuB;gBAExB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB;CAI1D;AAED;;;;;GAKG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,QAAQ,CAAC,IAAI,OAAwB;gBAEzB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB;CAI1D"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { acknowledge } from "./acknowledge";
|
|
2
2
|
export type { AcknowledgeOptions, SendingInfo } from "./acknowledge";
|
|
3
|
-
export {
|
|
4
|
-
export type {
|
|
3
|
+
export { AckCode, Hl7ErrorCode, Severity } from "./constants";
|
|
4
|
+
export type { AckCodeValue, AckSuccessCode, Hl7ErrorCodeValue, SeverityValue, } from "./constants";
|
|
5
|
+
export { AckApplicationError, AckApplicationReject, AckCommitError, AckCommitReject, AckException, } from "./exception";
|
|
6
|
+
export type { AckExceptionOptions } from "./exception";
|
|
7
|
+
export { ApplicationInternalError, CommitInternalError, UnsupportedMessageTypeReject, } from "./errors";
|
|
5
8
|
export { uid } from "./uid";
|
|
6
9
|
export type { Options as UidOptions } from "./uid";
|
|
7
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC9D,YAAY,EACV,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,YAAY,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,OAAO,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,36 @@ import { c, f, m, s } from "@rethinkhealth/hl7v2-builder";
|
|
|
3
3
|
import { value } from "@rethinkhealth/hl7v2-util-query";
|
|
4
4
|
import { Timestamp } from "@rethinkhealth/hl7v2-util-timestamp";
|
|
5
5
|
|
|
6
|
+
// src/constants.ts
|
|
7
|
+
var AckCode = {
|
|
8
|
+
ApplicationAccept: "AA",
|
|
9
|
+
ApplicationError: "AE",
|
|
10
|
+
ApplicationReject: "AR",
|
|
11
|
+
CommitAccept: "CA",
|
|
12
|
+
CommitError: "CE",
|
|
13
|
+
CommitReject: "CR"
|
|
14
|
+
};
|
|
15
|
+
var Hl7ErrorCode = {
|
|
16
|
+
MessageAccepted: "0",
|
|
17
|
+
SegmentSequenceError: "100",
|
|
18
|
+
RequiredFieldMissing: "101",
|
|
19
|
+
DataTypeError: "102",
|
|
20
|
+
TableValueNotFound: "103",
|
|
21
|
+
UnsupportedMessageType: "200",
|
|
22
|
+
UnsupportedEventCode: "201",
|
|
23
|
+
UnsupportedProcessingId: "202",
|
|
24
|
+
UnsupportedVersionId: "203",
|
|
25
|
+
UnknownKeyIdentifier: "204",
|
|
26
|
+
DuplicateKeyIdentifier: "205",
|
|
27
|
+
ApplicationRecordLocked: "206",
|
|
28
|
+
ApplicationInternalError: "207"
|
|
29
|
+
};
|
|
30
|
+
var Severity = {
|
|
31
|
+
Info: "I",
|
|
32
|
+
Warning: "W",
|
|
33
|
+
Error: "E"
|
|
34
|
+
};
|
|
35
|
+
|
|
6
36
|
// src/uid.ts
|
|
7
37
|
import { nanoid } from "nanoid";
|
|
8
38
|
var MAX_LENGTH = 20;
|
|
@@ -56,24 +86,32 @@ function buildMsh(origin, options) {
|
|
|
56
86
|
function buildMsa(code, controlId, message) {
|
|
57
87
|
return message ? s("MSA", f(code), f(controlId), f(message)) : s("MSA", f(code), f(controlId));
|
|
58
88
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
89
|
+
function acknowledge(origin, {
|
|
90
|
+
id,
|
|
91
|
+
processingId,
|
|
92
|
+
sending,
|
|
93
|
+
error,
|
|
94
|
+
includeErrSegment = true,
|
|
95
|
+
successCode = AckCode.ApplicationAccept
|
|
96
|
+
} = {}) {
|
|
64
97
|
const fields = extractOriginFields(origin);
|
|
65
|
-
const code = error?.code ??
|
|
98
|
+
const code = error?.code ?? successCode;
|
|
66
99
|
const segments = [
|
|
67
|
-
buildMsh(fields,
|
|
100
|
+
buildMsh(fields, {
|
|
101
|
+
id,
|
|
102
|
+
processingId,
|
|
103
|
+
sending
|
|
104
|
+
}),
|
|
68
105
|
buildMsa(code, fields.controlId, error?.message)
|
|
69
106
|
];
|
|
70
107
|
if (error && includeErrSegment) {
|
|
71
|
-
segments.push(
|
|
108
|
+
segments.push(error.toErrSegment());
|
|
72
109
|
}
|
|
73
110
|
return m(...segments);
|
|
74
111
|
}
|
|
75
112
|
|
|
76
|
-
// src/
|
|
113
|
+
// src/exception.ts
|
|
114
|
+
import { f as f2, s as s2 } from "@rethinkhealth/hl7v2-builder";
|
|
77
115
|
var AckException = class extends Error {
|
|
78
116
|
errorCode;
|
|
79
117
|
severity;
|
|
@@ -82,25 +120,92 @@ var AckException = class extends Error {
|
|
|
82
120
|
this.errorCode = options.errorCode;
|
|
83
121
|
this.severity = options.severity;
|
|
84
122
|
}
|
|
123
|
+
/** Build an ERR segment AST node from this exception's error code and severity. */
|
|
124
|
+
toErrSegment() {
|
|
125
|
+
return s2(
|
|
126
|
+
"ERR",
|
|
127
|
+
f2(""),
|
|
128
|
+
f2(""),
|
|
129
|
+
f2(this.errorCode),
|
|
130
|
+
f2(this.severity ?? Severity.Error)
|
|
131
|
+
);
|
|
132
|
+
}
|
|
85
133
|
};
|
|
86
|
-
var
|
|
87
|
-
code =
|
|
134
|
+
var AckApplicationError = class extends AckException {
|
|
135
|
+
code = AckCode.ApplicationError;
|
|
88
136
|
constructor(message, options) {
|
|
89
137
|
super(message, options);
|
|
90
|
-
this.name = "
|
|
138
|
+
this.name = "AckApplicationError";
|
|
91
139
|
}
|
|
92
140
|
};
|
|
93
|
-
var
|
|
94
|
-
code =
|
|
141
|
+
var AckApplicationReject = class extends AckException {
|
|
142
|
+
code = AckCode.ApplicationReject;
|
|
95
143
|
constructor(message, options) {
|
|
96
144
|
super(message, options);
|
|
97
|
-
this.name = "
|
|
145
|
+
this.name = "AckApplicationReject";
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
var AckCommitError = class extends AckException {
|
|
149
|
+
code = AckCode.CommitError;
|
|
150
|
+
constructor(message, options) {
|
|
151
|
+
super(message, options);
|
|
152
|
+
this.name = "AckCommitError";
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var AckCommitReject = class extends AckException {
|
|
156
|
+
code = AckCode.CommitReject;
|
|
157
|
+
constructor(message, options) {
|
|
158
|
+
super(message, options);
|
|
159
|
+
this.name = "AckCommitReject";
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// src/errors/application-internal-error.ts
|
|
164
|
+
var ApplicationInternalError = class extends AckApplicationError {
|
|
165
|
+
constructor(message, cause) {
|
|
166
|
+
super(message, {
|
|
167
|
+
errorCode: Hl7ErrorCode.ApplicationInternalError,
|
|
168
|
+
severity: Severity.Error,
|
|
169
|
+
cause
|
|
170
|
+
});
|
|
171
|
+
this.name = "ApplicationInternalError";
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// src/errors/commit-internal-error.ts
|
|
176
|
+
var CommitInternalError = class extends AckCommitError {
|
|
177
|
+
constructor(message, cause) {
|
|
178
|
+
super(message, {
|
|
179
|
+
errorCode: Hl7ErrorCode.ApplicationInternalError,
|
|
180
|
+
severity: Severity.Error,
|
|
181
|
+
cause
|
|
182
|
+
});
|
|
183
|
+
this.name = "CommitInternalError";
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// src/errors/unsupported-message-type-reject.ts
|
|
188
|
+
var UnsupportedMessageTypeReject = class extends AckApplicationReject {
|
|
189
|
+
constructor(message) {
|
|
190
|
+
super(message, {
|
|
191
|
+
errorCode: Hl7ErrorCode.UnsupportedMessageType,
|
|
192
|
+
severity: Severity.Error
|
|
193
|
+
});
|
|
194
|
+
this.name = "UnsupportedMessageTypeReject";
|
|
98
195
|
}
|
|
99
196
|
};
|
|
100
197
|
export {
|
|
101
|
-
|
|
198
|
+
AckApplicationError,
|
|
199
|
+
AckApplicationReject,
|
|
200
|
+
AckCode,
|
|
201
|
+
AckCommitError,
|
|
202
|
+
AckCommitReject,
|
|
102
203
|
AckException,
|
|
103
|
-
|
|
204
|
+
ApplicationInternalError,
|
|
205
|
+
CommitInternalError,
|
|
206
|
+
Hl7ErrorCode,
|
|
207
|
+
Severity,
|
|
208
|
+
UnsupportedMessageTypeReject,
|
|
104
209
|
acknowledge,
|
|
105
210
|
uid
|
|
106
211
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/acknowledge.ts","../src/uid.ts","../src/errors.ts"],"sourcesContent":["import type { Root, Segment } from \"@rethinkhealth/hl7v2-ast\";\nimport { c, f, m, s } from \"@rethinkhealth/hl7v2-builder\";\nimport { value } from \"@rethinkhealth/hl7v2-util-query\";\nimport { Timestamp } from \"@rethinkhealth/hl7v2-util-timestamp\";\n\nimport type { AckException } from \"./errors\";\nimport { uid } from \"./uid\";\n\nexport interface SendingInfo {\n application: string;\n facility: string;\n}\n\nexport interface AcknowledgeOptions {\n /** Custom MSH-10 control ID. Auto-generated via `uid()` when omitted. */\n id?: string;\n /** MSH-3/MSH-4 of the ACK. Defaults to the original message's MSH-5/MSH-6. */\n sending?: SendingInfo;\n /** MSH-11 processing ID. Defaults to the original message's MSH-11. */\n processingId?: string;\n /** When provided, sets the ACK code (AE/AR) and populates MSA-3 with the error message. */\n error?: AckException;\n /** Include ERR segment when an error is provided. Defaults to `true`. */\n includeErrSegment?: boolean;\n}\n\n// -- Field extraction ----\n\ninterface OriginFields {\n controlId: string;\n version: string;\n triggerEvent: string;\n processingId: string;\n sendingApp: string;\n sendingFac: string;\n receivingApp: string;\n receivingFac: string;\n}\n\nfunction extractOriginFields(tree: Root): OriginFields {\n return {\n controlId: value(tree, \"MSH-10\")?.value ?? \"\",\n processingId: value(tree, \"MSH-11\")?.value ?? \"P\",\n receivingApp: value(tree, \"MSH-5\")?.value ?? \"\",\n receivingFac: value(tree, \"MSH-6\")?.value ?? \"\",\n sendingApp: value(tree, \"MSH-3\")?.value ?? \"\",\n sendingFac: value(tree, \"MSH-4\")?.value ?? \"\",\n triggerEvent: value(tree, \"MSH-9.2\")?.value ?? \"\",\n version: value(tree, \"MSH-12\")?.value ?? \"\",\n };\n}\n\n// -- Segment builders ----\n\nfunction buildMsh(origin: OriginFields, options: AcknowledgeOptions): Segment {\n const sendApp = options.sending?.application ?? origin.receivingApp;\n const sendFac = options.sending?.facility ?? origin.receivingFac;\n const pid = options.processingId ?? origin.processingId;\n const controlId = options.id ?? uid();\n const msgType = origin.triggerEvent\n ? f(c(\"ACK\"), c(origin.triggerEvent))\n : f(\"ACK\");\n\n return s(\n \"MSH\",\n f(\"|\"),\n f(\"^~\\\\&\"),\n f(sendApp),\n f(sendFac),\n f(origin.sendingApp),\n f(origin.sendingFac),\n f(Timestamp.now().toString()),\n f(\"\"),\n msgType,\n f(controlId),\n f(pid),\n f(origin.version)\n );\n}\n\nfunction buildMsa(code: string, controlId: string, message?: string): Segment {\n return message\n ? s(\"MSA\", f(code), f(controlId), f(message))\n : s(\"MSA\", f(code), f(controlId));\n}\n\nfunction buildErr(error: AckException): Segment {\n return s(\"ERR\", f(\"\"), f(\"\"), f(error.errorCode), f(error.severity ?? \"E\"));\n}\n\n// -- Public API ----\n\nexport function acknowledge(\n origin: Root,\n options: AcknowledgeOptions = {}\n): Root {\n const { error, includeErrSegment = true } = options;\n const fields = extractOriginFields(origin);\n const code = error?.code ?? \"AA\";\n\n const segments: Segment[] = [\n buildMsh(fields, options),\n buildMsa(code, fields.controlId, error?.message),\n ];\n\n if (error && includeErrSegment) {\n segments.push(buildErr(error));\n }\n\n return m(...segments);\n}\n","import { nanoid } from \"nanoid\";\n\nconst MAX_LENGTH = 20;\n\nexport interface Options {\n prefix?: string;\n size?: number;\n}\n\nexport function uid(options: Options = {}): string {\n const { prefix, size = MAX_LENGTH } = options;\n\n if (!prefix) {\n return nanoid(size);\n }\n\n const remaining = size - prefix.length;\n\n if (remaining <= 0) {\n return prefix.slice(0, size);\n }\n\n return `${prefix}${nanoid(remaining)}`;\n}\n","export interface AckExceptionOptions extends ErrorOptions {\n errorCode: string;\n severity?: string;\n}\n\ntype AckCode = \"AE\" | \"AR\";\n\nexport abstract class AckException extends Error {\n abstract readonly code: AckCode;\n readonly errorCode: string;\n readonly severity: string | undefined;\n\n constructor(message: string, options: AckExceptionOptions) {\n super(message, { cause: options.cause });\n this.errorCode = options.errorCode;\n this.severity = options.severity;\n }\n}\n\nexport class AckError extends AckException {\n readonly code = \"AE\" as const;\n\n constructor(message: string, options: AckExceptionOptions) {\n super(message, options);\n this.name = \"AckError\";\n }\n}\n\nexport class AckReject extends AckException {\n readonly code = \"AR\" as const;\n\n constructor(message: string, options: AckExceptionOptions) {\n super(message, options);\n this.name = \"AckReject\";\n }\n}\n"],"mappings":";AACA,SAAS,GAAG,GAAG,GAAG,SAAS;AAC3B,SAAS,aAAa;AACtB,SAAS,iBAAiB;;;ACH1B,SAAS,cAAc;AAEvB,IAAM,aAAa;AAOZ,SAAS,IAAI,UAAmB,CAAC,GAAW;AACjD,QAAM,EAAE,QAAQ,OAAO,WAAW,IAAI;AAEtC,MAAI,CAAC,QAAQ;AACX,WAAO,OAAO,IAAI;AAAA,EACpB;AAEA,QAAM,YAAY,OAAO,OAAO;AAEhC,MAAI,aAAa,GAAG;AAClB,WAAO,OAAO,MAAM,GAAG,IAAI;AAAA,EAC7B;AAEA,SAAO,GAAG,MAAM,GAAG,OAAO,SAAS,CAAC;AACtC;;;ADgBA,SAAS,oBAAoB,MAA0B;AACrD,SAAO;AAAA,IACL,WAAW,MAAM,MAAM,QAAQ,GAAG,SAAS;AAAA,IAC3C,cAAc,MAAM,MAAM,QAAQ,GAAG,SAAS;AAAA,IAC9C,cAAc,MAAM,MAAM,OAAO,GAAG,SAAS;AAAA,IAC7C,cAAc,MAAM,MAAM,OAAO,GAAG,SAAS;AAAA,IAC7C,YAAY,MAAM,MAAM,OAAO,GAAG,SAAS;AAAA,IAC3C,YAAY,MAAM,MAAM,OAAO,GAAG,SAAS;AAAA,IAC3C,cAAc,MAAM,MAAM,SAAS,GAAG,SAAS;AAAA,IAC/C,SAAS,MAAM,MAAM,QAAQ,GAAG,SAAS;AAAA,EAC3C;AACF;AAIA,SAAS,SAAS,QAAsB,SAAsC;AAC5E,QAAM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S,KAAK,SAAS,KAAK,CAAC;AAAA,EAC/B;AAEA,SAAO,EAAE,GAAG,QAAQ;AACtB;;;AEvGO,IAAe,eAAf,cAAoC,MAAM;AAAA,EAEtC;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,SAA8B;AACzD,UAAM,SAAS,EAAE,OAAO,QAAQ,MAAM,CAAC;AACvC,SAAK,YAAY,QAAQ;AACzB,SAAK,WAAW,QAAQ;AAAA,EAC1B;AACF;AAEO,IAAM,WAAN,cAAuB,aAAa;AAAA,EAChC,OAAO;AAAA,EAEhB,YAAY,SAAiB,SAA8B;AACzD,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,YAAN,cAAwB,aAAa;AAAA,EACjC,OAAO;AAAA,EAEhB,YAAY,SAAiB,SAA8B;AACzD,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/acknowledge.ts","../src/constants.ts","../src/uid.ts","../src/exception.ts","../src/errors/application-internal-error.ts","../src/errors/commit-internal-error.ts","../src/errors/unsupported-message-type-reject.ts"],"sourcesContent":["import type { Root, Segment } from \"@rethinkhealth/hl7v2-ast\";\nimport { c, f, m, s } from \"@rethinkhealth/hl7v2-builder\";\nimport { value } from \"@rethinkhealth/hl7v2-util-query\";\nimport { Timestamp } from \"@rethinkhealth/hl7v2-util-timestamp\";\n\nimport { AckCode } from \"./constants\";\nimport type { AckSuccessCode } from \"./constants\";\nimport type { AckException } from \"./exception\";\nimport { uid } from \"./uid\";\n\nexport interface SendingInfo {\n application: string;\n facility: string;\n}\n\nexport type AcknowledgeOptions = {\n /** Custom MSH-10 control ID. Auto-generated via `uid()` when omitted. */\n id?: string;\n /** MSH-3/MSH-4 of the ACK. Defaults to the original message's MSH-5/MSH-6. */\n sending?: SendingInfo;\n /** MSH-11 processing ID. Defaults to the original message's MSH-11. */\n processingId?: string;\n} & (\n | {\n /** Sets the ACK code (AE/AR/CE/CR) and populates MSA-3 with the error message. */\n error: AckException;\n /** Include ERR segment when an error is provided. Defaults to `true`. */\n includeErrSegment?: boolean;\n successCode?: never;\n }\n | {\n error?: never;\n includeErrSegment?: never;\n /** MSA-1 code when no error is present. Defaults to `AckCode.ApplicationAccept`. */\n successCode?: AckSuccessCode;\n }\n);\n\n// -- Field extraction ----\n\ninterface OriginFields {\n controlId: string;\n version: string;\n triggerEvent: string;\n processingId: string;\n sendingApp: string;\n sendingFac: string;\n receivingApp: string;\n receivingFac: string;\n}\n\nfunction extractOriginFields(tree: Root): OriginFields {\n return {\n controlId: value(tree, \"MSH-10\")?.value ?? \"\",\n processingId: value(tree, \"MSH-11\")?.value ?? \"P\",\n receivingApp: value(tree, \"MSH-5\")?.value ?? \"\",\n receivingFac: value(tree, \"MSH-6\")?.value ?? \"\",\n sendingApp: value(tree, \"MSH-3\")?.value ?? \"\",\n sendingFac: value(tree, \"MSH-4\")?.value ?? \"\",\n triggerEvent: value(tree, \"MSH-9.2\")?.value ?? \"\",\n version: value(tree, \"MSH-12\")?.value ?? \"\",\n };\n}\n\n// -- Segment builders ----\n\nfunction buildMsh(\n origin: OriginFields,\n options: Pick<AcknowledgeOptions, \"id\" | \"sending\" | \"processingId\">\n): Segment {\n const sendApp = options.sending?.application ?? origin.receivingApp;\n const sendFac = options.sending?.facility ?? origin.receivingFac;\n const pid = options.processingId ?? origin.processingId;\n const controlId = options.id ?? uid();\n const msgType = origin.triggerEvent\n ? f(c(\"ACK\"), c(origin.triggerEvent))\n : f(\"ACK\");\n\n return s(\n \"MSH\",\n f(\"|\"),\n f(\"^~\\\\&\"),\n f(sendApp),\n f(sendFac),\n f(origin.sendingApp),\n f(origin.sendingFac),\n f(Timestamp.now().toString()),\n f(\"\"),\n msgType,\n f(controlId),\n f(pid),\n f(origin.version)\n );\n}\n\nfunction buildMsa(code: string, controlId: string, message?: string): Segment {\n return message\n ? s(\"MSA\", f(code), f(controlId), f(message))\n : s(\"MSA\", f(code), f(controlId));\n}\n\n// -- Public API ----\n\nexport function acknowledge(\n origin: Root,\n {\n id,\n processingId,\n sending,\n error,\n includeErrSegment = true,\n successCode = AckCode.ApplicationAccept,\n }: AcknowledgeOptions = {}\n): Root {\n const fields = extractOriginFields(origin);\n const code = error?.code ?? successCode;\n\n const segments: Segment[] = [\n buildMsh(fields, {\n id,\n processingId,\n sending,\n }),\n buildMsa(code, fields.controlId, error?.message),\n ];\n\n if (error && includeErrSegment) {\n segments.push(error.toErrSegment());\n }\n\n return m(...segments);\n}\n","/** HL7v2 Table 0008 — Acknowledgment codes used in MSA-1. */\nexport const AckCode = {\n ApplicationAccept: \"AA\",\n ApplicationError: \"AE\",\n ApplicationReject: \"AR\",\n CommitAccept: \"CA\",\n CommitError: \"CE\",\n CommitReject: \"CR\",\n} as const;\n\nexport type AckCodeValue = (typeof AckCode)[keyof typeof AckCode];\n\n/** Accept codes used as `successCode` in `acknowledge()`. */\nexport type AckSuccessCode =\n | typeof AckCode.ApplicationAccept\n | typeof AckCode.CommitAccept;\n\n/** HL7v2 Table 0357 — Message error condition codes used in ERR-3. Stable across all versions (v2.1–v2.9). */\nexport const Hl7ErrorCode = {\n MessageAccepted: \"0\",\n SegmentSequenceError: \"100\",\n RequiredFieldMissing: \"101\",\n DataTypeError: \"102\",\n TableValueNotFound: \"103\",\n UnsupportedMessageType: \"200\",\n UnsupportedEventCode: \"201\",\n UnsupportedProcessingId: \"202\",\n UnsupportedVersionId: \"203\",\n UnknownKeyIdentifier: \"204\",\n DuplicateKeyIdentifier: \"205\",\n ApplicationRecordLocked: \"206\",\n ApplicationInternalError: \"207\",\n} as const;\n\nexport type Hl7ErrorCodeValue =\n (typeof Hl7ErrorCode)[keyof typeof Hl7ErrorCode];\n\n/** HL7v2 Table 0516 — Error severity codes used in ERR-4. */\nexport const Severity = {\n Info: \"I\",\n Warning: \"W\",\n Error: \"E\",\n} as const;\n\nexport type SeverityValue = (typeof Severity)[keyof typeof Severity];\n","import { nanoid } from \"nanoid\";\n\nconst MAX_LENGTH = 20;\n\nexport interface Options {\n prefix?: string;\n size?: number;\n}\n\nexport function uid(options: Options = {}): string {\n const { prefix, size = MAX_LENGTH } = options;\n\n if (!prefix) {\n return nanoid(size);\n }\n\n const remaining = size - prefix.length;\n\n if (remaining <= 0) {\n return prefix.slice(0, size);\n }\n\n return `${prefix}${nanoid(remaining)}`;\n}\n","import type { Segment } from \"@rethinkhealth/hl7v2-ast\";\nimport { f, s } from \"@rethinkhealth/hl7v2-builder\";\n\nimport { AckCode, Severity } from \"./constants\";\nimport type {\n AckCodeValue,\n Hl7ErrorCodeValue,\n SeverityValue,\n} from \"./constants\";\n\nexport interface AckExceptionOptions extends ErrorOptions {\n errorCode: Hl7ErrorCodeValue;\n severity?: SeverityValue;\n}\n\n/**\n * Abstract base class for all HL7v2 acknowledgment exceptions.\n *\n * Subclasses map to specific MSA-1 acknowledgment codes (Table 0008).\n * Each exception carries an error code (Table 0357), optional severity\n * (Table 0516), and can build its own ERR segment AST via {@link toErrSegment}.\n *\n * Use `instanceof AckException` to detect any ACK-level error in middleware.\n */\nexport abstract class AckException extends Error {\n abstract readonly code: AckCodeValue;\n readonly errorCode: Hl7ErrorCodeValue;\n readonly severity: SeverityValue | undefined;\n\n constructor(message: string, options: AckExceptionOptions) {\n super(message, { cause: options.cause });\n this.errorCode = options.errorCode;\n this.severity = options.severity;\n }\n\n /** Build an ERR segment AST node from this exception's error code and severity. */\n toErrSegment(): Segment {\n return s(\n \"ERR\",\n f(\"\"),\n f(\"\"),\n f(this.errorCode),\n f(this.severity ?? Severity.Error)\n );\n }\n}\n\n/**\n * Application-level error (MSA-1 = `AE`).\n *\n * Throw when the message was understood but could not be processed\n * due to an application-level problem (e.g. validation failure, unknown key).\n */\nexport class AckApplicationError extends AckException {\n readonly code = AckCode.ApplicationError;\n\n constructor(message: string, options: AckExceptionOptions) {\n super(message, options);\n this.name = \"AckApplicationError\";\n }\n}\n\n/**\n * Application-level reject (MSA-1 = `AR`).\n *\n * Throw when the message is rejected outright at the application level\n * (e.g. unsupported message type, unsupported version).\n */\nexport class AckApplicationReject extends AckException {\n readonly code = AckCode.ApplicationReject;\n\n constructor(message: string, options: AckExceptionOptions) {\n super(message, options);\n this.name = \"AckApplicationReject\";\n }\n}\n\n/**\n * Commit-level error (MSA-1 = `CE`).\n *\n * Throw when the message could not be safely persisted/committed\n * (e.g. storage failure). Used in enhanced acknowledgment mode.\n */\nexport class AckCommitError extends AckException {\n readonly code = AckCode.CommitError;\n\n constructor(message: string, options: AckExceptionOptions) {\n super(message, options);\n this.name = \"AckCommitError\";\n }\n}\n\n/**\n * Commit-level reject (MSA-1 = `CR`).\n *\n * Throw when the message is rejected at the commit level\n * (e.g. message cannot be stored). Used in enhanced acknowledgment mode.\n */\nexport class AckCommitReject extends AckException {\n readonly code = AckCode.CommitReject;\n\n constructor(message: string, options: AckExceptionOptions) {\n super(message, options);\n this.name = \"AckCommitReject\";\n }\n}\n","import { Hl7ErrorCode, Severity } from \"../constants\";\nimport { AckApplicationError } from \"../exception\";\n\n/**\n * Application internal error (MSA-1 = `AE`, ERR-3 = `207`, ERR-4 = `E`).\n *\n * Used to wrap unexpected/unknown errors that don't map to a specific\n * HL7v2 error condition. This is the default error produced by\n * `ackMiddleware` when a handler throws an unrecognized exception.\n */\nexport class ApplicationInternalError extends AckApplicationError {\n constructor(message: string, cause?: Error) {\n super(message, {\n errorCode: Hl7ErrorCode.ApplicationInternalError,\n severity: Severity.Error,\n cause,\n });\n this.name = \"ApplicationInternalError\";\n }\n}\n","import { Hl7ErrorCode, Severity } from \"../constants\";\nimport { AckCommitError } from \"../exception\";\n\n/**\n * Commit-level internal error (MSA-1 = `CE`, ERR-3 = `207`, ERR-4 = `E`).\n *\n * Used when the message could not be persisted due to an internal\n * infrastructure failure (e.g. database unavailable).\n */\nexport class CommitInternalError extends AckCommitError {\n constructor(message: string, cause?: Error) {\n super(message, {\n errorCode: Hl7ErrorCode.ApplicationInternalError,\n severity: Severity.Error,\n cause,\n });\n this.name = \"CommitInternalError\";\n }\n}\n","import { Hl7ErrorCode, Severity } from \"../constants\";\nimport { AckApplicationReject } from \"../exception\";\n\n/**\n * Unsupported message type reject (MSA-1 = `AR`, ERR-3 = `200`, ERR-4 = `E`).\n *\n * Throw when the receiving application does not handle the inbound\n * message type (e.g. ADT^A01 sent to a system that only accepts ORU).\n */\nexport class UnsupportedMessageTypeReject extends AckApplicationReject {\n constructor(message: string) {\n super(message, {\n errorCode: Hl7ErrorCode.UnsupportedMessageType,\n severity: Severity.Error,\n });\n this.name = \"UnsupportedMessageTypeReject\";\n }\n}\n"],"mappings":";AACA,SAAS,GAAG,GAAG,GAAG,SAAS;AAC3B,SAAS,aAAa;AACtB,SAAS,iBAAiB;;;ACFnB,IAAM,UAAU;AAAA,EACrB,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,mBAAmB;AAAA,EACnB,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAChB;AAUO,IAAM,eAAe;AAAA,EAC1B,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,eAAe;AAAA,EACf,oBAAoB;AAAA,EACpB,wBAAwB;AAAA,EACxB,sBAAsB;AAAA,EACtB,yBAAyB;AAAA,EACzB,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,wBAAwB;AAAA,EACxB,yBAAyB;AAAA,EACzB,0BAA0B;AAC5B;AAMO,IAAM,WAAW;AAAA,EACtB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AACT;;;AC1CA,SAAS,cAAc;AAEvB,IAAM,aAAa;AAOZ,SAAS,IAAI,UAAmB,CAAC,GAAW;AACjD,QAAM,EAAE,QAAQ,OAAO,WAAW,IAAI;AAEtC,MAAI,CAAC,QAAQ;AACX,WAAO,OAAO,IAAI;AAAA,EACpB;AAEA,QAAM,YAAY,OAAO,OAAO;AAEhC,MAAI,aAAa,GAAG;AAClB,WAAO,OAAO,MAAM,GAA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AQ;AAAA,EAExB,YAAY,SAAiB,SAA8B;AACzD,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAQO,IAAM,iBAAN,cAA6B,aAAa;AAAA,EACtC,OAAO,QAAQ;AAAA,EAExB,YAAY,SAAiB,SAA8B;AACzD,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;AAQO,IAAM,kBAAN,cAA8B,aAAa;AAAA,EACvC,OAAO,QAAQ;AAAA,EAExB,YAAY,SAAiB,SAA8B;AACzD,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AAAA,EACd;AACF;;;AC/FO,IAAM,2BAAN,cAAuC,oBAAoB;AAAA,EAChE,YAAY,SAAiB,OAAe;AAC1C,UAAM,SAAS;AAAA,MACb,WAAW,aAAa;AAAA,MACxB,UAAU,SAAS;AAAA,MACnB;AAAA,IACF,CAAC;AACD,SAAK,OAAO;AAAA,EACd;AACF;;;ACVO,IAAM,sBAAN,cAAkC,eAAe;AAAA,EACtD,YAAY,SAAiB,OAAe;AAC1C,UAAM,SAAS;AAAA,MACb,WAAW,aAAa;AAAA,MACxB,UAAU,SAAS;AAAA,MACnB;AAAA,IACF,CAAC;AACD,SAAK,OAAO;AAAA,EACd;AACF;;;ACTO,IAAM,+BAAN,cAA2C,qBAAqB;AAAA,EACrE,YAAY,SAAiB;AAC3B,UAAM,SAAS;AAAA,MACb,WAAW,aAAa;AAAA,MACxB,UAAU,SAAS;AAAA,IACrB,CAAC;AACD,SAAK,OAAO;AAAA,EACd;AACF;","names":["f","s","s","f"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rethinkhealth/hl7v2-ack",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "HL7v2 acknowledgment message builder and typed error classes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ack",
|
|
@@ -31,20 +31,20 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"nanoid": "5.1.6",
|
|
34
|
-
"@rethinkhealth/hl7v2-
|
|
35
|
-
"@rethinkhealth/hl7v2-
|
|
36
|
-
"@rethinkhealth/hl7v2-
|
|
37
|
-
"@rethinkhealth/hl7v2-
|
|
34
|
+
"@rethinkhealth/hl7v2-util-query": "0.7.1",
|
|
35
|
+
"@rethinkhealth/hl7v2-util-timestamp": "0.7.1",
|
|
36
|
+
"@rethinkhealth/hl7v2-ast": "0.7.1",
|
|
37
|
+
"@rethinkhealth/hl7v2-builder": "0.7.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/node": "^
|
|
40
|
+
"@types/node": "^25.5.0",
|
|
41
41
|
"@vitest/coverage-v8": "4.0.18",
|
|
42
42
|
"tsup": "^8.5.1",
|
|
43
43
|
"typescript": "^5.9.3",
|
|
44
44
|
"vitest": "4.1.0",
|
|
45
|
-
"@rethinkhealth/hl7v2-to-hl7v2": "0.7.0",
|
|
46
45
|
"@rethinkhealth/testing": "0.0.2",
|
|
47
|
-
"@rethinkhealth/tsconfig": "0.0.1"
|
|
46
|
+
"@rethinkhealth/tsconfig": "0.0.1",
|
|
47
|
+
"@rethinkhealth/hl7v2-to-hl7v2": "0.7.1"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
50
|
"node": ">=18"
|
package/dist/errors.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export interface AckExceptionOptions extends ErrorOptions {
|
|
2
|
-
errorCode: string;
|
|
3
|
-
severity?: string;
|
|
4
|
-
}
|
|
5
|
-
type AckCode = "AE" | "AR";
|
|
6
|
-
export declare abstract class AckException extends Error {
|
|
7
|
-
abstract readonly code: AckCode;
|
|
8
|
-
readonly errorCode: string;
|
|
9
|
-
readonly severity: string | undefined;
|
|
10
|
-
constructor(message: string, options: AckExceptionOptions);
|
|
11
|
-
}
|
|
12
|
-
export declare class AckError extends AckException {
|
|
13
|
-
readonly code: "AE";
|
|
14
|
-
constructor(message: string, options: AckExceptionOptions);
|
|
15
|
-
}
|
|
16
|
-
export declare class AckReject extends AckException {
|
|
17
|
-
readonly code: "AR";
|
|
18
|
-
constructor(message: string, options: AckExceptionOptions);
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,KAAK,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3B,8BAAsB,YAAa,SAAQ,KAAK;IAC9C,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB;CAK1D;AAED,qBAAa,QAAS,SAAQ,YAAY;IACxC,QAAQ,CAAC,IAAI,EAAG,IAAI,CAAU;gBAElB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB;CAI1D;AAED,qBAAa,SAAU,SAAQ,YAAY;IACzC,QAAQ,CAAC,IAAI,EAAG,IAAI,CAAU;gBAElB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB;CAI1D"}
|