web stats
Dealing with a simple array (sent by POST) - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 01-13-2015, 07:34 AM
henriquetomaz henriquetomaz is offline
OBX.1 Kenobi
 
Join Date: Dec 2014
Posts: 45
henriquetomaz is on a distinguished road
Unhappy Dealing with a simple array (sent by POST)

Hi,

I am sending from my Application to MIRTH an array with samples IDs.

From my Application:

App::import('Core', 'HttpSocket');
$HttpSocket = new HttpSocket();
$results = $HttpSocket->post('http://xxx.x.x.x:yyyy/new_sample/', array('sendAp' => 'LINK',
'sendFac' => 'HOSPITAL',
'recAp' => 'DEP',
'recFac' => 'SYS',
'PID' => $pat_id['MirthLog']['rgh'],
'pName' => $pat_name['MirthLog']['nome'],
'pBirth' => $pat_bir['MirthLog']['nasc'],
'pGend' => 'F',
'bcode' => $sample, // array with samples ID***
'ncode' => $n_amostra, // number of samples
'orcID' => $exam_id['MirthLog']['codigo_coleta'],
'sender' => 'APPLIC'));

I am getting all this parameters in MIRTH, except the array "bcode"

From MIRTH side:

//NOT WORKING - empty array
var barCode = sourceMap.get('parameters').get('bcode');

// WORKS WHEN I GET ELEMENTS INDIVIDUALLY
var barCode0 = sourceMap.get('parameters').get('bcode[0]');
var barCode1 = sourceMap.get('parameters').get('bcode[0]');

// NOT WORKING USING FOR - EMPTY ARRAY
var barCode = [];
var nCode = sourceMap.get('parameters').get('ncode'); // number of samples
for (var i = 0; i < nCode; i++){
var i2=i.toString();
barCode[i] = sourceMap.get('parameters').get('bcode[i2]'); // SPM (samples)
}

What is wrong???
Sorry, for this basic question, but I got stuck here since yesterday.

Thanks a lot.

Henrique Amaral
Reply With Quote
  #2  
Old 01-13-2015, 07:36 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,277
cory_cole is on a distinguished road
Default

barCode[i] = sourceMap.get('parameters').get('bcode[i2]'); // SPM (samples)
i2 is a literal the way you have it. try

barCode[i] = sourceMap.get('parameters').get('bcode' + [i2]); // SPM (samples)
Reply With Quote
  #3  
Old 01-13-2015, 09:35 AM
henriquetomaz henriquetomaz is offline
OBX.1 Kenobi
 
Join Date: Dec 2014
Posts: 45
henriquetomaz is on a distinguished road
Default

Thanks cory cole!
You helped me a lot.
I just had to make slightly changes from your suggestion to get it working:

var barCode = [];//initialize array
var nCode = sourceMap.get('parameters').get('ncode'); // number of samples
for (var i = 0; i < nCode; i++){
var i2 = i.toString();
barCode[i] = sourceMap.get('parameters').get('bcode'+'['+i2+']');
}

Henrique Amaral-SIlva
Reply With Quote
Reply

Tags
array, mapping, sourcemap

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 02:46 AM.


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