Skip to content

Commit

Permalink
docs: msh doc changes
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Bugs5382 committed Jun 30, 2024
1 parent 2d24544 commit 45cb78c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 239 deletions.
63 changes: 5 additions & 58 deletions src/specification/2.3.1.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'
Expand All @@ -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
}

Expand All @@ -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)
}
}
14 changes: 12 additions & 2 deletions src/specification/2.3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' | ''
}

/**
Expand Down Expand Up @@ -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
}

Expand All @@ -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)
}
}
Expand Down
21 changes: 2 additions & 19 deletions src/specification/2.4.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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' | ''
Expand Down
29 changes: 2 additions & 27 deletions src/specification/2.5.1.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
29 changes: 2 additions & 27 deletions src/specification/2.5.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
29 changes: 2 additions & 27 deletions src/specification/2.6.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
28 changes: 2 additions & 26 deletions src/specification/2.7.1.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
28 changes: 2 additions & 26 deletions src/specification/2.7.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 45cb78c

Please sign in to comment.