Announcement

Collapse
No announcement yet.

Multiple Comments for Results Question

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

  • Multiple Comments for Results Question

    Hi All,

    I tried to use the getSegmentsAfter to get the all comments of the results like the following data format.

    I want to get the all consecutive Comment ('C') after the first R segment:
    for each (c in getSegmentsAfter(msg,msg.R[i],'C',true))

    But in fact, I get the Comment from the Order ('O').

    I have no idea where is worng. Could you help to check and fix it?

    ----------------------
    Data Format:

    H|\^&|||NUD-57N1||||||||1|20180806094836
    P|1||||^|||U||||||||^^^|||||||||
    O|1||Sample #^171412|^^^12345|||||||||||Not specified^||||||||||C
    C|1|I|111^test||I
    R|1|^^^pH^M|7.055||^^^|N||F|||20180806095200|20180 806095200
    C|1|I|789^The result has a question||I
    C|2|I|476^device error||I
    R|2|^^^pO2^M|155|mmHg|^^^|N||F
    ----------

    The transform code:
    --------------------
    $co('resultsArray',[]);

    var i = 0;
    var j = 0;
    for each (R in msg.R){
    var reslutInfo = {};

    reslutInfo.examName = msg['R'][i]['R.2']['R.2.4'].toString();
    reslutInfo.examType = msg['R'][i]['R.4']['R.4.1'].toString();
    reslutInfo.examValue = msg['R'][i]['R.3']['R.3.1'].toString();
    reslutInfo.examMinValue = msg['R'][i]['R.5']['R.5.1'].toString();
    reslutInfo.examMaxValue = msg['R'][i]['R.5']['R.5.2'].toString();

    for each (c in getSegmentsAfter(msg,msg.R[i],'C',true)) {

    reslutInfo.comment += msg['C'][j]['C.3']['C.3.1'].toString() + '_'+ msg['C'][j]['C.3']['C.3.2'].toString() + ' ';
    j++;
    }
    i++;
    $co('resultsArray').push(reslutInfo);
    }

  • #2
    I'm not familiar with that data format, but usually you don't want to mix index variables (i,j) with for each..in or for..in loops. This might work for you.

    Code:
    $co('resultsArray',[]);
    
    for each (var R in msg.R){
    	var resultInfo = {};
    
    	resultInfo.examName = R['R.2']['R.2.4'].toString();
    	resultInfo.examType = R['R.4']['R.4.1'].toString();
    	resultInfo.examValue = R['R.3']['R.3.1'].toString();
    	resultInfo.examMinValue = R['R.5']['R.5.1'].toString();
    	resultInfo.examMaxValue = R['R.5']['R.5.2'].toString();
    
    	resultInfo.comment = '';
    
    	for each (var c in getSegmentsAfter(msg, R, 'C', true)) {
    		resultInfo.comment += c['C.3']['C.3.1'].toString() + '_'+ c['C.3']['C.3.2'].toString() + ' ';
    	}
    	$co('resultsArray').push(resultInfo);
    }

    Comment


    • #3
      Hi agermano,

      I tried it and it work fine now. Thanks for your help.

      Comment

      Working...
      X