Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow setting acknowledgment fields dynamically based on inbound message #114

Closed
jtarvainen opened this issue Dec 10, 2024 · 7 comments · Fixed by #116
Closed

feat: Allow setting acknowledgment fields dynamically based on inbound message #114

jtarvainen opened this issue Dec 10, 2024 · 7 comments · Fixed by #116
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers minor

Comments

@jtarvainen
Copy link

Feature Request

Describe the Feature Request

Version 3.0.0 added support for overriding the acknowledgment message MSH content with the mshOverrides prop (#103). In updating to the new version, I realized that the functionality doesn't allow us to retrieve acknowledgment message field values from the inbound message because the mshOverrides content is specified upon server creation, before any messages are received.

Describe Preferred Solution

I propose that we extend mshOverrides to accept, for each specified acknowledgment field, either field value as a string (as it does now) or a function that takes the inbound message as an optional argument and returns the field value.

Related Code

We would define mshOverrides as follows:

import type { Message } from 'node-hl7-client';

export interface ListenerOptions {
  mshOverrides?: Record<string, string | (message?: Message) => string>;
  // ...
}

And use it like this:

import type { Message } from 'node-hl7-client';

new Server().createInbound({
  mshOverrides: {
    '7': () => format(new Date(), 'yyyyMMddHHmmssxx') // set MSH.7 to formatted timestamp representing time of response creation
    '9.3': 'ACK' // set hardcoded MSH.9.3 field value
    '12': (message: Message) => message.get('MSH.12').toString() // copy MSH.12 value from inbound message to response
  }
});

And internally it would do this:

if (typeof this._mshOverrides === 'object') {
  Object.entries(this._mshOverrides).forEach(([path, override]) => {
    ackMessage.set(`MSH.${path}`, typeof override === 'function' ? override(message) : override);
  });
}

If the feature request is approved, would you be willing to submit a PR?

Yes!

@jtarvainen jtarvainen added the enhancement New feature or request label Dec 10, 2024
@Bugs5382
Copy link
Owner

@jtarvainen Looks good. Go ahead and submit one!

@Bugs5382 Bugs5382 added good first issue Good for newcomers minor labels Dec 20, 2024
@Bugs5382
Copy link
Owner

Make sure you update the documentation with examples.

@jtarvainen
Copy link
Author

Great! I'll get on it after the holidays.

@Bugs5382
Copy link
Owner

Bugs5382 commented Dec 21, 2024

@jtarvainen Enjoy the holidays. :)

@Bugs5382
Copy link
Owner

@jtarvainen Updates?

@jtarvainen
Copy link
Author

@Bugs5382 Thanks for the reminder, I'll get right on it.

jtarvainen pushed a commit to jtarvainen/node-hl7-server-fork that referenced this issue Jan 22, 2025
jtarvainen pushed a commit to jtarvainen/node-hl7-server-fork that referenced this issue Jan 22, 2025
jtarvainen pushed a commit to jtarvainen/node-hl7-server-fork that referenced this issue Jan 22, 2025
@Bugs5382
Copy link
Owner

@jtarvainen I'll review this weekend during normal coding time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers minor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants