Forgive me if this is in the wrong area of the forum. I am trying to create a simple import of a CSV file with quotes. I am running the script belown in the preprocessor and have just one problem: If the field contains a comma, it tries to make it into two fields.
Example "AAA111111","XX-01-87(06)","SMITH, JOE P",07/XX/07,
I get the fields:
AAA111111
XX-01-87(06)
SMITH
JOE P
07/XX/07
I am new to JS, but I am pretty sure that there should be a way to ignore a comma inside of a set of quotes. Any help would be appreciated.
John
Code:
// Modify the message variable below to pre process data
message = message.replace(/[\r\n]/g, "\n");
var columnnames = new Array("Chart","XRay","PatientName","DateScheduled" ,"DOB","Sex","ReferenceCode","Doctor","ReferenceNo ","Recall","Reason");
var nofcolumns = 11;
var lines = new Array();
var newmessage = new String();
newmessage = "<!-- Generated using Mirth PreProc -->\n";
newmessage += "<Root>\n";
rawData = message;
lines = rawData.split("\n");
for (var i=0;i<lines.length;i++) {
currline = lines[i];
newmessage += "<Patient>\n";
var data = new Array();
data = currline.split(Chr()",");
for (var j = 0; j < nofcolumns; j++){
newmessage += "<" + columnnames[j] + ">" + data[j] + "</" + columnnames[j] + ">\n";
}
newmessage += "</Patient>\n";
}
newmessage += "</Root>\n";
return newmessage
return message;
Example "AAA111111","XX-01-87(06)","SMITH, JOE P",07/XX/07,
I get the fields:
AAA111111
XX-01-87(06)
SMITH
JOE P
07/XX/07
I am new to JS, but I am pretty sure that there should be a way to ignore a comma inside of a set of quotes. Any help would be appreciated.
John
Code:
// Modify the message variable below to pre process data
message = message.replace(/[\r\n]/g, "\n");
var columnnames = new Array("Chart","XRay","PatientName","DateScheduled" ,"DOB","Sex","ReferenceCode","Doctor","ReferenceNo ","Recall","Reason");
var nofcolumns = 11;
var lines = new Array();
var newmessage = new String();
newmessage = "<!-- Generated using Mirth PreProc -->\n";
newmessage += "<Root>\n";
rawData = message;
lines = rawData.split("\n");
for (var i=0;i<lines.length;i++) {
currline = lines[i];
newmessage += "<Patient>\n";
var data = new Array();
data = currline.split(Chr()",");
for (var j = 0; j < nofcolumns; j++){
newmessage += "<" + columnnames[j] + ">" + data[j] + "</" + columnnames[j] + ">\n";
}
newmessage += "</Patient>\n";
}
newmessage += "</Root>\n";
return newmessage
return message;
Comment