From 77b63ac59ac2f85c7dff8e468c4922bfdaa05598 Mon Sep 17 00:00:00 2001 From: cecilia-donnelly Date: Wed, 5 Aug 2015 12:27:55 -0500 Subject: [PATCH] Start import sorting: #25 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. --- public/js/index.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index 468464a..f3c054c 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -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 }); }