web stats
Pulling all values from DB into a list - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-30-2018, 08:07 AM
mmonisky mmonisky is offline
OBX.1 Kenobi
 
Join Date: Aug 2015
Posts: 35
mmonisky is on a distinguished road
Default Pulling all values from DB into a list

MC v 2.2.2.6388

If the patient ID has multiple UUIDs, I want to grab them all and put into a list on the channel map

Source Transformer:
var dbConn = DatabaseConnectionFactory.createDatabaseConnection ("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/localhost", 'root', 'password');

var sql = "SELECT UUID FROM study WHERE patientid = '"+ $('patient_origid') +"' ";
var UUID = '';


var results = dbConn.executeCachedQuery(sql);

while(results.next())
{

UUID = results.getString(1);


}
dbConn.close();



channelMap.put ('UUID', UUID);

How do I grab the additional UUIDs?
Attached Images
File Type: png 2018-08-30_1205.png (13.9 KB, 7 views)
Reply With Quote
  #2  
Old 08-30-2018, 06:37 PM
mmonisky mmonisky is offline
OBX.1 Kenobi
 
Join Date: Aug 2015
Posts: 35
mmonisky is on a distinguished road
Default

I think I figured out part of it.
Results = [1.3.6.1.4.1.11157.2017119715567237.1529796907.1138 103, 1.3.6.1.4.1.11157.2017119715567237.1533839737.1028 88502, 1.3.6.1.4.1.11157.2221112312811.1505231752.93, 1.3.6.1.4.1.11157.2221112312811.1505839091.2470648]

What is the best way to loop through and parse the results?

var dbConn;
var result;
var UUID;
var entryList = java.util.ArrayList();


try {
dbConn = DatabaseConnectionFactory.createDatabaseConnection ("com.mysql.jdbc.Driver", 'jdbc:mysql://localhost:3306/here','root','somepassword');
result = dbConn.executeCachedQuery("SELECT UUID FROM study WHERE patientid = '"+ $('patientid') +"' ");
while (result.next()) {
var entry = result.getString('UUID');

}

} finally {
if (dbConn) {
dbConn.close();
}
}

channelMap.put('entryList', entryList);
Reply With Quote
  #3  
Old 09-05-2018, 01:59 AM
mdehoog mdehoog is offline
Mirth Guru
 
Join Date: Mar 2011
Location: Apeldoorn the Netherlands
Posts: 284
mdehoog is on a distinguished road
Send a message via Skype™ to mdehoog
Default Try using database reader

Why not try using the database reader with Aggregate Results=Yes??

Your query would give you then a XML message with all the results included.
From there you can do what you want.

Code:
<results>
    <result>
        <patient_pat_zipcode>NL-7327KJ</patient_pat_zipcode>
        <patient_pat_city>Apeldoorn</patient_pat_city>
        <patient_processed>true</patient_processed>
        <patient_pat_gender>Male</patient_pat_gender>
        <patient_pat_street_nr>Landmetersveld 704</patient_pat_street_nr>
        <patient_pat_last_name>de Hoog</patient_pat_last_name>
        <patient_pat_id>1234</patient_pat_id>
        <patient_pat_dob>14-02-1960</patient_pat_dob>
    </result>
    <result>
        <patient_processed>true</patient_processed>
        <patient_pat_gender>F</patient_pat_gender>
        <patient_pat_id>1001</patient_pat_id>
        <patient_pat_dob>19850704</patient_pat_dob>
    </result>
    <result>
        <patient_processed>true</patient_processed>
        <patient_pat_gender>F</patient_pat_gender>
        <patient_pat_id>1001</patient_pat_id>
        <patient_pat_dob>19850704</patient_pat_dob>
    </result>
    <result>
        <patient_pat_zipcode>DE-7327KJ</patient_pat_zipcode>
        <patient_pat_city>Freiburg</patient_pat_city>
        <patient_processed>true</patient_processed>
        <patient_pat_gender>Male</patient_pat_gender>
        <patient_pat_street_nr>First street 77</patient_pat_street_nr>
        <patient_pat_last_name>Smith</patient_pat_last_name>
        <patient_pat_id>12345</patient_pat_id>
        <patient_pat_dob>13-03-1962</patient_pat_dob>
    </result>
</results>
Attached Images
File Type: png Capture.PNG (18.2 KB, 6 views)
__________________
X Connections
https://documentor.email
https://www.x-connections.com
Reply With Quote
  #4  
Old 09-05-2018, 02:19 AM
AlexNeiva AlexNeiva is offline
Mirth Guru
 
Join Date: Oct 2013
Location: Portugal
Posts: 275
AlexNeiva is on a distinguished road
Default

Hello,


from my understanding you want an array of the multiple UUID that the DB return correct?


Code:
var dbConn;
var result;
var entryList = [];

try 

{
        dbConn = DatabaseConnectionFactory.createDatabaseConnection      ("com.mysql.jdbc.Driver",  'jdbc:mysql://localhost:3306/here','root','somepassword');
        result = dbConn.executeCachedQuery("SELECT UUID FROM study WHERE patientid = '"+ $('patientid') +"' ");
        while (result.next()) 

   {
       entryList.push(result.getString('UUID'));
        }
} 

finally 

{
        if (dbConn) 

    {
               dbConn.close();
        }


   channelMap.put('entryList', entryList);

 }

with that you will have a mapper containing and array will all the UUID for that patient.
__________________
Best Regards,
Alex Neiva
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 01:04 AM.


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