Announcement

Collapse
No announcement yet.

Pulling all values from DB into a list

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 Files

  • #2
    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);

    Comment


    • #3
      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 Files
      X Connections
      https://documentor.email
      https://www.x-connections.com

      Comment


      • #4
        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

        Comment

        Working...
        X