Skip to content

Commit

Permalink
Issue #7: Refactor input validation code
Browse files Browse the repository at this point in the history
Check <health card, province> pair that was already encountered on a previous line
  • Loading branch information
veronikaslc committed Oct 19, 2020
1 parent e38ee1a commit 9ebff55
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion guids-generator.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@
return HC_VALIDATOR[province](value, dob) || HC_VALIDATOR['CA'](value);
}

// For any line check previously enered lines that contains a <health card, province> pair
let checkDuplicates = (line, healthCard, province, postProcessed, index) => {
let duplicates = postProcessed.filter( item => (item.healthCard == healthCard && item.province == province) );
if (duplicates.length > 0) {
return {"error" : province + " health card number " + line.trim().split(/[\t,]+/)[0] + " has already been entered on line " + index + " with a different date of birth"};

This comment has been minimized.

Copy link
@marta-

marta- Oct 19, 2020

Contributor

Wrong index reported, should be the one from the first identified duplicate

This comment has been minimized.

Copy link
@marta-

marta- Oct 19, 2020

Contributor

Addressed in 410f7f9

}
return {};
}

// Input validation and sanitising
let validate = () => {
let value = binput;
Expand Down Expand Up @@ -322,8 +331,15 @@
info[0] = healthCard;
}

// Check duplicated <health card, province> pair
let duplicates = checkDuplicates(line, healthCard, province, postProcessed, index);
if (duplicates.error) {
postProcessed.push({"line" : line, "index": index, "value": duplicates.error, "isError": true});
continue;
}

// If the input is found valid, concatenate the post-processed health card number and date of birth and generate the GUID
postProcessed.push({"line" : line, "index": index, "value": info[0] + info[2]});
postProcessed.push({"line" : line, "index": index, "healthCard": healthCard, "province": province, "value": info[0] + info[2]});
}

setValidatedData(postProcessed);
Expand Down

0 comments on commit 9ebff55

Please sign in to comment.