web stats
why is my logic only placing one name in the affirmation file? - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2019, 06:28 AM
msmusic2 msmusic2 is offline
Mirth Newb
 
Join Date: May 2019
Location: Tennessee
Posts: 10
msmusic2 is on a distinguished road
Send a message via Skype™ to msmusic2
Default why is my logic only placing one name in the affirmation file?

This logic is supposed to search through my HL7 file and grab data from each patient and place it in a flat file. But it's only grabbing the last patient's data.

I am attaching the transformer and we are on Mirth 3.5.1

Is it the "for each" statement at the beginning?

Any help, as always, is greatly appreciated.

Mark
Attached Files
File Type: xml TX Affirmation file builder.xml (8.8 KB, 2 views)

Last edited by msmusic2; 06-12-2019 at 06:31 AM. Reason: missed word
Reply With Quote
  #2  
Old 06-12-2019, 06:51 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,243
cory_cole is on a distinguished road
Default

I don't see where you are writing to the file. I see you writing to the channelMap. But the map key is hard coded. Therefore, every time you write to it, it will have the same key. Hence, you overwrite it everytime

channelMap.put("AffirmFileName",...)
channelMap.put("AffirmFileContent", ...);

this would fix that
channelMap.put("AffirmFileName" + some_counter,...)
channelMap.put("AffirmFileContent" + some_counter, ...);
Reply With Quote
  #3  
Old 06-12-2019, 07:14 AM
msmusic2 msmusic2 is offline
Mirth Newb
 
Join Date: May 2019
Location: Tennessee
Posts: 10
msmusic2 is on a distinguished road
Send a message via Skype™ to msmusic2
Default

it actually grabs the data from FHS.9.1, prepends it with AFFIRM and ends it with imp (the number is different every week)

ex. AFFIRM.lkgmc19160.imp

grabbing my example from this FHS segment of the batch file

FHS|^~\&|HMS|1180920006|TxImmTrac|TxDSHS|201906090 12203 ||lkgmc19160.HL7|Weekly VXU Transfer to ImmTrac|71||
Reply With Quote
  #4  
Old 06-12-2019, 07:19 AM
msmusic2 msmusic2 is offline
Mirth Newb
 
Join Date: May 2019
Location: Tennessee
Posts: 10
msmusic2 is on a distinguished road
Send a message via Skype™ to msmusic2
Default

the example I provided had 160 patient submissions but only the last patients name was in the .imp file so there's good chance that 159 entries or updates didn't happen on the receivers end due to lack of data in the flat file
Reply With Quote
  #5  
Old 06-12-2019, 07:37 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,243
cory_cole is on a distinguished road
Default

That is done in the value but the key never changes so it will overwrite every time.
Reply With Quote
  #6  
Old 06-12-2019, 07:48 AM
msmusic2 msmusic2 is offline
Mirth Newb
 
Join Date: May 2019
Location: Tennessee
Posts: 10
msmusic2 is on a distinguished road
Send a message via Skype™ to msmusic2
Default

how would you propose to code the counter?

Here is the batch build for the HL7 message...


buildString = 'BHS|^~\\&|HMS|' + siteName + '|TxImmTrac|TxDSHS|' + DateUtil.getCurrentDate('yyyyMMddHHmmss') + '|||Batch-1|' + connectorMessage.getMessageId() + '||\r' + buildString;
buildString += 'BTS|' + msgCount + '|\r';

buildString = 'FHS|^~\\&|HMS|' + siteName + '|TxImmTrac|TxDSHS|' + DateUtil.getCurrentDate('yyyyMMddHHmmss') + ' ||' + fn + '|Weekly VXU Transfer to ImmTrac|' + connectorMessage.getMessageId() +'||\r' + buildString;
buildString += 'FTS|1|Weekly VXU Transfer to ImmTrac Complete|\r';


channelMap.put('myFileConents', buildString);
channelMap.put('msgCount', msgCount);

if (msgCount > 0) {
return true;
}

return false;

Last edited by msmusic2; 06-12-2019 at 07:53 AM. Reason: updated code
Reply With Quote
  #7  
Old 06-12-2019, 09:26 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,243
cory_cole is on a distinguished road
Default

var message_counter = 1;
for each (seg in msg.PID) {

message_counter++;
}
Reply With Quote
  #8  
Old 06-12-2019, 10:55 AM
msmusic2 msmusic2 is offline
Mirth Newb
 
Join Date: May 2019
Location: Tennessee
Posts: 10
msmusic2 is on a distinguished road
Send a message via Skype™ to msmusic2
Default

so put that at the beginning of the logic? or in the AffirmFileName channelMap?

Last edited by msmusic2; 06-12-2019 at 10:59 AM.
Reply With Quote
  #9  
Old 06-12-2019, 11:17 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 894
agermano is on a distinguished road
Default

The delimited data type allows for fixed with fields. That's what I would use.

Use this code in your transformer:
Code:
channelMap.put("AffirmFileName", 'AFFIRM.' + msg['FHS']['FHS.9']['FHS.9.1'].toString().slice(0, -4)  + '.imp');
var dateFormatter = java.time.format.DateTimeFormatter.ofPattern('yyyyMMdd');

var newMsg = <delimited/>;

for each (var seg in msg.PID) {
	var bd = java.time.LocalDate.parse(seg['PID.7']['PID.7.1'].toString().slice(0,8), dateFormatter);

	// The column names are arbitrary and can be changed. They just need to be in the correct order.
	var row = <row>
		<C.1>C</C.1>
		<C.2/>
		<C.3>{seg['PID.5']['PID.5.1'].toString()}</C.3>
		<C.4>{seg['PID.5']['PID.5.2'].toString()}</C.4>
		<C.5>{seg['PID.5']['PID.5.3'].toString()}</C.5>
		<C.6>{seg['PID.19']['PID.19.1'].toString()}</C.6>
		<C.7>{seg['PID.8']['PID.8.1'].toString()}</C.7>
		<C.8>{seg['PID.10']['PID.10.4'].toString()}</C.8>
		<C.9/>
		<C.10>{seg['PID.7']['PID.7.1'].toString()}</C.10>
		<C.11/>
		<C.12/>
		<C.13/>
		<C.14/>
		<C.15/>
		<C.16/>
		<C.17>{(bd.isBefore(java.time.LocalDate.now().minusYears(18))) ? 'A' : 'Y'}</C.17>
		<C.18>{seg['PID.11']['PID.11.1'].toString()}</C.18>
		<C.19>{seg['PID.11']['PID.11.2'].toString()}</C.19>
		<C.20>{seg['PID.11']['PID.11.3'].toString()}</C.20>
		<C.21>{seg['PID.11']['PID.11.4'].toString()}</C.21>
		<C.22>{seg['PID.11']['PID.11.5'].toString()}</C.22>
		<C.23/>
		<C.24>{seg['PID.12']['PID.12.1'].toString()}</C.24>
		<C.25>{seg['PID.11']['PID.11.6'].toString()}</C.25>
		<C.26>{seg['PID.13']['PID.13.1'].toString()}</C.26>
		<C.27>{seg['PID.3']['PID.3.1'].toString()}</C.27>
		<A.1>A</A.1>
		<A.2>{msg['FHS']['FHS.4']['FHS.4.1'].toString()}</A.2>
		<A.3>{java.time.LocalDate.now().format(dateFormatter)}</A.3>
		<T.1>TR</T.1>
	</row>;

	newMsg.appendChild(row);
}

msg = newMsg;
Set your column widths and record delimiter in the properties (see screenshot)
Code:
2,10,20,20,20,9,1,2,9,8,20,20,20,20,20,20,1,32,20,20,2,5,4,3,2,10,16,2,25,8,2
Leave the transformer outbound template blank. This will make the transformer look to the msg variable to apply your outbound properties and create the encoded data. This is why we point msg to newMsg in the last line.

Use ${message.encodedData} in your connector template.

Edit: In the screenshot, the record delimiter should be \r\n
Attached Images
File Type: png delimited-fixed.png (22.5 KB, 8 views)

Last edited by agermano; 06-12-2019 at 11:22 AM.
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:29 AM.


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