web stats
Saving a message to be sent later - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-27-2018, 07:00 AM
radams radams is offline
OBX.1 Kenobi
 
Join Date: May 2015
Posts: 27
radams is on a distinguished road
Default Saving a message to be sent later

I need to do the following (Mirth 3.2.1):

1. Receive messages via HL7
2. Hold messages until the top of the hour
3. Check all held messages and only send the most recent one for each accession
4. Send messages at top of the hour

I think this is my logic (open to better suggestions!):
1. Channel A to receive messages with a Destination to save messages to a database, including separate columns with date/time received and accession number
2. Channel B to read database, polling hourly
3. Filter on destination in Channel B that will read database to see if there are more recent messages and if there are, filter this message out
4. Send message in HL7 format to destination

I don't know how to do the following:
1. Save the message to a database so it is readable by Channel B as an entire HL7 message
2. Make sure the polling takes place at the top of the hour, not just hourly from when the channel is started
3. Read the entire message from the database and put it into the format I need to send it (I have read fields from a database and put them into a message, but I know I don't want to parse the message and then recompile it). I know how to do the filter on this.

Are there any examples or tutorials that will help me with this? Thanks.

Last edited by radams; 02-27-2018 at 07:01 AM. Reason: Added version
Reply With Quote
  #2  
Old 02-27-2018, 12:02 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 795
agermano is on a distinguished road
Default

I think your general plan is good. I'd make sure your db query in Channel B only returns the most recent record for each accession number to eliminate the need for the destination filter. Also, would you want to delay pulling records that are not yet a certain age? I.e. if you just received a message 5 seconds before Channel B polls, do you want to wait for updates instead of returning the message?

Here's a sample query for Channel B db reader:
Code:
select message, accession
from myTable t inner join
(
	select accession, max(received) received
	from myTable
	group by accession
) m on t.accession = m.accession and t.received = m.received
-- Below line is optional and syntax will depend on your database.
-- This is mysql/mariadb.
-- Pull only accession numbers where the most recent update is at least an
-- hour old.
having m.received < date_add(now(), interval - 1 hour);
Your post-process SQL could look like this after each message.
Code:
delete from myTable where accession = ${accession} and received <= ${received}
Your channel A db writer would look something like this. I'm assuming you have put the accession and received values into map variables of the same name in your transformer.
Code:
insert values(message, accession, received) into test (${message.encodedData}, ${accession}, ${received})
I'm pretty sure if you set your polling schedule to a 1 hour interval it will run at the top of the hour, but if for some reason it doesn't, you can use cron scheduling. I think 0 0 * * * ? should do it.

In your Channel B source transformer make sure the outbound data type is HL7v2. The database reader should force the inbound type to XML. Add a javascript step with the following code to pass just the hl7 message to the destination. Then in your destination you can handle this as any other HL7 message.
Code:
msg = SerializerFactory.getSerializer('HL7V2').toXML(msg['message']);

Last edited by agermano; 02-27-2018 at 12:05 PM.
Reply With Quote
Reply

Tags
database polling, database reader, database writer

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 11:38 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation