web stats
deleting entire segment in hl7 message - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-12-2019, 05:39 AM
daniel_11223 daniel_11223 is offline
What's HL7?
 
Join Date: Jul 2019
Posts: 4
daniel_11223 is on a distinguished road
Default deleting entire segment in hl7 message

Hey,

i have a little problem. I created a transformer. I need to search for several FT1 Segments. If FT1.20.1 is like the case 26640,26646 or 26447 then do nothing. Otherwise delete this complete FT1 line.

I dont know, where my problem is. Maybe somebody can help me?

Code:
for each (ft1 in msg.FT1)

switch (ft1['FT1.20']['FT1.20.1'].toString()) {
	case '26640':
	case '26646':		
	case '26647':
	break;

	default:
	delete ft1;
}

This is a part of my HL7 Message:

FT1|1|38930309|10021|201908100734|||3560^Glukose ^H|UPDATE||1||||||||||22510^^^^^^^^^^^^CC|53001^^^ ^^^^^^^^^CC~^^^^^^^^^^^^XX|1
FT1|2|38930310|10021|201908101034|||3560^Glukose ^H|UPDATE||1||||||||||22510^^^^^^^^^^^^CC|53001^^^ ^^^^^^^^^CC~^^^^^^^^^^^^XX|1
FT1|3|38921358|10021|201908101300|||A3/S3^3^H|UPDATE||1||||||||||53001^^^^^^^^^^^^CC~^^^^ ^^^^^^^^XX|53001^^^^^^^^^^^^CC~^^^^^^^^^^^^XX|1
FT1|4|38930311|10021|201908101423|||3560^Glukose ^H|UPDATE||1||||||||||22510^^^^^^^^^^^^CC|53001^^^ ^^^^^^^^^CC~^^^^^^^^^^^^XX|1
FT1|5|38930312|10021|201908101923|||3560^Glukose ^H|UPDATE||1||||||||||22510^^^^^^^^^^^^CC|53001^^^ ^^^^^^^^^CC~^^^^^^^^^^^^XX|1
FT1|6|38932081|10021|201908111300|||A3/S3^3^H|UPDATE||1||||||||||53001^^^^^^^^^^^^CC~^^^^ ^^^^^^^^XX|53001^^^^^^^^^^^^CC~^^^^^^^^^^^^XX|1
FT1|7|38937630|10021|201908121150|||DYSPHAGIE_D^Dy sphagiediagnostik 20 Min.^H|INSERT||1||||||||||26647^^^^^^^^^^^^CC~^^^^ ^^^^^^^^XX|53001^^^^^^^^^^^^CC~^^^^^^^^^^^^XX|1|LS TM-2019-038754-1|^^^^^^^^^L
FT1|8|38936352|10021|201908121300|||3^H|UPDATE||1| |||||||||53001^^^^^^^^^^^^CC~^^^^^^^^^^^^XX|53001^ ^^^^^^^^^^^CC~^^^^^^^^^^^^XX|1
Reply With Quote
  #2  
Old 08-12-2019, 06:20 AM
mdehoog mdehoog is offline
Mirth Guru
 
Join Date: Mar 2011
Location: Apeldoorn the Netherlands
Posts: 289
mdehoog is on a distinguished road
Send a message via Skype™ to mdehoog
Default add {}

Did not test it but should you not add {} for the for each?
Code:
for each (ft1 in msg.FT1){
	switch (ft1['FT1.20']['FT1.20.1'].toString()) {
		case '26640':
		case '26646':		
		case '26647':
		break;
	
		default:
		delete ft1;
	}
}
__________________
X Connections
https://documentor.email
https://www.x-connections.com
Reply With Quote
  #3  
Old 08-12-2019, 07:08 AM
mdehoog mdehoog is offline
Mirth Guru
 
Join Date: Mar 2011
Location: Apeldoorn the Netherlands
Posts: 289
mdehoog is on a distinguished road
Send a message via Skype™ to mdehoog
Default Multiple FT1.20.1 segments

Also you have multiple FT1.20.1 segments in some of your FT1 segments..

This will result in the fact your case statement will have this as a value: <FT1.20.1>53001</FT1.20.1><FT1.20.1/> Not just the number.
But it would still work.

delete ft1 seems not to work.

Give this a try:

Code:
var i = 0;

for each (ft1 in msg.FT1){
	logger.info(ft1['FT1.20']['FT1.20.1'].toString());
	
	switch (ft1['FT1.20']['FT1.20.1'].toString()) {		
		case '26640':
			break;
		case '26646':		
			break;
		case '26647':
			break;

		default:
			logger.info("ft1 = " + ft1);
			delete msg['FT1'][i];
			break;
	}
	i++;
}
__________________
X Connections
https://documentor.email
https://www.x-connections.com
Reply With Quote
  #4  
Old 08-12-2019, 07:40 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 861
agermano is on a distinguished road
Default

Changing delete ft1; to delete ft1[0]; should get the delete to work, but you also have repeating FT1.20 fields in some of your segments, including the segment from the sample that you wish to keep.

Calling ft1['FT1.20']['FT1.20.1'].toString() for those segments which have a repeating FT1-20 field will return XML, so it won't match your switch cases causing the segment to get deleted.

Code:
for each (var ft1 in msg.FT1) {
    // Use e4x filter to find repetition where type is 'CC'
    var ft1_20 = ft1['FT1.20'].(function() {return new XML(this)['FT1.20.13'].toString() == 'CC'}());
    switch (ft1_20['FT1.20.1'].toString()) {
        case '26640':
        case '26646':		
        case '26647':
        break;

        default:
        delete ft1[0];
    }
}
The filter line is the equivalent of doing this:
Code:
    // Intialize with empty XMLList
    var ft1_20 = <></>;
    for each (var rep in ft1['FT1.20']) {
        if (rep['FT1.20.13'].toString() == 'CC') {
            ft1_20 += rep;
        }
    }
This solution assumes there will be at most one repetition where the type is CC.
Reply With Quote
  #5  
Old 08-12-2019, 10:03 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 861
agermano is on a distinguished road
Default

Oops, I had this open for a while before I responded to it. Didn't realize @mdehoog had already identified the repeating field issue.

As far as his first question, those curly braces weren't required in the additional code. It would have made it more readable, but they are optional when there is only a single statement (the switch) in the loop.

Last edited by agermano; 08-12-2019 at 10:05 AM.
Reply With Quote
  #6  
Old 08-14-2019, 02:36 AM
daniel_11223 daniel_11223 is offline
What's HL7?
 
Join Date: Jul 2019
Posts: 4
daniel_11223 is on a distinguished road
Default

solution was easy.

I just had to replace "delete ft1" with "delete ft1[0]" like agermano said. Sometimes its just those small things

thank you very much!
Reply With Quote
  #7  
Old 08-15-2019, 12:06 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 861
agermano is on a distinguished road
Default

Not sure if you're going to check back on this thread, but as @mdehoog and I both pointed out, you have another issue. When FT1-20 repeats, you will always delete that segment, even if the segment contains one of the values you want to keep.
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:18 AM.


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