0

I am trying to write a JavaScript to remove string in OBX 5.1 after "\."

Here is the inbound OBX segment:

OBX|2|NM|WBC^White Blood Cell Count^WinPath||3.2\\.br\\This result could indicate your patient might have\\.br\\sepsis. Take into consideration the absolute\\.br\\neutrophil and lymphocyte counts when making your|x 10^9/l|4 - 10|L|||F|||||

Here is the expected outbound OBX segment:

OBX|2|NM|WBC^White Blood Cell Count^WinPath||3.2|x 10^9/l|4 - 10|L|||F|||||

I have written this Javascript code. It is compiling but not removing the unwanted text.

Here is what I have written:

var RegExp_pattern = "\\.";

function indexOf(stringToTrim) {
    return stringToTrim.indexOf(RegExp_pattern);
}

function substring(ssstringToTrim) {
    return ssstringToTrim.substring(indexOf(OBX_TestValue), -1);
}


/* Single input message case */
var next = output.append(input[0]);


// loop through Order Group (OBR) & Result Group (OBX)
//
var cntObs = next.getRepeatCount("ObservationMessage");
for (var i = 0; i < cntObs; i++) {
    var cntOrders = next.getRepeatCount("ObservationMessage[" + i + "]/Order");
    for (var j = 0; j < cntOrders; j++) {
        var cntResults = next.getRepeatCount("ObservationMessage[" + i + "]/Order[" + j + "]/Results");
        for (var k = 0; k < cntResults; k++) {


            var OBX_TestValue = next.getField("ObservationMessage[" + i + "]/Order[" + j + "]/Results[" + k + "]/OBX/ObservationValue");


            if (OBX_TestValue.indexOf(OBX_TestValue) > 0) {


                OBX_TestValue = substring(OBX_TestValue);


            }

        }

    }
}
user229044
  • 232,980
  • 40
  • 330
  • 338
softgi
  • 13
  • 5

1 Answers1

0

To remove everything from the first occurance of "\." until the end of the string you should use a regular expression.

var str = "OBX|2|NM|WBC^White Blood Cell Count^WinPath||3.2\\.br\\This result could indicate your patient might have\\.br\\sepsis. Take into consideration the absolute\\.br\\neutrophil and lymphocyte counts when making your|x 10^9/l|4 - 10|L|||F|||||";

var mtch = str.replace(/\\\..*/, '');
console.log(mtch);
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
  • Thank you for your help. I used this for my purpose: str = "OBX|2|NM|WBC^White Blood Cell Count^WinPath||3.2\\.br\\This result could indicate your patient might have\\.br\\sepsis. Take into consideration the absolute\\.br\\neutrophil and lymphocyte counts when making your|x 10^9/l|4 - 10|L|||F|||||"; r = str.replace(/\\\.[^|]*/,""); – softgi Nov 23 '21 at 23:06