web stats
if statement then iterate through repeating segments and then append - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 09-10-2018, 01:37 PM
tomd2121 tomd2121 is offline
What's HL7?
 
Join Date: Sep 2018
Posts: 3
tomd2121 is on a distinguished road
Default if statement then iterate through repeating segments and then append

Hi All,

Ive searched through the forum and I do see much to do about parsing in repeating segments. I was hoping for a tid bit of guidance on best method for a case if statement or if/then loop for the following rule:

The rule is

If OBR4.2 = Place In:
Look for ZOR18.3 = “ExtendedOrderUserDefinedString5” and then append the value from ZOR18-5 to the OBR4.2 , the zor fields are repeating, and can have multiple matches

I have the following message
Code:
MSH|^~\&|OARIAN|WMH|XCELERA||20250826140956||ORM^O19|276644011|P|2.4
PID|1|4181930|||ENGLERT^TANDRA||19370303|F||||||||||990-55-8990|||||||||||
PV1|1|I|CACU^WCAU^09||||010413|||MDS|||||||010413|IP||||||||||||||||||||||||||20250826102601
OBR|1|80228251||AdmitTransferTo^Place In:|||20250826140801|||||||||010413^
ZOR||||||||||||||||||^^ExtendedOrderUserDefinedString2^^AS~^^ExtendedOrderUserDefinedString5^^Admit to Inpatient Services: LOS anticipated to exceed two (2) midnights~^^ExtendedOrderUserDefinedString5^^Critical Care~^^OrderSuppInfoAdmittingPhysician^^DukeSmith~^^OrderSuppInfoAttendingPhysician^^DukeSmith~^^OrderSuppInfoInstruction^^TAVR~^^OrderSuppInfoIsolationFlag^^0~^^OrderSuppInfoVerbalOrderIndicator^^0~^^OrderSuppInfoExtStartOnEvent^^Post-op~^^ADT_Patient.Condition^^Satisfactory~^^ADT_LevelOfCare^^MedSurg Semi
As you can see the case if is found in OBR4.2 'Place in:'

The expected result should be
OBR|1|80228251||AdmitTransferTo^Place In: Admit to Inpatient Services: LOS anticipated to exceed two (2) midnights Critical Care|||20250826140801|||||||||010413^

One of the main issues im having is getting the 2nd iteration of both zor18.3[2] and zor18.5[2] to stay "combined" in the variables and my logic has either gotten me all 18.5's in one big array of xml, or im getting zor18.5[0] appended. The second is getting the loop logic correct to find all matches in the proper serialization sequence.

Ive been trying if elses with loops to no success an attempted case logic is as follows for mirth 3.5.1 (with Parse Field Repetitions checked):

zor = msg['ZOR'][i]['ZOR.18']['ZOR.18.5'];
for (var i = 0; i < zor.length(); i++) {

if (msg['OBR']['OBR.4']['OBR.4.2'].toString() == 'Place In:') {
msg['OBR']['OBR.4']['OBR.4.2'] = msg['OBR']['OBR.4']['OBR.4.2'].toString() + ' ' + zor[i].toString();
}
logger.info('zor185is: ' + zor);
channelMap.put('titleMap',msg);

}


for the case ive been following:

switch (msg['OBR']['OBR.4']['OBR.4.2'].toString() == 'Place In:') {
case 'A':
msg['OBR']['OBR.4']['OBR.4.2'] = msg['OBR']['OBR.4']['OBR.4.2'].toString() + ' ' + msg['ZOR']['ZOR.18'][i]['ZOR.18.5'].toString();
break;


First and formost...what do the GURU's summize as the best avenue for the task here? Do you have a template tid bit for a nested loop in a case statement thats on hand? Is a if then nested loop the avenue to pursue?

Id appreciate and be gracious for any input provided.
Reply With Quote
  #2  
Old 09-11-2018, 01:46 AM
amble amble is offline
OBX.2 Kenobi
 
Join Date: Nov 2015
Posts: 89
amble is on a distinguished road
Default

Code:
var placeFlag = msg['OBR']['OBR.4']['OBR.4.2'].toString();
var zor183c = "";

if (placeFlag == "Place In:")
{	
	for (i = 0; i < 3; i++)
	{
		zor183c += msg['ZOR']['ZOR.18'][i]['ZOR.18.5'].toString() +" ";
	}

	msg['OBR']['OBR.4']['OBR.4.2'] = msg['OBR']['OBR.4']['OBR.4.2'].toString() +" " +zor183c;
}
You have a few issues. OBR can be a repeating segment - will you only ever receive one?
I'v used the number 3 as the index range (bolded) - is the data you want only in those repetition indexes? Because if not you're going to have to iterate over the whole thing and pick up data like 'DukeSmith' and '0'. If this is changeable I'm not sure how you're going to filter it out or drop it easily?

Last edited by amble; 09-11-2018 at 04:42 AM.
Reply With Quote
  #3  
Old 09-11-2018, 05:58 AM
tomd2121 tomd2121 is offline
What's HL7?
 
Join Date: Sep 2018
Posts: 3
tomd2121 is on a distinguished road
Default

Thanks for the input!

Yes reference ranges are a part of the challenge. OBR could possibly be repeating which I have not yet seen in the data, but yes, the index ranges can be randomly throughout the segment, and contain multiple iterations.

Last edited by tomd2121; 09-11-2018 at 06:11 AM.
Reply With Quote
  #4  
Old 09-11-2018, 09:13 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 435
agermano is on a distinguished road
Default

This is how I would do it. It works for multiple OBR segments. E4x filtering is used to set the value of filtered to be the list of only occurances of ZOR.18 where ZOR.18.3 is ExtendedOrderUserDefinedString5.

Code:
var filtered = msg.ZOR['ZOR.18'].(function() { return new XML(this)['ZOR.18.3'].toString() == 'ExtendedOrderUserDefinedString5' }());
for each (var obr in msg.OBR) {
    if (obr['OBR.4']['OBR.4.2'].toString() == 'Place In:') {
        for each (var zor18 in filtered) {
            obr['OBR.4']['OBR.4.2'] += ' ' + zor18['ZOR.18.5'].toString();
        }
    }
}
Excellent post, by the way. Your problem and goal were explained very well.

Last edited by agermano; 09-11-2018 at 09:26 AM.
Reply With Quote
  #5  
Old 09-11-2018, 12:44 PM
tomd2121 tomd2121 is offline
What's HL7?
 
Join Date: Sep 2018
Posts: 3
tomd2121 is on a distinguished road
Default

Excellent Code Guru!!!

Saved me and saved the day.

Thanks!
Reply With Quote
  #6  
Old 09-11-2018, 10:10 PM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 808
siddharth is on a distinguished road
Default

Behind every great piece of code, there is Tony!
__________________
HL7v2.7 Certified Control Specialist!
Reply With Quote
  #7  
Old 09-12-2018, 04:55 AM
stormcel stormcel is offline
OBX.3 Kenobi
 
Join Date: Mar 2010
Location: Phoenix
Posts: 139
stormcel is on a distinguished road
Unhappy

Quote:
Originally Posted by agermano View Post

Excellent post, by the way. Your problem and goal were explained very well.
Tony never compliments my questions.
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 12:13 AM.


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