web stats
How to read a whole segment from database in transformer and add as a segment - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2018, 09:45 AM
onapping onapping is offline
What's HL7?
 
Join Date: May 2014
Posts: 2
onapping is on a distinguished road
Default How to read a whole segment from database in transformer and add as a segment

Hi,
I have searched a lot and could not find what I was looking for. I am kind a newbie with Mirth.
My scenario is

I am getting an MDM message from our Document management system. Some elements are missing in the message so that I need to create them to convert the message to ORU.

I am trying to the PV1 segment which I have access from a Database for the viist and append to the MDM message. I am struggling to add the whole segment (PV1) from the string data (entire PV1 segment is coming from the DB as string) that is read from the database.

Thanks
Reply With Quote
  #2  
Old 03-19-2018, 01:07 PM
AlexNeiva AlexNeiva is offline
Mirth Guru
 
Join Date: Oct 2013
Location: Portugal
Posts: 282
AlexNeiva is on a distinguished road
Default

Hello,

Can you post your channel just to have an idea on what you pretend?
__________________
Best Regards,
Alex Neiva
Reply With Quote
  #3  
Old 03-20-2018, 12:30 AM
aTom aTom is offline
OBX.3 Kenobi
 
Join Date: Feb 2016
Location: Lake Geneva Area
Posts: 115
aTom is on a distinguished road
Default

Hi,

I understand that you are able to read your PV1 from your DB but you don't see how to add it to your message, am I right?

Actually you can simply parse it:

Code:
// query your data base and retrieve your PV1 string
var pv1String = rs.getString('YOUR COLUMN NAME');
var pv1Xml = SerializerFactory.getSerializer('HL7V2').toXML(pv1String);
msg['PV1'] = pv1Xml['PV1'];
Note that if msg doesn't already contain a PV1 segment, your PV1 will be inserted at the end of msg. In this case you will have to create an empty PV1 at the right place before replacing it with your PV1 :

Code:
createSegmentAfter('PV1', msg['PID']) ;
msg['PV1'] = pv1Xml['PV1'];
__________________
Tom

Last edited by aTom; 03-20-2018 at 12:33 AM. Reason: intro added
Reply With Quote
  #4  
Old 03-20-2018, 05:38 AM
onapping onapping is offline
What's HL7?
 
Join Date: May 2014
Posts: 2
onapping is on a distinguished road
Thumbs up Great. Thanks Tom!

Thanks Tom!
That was exactly what I was looking for. I got a "PV1|undefined" when I used "msg['PV1'] = pv1Xml['PV1'];"
I have managed to do with substring and the result is good.
Would you be able to explain what does "pv1Xml['PV1'];" do? Just to learn.
Thanks
Reply With Quote
  #5  
Old 03-20-2018, 06:09 AM
aTom aTom is offline
OBX.3 Kenobi
 
Join Date: Feb 2016
Location: Lake Geneva Area
Posts: 115
aTom is on a distinguished road
Default

Yeah, well sorry, there is something missing in my original code exerpt. This will work :

Code:
var pv1Xml = new XML(SerializerFactory.getSerializer('HL7V2').toXML(pv1String));
msg['PV1'] = pv1Xml['PV1'];
The idea is to XML-ize your string PV1 segment and add it to msg (or tmp) as an XML so that you later can navigate and get some extra values, i.e. msg['PV1']['PV1.19']['PV1.19.1'].

In the original version :
Code:
var pv1Xml = SerializerFactory.getSerializer('HL7V2').toXML(pv1String);
pv1Xml seems to be a true xml but I missed that doing so, the toXML() method adds an xml directive (<?xml version="1.0" encoding="UTF-8"?>) to it that Mirth do not handle. This is why you get 'undefined' when trying to get pv1Xml['PV1'].

With the second version
Code:
var pv1Xml = new XML(SerializerFactory.getSerializer('HL7V2').toXML(pv1String));
new XML() ensures you have a true E4X XML object : it will look like "<Hl7Message><PV1><PV1.1>... </PV1.1></PV1></Hl7Message>"and will be fully browsable, like msg/tmp are :
Code:
pv1Xml['PV1']['PV1.19']['PV1.19.1'].toString();
__________________
Tom
Reply With Quote
Reply

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 03:01 AM.


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