Skip to content

Commit

Permalink
feat: client work x2
Browse files Browse the repository at this point in the history
- fully working
- some lint errors, to solve later

#15

[ci skip]
  • Loading branch information
Bugs5382 committed Dec 12, 2023
1 parent 25a94a5 commit 74eeb28
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 183 deletions.
92 changes: 31 additions & 61 deletions __tests__/hl7.build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ describe('node hl7 client - builder tests', () => {
test("error - Message Object - msh 9.1 is empty ", async () => {
try {
new Message({
// @ts-expect-error 9.1 should be not empty
messageHeader: {
// @ts-expect-error 9.1 should be not empty
msh_9: {
msh_9_1: "",
},
msh_9_1: "",
}
})
} catch (err) {
expect(err).toEqual(new Error('MSH.9.1 & MSH 9.2 & MSH 9.3 must be defined.'))
expect(err).toEqual(new Error('MSH.9.1 & MSH 9.2 must be defined.'))
}
})

Expand All @@ -52,10 +50,8 @@ describe('node hl7 client - builder tests', () => {
new Message({
// @ts-expect-error 9.2 should be not empty
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "",
},
msh_9_1: "ADT",
msh_9_2: "",
}
})
} catch (err) {
Expand All @@ -67,10 +63,8 @@ describe('node hl7 client - builder tests', () => {
try {
new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADTY",
msh_9_2: "A01"
},
msh_9_1: "ADTY",
msh_9_2: "A01",
msh_10: "123456"
}
})
Expand All @@ -83,10 +77,8 @@ describe('node hl7 client - builder tests', () => {
try {
new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01Y"
},
msh_9_1: "ADT",
msh_9_2: "A01Y",
msh_10: "123456"
}
})
Expand All @@ -99,10 +91,8 @@ describe('node hl7 client - builder tests', () => {
try {
new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: "AaasdfjlsdjflskdfsdflkjjsdlkflkasdflsjdflkjasdlfjsldkjlskjdfksajflksjdfAaasdfjlsdjflskdfsdflkjjsdlkflkasdflsjdflkjasdlfjsldkjlskjdfksajflksjdfAaasdfjlsdjflskdfsdflkjjsdlkflkasdflsjdflkjasdlfjsldkjlskjdfksajflksjdf"
}
})
Expand All @@ -115,10 +105,8 @@ describe('node hl7 client - builder tests', () => {
try {
new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: ""
}
})
Expand All @@ -137,10 +125,8 @@ describe('node hl7 client - builder tests', () => {
beforeEach(async () => {
message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: randomControlID
}
})
Expand Down Expand Up @@ -194,10 +180,8 @@ describe('node hl7 client - builder tests', () => {
beforeEach(async () => {
message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: "12345"
}
})
Expand Down Expand Up @@ -367,10 +351,8 @@ describe('node hl7 client - builder tests', () => {

message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: 'CONTROL_ID'
}
})
Expand All @@ -385,10 +367,8 @@ describe('node hl7 client - builder tests', () => {

message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: 'CONTROL_ID'
}
})
Expand All @@ -405,10 +385,8 @@ describe('node hl7 client - builder tests', () => {

message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: 'CONTROL_ID'
}
})
Expand All @@ -426,10 +404,8 @@ describe('node hl7 client - builder tests', () => {

message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: 'CONTROL_ID'
}
})
Expand Down Expand Up @@ -481,10 +457,8 @@ describe('node hl7 client - builder tests', () => {

let message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: 'CONTROL_ID'
}
})
Expand All @@ -509,10 +483,8 @@ describe('node hl7 client - builder tests', () => {

const message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: 'CONTROL_ID'
}
})
Expand All @@ -524,10 +496,8 @@ describe('node hl7 client - builder tests', () => {

const message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: 'CONTROL_ID'
}
})
Expand Down
32 changes: 12 additions & 20 deletions __tests__/hl7.client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ describe('node hl7 client', () => {
stopPort: 65353
})

const server = new Server({ bindAddress: 'localhost'})
const server = new Server({ bindAddress: '0.0.0.0'})
const listener = server.createInbound({port: LISTEN_PORT}, async () => {})

const client = new Client({ host: 'localhost'})
const client = new Client({ host: '0.0.0.0'})
const outGoing = client.createOutbound({ port: LISTEN_PORT }, async () => {})

await expectEvent(listener, 'client.connect')
Expand Down Expand Up @@ -151,10 +151,10 @@ describe('node hl7 client', () => {
stopPort: 65353
})

server = new Server({bindAddress: 'localhost'})
server = new Server({bindAddress: '0.0.0.0'})
listener = server.createInbound({port: LISTEN_PORT}, async () => {})

client = new Client({host: 'localhost'})
client = new Client({host: '0.0.0.0'})
outGoing = client.createOutbound({port: LISTEN_PORT, waitAck: waitAck !== 2}, async () => {})

})
Expand All @@ -170,10 +170,8 @@ describe('node hl7 client', () => {

let message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: 'CONTROL_ID'
}
})
Expand All @@ -187,10 +185,8 @@ describe('node hl7 client', () => {
try {
let message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: 'CONTROL_ID'
}
})
Expand All @@ -209,10 +205,8 @@ describe('node hl7 client', () => {

let message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: 'CONTROL_ID'
}
})
Expand All @@ -221,10 +215,8 @@ describe('node hl7 client', () => {

message = new Message({
messageHeader: {
msh_9: {
msh_9_1: "ADT",
msh_9_2: "A01"
},
msh_9_1: "ADT",
msh_9_2: "A01",
msh_10: 'CONTROL_ID'
}
})
Expand Down
6 changes: 3 additions & 3 deletions src/builder/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export class Message extends RootBase {
if (typeof this._opt.messageHeader !== 'undefined') {
if (this._opt.specification.checkMSH(this._opt.messageHeader) === true) {
this.set('MSH.7', Util.createHL7Date(new Date()))
this.set('MSH.9.1', this._opt.messageHeader.msh_9.msh_9_1.toString())
this.set('MSH.9.2', this._opt.messageHeader.msh_9.msh_9_2.toString())
this.set('MSH.9.3', `${this._opt.messageHeader.msh_9.msh_9_1.toString()}_${this._opt.messageHeader.msh_9.msh_9_2.toString()}`)
this.set('MSH.9.1', this._opt.messageHeader.msh_9_1.toString())
this.set('MSH.9.2', this._opt.messageHeader.msh_9_2.toString())
this.set('MSH.9.3', `${this._opt.messageHeader.msh_9_1.toString()}_${this._opt.messageHeader.msh_9_2.toString()}`)
this.set('MSH.10', this._opt.messageHeader.msh_10.toString())
this.set('MSH.12', this._opt.specification.name.toString())
}
Expand Down
5 changes: 2 additions & 3 deletions src/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EventEmitter from 'events'
import { normalizeClientOptions, ClientListenerOptions, ClientOptions } from '../utils/normalizedClient.js'
import {HL7Outbound, OutboundHandler} from "./hl7Outbound";
import { HL7Outbound, OutboundHandler } from './hl7Outbound'

/**
* Client Class
Expand All @@ -20,8 +20,7 @@ export class Client extends EventEmitter {
return new HL7Outbound(this, props, cb)
}

getHost(): string {
getHost (): string {
return this._opt.host
}

}
Loading

0 comments on commit 74eeb28

Please sign in to comment.