web stats
Filter message based on SQL result - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 11-22-2017, 10:32 AM
dforesman dforesman is offline
Mirth Newb
 
Join Date: Mar 2016
Posts: 25
dforesman is on a distinguished road
Default Filter message based on SQL result

I have searched the forum for a bit and I am sure I am missing the obvious; but my goal is to look up and see if the patient exists using the SQL query below.

If the query returns nothing it SHOULD skip the message but at this time it doesn't. Any guidance is greatly appreciated!

var dbConn;
var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('oracle.jdbc.driver.OracleDriver','jdbc: oracle:thin:@IP_HERE:PORT: DB_NAME','USER','PWD');

var drc = msg['PID']['PID.3']['PID.3.1'];
var sql = "SELECT DISTINCT(PAT_ALT_LOOKUP) FROM PP_TEST_UPD.MRAI99 WHERE ALTERNATIVE='SH SF MRN' AND PAT_ALT_LOOKUP='"+drc+"'";
var result = dbConn.executeCachedQuery(sql);
// You may access this result below with $('column_name')
result.next();
dbConn.close();
//var sql_result=result.getString(1);


if(result == ""){
return false;
}
return true;
Reply With Quote
  #2  
Old 11-22-2017, 10:16 PM
obsessio obsessio is offline
Mirth Guru
 
Join Date: Mar 2015
Location: Turkey
Posts: 177
obsessio is on a distinguished road
Default

Further read = https://stackoverflow.com/questions/...k-variables-in
Reply With Quote
  #3  
Old 11-23-2017, 02:15 AM
amble amble is offline
OBX.2 Kenobi
 
Join Date: Nov 2015
Posts: 95
amble is on a distinguished road
Post

Can you do something like this:

PHP Code:
var qResult '';

if (
result.next() == false
        { 
                   
qResult "empty";
                    break;
        }

        else do
        { 
                   
qResult result.getString(1);
                    break;
        }
        
        while(
result.next());    

if (
qResult == "empty")
{
destinationSet.removeAll();
}
else
{
return 
true;

Reply With Quote
  #4  
Old 11-29-2017, 05:20 AM
dforesman dforesman is offline
Mirth Newb
 
Join Date: Mar 2016
Posts: 25
dforesman is on a distinguished road
Default

Thank you Obsessio and Amble; I ended up solving this after reading the link from Obsessio.

So I ended up modifying the SQL string to include a case statement when = false else true; then I modified the if like below and now it works.

if (result.getString(1) == 'true'){
return true;
}
else {

return false;
}
Reply With Quote
  #5  
Old 11-29-2017, 05:54 AM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 841
siddharth is on a distinguished road
Default

You might want to change this below statement of yours to check for booleans in the right way.

if (result.getString(1) == 'true')
__________________
HL7v2.7 Certified Control Specialist!
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 04:04 AM.


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