web stats
Move NTE Section Down below OBX when OBX is last. - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 10-11-2019, 09:48 AM
fosterb fosterb is offline
What's HL7?
 
Join Date: Jan 2013
Posts: 3
fosterb is on a distinguished road
Default Move NTE Section Down below OBX when OBX is last.

I can't seem to find any code that accomplishes what I want to do. I have tried several of the getSegmentsAfter examples, but none have worked. Several move the NTE segments around or delete the rows.

What I am trying to accomplish is to change this message:

MSH|^~\&|MIC|DOM|||20191011081033-0400||ORU^R01|1654390.1|P|2.3|
PID|1|||||||||||||||D||D1|
PV1|1|O|LAB ONLY|EL||||||||||PHY||||REF||HMOMCR||||||||||||||| ||||DOM||REG|||201910090928|
IN1|1|HCPPO|||||||||||||||SP||||||||||||20191009|| ||||||||||||M||PENDING|
OBR|1|2545100^MIC|2545100^MIC|AFB^AFB CULTURE^L|||201910090400|||||||201910090934|SPUT|| |||||||MB|P||^^^^^R||^MIC|
NTE|1||TEST NOT PERFORMED|
NTE|2||TEST NOT PERFORMED|
NTE|3||TEST NOT PERFORMED|
NTE|4||NOTIFIED OFFICE 10/10/19 11:00|
OBR|2|2545100^MIC|2545100^MIC|SPUTCX^SPUTUM CULTURE^L|||201910090400|||||||201910090934|SPUT|| |||||||MB|F||^^^^^R||^MIC|
NTE|5|| Source: SPUTUM Collected: 10/09/19 04:00|
NTE|6|| Site: Received : 10/09/19 14:06|
NTE|7|
NTE|8||Comments:|
NTE|9|
NTE|10|
NTE|11|
NTE|12|
NTE|13||19:MR0|
NTE|14||GRAM STAIN FINAL 10/09/19|
NTE|15|
NTE|16||>10 Squamous Epithelial Cells/low power field|
NTE|17||<25 PMN's/low power field|
NTE|18||The presence of large numbers of Squamous Epithelial|
NTE|19||Cells indicates that the specimen is contaminated with|
NTE|20||oropharyngeal microorganisms. Specimen not cultured|
NTE|21||for organisms colonizing the upper respiratory tract|
NTE|22||airways or mouth.|
OBX|1|ST|GSTAIN^GRAM STAIN^L||MICRO REPORT FOLLOWS||||||F|||201910091803||
NTE|23|| Source: SPUTUM Collected: 10/09/19 04:00|
NTE|24|| Site: Received : 10/09/19 14:06|
NTE|25|
NTE|26||Comments:|
NTE|27|
NTE|28|
NTE|29|
NTE|30|
NTE|31||19:MR00|
NTE|32||AEROBIC CULTURE CANCELLED 10/09/19|
NTE|33|
NTE|34|| Test not performed Refer to Gram Stain result.|
NTE|35|
OBX|2|ST|AERSPU^AEROBIC CULTURE^L||MICRO REPORT FOLLOWS||||||F|||201910091803||
NTE|36|| Source: SPUTUM Collected: 10/09/19 04:00|
NTE|37|| Site: Received : 10/09/19 14:06|
NTE|38|
NTE|39||Comments:|
NTE|40|
NTE|41|
NTE|42|
NTE|43|
NTE|44||19:MR0|
NTE|45||LEGIONELLA CULTURE PRELIMINARY 10/10/19|
NTE|46|
NTE|47||Testing in progress|
OBX|3|ST|LEGSPUT^LEGIONELLA CULTURE^L||MICRO REPORT FOLLOWS||||||P|||201910101212||

To this new message with NTE groups below the OBX segment:

MSH|^~\&|MIC|DOM|||20191011081033-0400||ORU^R01|1654390.1|P|2.3|
PID|1|||||||||||||||D||D1|
PV1|1|O|LAB ONLY|EL||||||||||PHY||||REF||HMOMCR||||||||||||||| ||||DOM||REG|||201910090928|
IN1|1|HCPPO|||||||||||||||SP||||||||||||20191009|| ||||||||||||M||PENDING|
OBR|1|2545100^MIC|2545100^MIC|AFB^AFB CULTURE^L|||201910090400|||||||201910090934|SPUT|| |||||||MB|P||^^^^^R||^MIC|
NTE|1||TEST NOT PERFORMED|
NTE|2||TEST NOT PERFORMED|
NTE|3||TEST NOT PERFORMED|
NTE|4||NOTIFIED OFFICE 10/10/19 11:00|
OBR|2|2545100^MIC|2545100^MIC|SPUTCX^SPUTUM CULTURE^L|||201910090400|||||||201910090934|SPUT|| |||||||MB|F||^^^^^R||^MIC|
OBX|1|ST|GSTAIN^GRAM STAIN^L||MICRO REPORT FOLLOWS||||||F|||201910091803||
NTE|5|| Source: SPUTUM Collected: 10/09/19 04:00|
NTE|6|| Site: Received : 10/09/19 14:06|
NTE|7|
NTE|8||Comments:|
NTE|9|
NTE|10|
NTE|11|
NTE|12|
NTE|13||19:MR0|
NTE|14||GRAM STAIN FINAL 10/09/19|
NTE|15|
NTE|16||>10 Squamous Epithelial Cells/low power field|
NTE|17||<25 PMN's/low power field|
NTE|18||The presence of large numbers of Squamous Epithelial|
NTE|19||Cells indicates that the specimen is contaminated with|
NTE|20||oropharyngeal microorganisms. Specimen not cultured|
NTE|21||for organisms colonizing the upper respiratory tract|
NTE|22||airways or mouth.|
OBX|2|ST|AERSPU^AEROBIC CULTURE^L||MICRO REPORT FOLLOWS||||||F|||201910091803||
NTE|23|| Source: SPUTUM Collected: 10/09/19 04:00|
NTE|24|| Site: Received : 10/09/19 14:06|
NTE|25|
NTE|26||Comments:|
NTE|27|
NTE|28|
NTE|29|
NTE|30|
NTE|31||19:MR00|
NTE|32||AEROBIC CULTURE CANCELLED 10/09/19|
NTE|33|
NTE|34|| Test not performed Refer to Gram Stain result.|
NTE|35|
OBX|3|ST|LEGSPUT^LEGIONELLA CULTURE^L||MICRO REPORT FOLLOWS||||||P|||201910101212||
NTE|36|| Source: SPUTUM Collected: 10/09/19 04:00|
NTE|37|| Site: Received : 10/09/19 14:06|
NTE|38|
NTE|39||Comments:|
NTE|40|
NTE|41|
NTE|42|
NTE|43|
NTE|44||19:MR0|
NTE|45||LEGIONELLA CULTURE PRELIMINARY 10/10/19|
NTE|46|
NTE|47||Testing in progress|

Any ideas or threads for me to look at?

Thank You
Reply With Quote
  #2  
Old 10-11-2019, 11:39 AM
jackwhaines jackwhaines is offline
 
Join Date: May 2011
Location: Kansas City, Missouri
Posts: 181
jackwhaines is on a distinguished road
Send a message via Skype™ to jackwhaines
Default

I would probably use an iterator over all segments, move ALL the NTEs (after the OBX) into their own XML "groups", remove all the NTEs, and put them back in the appropriate places using the "Source:" in the first NTE maybe?
__________________

-= 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
  #3  
Old 10-11-2019, 11:49 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,277
cory_cole is on a distinguished road
Default

I wrote this for somebody else who was having a similar issue. After the last iteration of code, they were still having issues. I have had time to do more. Take a look at it. It should be at least enough to get you started.
Attached Files
File Type: xml LAB hl7 to PDF.xml (85.8 KB, 3 views)
Reply With Quote
  #4  
Old 10-11-2019, 06:58 PM
fosterb fosterb is offline
What's HL7?
 
Join Date: Jan 2013
Posts: 3
fosterb is on a distinguished road
Default

Ok, thank you , I will check it out.
Reply With Quote
  #5  
Old 10-12-2019, 05:43 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 964
agermano is on a distinguished road
Default

Code:
// Empty XMLList to hold accumulated NTE segments that belong together
var nteList = <></>;
// Array of objects containing nte segment lists and the obx segment with which they belong.
var nteGroups = [];

for each (var seg in msg.children()) {
    if (seg.localName() == 'NTE') {
        nteList += seg;
    }
    else {
        // The nteList accumulated so far gets associated with this obx segment
        if (seg.localName() == 'OBX') {
            nteGroups.push({nteList: nteList, obx: seg});
            // These segments will be added back later. Remove them from msg for now.
            for each (var nte in nteList) {
                delete msg.child(nte.childIndex())[0];
            }
        }
        // Accumulated list has either been added to nteGroups or is to be ignored. Reset the list.
        nteList = <></>;
    }
}
// Add saved and deleted groups back to msg.
nteGroups.forEach(function(group) {
    // insertChildAfter can insert XMLLists as well as single nodes. No need to add each segment individually.
    msg.insertChildAfter(group.obx[0], group.nteList);
});

Last edited by agermano; 10-12-2019 at 05:57 AM.
Reply With Quote
  #6  
Old 10-13-2019, 12:25 PM
ASIFM786 ASIFM786 is offline
Mirth Newb
 
Join Date: Oct 2008
Posts: 17
ASIFM786
Default

Quote:
Originally Posted by agermano View Post
Code:
// Empty XMLList to hold accumulated NTE segments that belong together
var nteList = <></>;
// Array of objects containing nte segment lists and the obx segment with which they belong.
var nteGroups = [];

for each (var seg in msg.children()) {
    if (seg.localName() == 'NTE') {
        nteList += seg;
    }
    else {
        // The nteList accumulated so far gets associated with this obx segment
        if (seg.localName() == 'OBX') {
            nteGroups.push({nteList: nteList, obx: seg});
            // These segments will be added back later. Remove them from msg for now.
            for each (var nte in nteList) {
                delete msg.child(nte.childIndex())[0];
            }
        }
        // Accumulated list has either been added to nteGroups or is to be ignored. Reset the list.
        nteList = <></>;
    }
}
// Add saved and deleted groups back to msg.
nteGroups.forEach(function(group) {
    // insertChildAfter can insert XMLLists as well as single nodes. No need to add each segment individually.
    msg.insertChildAfter(group.obx[0], group.nteList);
});
This is great agermano, this works well if you have one OBX and multiple NTE, but if you have Multiple OBX e.g. 10+ and multiple NTE how would you do that?
Reply With Quote
  #7  
Old 10-14-2019, 05:06 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 964
agermano is on a distinguished road
Default

Quote:
Originally Posted by ASIFM786 View Post
This is great agermano, this works well if you have one OBX and multiple NTE, but if you have Multiple OBX e.g. 10+ and multiple NTE how would you do that?
I'm not sure what you're talking about. It works for the example given in the original post.
Reply With Quote
  #8  
Old 10-14-2019, 07:11 AM
fosterb fosterb is offline
What's HL7?
 
Join Date: Jan 2013
Posts: 3
fosterb is on a distinguished road
Default

I have tried the code provided on several messages and it works perfectly for what I need. Thank You agermano for the code.
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 08:56 PM.


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