web stats
Create Multiple OBR with OBX Segments from SQL DB - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 09-18-2018, 02:14 PM
vackerman vackerman is offline
Mirth Newb
 
Join Date: May 2015
Posts: 23
vackerman is on a distinguished road
Default Create Multiple OBR with OBX Segments from SQL DB

I need to take these results queried from a database and create 1 OBR segment for each time listed in the OBR_7 column and follow it by multiple OBX's.

OBR_7 OBX_1 OBX_2 OBX_3 OBX_5
20180625130000 9 NM NBP_S 176
20180625130000 10 NM NBP_D 88
20180625130000 11 NM NBP_M 117
20180625130100 9 NM NBP_S 178
20180625130100 10 NM NBP_D 84
20180625130100 11 NM NBP_M 115


Something similar to this,

OBR|||||||20180914130000
OBX|0|ST|HR||70||||||R
OBX|1|ST|PVC||1||||||R
OBX|2|ST|ST-I||0.30||||||R
OBX|3|ST|ST-II||-0.10||||||R
OBX|4|ST|ST-III||-0.40||||||R
OBX|5|ST|ST-V1||0.50||||||R
OBX|6|ST|ST-AVR||-0.10||||||R
OBX|7|ST|ST-AVL||0.30||||||R
OBX|8|ST|ST-AVF||-0.20||||||R
OBR|||||||20180914130100
OBX|0|ST|HR||71||||||R
OBX|1|ST|PVC||0||||||R
OBX|2|ST|ST-I||0.30||||||R
OBX|3|ST|ST-II||-0.10||||||R
OBX|4|ST|ST-III||-0.50||||||R
OBX|5|ST|ST-V1||0.30||||||R
OBX|6|ST|ST-AVR||-0.10||||||R
OBX|7|ST|ST-AVL||0.40||||||R
OBX|8|ST|ST-AVF||-0.30||||||R

Thanks!
Reply With Quote
  #2  
Old 09-18-2018, 10:46 PM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 835
siddharth is on a distinguished road
Default

Is there anything you have already done, and is not working? Show us your code please.
__________________
HL7v2.7 Certified Control Specialist!
Reply With Quote
  #3  
Old 09-19-2018, 01:11 PM
vackerman vackerman is offline
Mirth Newb
 
Join Date: May 2015
Posts: 23
vackerman is on a distinguished road
Default

The only thing that I have completed so far is to get the data from the database, just not sure how to interpret it into the OBR's with OBX's.

The following is just pulling the OBR field from the database as a starting point.


var acct = msg['QRD']['QRD.8']['QRD.8.1'].toString();
var from = msg['QRF']['QRF.2']['QRF.2.1'];
var thru = msg['QRF']['QRF.3']['QRF.3.1'];
var qt = '\'';

var dbConn = DatabaseConnectionFactory.createDatabaseConnection

var sql = "SELECT DISTINCT OBR_7 from <tablename> where PID_3 =" + qt + acct + qt + "and OBR_7 >=" + qt + from + qt + "and OBR_7 <=" + qt + thru + qt;
var results = dbConn.executeCachedQuery(sql);

var obr = "";
while(results.next())
{
obr = results.getString(1);

}

dbConn.close();
Reply With Quote
  #4  
Old 09-24-2018, 12:06 PM
vackerman vackerman is offline
Mirth Newb
 
Join Date: May 2015
Posts: 23
vackerman is on a distinguished road
Default

I now have data pulling in, but my last line in my delimited file is "undefined", not sure where that is coming from? I did check the resultSize variable to the database query and it is correct.

Here is what I have;

var result = dbConn.executeCachedQuery(resultquery);
var resultSize = result.size();
//logger.info(resultSize);
for (var i = 0;i < resultSize;i++)
{
(result.next())
var data = result.getString(4);

var output = data + "\r" + output;

channelMap.put('Data',output)

}

When it writes the file, the last line is always "undefined",
.......
OBX|9|ST|InspCO2||0||||||R
undefined
Reply With Quote
  #5  
Old 09-24-2018, 02:54 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,037
agermano is on a distinguished road
Default

You're appending what is already stored in output to the end of data and storing the result in output, but since you never initialized output, the first time you call it, the previous value is undefined.
Reply With Quote
  #6  
Old 09-25-2018, 05:55 AM
vackerman vackerman is offline
Mirth Newb
 
Join Date: May 2015
Posts: 23
vackerman is on a distinguished road
Default

Well, that was a simple fix.

Thanks
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:41 AM.


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