Skip to content

Commit

Permalink
Start import sorting: #25
Browse files Browse the repository at this point in the history
Test whether a record to be imported has an SSN that matches an existing
record.  This commit adds several lines for interpreting the response
from the Node server.  Those may change.  I just tested with a file that
was exported from our db and PapaParse didn't split the lines into their
own arrays as it should, so it looked like the whole file was in one
array (which meant that the rest of the code did not work correctly).
Next commit will resolve that and possibly add the POST lines for new
data.  I need to turn the csv record into a correctly formatted Client,
before POSTing.
  • Loading branch information
cecilia-donnelly committed Aug 5, 2015
1 parent f356e4c commit 77b63ac
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,11 +989,36 @@ $(function() {
}).done(function(response) {
// read each line of file
var result = Papa.parse(response);
console.log("DEBUG: " + result);
// set the data as its own array
var data_array = result['data'];
// check whether there even is an ssn column (assumes there
// is a header row)
var data_header = data_array[0];
var ssn_index = data_header.indexOf("SocialSecurityNumber");
// get all existing ssn's
// full set of data retrieved via API
var dataset = $("#index").data("full-data");
var ssn_array = [];
for (var client in dataset){
ssn_array.push(dataset[client]['ssn']);
}
// loop through array
// for each line, check whether ssn exists via API
// if it does, put that record in a list of possible duplicates
// if it doesn't, POST that record to the API
var line_counter = 1;
for (var line in data_array){
if (data_array.hasOwnProperty(line)) {
// for each line, check whether ssn exists via API
// if it does, put that record in a list of possible duplicates
if (ssn_array.indexOf(data_array[line][ssn_index]) > 0) {
console.log("DEBUG: line " + line_counter + " already exists");
}
// if it doesn't, POST that record to the API
else {
console.log("DEBUG: ready to import line: " + line_counter);

}
}
line_counter++;
}
// display the list of possible duplicates to the user
});
}
Expand Down

0 comments on commit 77b63ac

Please sign in to comment.