I'm starting out with Mirth and HL7 and I'm trying to send a message to a remote server. My MSH looks as follows:
MSH|^~\&|EPIC|EPIC|IMG_SCHEDULE_APPT|REMOTE|20170328193318|PERSONNAME|ORM^O01|12345678|T|2.4||||||||||
The response looks as follows:
MSH|^~\&|IMG_SCHEDULE_APPT|REMOTE|EPIC|EPIC|20170328193318||ACK|12345678|T|2.4|
MSA|AA|||
and I get an error saying ERROR: Message control Ids do not match.
As far as I understand this error means that the Message Control Id which is returned in the ACK message is not the same.
From what I can see, the number 12345678 is the Message Control Id, and I see that number both in the message I send as well as the in the ACK which is returned. So what is wrong here? And who is at fault? Me or the remote party?
Does anybody know how I can solve or debug this?
If you don't want to validate the message control ID, you can open the Response Validation properties and uncheck "Validate Message Control Id":
If the remote system cannot change their logic and you still want to validate the control ID, you can do that in a response transformer:
if (responseStatus == ERROR) {
// msg here is the ACK, origMsg is the encoded data that was sent outbound
var origMsg = new XML(SerializerFactory.getSerializer('HL7V2').toXML(connectorMessage.getEncodedData()));
if (origMsg.MSH['MSH.10']['MSH.10.1'].toString() == msg.MSH['MSH.10']['MSH.10.1'].toString()) {
responseStatus = SENT;
}
}
MSA.2 (Message Control ID) is required and should be the same as the ControlId in the former message that the ACK message acknowleges..
Related
I have setup a webhook and everything is working properly, however iam used to using a long number where STOP is handled automatically, but now I have a short code where we have to handle STOP ourselves. This isnt an issue on sending a message as I can check with my 'blacklist' numbers before sending the message. My question is in the Reply webhook, what is the best way or standard way to NOT send the reply message.
Below is twilios sample code (i added the comment where i would check if they are black listed)
public class SmsController : TwilioController
{
public TwiMLResult Index(SmsRequest incomingMessage)
{
var messagingResponse = new MessagingResponse();
// check for phone number in blacklist to NOT SEND
messagingResponse.Message("The copy cat says: " +
incomingMessage.Body);
return TwiML(messagingResponse);
}
}
If the number is blacklisted and i dont want to send the reply how do I "gracefully" not reply to them as this example takes a TwiMLResult and message response. Do i just set the message to an empty string ? do I return null? Any thoughts ? Thank you !
I store sent messages in a log table with their unique SIDs. With a periodic console task I iterate over the records having status = undelivered and request the status of it and if it's still undelivered, I'd like to re-send that very message. I don't want a new one as the message contains a verification code and we store only hash of it. Is it possible to re-send the old message having its SID?
Twilio Developer Evangelist here,
There is not a way to automatically resend an undelivered message using the API. You can work around this by grabbing the messages by SID and sending the undelivered ones again to the same number with the same body. When you use the REST API to get a message by SID, you have access to all of the data from that message, including the exact message body.
A quick example using the Twilio PHP Library would look like this:
<?php
$client = new Services_Twilio($AccountSid, $AuthToken);
$messageSIDs = array("Insert", "Array of", "Message SIDs", "here");
foreach ($messageSIDs as $sid) {
$msg = $client->account->messages->get($sid);
if ($msg->status == "undelivered") {
echo "Resending undelivered message for SID: $sid\n";
$sms = $client->account->messages->sendMessage(
// The number we are sending from.
$msg->from,
// The number we are sending to.
$msg->to,
// The sms body.
$msg->body
);
}
}
You can see all of the data that the REST API gives you about messages here
I have tried to find a solution to this with any luck, so i decided to post it here.
The problem is, when i send a message with javaMail, it automatically generates a Message-Id (The one i store into my database to then identify replies to this message) but it is being changed for some reason by the smpt server when the message is sent so i wont be able to trace any related to this message.
For example
I first send a message via gmail to one of the accounts sycronized with my mail client, then i check the message with my message client and everything is ok the Message-Id is
<CAPDSfCN1qPAhBCRmFK-zwP=MM=KjgpYuvhVRFAPwz1PjOqtnFA#mail.gmail.com>
Then i send a reply for this message via my message client, the id generated by javaMail is
<1907960987.0.1322086080735.JavaMail.root#smtp.live.com>
Finally, when i go to check the reply in my email account it has the following values in its headers
Message-ID: <BLU0-SMTP33091BE2B32A7F46E370665C2C90#phx.gbl> FAIL
In-Reply-To: <CAPDSfCN1qPAhBCRmFK-zwP=MM=KjgpYuvhVRFAPwz1PjOqtnFA#mail.gmail.com> OK
As you see, the Message-Id is changed, i was expecting it to be
<1907960987.0.1322086080735.JavaMail.root#smtp.live.com>
Why is this happening?
I appreciate any help
Thank you all
--Edit
According to sugestions i made a test using smtpsend demo from javaMail (I implemented a subclass of MimeMessage to generate my own Message-Id).
java -jar -Dmail.smtp.starttls.enable=true -Dmail.smtp.port=587 SMTPSend.jar -d -M smtp.live.com -U myaccount#hotmail.com -P mypass -o myaccount#hotmail.com -A anotheraccount#gmail.com
Between smtpsend output when message was sent, there was the Message-Id generated
<60eea6ae-2657-41bd-b475-3a57eff885ac#mydomain.com>
But then, when i went to check this message on anotheraccount#gmail.com, the Message-Id was different
<BLU0-SMTP109215E6BB99B93FC106B1E88B00#phx.gbl>
Why is it changing my Message-Id on the fly... i dont get it
--Edit 2
I noticed that the problem is now happening just when i send mails from a hotmail account
message-id is not changing anymore when i send mails from a gmail account (i think that implementing my own Message-Id generation method helped to solve that)
Thanks for replying
I know this is an old thread, but this answer could still maybe help people.
You need to overrule updateMessageID() in MimeMessage as it gets called everytime before sending an e-mail.
class MyMessage extends MimeMessage {
public MyMessage(Session session) {
super(session);
}
protected void updateMessageID() throws MessagingException {
setHeader("Message-ID", "<your-message-id#domain.nl>");
}
}
And if you would like to pass the unique id for each MyMessage...
class MyMessage extends MimeMessage {
String uniqueMessageId;
public MyMessage(Session session, String uniqueMessageId) {
super(session);
this.uniqueMessageId = uniqueMessageId;
}
protected void updateMessageID() throws MessagingException {
setHeader("Message-ID", "<" + uniqueMessageId + ">");
}
}
And then call it, eg:
MyMessage message = new MyMessage(session, "201610131428_newsletter1#domain.nl");
We've encountered the same issue with Simple Java Mail and as far as I know the only way to catch the actual ID assigned by the SMTP server is to parse the 250 OK response which includes it (in case of MS Exchange).
As Bill (the prime author of the original JavaMail) mentions below, the SMTP server should actually never change the Message ID, but some servers like MS Exchange explicitly allow configuration otherwise. For example see: https://social.technet.microsoft.com/Forums/en-US/132df54c-871b-4e9d-98c9-5b5caa993322/custom-message-id-replaced-by-outlook-smtp-server?forum=exchangesvrclients.
If you are seeing this behavior with all servers you connect to, chances are you are not setting MessageID the right way (Java/Jakarta Mail is a little obtuse about this). In that case refer to the other answer.
Your mail server is broken. It should not be changing the Message-ID header.
Report the problem to the owner of your mail server.
I am using Mirth with a LLP listener receiving HL7v2 message.
The customer expects an ACK message from us and so we checked the "Send ACK" radio button. The only problem is that in the default ACK it puts MIRTH in the MSH-3.1 field. I need to change this to another value to say where it came from.
Is this possible?
Mirth has a feature for customizing acks. I don't think it's documented, but their support staff directed us to it.
In the postprocessor:
var ackString = ""; //build a javascript string for your custom ack
var ackResponse = ResponseFactory.getSuccessReponse (ackString);
responseMap.put("Custom ACK", ackResponse);
Mirth parses the postprocessor code, and discovers the reponseMap code. On the source tab, you can now select "Respond from" and "Custom ACK" will appear as an option there.
The full code for building my custom acks is about 20 lines.
I think the only way you will get around that is to use the "Respond From" setting under "Send Ack" and set your first Destination under "Destinations" to be an "Ack Sender" and build and send an Ack from there.
You could also use this mechanism if you ever encounter a situation where you should only Ack if you could successfully deliver the message in which case you would place your "Ack Sender" after the actual destination you send the message on with. Your "Ack Sender" destination would then have to build an Ack or Nack based on successful delivery. You could check that by checking the return status of the previous destination with something like:
var returnState = responseMap.get('DestinationName').toString();
if (returnState.substr(0,8) == 'SUCCESS:')
// Successful Delivery or Processing
else
// Failed Delivery or processing
Let me know if you need any more help ...
Frans
I am receiving lab HL7 messages from a static host and a dynamic port. For each message received I need to send a ACK message back to this host and port.
I have a destination TCP Writer channel with the correct message in there. Though the port number has to be fixed.
How do I tell Mirth to send this message to the sending host and port?
Thanks in advance
Abhi
You should configure your channel to use the LLP Listener instead, which has the option to reply with a custom HL7 ACK message. The message will be send back on the same connection so you don't have to keep track of the address of the sending system.
In Mirth you send a customized ACK message.
In Scripts, select the Postprocessor (This script executes once after a message has been processed)
and write this code
var ackString = ""; //build a javascript string for your custom ack
var ackResponse = ResponseFactory.getSuccessReponse(ackString);
responseMap.put("Custom ACK", ackResponse);
Mirth will then parse the Postprocessor script, and discovers the reponseMap code. On the source tab, go to the Send ACK radio list, you can now select "Respond from" and "Custom ACK" from the options in the dropdownlist avaiable.