Bugs5382 / node-hl7-client

A pure Node.js HL7 Client that allows for communication to a HL7 Broker/Server that can send properly formatted HL7 messages with ease.It can also parse and then you can extract message segments out.
MIT License
14 stars 4 forks source link

Unhandled error on connection #72

Closed glenarama closed 7 months ago

glenarama commented 7 months ago

Thanks for the library!

Receiving an error on connection - any help appreciated: Version: node-hl7-client 1.1.3

try {
  const client = new Client({ host: "xx.xx.xx.xx" });
  client.createOutbound({ port: xxxxx }, async () => {});
} catch (err) {
  console.log("Error", err);
}

Client creation seems fine, but outbound request throws:

  Error [ERR_UNHANDLED_ERROR]: Unhandled error. (undefined)
  at new NodeError (node:internal/errors:399:5)
  at HL7Outbound.emit (node:events:501:17)
  at Socket.eval (webpack-internal:///(rsc)/../../node_modules/.pnpm/node-hl7-client@1.1.3/node_modules/node-hl7-client/lib/esm/client/hl7Outbound.js:259:26)
  at Socket.emit (node:events:512:28)
  at TCP.<anonymous> (node:net:332:12)
  at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
  code: 'ERR_UNHANDLED_ERROR',
  context: undefined
}
Bugs5382 commented 7 months ago

Will look into! I am actually working on better error handling so I'll add this to the queue for checks.

Bugs5382 commented 7 months ago

Anything else in your code? Or Just that?

glenarama commented 7 months ago

Thanks for looking at this:

Anything else in your code? Or Just that?

Just the import - full index.ts file:

import { Client } from "node-hl7-client";

try {
  const client = new Client({ host: "xx.xx.xx.xx" });
  client.createOutbound({ port: xxxxx }, async () => {});
} catch (err) {
  console.log("Error", err);
}
Bugs5382 commented 7 months ago

Roger. I just ran it @ work real quick. Yep. An error. sigh. Ok will do a deep dive tonight.

Bugs5382 commented 7 months ago

@glenarama I think I narrowed down the issue. Just to make sure so I can test correctly,..

  1. The Ip and port a valid server?

I am doing a test with Corepoint, and even though the port is open, etc. it's not connecting (more fun news), but with my node-hl7-server package it's working fine.

glenarama commented 7 months ago

Am sending to a third party - it is a valid destination but i can't confirm if their server is responding correctly.

Bugs5382 commented 7 months ago

Ok. You and I are having the same issue then....

So two errors:

Bugs5382 commented 7 months ago

So.. more updates..

const {Client, Message} = require("node-hl7-client");

try {
    const client = new Client({ host: 'x.x.x.x'})
    const test = client.createOutbound({port: 19999 }, async (res) => {
        const message = res.getMessage()
        console.log(message.toString())
    })
    const message = new Message({
        messageHeader: {
            msh_9_1: "ADT",
            msh_9_2: "A01",
            msh_10: "1234567890",
            msh_11_1: "D"
        }
    })
    test.sendMessage(message)
    test.close()
} catch (e) {
    console.log(e)
}

When I did this and did a wireshark capture on my Corepoint server, I saw:

image

And Corepoint was processing it correctly (IB on corepoint is not set to send the ACK right now), but it did process it,

Maybe it's a design issue...

createOutbound doesn't try to "connect" until sendMessage is done and then doing the "open" and "close" in that seqeuence making the code simpler (and breaking the API).

Bugs5382 commented 7 months ago

I am working on revising the structure so that sendMessage is the only thing being used. More than likely I will mark this breaking. I am not sure how many people are using this NPM package yet...

Bugs5382 commented 7 months ago

Almost got this corrected...

glenarama commented 7 months ago

Great! Let me know if you'd like some testing on a version.

Bugs5382 commented 7 months ago

@glenarama I haven't commit the bulk changes even locally yet because I just want to make sure that I am tracking the changes. It will break a lot of the current API so I am being careful. I am checking all my other unit testing outside of this internal checking so it's a lot longer process. Tried to get it out this weekend, but just to much to look over. Needs to be perfect.

Bugs5382 commented 7 months ago

@glenarama the code is pushed. still trying to fix a linting issue, but my head to to tired for get to it tonight.

Bugs5382 commented 7 months ago

:tada: This issue has been resolved in version 2.0.0-beta.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Bugs5382 commented 7 months ago

@glenarama Ok.. so release..

Here is a quick script:

const client = new Client({ host: 'x.x.x.x' })
const outbound = client.createConnection({ port: 19999 }, async (res) => {
    const messageRes = res.getMessage()
    console.log(messageRes.toString())
})
let message = new Message({
    messageHeader: {
        msh_9_1: 'ADT',
        msh_9_2: 'A01',
        msh_10: 'CONTROL_ID',
        msh_11_1: 'D'
    }
})
outbound.sendMessage(message)

that I been using as my test to a Corepoint server vs. my node-hl7-server package. I tested it out there too, but I have to update that package to work with this 2.0.0-beta.1 before fully committing this to main.

Bugs5382 commented 7 months ago

All my unit tests are messed up. Some how jest is not closing the port after I tell it too... sigh. Why do I even bother anymore..

Bugs5382 commented 7 months ago

:tada: This issue has been resolved in version 2.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

glenarama commented 7 months ago

I've managed to get a working connection with the new release Thankyou!. A couple of question i can't find documented or in the code:

Note this is a TLS connection:

try {
    const client = new Client({host: "xx.xx.xx.xx", tls: { rejectUnauthorized: false }});
    const outbound = client.createConnection({ port: xxxxx }, async (res) => {
        const messageRes = res.getMessage();
        console.log("msg: ", messageRes.toString());
      },
    );
    let message = new Message({
      messageHeader: {
        msh_9_1: "ADT",
        msh_9_2: "A01",
        msh_10: "CONTROL_ID",
        msh_11_1: "D",
      },
    });
    outbound.sendMessage(message);
  } catch (err) {
    console.log("Error", err);
}
Bugs5382 commented 2 months ago

@glenarama A fix in 2.3.1 fixes this issue.