web stats
Splitting NTE (only after OBR) - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 10-16-2013, 01:26 PM
seaston seaston is offline
OBX.3 Kenobi
 
Join Date: Feb 2010
Location: London, UK
Posts: 168
seaston is on a distinguished road
Default Splitting NTE (only after OBR)

I wonder if anyone can help with the following problem?

I want to split up NTE segments containing line breaks, but only when they appear under a OBR.

For example:

Code:
NTE|1|H_SETCOM_25DQ|  <30 nmol/L: severe vitamin D deficiency\.br\30-70 nmol/L: borderline deficiency ranging to insufficiency\.br\70-200 nmol/L: optimally replete\.br\ >250 nmol/L: possible vitamin D toxicity if sustained
would become

Code:
OBR|1|REFLEXVITD^HIS|E,13.7607716.Z_H_c^L|H_25DQ^25 OH Vitamin D^L~VITD^25 OH Vitamin D^HIS|R||20131016100300|||^|||NOTH|20131016152600|^^^^^|||||||20131016201400||Blood Sciences|F|||||||Thomas Ampatt
NTE|1|H_SETCOM_25DQ|  <30 nmol/L: severe vitamin D deficiency
NTE|2|H_SETCOM_25DQ|30-70 nmol/L: borderline deficiency ranging to insufficiency
NTE|3|H_SETCOM_25DQ|70-200 nmol/L: optimally replete
NTE|4|H_SETCOM_25DQ| >250 nmol/L: possible vitamin D toxicity if sustained
I am using the following code that will work on all NTE segments in the message:

Code:
for each (seg in msg.children()) {

	

	if (seg.name().toString() == "NTE") {
		
		var comm = seg['NTE.3']['NTE.3.1'].toString();
		var type = seg['NTE.2']['NTE.2.1'].toString();
		
		var ntes = <></>;
	
		if (comm.indexOf("\\.br\\") != -1) {
			var comms = comm.split("\\.br\\");
			for (c in comms) {
				var nte = <NTE/>;
				nte['NTE.1']['NTE.1.1'] = parseInt(c)+1;
				nte['NTE.2']['NTE.2.1'] = type;
				nte['NTE.3']['NTE.3.1'] = comms[c];
				//logger.info(nte.toString());
				//logger.info("index " + seg.childIndex() );
				ntes += nte ;
				
			}	
			//logger.info(ntes.toString());			    	
			//logger.info(msg.child(seg.childIndex()) );
			//delete msg.children()[seg.childIndex()];
			msg.insertChildAfter(msg.children()[seg.childIndex()], ntes);
			delete msg.children()[seg.childIndex()];
			
    	}
		
	}
}
How can I amend my code so that it will only act on NTEs following an OBR (and get the indexing correct in NTE.1)?

Last edited by seaston; 10-16-2013 at 01:30 PM.
Reply With Quote
  #2  
Old 10-16-2013, 01:38 PM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

You can use getSegmentsAfter:

Code:
for each (obr in msg.OBR) {
	var setID = 1;
	for each (nte in getSegmentsAfter(msg,obr,'NTE',true)) {
		var comm = nte['NTE.3']['NTE.3.1'].toString();
		var type = nte['NTE.2']['NTE.2.1'].toString();

		var ntes = <></>;

		if (comm.indexOf('\\.br\\') != -1) {
			var comms = comm.split('\\.br\\');
			for (c in comms) {
				var newNte = <NTE/>;
				newNte['NTE.1']['NTE.1.1'] = setID++;
				newNte['NTE.2']['NTE.2.1'] = type;
				newNte['NTE.3']['NTE.3.1'] = comms[c];
				ntes += newNte;
			}

			msg.insertChildAfter(nte,ntes);
			delete msg.children()[nte.childIndex()];
		} else {
			nte['NTE.1']['NTE.1.1'] = setID++;
		}
	}
}
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 10-16-2013, 01:54 PM
seaston seaston is offline
OBX.3 Kenobi
 
Join Date: Feb 2010
Location: London, UK
Posts: 168
seaston is on a distinguished road
Default

Very clever Nick. I have tried this and it works perfectly!
Reply With Quote
  #4  
Old 06-23-2014, 06:40 AM
LDHL7 LDHL7 is offline
Mirth Guru
 
Join Date: Apr 2011
Posts: 200
LDHL7 is on a distinguished road
Default

I had to complete essentially the same type of workflow, except in an NTE following the OBX. So I included the OBX iteration and used the getSegmentsAfter for the OBX, but it is returning a error of:

TypeError: Cannot read property "NTE.3.1" from undefined

If I change the getSegmentsAfter line to just read in all of the msg.NTE it does not error, but would also do this for all of the NTE segments in the message. I guess that would not be a problem, but I would like to understand why it is throwing the error

Message to transform:
Code:
MSH|^~\&|LAB||||201406021253||ORU^R01||P|2.4|||||||||
PID|1||0041121||CPSI^TEST^PATIENT^||19681231|M|||111 CPSI WAY^^MOBILE^AL^36695||2516398100|||||CPSI011|012345678|||||||||||||||||
ORC|RE|243960120140514|183744||||||201405141331|||999999^ER^^^^^^P||||^|
OBR|2|243960120140514|183744|4360426^TESTOSTERONE FREE^CPL_MISYS^84402^^CPT|||201405141331||||A|||201405141331||999999^ER^^^^^^P||||CPL_MISYS||201405231751|||F||1^^^^^R^^^||||||||||
DG1|1|I9|789.00|Abdmnal pain unspcf site|201405141331||||||||||
DG1|2|I9|401.9|Hypertension NOS|201405141331||||||||||
DG1|3|I9|250.00|DMII wo cmp nt st uncntr|201405141331||||||||||
DG1|4|I9|715.90|Osteoarthros NOS-unspec|201405141331||||||||||
DG1|5|I9|V58.69|Long-term use meds NEC|201405141331||||||||||
OBX|1|NM|E5772^Testosterone Free||4.30|ng/dL|0.95-4.30||||F|||201405231751||||||201405231751
NTE|1|L|\.br\ REFERENCE RANGE for Testosterone Free\.br\        Males:\.br\          20-49 yrs . . . . . 0.95-4.30 ng/dL\.br\          > or = 50 yrs . . . 0.80-3.50 ng/dL\.br\        Females:\.br\          Ovulating . . . .  Up to 0.38 ng/dL\.br\          Postmenopausal. .  Up to 0.18 ng/dL\.br\
Transformer:
Code:
for each(obr in msg.OBR){
	for each (obx in msg.OBX){
		var setID = 1;
		for each (nte in getSegmentsAfter(msg,obx,'NTE')){
				var comm = nte['NTE.3']['NTE.3.1'].toString();

				var ntes = <></>;

				if (comm.indexOf('\\.br\\') != -1) {
					var comms = comm.split('\\.br\\');
					for (c in comms) {
						var newNte = <NTE/>;
						newNte['NTE.1']['NTE.1.1'] = setID++;
						newNte['NTE.2']['NTE.2.1'] = 'L';
						newNte['NTE.3']['NTE.3.1'] = comms[c];
						ntes += newNte;
					}

					msg.insertChildAfter(nte,ntes);
					delete msg.children()[nte.childIndex()];
				} else {
					nte['NTE.1']['NTE.1.1'] = setID++;
				}
		}
	}
}
Reply With Quote
Reply

Tags
multiple, nte, split

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 09:55 AM.


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