web stats
File Reader store record in an array/list - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-28-2017, 09:25 AM
DragonQueen DragonQueen is offline
OBX.1 Kenobi
 
Join Date: Aug 2016
Posts: 37
DragonQueen is on a distinguished road
Default File Reader store record in an array/list

I am trying to read from a file using File reader and add the ID sent in each record to an array or list at the destination connector so at the end of the file all the IDs from the file are stored in a list.

I want to use that list to compare with another list and process a SQL statement for the Ids not on the list.

What is the best way to do this?
Reply With Quote
  #2  
Old 02-28-2017, 10:30 AM
odo odo is offline
OBX.3 Kenobi
 
Join Date: Feb 2017
Location: Luxembourg
Posts: 139
odo is on a distinguished road
Default

Use an (Java) ArrayList and add all processed ids. Then, when processing the 2nd list, check if the ArrayList already contains the id. If the function call returns false, go on with your sql statement.
Reply With Quote
  #3  
Old 02-28-2017, 10:35 AM
jackwhaines jackwhaines is offline
 
Join Date: May 2011
Location: Kansas City, Missouri
Posts: 205
jackwhaines is on a distinguished road
Send a message via Skype™ to jackwhaines
Default

Something like this? I didn't run it, but the logic should work... Obviously, create the lists/arrays however you need to.

Code:
var list1 = array("a", "b", "c");
var list2 = array("c", "d", "e");

for (var i = 0; i < list1.length; i++)
   {
    if (list2.indexOf(list1[i]) == -1)
       {
        // sql insert here
       }
  }
__________________

-= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
-= jack.haines@HealthcareIntegrations.com
-= Mirth Connect (Advanced)-certified
-= Gold member of HL7.org
-= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines
Reply With Quote
  #4  
Old 02-28-2017, 11:53 AM
DragonQueen DragonQueen is offline
OBX.1 Kenobi
 
Join Date: Aug 2016
Posts: 37
DragonQueen is on a distinguished road
Default

I am trying to save the ids into an array or list in the destination connector. the id is transformed at the source of a file reader. I am unable to add onto the list. Each time a record is processed, it clears the old record and inserts the new one. What am I missing?
Reply With Quote
  #5  
Old 02-28-2017, 11:55 AM
jackwhaines jackwhaines is offline
 
Join Date: May 2011
Location: Kansas City, Missouri
Posts: 205
jackwhaines is on a distinguished road
Send a message via Skype™ to jackwhaines
Default

If multiple messages are coming in to build either list, and you already have access to a database, I would write to a database/table instead of trying to have Mirth "remember" the lists through multiple messages, but that's me. If you really don't wanna do that, you could use a globalMap variable.
__________________

-= Jack Haines : Founder/CEO of Healthcare Integrations, LLC
-= jack.haines@HealthcareIntegrations.com
-= Mirth Connect (Advanced)-certified
-= Gold member of HL7.org
-= Available for Mirth Connect channel development and consultation! Schedule a FREE call with me at https://calendly.com/jackhaines
Reply With Quote
  #6  
Old 03-02-2017, 05:05 AM
odo odo is offline
OBX.3 Kenobi
 
Join Date: Feb 2017
Location: Luxembourg
Posts: 139
odo is on a distinguished road
Default

Quote:
Originally Posted by DragonQueen View Post
I am trying to save the ids into an array or list in the destination connector. the id is transformed at the source of a file reader. I am unable to add onto the list. Each time a record is processed, it clears the old record and inserts the new one. What am I missing?
You can make your variable persistent at different scopes:
globalChannelMap - persistence throughout the lifetime of a channel
globalMap - throughout the lifetime of the mirth service

You have read and write access to those maps by get() and put() - e.g.
PHP Code:
channelMap.put('indexList', <Your array or list>); 
and
PHP Code:
var yourArray channelMap.get('indexList'); 
If you need persistence beyond the lifetime of a mirth instance, you should use a databasetable as mentioned above.
Reply With Quote
  #7  
Old 03-02-2017, 06:58 AM
DragonQueen DragonQueen is offline
OBX.1 Kenobi
 
Join Date: Aug 2016
Posts: 37
DragonQueen is on a distinguished road
Default

I tried this code and it did not work. I save both the lists in the globalMap. I get the lists and store it in a local variable and when I run the code, I get the following error:
Java class "java.util.ArrayList" has no public instance field or method named "0"

I even tried converting it into local array variables and still get the same error.

Can somebody guide me? I am trying to compare two lists.

Thanks
Reply With Quote
  #8  
Old 03-02-2017, 07:13 AM
odo odo is offline
OBX.3 Kenobi
 
Join Date: Feb 2017
Location: Luxembourg
Posts: 139
odo is on a distinguished road
Default

Quote:
Originally Posted by DragonQueen View Post
I tried this code and it did not work.
Please post your transformer code
Reply With Quote
  #9  
Old 03-02-2017, 07:55 AM
DragonQueen DragonQueen is offline
OBX.1 Kenobi
 
Join Date: Aug 2016
Posts: 37
DragonQueen is on a distinguished road
Default

x = globalMap.get('dbID');
y = globalMap.get('ID');
xlength = parseInt(globalMap.get('dbIDCount'));
ylength = parseInt(globalMap.get('IDcount'));

for (var i = 0; i < xlength; i++)
{
if (x.indexOf(y[i]) == -1)
{
globalMap.get('diff').push(x[i])
}
}

I need a list of IDs that exist in the dbID but not in ID lists.
Reply With Quote
  #10  
Old 03-02-2017, 01:08 PM
odo odo is offline
OBX.3 Kenobi
 
Join Date: Feb 2017
Location: Luxembourg
Posts: 139
odo is on a distinguished road
Default

Please be aware that the subsequent code is not tested and thus may contain typos. It's purpose is to give you an idea what to do to solve your issue:

PHP Code:
// part 1 write ids to dbId
// first get the array from global channel map or greate it if not existent
var dbId globalChannelMap.get('dbId') ? globalChannelMap.get('dbId'): [];

// now add your values from the first list to the array
dbId.push(<your value>);
// place the array in the globalChannelMap
globalChannelMap.put('dbId'dbId);

// part 2: when all elements from 1st list are pushed to the array, check for the 2nd list if the ids already treated
var dbId globalChannelMap.get('dbId');
// if the id from the 2nd list is not found in the 1st list
if(!(dbId.indexOf(<your id from 2nd list>)+1)){
   
// do something special
   
logger.info('The id ' + <your id from 2nd list> + ' of the second list was not in the 1st list. Something special happens now...');

To me it is not clear if part 1 and part 2 are handled in 2 different transformers or if you simply want to assure to execute an action only once for each id no matter which list it is part of. For the later, the code would be like follows:
PHP Code:
// first get the array from global channel map or greate it if not existent
var dbId globalChannelMap.get('dbId') ? globalChannelMap.get('dbId'): [];

// if the id is not found in the list
if(!(dbId.indexOf(<your id>)+1)){
   
// do something special
   
logger.info('The id ' + <your id> + ' has not yet been treated. Something special happens now...');
   
// now add your values from the first list to the array
   
dbId.push(<your id>);
  
// place the array in the globalChannelMap
  
globalChannelMap.put('dbId'dbId);


Last edited by odo; 03-02-2017 at 01:11 PM. Reason: typo
Reply With Quote
Reply

Tags
file reader

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 07:37 PM.


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