Announcement

Collapse
No announcement yet.

Splitting NTE (only after OBR)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 01:30 PM.

  • #2
    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.

    Comment


    • #3
      Very clever Nick. I have tried this and it works perfectly!

      Comment


      • #4
        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++;
        				}
        		}
        	}
        }

        Comment

        Working...
        X