Skip to content

Commit

Permalink
fix: 2.4 spec MSH9.3
Browse files Browse the repository at this point in the history
- fixed MSH 2.4 and above to support MSH9.3 as an ACK
  • Loading branch information
Bugs5382 committed Jun 3, 2024
1 parent a7f4fd2 commit 7af0970
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 10 deletions.
32 changes: 32 additions & 0 deletions __tests__/hl7.build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ describe('node hl7 client - builder tests', () => {
expect(message.toString()).toBe('MSH|^~\\&|||||20081231||ADT^A01|12345|D^A|2.3.1')
})

test('2.3.1 - build - MSH9.3 has no bearing', async () => {
const message = new Message({
specification: new HL7_2_3_1(),
messageHeader: {
msh_9_1: 'ADT',
msh_9_2: 'A01',
msh_9_3: 'ACK',
msh_10: '12345',
msh_11_1: 'D',
msh_11_2: 'A'
}
})
message.set('MSH.7', '20081231')
expect(message.toString()).toBe('MSH|^~\\&|||||20081231||ADT^A01|12345|D^A|2.3.1')
})

test('2.4 - build', async () => {
const message = new Message({
specification: new HL7_2_4(),
Expand All @@ -135,6 +151,22 @@ describe('node hl7 client - builder tests', () => {
expect(message.toString()).toBe('MSH|^~\\&|||||20081231||ADT^A01^ADT_A01|12345|D^A|2.4')
})

test('2.4 - build - MSH9.3 override', async () => {
const message = new Message({
specification: new HL7_2_4(),
messageHeader: {
msh_9_1: 'ACK',
msh_9_2: 'A01',
msh_9_3: 'ACK',
msh_10: '12345',
msh_11_1: 'D',
msh_11_2: 'A'
}
})
message.set('MSH.7', '20081231')
expect(message.toString()).toBe('MSH|^~\\&|||||20081231||ACK^A01^ACK|12345|D^A|2.4')
})

test('2.5 - build', async () => {
const message = new Message({
specification: new HL7_2_5(),
Expand Down
37 changes: 37 additions & 0 deletions __tests__/hl7.sanity.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, test } from 'vitest';
import {Batch, FileBatch, isBatch, isFile, Message} from "../src";
import {HL7_2_4} from "../src/specification/2.4";
import {MSH_HEADER} from "./__data__/constants";

describe('node hl7 client - sanity tests', () => {
Expand Down Expand Up @@ -88,6 +89,42 @@ describe('node hl7 client - sanity tests', () => {
}
})

test('error - Message Object - msh 9.3 less than 3.', async () => {
try {
new Message({
specification: new HL7_2_4(),
messageHeader: {
msh_9_1: 'ADT',
msh_9_2: 'A01',
msh_9_3: 'AC',
msh_10: '12345',
msh_11_1: 'D',
msh_11_2: 'A'
}
})
} catch (err) {
expect(err).toEqual(new Error('MSH.9.3 must be 3 to 10 characters in length if specified.'))
}
})

test('error - Message Object - msh 9.3 more than 10.', async () => {
try {
new Message({
specification: new HL7_2_4(),
messageHeader: {
msh_9_1: 'ADT',
msh_9_2: 'A01',
msh_9_3: 'ADT_A01Y',
msh_10: '12345',
msh_11_1: 'D',
msh_11_2: 'A'
}
})
} catch (err) {
expect(err).toEqual(new Error('MSH.9.3 must be 3 to 10 characters in length if specified.'))
}
})

test('error - Message Object - msh 10 is more than 199 characters ', async () => {
try {
new Message({
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@the-rabbit-hole/semantic-release-config": "^1.5.0",
"@types/node": "^20.11.21",
"@types/node": "^20.14.0",
"@types/tcp-port-used": "^1.0.4",
"@typescript-eslint/parser": "^7.1.0",
"@vitest/coverage-v8": "^1.3.1",
"@vitest/ui": "^1.3.1",
"node-hl7-server": "^2.0.0",
"npm-check-updates": "^16.14.15",
"@typescript-eslint/parser": "^7.11.0",
"@vitest/coverage-v8": "^1.6.0",
"@vitest/ui": "^1.6.0",
"node-hl7-server": "^2.2.0",
"npm-check-updates": "^16.14.20",
"npm-package-json-lint": "^7.1.0",
"portfinder": "^1.0.32",
"pre-commit": "^1.2.2",
Expand All @@ -91,9 +91,9 @@
"ts-node": "^10.9.2",
"ts-standard": "^12.0.2",
"tsd": "^0.31.0",
"typedoc": "^0.25.9",
"typedoc": "^0.25.13",
"typescript": "5.4.5",
"vitest": "^1.3.1"
"vitest": "^1.6.0"
},
"precommit": [
"lint:fix",
Expand Down
2 changes: 1 addition & 1 deletion src/hl7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export { HL7_2_7, HL7_2_7_MSH } from './specification/2.7.js'
export { HL7_2_7_1, HL7_2_7_1_MSH } from './specification/2.7.1.js'
export { HL7_2_8, HL7_2_8_MSH } from './specification/2.8.js'
export { HL7_SPEC, HL7_SPEC_BASE } from './specification/specification.js'
export { MSH } from './specification/specification.js'
export { MSH } from './specification/specification.js'
9 changes: 8 additions & 1 deletion src/specification/2.4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface HL7_2_4_MSH {
/** 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
* @description This ID is unique to the message being sent
* so the client can track
Expand Down Expand Up @@ -66,6 +70,9 @@ export class HL7_2_4 extends HL7_2_3_1 {
*/
checkMSH (msh: HL7_2_4_MSH): boolean {
super.checkMSH(msh)
if (typeof msh.msh_9_3 !== 'undefined' && (msh.msh_9_3.length < 3 || msh.msh_9_3.length > 10)) {
throw new Error('MSH.9.3 must be 3 to 10 characters in length if specified.')
}
return true
}

Expand All @@ -77,6 +84,6 @@ export class HL7_2_4 extends HL7_2_3_1 {
*/
buildMSH (mshHeader: HL7_2_4_MSH, message: Message): void {
super.buildMSH(mshHeader, message)
message.set('MSH.9.3', `${mshHeader.msh_9_1.toString()}_${mshHeader.msh_9_2.toString()}`)
message.set('MSH.9.3', typeof mshHeader.msh_9_3 !== 'undefined' ? mshHeader.msh_9_3.toString() : `${mshHeader.msh_9_1.toString()}_${mshHeader.msh_9_2.toString()}`)
}
}
4 changes: 4 additions & 0 deletions src/specification/2.5.1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface HL7_2_5_1_MSH {
/** 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
* @description This ID is unique to the message being sent
* so the client can track
Expand Down
4 changes: 4 additions & 0 deletions src/specification/2.5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface HL7_2_5_MSH {
/** 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
* @description This ID is unique to the message being sent
* so the client can track
Expand Down
4 changes: 4 additions & 0 deletions src/specification/2.6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface HL7_2_6_MSH {
/** 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
* @description This ID is unique to the message being sent
* so the client can track
Expand Down
5 changes: 5 additions & 0 deletions src/specification/2.7.1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export interface HL7_2_7_1_MSH {
/** 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
* @description This ID is unique to the message being sent
* so the client can track
Expand Down Expand Up @@ -68,6 +72,7 @@ export class HL7_2_7_1 extends HL7_2_7 {

/**
* Build HL7 MSH Segment
* @since 1.0.0
* @param mshHeader
* @param message
*/
Expand Down
5 changes: 5 additions & 0 deletions src/specification/2.7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export interface HL7_2_7_MSH {
/** 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
* @description This ID is unique to the message being sent
* so the client can track
Expand Down Expand Up @@ -85,6 +89,7 @@ export class HL7_2_7 extends HL7_2_6 {

/**
* Build HL7 MSH Segment
* @since 1.0.0
* @param mshHeader
* @param message
*/
Expand Down
5 changes: 5 additions & 0 deletions src/specification/2.8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export interface HL7_2_8_MSH {
/** 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
* @description This ID is unique to the message being sent
* so the client can track
Expand Down Expand Up @@ -68,6 +72,7 @@ export class HL7_2_8 extends HL7_2_7_1 {

/**
* Build HL7 MSH Segment
* @since 1.0.0
* @param mshHeader
* @param message
*/
Expand Down

0 comments on commit 7af0970

Please sign in to comment.