From 45cb78cb3878a36fcd5eae47dd5134b72b66fb97 Mon Sep 17 00:00:00 2001 From: Bugs5382 Date: Sun, 30 Jun 2024 07:33:47 -0400 Subject: [PATCH] docs: msh doc changes - added 2 checks missing in the msh header from 2.3 - also refactors code in 2.3 and 2.3.1 for building the MSH --- src/specification/2.3.1.ts | 63 +++----------------------------------- src/specification/2.3.ts | 14 +++++++-- src/specification/2.4.ts | 21 ++----------- src/specification/2.5.1.ts | 29 ++---------------- src/specification/2.5.ts | 29 ++---------------- src/specification/2.6.ts | 29 ++---------------- src/specification/2.7.1.ts | 28 ++--------------- src/specification/2.7.ts | 28 ++--------------- src/specification/2.8.ts | 30 ++---------------- 9 files changed, 32 insertions(+), 239 deletions(-) diff --git a/src/specification/2.3.1.ts b/src/specification/2.3.1.ts index 8cf9216..c34dc10 100644 --- a/src/specification/2.3.1.ts +++ b/src/specification/2.3.1.ts @@ -1,6 +1,5 @@ import { Message } from '../builder/message.js' -import { createHL7Date, randomString } from '../utils/utils.js' -import { HL7_SPEC_BASE } from './specification.js' +import { HL7_2_3, HL7_2_3_MSH } from './2.3.js' /** * HL7 2.3.1 MSH Specification @@ -25,35 +24,14 @@ import { HL7_SPEC_BASE } from './specification.js' * so this way your code is much neater. * */ -export interface HL7_2_3_1_MSH { - /** Message Code - * @since 1.0.0 */ - msh_9_1: string - /** Trigger Event - * @since 1.0.0 */ - msh_9_2: string - /** Message Control ID - * @remarks This ID is unique to the message being sent - * so the client can track - * to see if they get a response back from the server that this particular message was successful. - * Max 20 characters. - * @since 1.0.0 - * @default Random 20 Character String {@link randomString} if this is set to nothing or not included. */ - msh_10?: string - /** Processing ID - * @since 1.0.0 */ - msh_11_1: 'D' | 'P' | 'T' - /** Processing Mode - * @since 1.0.0 */ - msh_11_2?: 'A' | 'I' | 'R' | 'T' | '' -} +export type HL7_2_3_1_MSH = HL7_2_3_MSH /** * Hl7 Specification Version 2.3.1 * @remarks Used to indicate that the message should follow 2.7 specification for retrieval or building a message. * @since 1.0.0 */ -export class HL7_2_3_1 extends HL7_SPEC_BASE { +export class HL7_2_3_1 extends HL7_2_3 { constructor () { super() this.name = '2.3.1' @@ -66,23 +44,7 @@ export class HL7_2_3_1 extends HL7_SPEC_BASE { * @return boolean */ checkMSH (msh: HL7_2_3_1_MSH): boolean { - if (typeof msh.msh_9_1 === 'undefined' || - typeof msh.msh_9_2 === 'undefined') { - throw new Error('MSH.9.1 & MSH 9.2 must be defined.') - } - - if (msh.msh_9_1.length !== 3) { - throw new Error('MSH.9.1 must be 3 characters in length.') - } - - if (msh.msh_9_2.length !== 3) { - throw new Error('MSH.9.2 must be 3 characters in length.') - } - - if (typeof msh.msh_10 !== 'undefined' && (msh.msh_10.length < 0 || msh.msh_10.length > 20)) { - throw new Error('MSH.10 must be greater than 0 and less than 20 characters.') - } - + super.checkMSH(msh) return true } @@ -93,21 +55,6 @@ export class HL7_2_3_1 extends HL7_SPEC_BASE { * @param message */ buildMSH (mshHeader: HL7_2_3_1_MSH, message: Message): void { - if (typeof mshHeader !== 'undefined') { - message.set('MSH.7', createHL7Date(new Date(), message._opt.date)) - message.set('MSH.9.1', mshHeader.msh_9_1.toString()) - message.set('MSH.9.2', mshHeader.msh_9_2.toString()) - // if control ID is blank, then randomize it. - if (typeof mshHeader.msh_10 === 'undefined') { - message.set('MSH.10', randomString()) - } else { - message.set('MSH.10', mshHeader.msh_10.toString()) - } - message.set('MSH.11.1', mshHeader.msh_11_1) - if (typeof mshHeader.msh_11_2 !== 'undefined') { - message.set('MSH.11.2', mshHeader.msh_11_2) - } - message.set('MSH.12', this.name) - } + super.buildMSH(mshHeader, message) } } diff --git a/src/specification/2.3.ts b/src/specification/2.3.ts index e0871b1..3159baf 100644 --- a/src/specification/2.3.ts +++ b/src/specification/2.3.ts @@ -45,7 +45,7 @@ export interface HL7_2_3_MSH { msh_11_1: 'D' | 'P' | 'T' /** Processing Mode * @since 1.0.0 */ - msh_11_2?: 'A' | 'I' | 'R' | 'T' | '' + msh_11_2?: 'A' | 'I' | 'R' | '' } /** @@ -83,6 +83,14 @@ export class HL7_2_3 extends HL7_SPEC_BASE { throw new Error('MSH.10 must be greater than 0 and less than 20 characters.') } + if (msh.msh_11_1.length > 1) { + throw new Error('MSH.11.1 has to be 1 character long. Valid inputs are: D, P, or T') + } + + if (typeof msh.msh_11_2 !== 'undefined' && (msh.msh_11_2.length > 1 || msh.msh_11_2 === '')) { + throw new Error('MSH.11.2 can either be undefined/blank and 1 character long.') + } + return true } @@ -104,7 +112,9 @@ export class HL7_2_3 extends HL7_SPEC_BASE { message.set('MSH.10', mshHeader.msh_10.toString()) } message.set('MSH.11.1', mshHeader.msh_11_1) - message.set('MSH.11.2', mshHeader.msh_11_2) + if (typeof mshHeader.msh_11_2 !== 'undefined') { + message.set('MSH.11.2', mshHeader.msh_11_2) + } message.set('MSH.12', this.name) } } diff --git a/src/specification/2.4.ts b/src/specification/2.4.ts index 950fbf6..8756cd9 100644 --- a/src/specification/2.4.ts +++ b/src/specification/2.4.ts @@ -1,5 +1,5 @@ import { Message } from '../builder/message.js' -import { HL7_2_3_1 } from './2.3.1.js' +import { HL7_2_3_1, HL7_2_3_1_MSH } from './2.3.1.js' /** * HL7 2.4 MSH Specification @@ -24,28 +24,11 @@ import { HL7_2_3_1 } from './2.3.1.js' * so this way your code is much neater. * */ -export interface HL7_2_4_MSH { - /** Message Code - * @since 1.0.0 */ - msh_9_1: string - /** Trigger Event - * @since 1.0.0 */ - msh_9_2: string +export type HL7_2_4_MSH = HL7_2_3_1_MSH & { /** Message Structure * @since 2.2.0 * @default If not specified, it will be the combo of 9.1 and 9.2 with an underscore. */ msh_9_3?: string - /** Message Control ID - * @remarks This ID is unique to the message being sent - * so the client can track - * to see if they get a response back from the server that this particular message was successful. - * Max 20 characters. - * @since 1.0.0 - * @default Random 20 Character String {@link randomString} if this is set to nothing or not included. */ - msh_10?: string - /** Processing ID - * @since 1.0.0 */ - msh_11_1: 'D' | 'P' | 'T' /** Processing Mode * @since 1.0.0 */ msh_11_2?: 'A' | 'I' | 'R' | 'T' | '' diff --git a/src/specification/2.5.1.ts b/src/specification/2.5.1.ts index 0d8c0d0..28eaa46 100644 --- a/src/specification/2.5.1.ts +++ b/src/specification/2.5.1.ts @@ -1,5 +1,5 @@ import { Message } from '../builder/message.js' -import { HL7_2_5 } from './2.5.js' +import { HL7_2_5, HL7_2_5_MSH } from './2.5.js' /** * HL7 2.5.1 MSH Specification @@ -24,32 +24,7 @@ import { HL7_2_5 } from './2.5.js' * so this way your code is much neater. * */ -export interface HL7_2_5_1_MSH { - /** Message Code - * @since 1.0.0 */ - msh_9_1: string - /** Trigger Event - * @since 1.0.0 */ - msh_9_2: string - /** Message Structure - * @since 2.2.0 - * @default If not specified, it will be the combo of 9.1 and 9.2 with an underscore. */ - msh_9_3?: string - /** Message Control ID - * @remarks This ID is unique to the message being sent - * so the client can track - * to see if they get a response back from the server that this particular message was successful. - * Max 20 characters. - * @since 1.0.0 - * @default Random 20 Character String {@link randomString} if this is set to nothing or not included. */ - msh_10?: string - /** Processing ID - * @since 1.0.0 */ - msh_11_1: 'D' | 'P' | 'T' - /** Processing Mode - * @since 1.0.0 */ - msh_11_2?: 'A' | 'I' | 'R' | 'T' | '' -} +export type HL7_2_5_1_MSH = HL7_2_5_MSH /** * Hl7 Specification Version 2.5.1 diff --git a/src/specification/2.5.ts b/src/specification/2.5.ts index 44b87b9..6131859 100644 --- a/src/specification/2.5.ts +++ b/src/specification/2.5.ts @@ -1,5 +1,5 @@ import { Message } from '../builder/message.js' -import { HL7_2_4 } from './2.4.js' +import { HL7_2_4, HL7_2_4_MSH } from './2.4.js' /** * HL7 2.5 MSH Specification @@ -24,32 +24,7 @@ import { HL7_2_4 } from './2.4.js' * so this way your code is much neater. * */ -export interface HL7_2_5_MSH { - /** Message Code - * @since 1.0.0 */ - msh_9_1: string - /** Trigger Event - * @since 1.0.0 */ - msh_9_2: string - /** Message Structure - * @since 2.2.0 - * @default If not specified, it will be the combo of 9.1 and 9.2 with an underscore. */ - msh_9_3?: string - /** Message Control ID - * @remarks This ID is unique to the message being sent - * so the client can track - * to see if they get a response back from the server that this particular message was successful. - * Max 20 characters. - * @since 1.0.0 - * @default Random 20 Character String {@link randomString} if this is set to nothing or not included. */ - msh_10?: string - /** Processing ID - * @since 1.0.0 */ - msh_11_1: 'D' | 'P' | 'T' - /** Processing Mode - * @since 1.0.0 */ - msh_11_2?: 'A' | 'I' | 'R' | 'T' | '' -} +export type HL7_2_5_MSH = HL7_2_4_MSH /** * Hl7 Specification Version 2.5 diff --git a/src/specification/2.6.ts b/src/specification/2.6.ts index fb04afe..d125721 100644 --- a/src/specification/2.6.ts +++ b/src/specification/2.6.ts @@ -1,5 +1,5 @@ import { Message } from '../builder/message.js' -import { HL7_2_5_1 } from './2.5.1.js' +import { HL7_2_5_1, HL7_2_5_1_MSH } from './2.5.1.js' /** * HL7 2.6 MSH Specification @@ -24,32 +24,7 @@ import { HL7_2_5_1 } from './2.5.1.js' * so this way your code is much neater. * */ -export interface HL7_2_6_MSH { - /** Message Code - * @since 1.0.0 */ - msh_9_1: string - /** Trigger Event - * @since 1.0.0 */ - msh_9_2: string - /** Message Structure - * @since 2.2.0 - * @default If not specified, it will be the combo of 9.1 and 9.2 with an underscore. */ - msh_9_3?: string - /** Message Control ID - * @remarks This ID is unique to the message being sent - * so the client can track - * to see if they get a response back from the server that this particular message was successful. - * Max 20 characters. - * @since 1.0.0 - * @default Random 20 Character String {@link randomString} if this is set to nothing or not included. */ - msh_10?: string - /** Processing ID - * @since 1.0.0 */ - msh_11_1: 'D' | 'P' | 'T' - /** Processing Mode - * @since 1.0.0 */ - msh_11_2?: 'A' | 'I' | 'R' | 'T' | '' -} +export type HL7_2_6_MSH = HL7_2_5_1_MSH /** * Hl7 Specification Version 2.6 diff --git a/src/specification/2.7.1.ts b/src/specification/2.7.1.ts index 61c0c5f..444b8e2 100644 --- a/src/specification/2.7.1.ts +++ b/src/specification/2.7.1.ts @@ -1,5 +1,5 @@ import { Message } from '../builder/message.js' -import { HL7_2_7 } from './2.7.js' +import { HL7_2_7, HL7_2_7_MSH } from './2.7.js' /** * HL7 2.7.1 MSH Specification @@ -23,31 +23,7 @@ import { HL7_2_7 } from './2.7.js' * so this way your code is much neater. * */ -export interface HL7_2_7_1_MSH { - /** Message Code - * @since 1.0.0 */ - msh_9_1: string - /** Trigger Event - * @since 1.0.0 */ - msh_9_2: string - /** Message Structure - * @since 2.2.0 - * @default If not specified, it will be the combo of 9.1 and 9.2 with an underscore. */ - msh_9_3?: string - /** Message Control ID - * @remarks This ID is unique to the message being sent - * so the client can track - * to see if they get a response back from the server that this particular message was successful. - * @since 1.0.0 - * @default Random 20 Character String {@link randomString} if this is set to nothing or not included. */ - msh_10?: string - /** Processing ID - * @since 1.0.0 */ - msh_11_1: 'D' | 'P' | 'T' - /** Processing Mode - * @since 1.0.0 */ - msh_11_2?: 'A' | 'I' | 'R' | 'T' | '' -} +export type HL7_2_7_1_MSH = HL7_2_7_MSH /** * Hl7 Specification Version 2.7.1 diff --git a/src/specification/2.7.ts b/src/specification/2.7.ts index d3efebb..ac93f9b 100644 --- a/src/specification/2.7.ts +++ b/src/specification/2.7.ts @@ -1,5 +1,5 @@ import { Message } from '../builder/message.js' -import { HL7_2_6 } from './2.6.js' +import { HL7_2_6, HL7_2_6_MSH } from './2.6.js' /** * HL7 2.7 MSH Specification @@ -23,31 +23,7 @@ import { HL7_2_6 } from './2.6.js' * so this way your code is much neater. * */ -export interface HL7_2_7_MSH { - /** Message Code - * @since 1.0.0 */ - msh_9_1: string - /** Trigger Event - * @since 1.0.0 */ - msh_9_2: string - /** Message Structure - * @since 2.2.0 - * @default If not specified, it will be the combo of 9.1 and 9.2 with an underscore. */ - msh_9_3?: string - /** Message Control ID - * @remarks This ID is unique to the message being sent - * so the client can track - * to see if they get a response back from the server that this particular message was successful. - * @since 1.0.0 - * @default Random 20 Character String {@link randomString} if this is set to nothing or not included. */ - msh_10?: string - /** Processing ID - * @since 1.0.0 */ - msh_11_1: 'D' | 'P' | 'T' - /** Processing Mode - * @since 1.0.0 */ - msh_11_2?: 'A' | 'I' | 'R' | 'T' | '' -} +export type HL7_2_7_MSH = HL7_2_6_MSH /** * Hl7 Specification Version 2.7 diff --git a/src/specification/2.8.ts b/src/specification/2.8.ts index 1dd4d42..ee0b5c9 100644 --- a/src/specification/2.8.ts +++ b/src/specification/2.8.ts @@ -1,5 +1,5 @@ import { Message } from '../builder/message.js' -import { HL7_2_7_1 } from './2.7.1.js' +import { HL7_2_7_1, HL7_2_7_1_MSH } from './2.7.1.js' /** * HL7 2.8 MSH Specification @@ -23,35 +23,11 @@ import { HL7_2_7_1 } from './2.7.1.js' * so this way your code is much neater. * */ -export interface HL7_2_8_MSH { - /** Message Code - * @since 1.0.0 */ - msh_9_1: string - /** Trigger Event - * @since 1.0.0 */ - msh_9_2: string - /** Message Structure - * @since 2.2.0 - * @default If not specified, it will be the combo of 9.1 and 9.2 with an underscore. */ - msh_9_3?: string - /** Message Control ID - * @remarks This ID is unique to the message being sent - * so the client can track - * to see if they get a response back from the server that this particular message was successful. - * @since 1.0.0 - * @default Random 20 Character String {@link randomString} if this is set to nothing or not included. */ - msh_10?: string - /** Processing ID - * @since 1.0.0 */ - msh_11_1: 'D' | 'P' | 'T' - /** Processing Mode - * @since 1.0.0 */ - msh_11_2?: 'A' | 'I' | 'R' | 'T' | '' -} +export type HL7_2_8_MSH = HL7_2_7_1_MSH /** * Hl7 Specification Version 2.8 - * @remarks Used to indicate that the message should follow 2.7 specification for retrieval or building a message. + * @remarks Used to indicate that the message should follow 2.7.1 specification for retrieval or building a message. * @since 1.0.0 */ export class HL7_2_8 extends HL7_2_7_1 {