I'm trying to accomplish padding PID3 with zeros when PID3 is less than 8 digits in length. Ultimately the MRN field should always be 8char
Here's the code that I'm struggling with. When ran the variable "val" is not recognized.
//Pad with 0's
function padleft(val, ch, num) {
var re = new RegExp(".{" + 8 + "}$");
var pad = "";
var val = msg['PID']['PID.3']['PID.3.1'].toString();
}
if (val.length < 8)
do {
pad += 0;
}while(pad.length < 8);
return re.exec(pad + val);
SAMPLE MSG:
MSH|^~\&|ONLINE_ORDERS|WMH|||20080104171437||ORM^O 01|1|P|2.3|||NE|NE
PID|||909-2||TEST^JACK|||||B|123 B STREET^^INDIANAPOLIS^IN^46202||()||||||999-99-9999
PV1||I|4N^^W4112A|||MED1^^W4112A
ORC|NW|D527-1^GPHI|||||||20080104171437|10083-4||10083-4^WARVEL^JACK^^^^^^^^4^^DN
OBR|002|D527-1^GPHI||12236^CALCIUM^STAR||20080104171256|||||||| ||10083-4^WARVEL^JACK^^^^^^^^4^^DN||||||||T|||QAM|||||1008 3-4
NTE|003||QAM
Thanks,
D
Here's the code that I'm struggling with. When ran the variable "val" is not recognized.
//Pad with 0's
function padleft(val, ch, num) {
var re = new RegExp(".{" + 8 + "}$");
var pad = "";
var val = msg['PID']['PID.3']['PID.3.1'].toString();
}
if (val.length < 8)
do {
pad += 0;
}while(pad.length < 8);
return re.exec(pad + val);
SAMPLE MSG:
MSH|^~\&|ONLINE_ORDERS|WMH|||20080104171437||ORM^O 01|1|P|2.3|||NE|NE
PID|||909-2||TEST^JACK|||||B|123 B STREET^^INDIANAPOLIS^IN^46202||()||||||999-99-9999
PV1||I|4N^^W4112A|||MED1^^W4112A
ORC|NW|D527-1^GPHI|||||||20080104171437|10083-4||10083-4^WARVEL^JACK^^^^^^^^4^^DN
OBR|002|D527-1^GPHI||12236^CALCIUM^STAR||20080104171256|||||||| ||10083-4^WARVEL^JACK^^^^^^^^4^^DN||||||||T|||QAM|||||1008 3-4
NTE|003||QAM
Thanks,
D
Comment