Skip to content

Commit

Permalink
subtle bug that will trigger duplicate columns when there are not dup…
Browse files Browse the repository at this point in the history
…licates. Added functionality to detect duplicates when column headers are not part of the initially calculated required headers for CSV wide
  • Loading branch information
shaselton-usds committed May 22, 2024
1 parent 6716018 commit 6ed08e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/versions/2.0/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ export function validateColumns(columns: string[]): CsvValidationError[] {
duplicateErrors.push(
csvErr(rowIndex, index, "column", ERRORS.DUPLICATE_COLUMN(column))
)
} else {
// Even if the column isn't part of the calculated remainingColumns, we still want to add it to the discoveredColumns array
discoveredColumns[index] = column
}
}
})
Expand Down
5 changes: 4 additions & 1 deletion src/versions/common/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export function cleanColumnNames(columns: string[]) {
export function sepColumnsEqual(colA: string, colB: string) {
const cleanA = colA.split("|").map((v) => v.trim().toUpperCase())
const cleanB = colB.split("|").map((v) => v.trim().toUpperCase())
return cleanA.every((a, idx: number) => a === cleanB[idx])
return (
cleanA.length === cleanB.length &&
cleanA.every((a, idx: number) => a === cleanB[idx])
)
}

export const ASCII_UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Expand Down
15 changes: 15 additions & 0 deletions test/2.0/csv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,16 @@ test("validateColumns wide", (t) => {
"estimated_amount | Payer One | Basic Plan",
"additional_payer_notes | Payer One | Basic Plan",
]

//The idea is that a column could be misnamed.
const additionalColumns = [
"standard_charge|[payer_AETNA LIFE AND CAUSAULTY | HMO/PPO]",
"standard_charge|[payer_AETNA LIFE AND CAUSAULTY | HMO/PPO] |percent",
"standard_charge|[payer_AETNA LIFE AND CAUSAULTY | HMO/PPO] |contracting_method",
"additional_payer_notes |[payer_AETNA LIFE AND CAUSAULTY | HMO/PPO]",
"standard_charge|[payer_ASR HEALTH BEN CIGNA | COMMERCIAL]",
"standard_charge|[payer_ASR HEALTH BEN CIGNA | COMMERCIAL]",
]
t.is(validateColumns(columns).length, 0)
// any order is okay
const reverseColumns = [...columns].reverse()
Expand All @@ -977,6 +987,11 @@ test("validateColumns wide", (t) => {
"Column additional_payer_notes | Payer One | Basic Plan is miscoded or missing from row 3. You must include this column and confirm that it is encoded as specified in the data dictionary."
)
t.is(someColumnsMissingErrors[1].warning, undefined)

const customWideColumns = [...columns, ...additionalColumns]

const someDuplicateErrors = validateColumns(customWideColumns)
t.is(someDuplicateErrors.length, 12)
})

test("validateRow wide conditionals", (t) => {
Expand Down

0 comments on commit 6ed08e8

Please sign in to comment.