Announcement

Collapse
No announcement yet.

Filter - Javascript

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

  • Filter - Javascript

    I am using the below javascript to validate the message structure:
    MSH EVN PID PV1 [PD1] [{ROL}]

    But after PD1, I am not able to get it right. Any help is really appreciated.

    var index = 0;
    var insGroupIndex = 0;

    for each (seg in msg.children()) {
    var segName = seg.name().toString();

    if (index == 0 && segName != 'MSH' || index == 1 && segName != 'EVN' || index == 2 && segName != 'PID' || index == 3 && segName != 'PV1') {
    return false;
    } else if (index > 3 ) {
    if (insGroupIndex == 0 && segName != 'PD1')
    return false;
    if (segName != 'PD1')
    insGroupIndex = 0;
    if (insGroupIndex == 0 && segName != 'ROL')
    return false;
    insGroupIndex = (insGroupIndex + 1) % 3;
    }

    index++;
    }

    return true;

  • #2
    Using the below code I am able to validate MSH EVN PID PV1 [PD1] or MSH EVN PID PV1 [ROL]. But still not able to validate MSH EVN PID PV1 [PD1] [{ROL}]

    var index = 0;
    var GroupIndex = 0;
    var rGroupIndex = 0;

    for each (seg in msg.children()) {
    var segName = seg.name().toString();
    if (index == 0 && segName != 'MSH' || index == 1 && segName != 'EVN' || index == 2 && segName != 'PID' || index == 3 && segName != 'PV1') {
    return false;
    } else if (index > 3 && index < msg.children().length() - 1) {
    if (GroupIndex == 0 && segName != 'PD1' || rGroupIndex == 0 && segName != 'ROL')
    GroupIndex++;
    return false;
    }
    index++;
    }
    return true;

    How do I validate a message for the format MSH EVN PID PV1 [PD1] [{ROL}]

    Comment

    Working...
    X