Skip to content

Commit

Permalink
removing copied CSV ENUMs, uppercasing where the ENUMs are being eval…
Browse files Browse the repository at this point in the history
…uated instead.
  • Loading branch information
shaselton-usds committed Jan 16, 2024
1 parent 44b1067 commit 194603b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
29 changes: 15 additions & 14 deletions src/versions/1.1/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ import {
DrugUnit,
} from "./types.js"

// CSV is being allowed to have case insensitive values...
const STATE_CODES_CSV = STATE_CODES.map((state) => state.toLowerCase())
const BILLING_CODE_TYPES_CSV = BILLING_CODE_TYPES.map((code) =>
code.toLowerCase()
)
const DRUG_UNITS_CSV = DRUG_UNITS.map((unit) => unit.toLowerCase())

export const HEADER_COLUMNS = [
"hospital_name",
"last_updated_on",
Expand Down Expand Up @@ -210,7 +203,9 @@ export function validateRow(
)

if (
!BILLING_CODE_TYPES_CSV.includes(row["code | 1 | type"] as BillingCodeType)
!BILLING_CODE_TYPES.includes(
row["code | 1 | type"].toUpperCase() as BillingCodeType
)
) {
errors.push(
csvErr(
Expand All @@ -220,7 +215,7 @@ export function validateRow(
ERRORS.ALLOWED_VALUES(
"code | 1 | type",
row["code | 1 | type"],
BILLING_CODE_TYPES_CSV as unknown as string[]
BILLING_CODE_TYPES as unknown as string[]
),
true
)
Expand All @@ -230,7 +225,9 @@ export function validateRow(
// TODO: Code itself is required, need to check all of those, not all checked here
if (
row["code | 2"] &&
!BILLING_CODE_TYPES_CSV.includes(row["code | 2 | type"] as BillingCodeType)
!BILLING_CODE_TYPES.includes(
row["code | 2 | type"].toUpperCase() as BillingCodeType
)
) {
errors.push(
csvErr(
Expand All @@ -240,7 +237,7 @@ export function validateRow(
ERRORS.ALLOWED_VALUES(
"code | 2 | type",
row["code | 2 | type"],
BILLING_CODE_TYPES_CSV as unknown as string[]
BILLING_CODE_TYPES as unknown as string[]
)
)
)
Expand Down Expand Up @@ -292,7 +289,11 @@ export function validateRow(
)
)
}
if (!DRUG_UNITS_CSV.includes(row["drug_type_of_measurement"] as DrugUnit)) {
if (
!DRUG_UNITS.includes(
row["drug_type_of_measurement"].toUpperCase() as DrugUnit
)
) {
errors.push(
csvErr(
index,
Expand All @@ -301,7 +302,7 @@ export function validateRow(
ERRORS.ALLOWED_VALUES(
"drug_type_of_measurement",
row["drug_type_of_measurement"],
DRUG_UNITS_CSV as unknown as string[]
DRUG_UNITS as unknown as string[]
)
)
)
Expand Down Expand Up @@ -389,7 +390,7 @@ function validateLicenseStateColumn(
return [csvErr(rowIndex, columnIndex, LICENSE_STATE, invalidMessage)]
}
const stateCode = column.split("|").slice(-1)[0].trim()
if (!STATE_CODES_CSV.includes(stateCode as StateCode)) {
if (!STATE_CODES.includes(stateCode.toUpperCase() as StateCode)) {
return [
csvErr(
rowIndex,
Expand Down
31 changes: 17 additions & 14 deletions src/versions/2.0/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import {
DrugUnit,
} from "./types"

// CSV is being allowed to have case insensitive values...
const STATE_CODES_CSV = STATE_CODES.map((state) => state.toLowerCase())
const BILLING_CODE_TYPES_CSV = BILLING_CODE_TYPES.map((code) =>
code.toLowerCase()
)
const DRUG_UNITS_CSV = DRUG_UNITS.map((unit) => unit.toLowerCase())

export const HEADER_COLUMNS = [
"hospital_name",
"last_updated_on",
Expand Down Expand Up @@ -208,7 +201,11 @@ export function validateRow(
)
)

if (!BILLING_CODE_TYPES_CSV(row["code | 1 | type"] as BillingCodeType)) {
if (
!BILLING_CODE_TYPES.includes(
row["code | 1 | type"].toUpperCase() as BillingCodeType
)
) {
errors.push(
csvErr(
index,
Expand All @@ -217,7 +214,7 @@ export function validateRow(
ERRORS.ALLOWED_VALUES(
"code | 1 | type",
row["code | 1 | type"],
BILLING_CODE_TYPES_CSV as unknown as string[]
BILLING_CODE_TYPES as unknown as string[]
),
true
)
Expand All @@ -227,7 +224,9 @@ export function validateRow(
// TODO: Code itself is required, need to check all of those, not all checked here
if (
row["code | 2"] &&
!BILLING_CODE_TYPES_CSV.includes(row["code | 2 | type"] as BillingCodeType)
!BILLING_CODE_TYPES.includes(
row["code | 2 | type"].toUpperCase() as BillingCodeType
)
) {
errors.push(
csvErr(
Expand All @@ -237,7 +236,7 @@ export function validateRow(
ERRORS.ALLOWED_VALUES(
"code | 2 | type",
row["code | 2 | type"],
BILLING_CODE_TYPES_CSV as unknown as string[]
BILLING_CODE_TYPES as unknown as string[]
)
)
)
Expand Down Expand Up @@ -289,7 +288,11 @@ export function validateRow(
)
)
}
if (!DRUG_UNITS_CSV.includes(row["drug_type_of_measurement"] as DrugUnit)) {
if (
!DRUG_UNITS.includes(
row["drug_type_of_measurement"].toUpperCase() as DrugUnit
)
) {
errors.push(
csvErr(
index,
Expand All @@ -298,7 +301,7 @@ export function validateRow(
ERRORS.ALLOWED_VALUES(
"drug_type_of_measurement",
row["drug_type_of_measurement"],
DRUG_UNITS_CSV as unknown as string[]
DRUG_UNITS as unknown as string[]
)
)
)
Expand Down Expand Up @@ -386,7 +389,7 @@ function validateLicenseStateColumn(
return [csvErr(rowIndex, columnIndex, LICENSE_STATE, invalidMessage)]
}
const stateCode = column.split("|").slice(-1)[0].trim()
if (!STATE_CODES_CSV.includes(stateCode as StateCode)) {
if (!STATE_CODES.includes(stateCode.toUpperCase() as StateCode)) {
return [
csvErr(
rowIndex,
Expand Down
4 changes: 2 additions & 2 deletions test/csv.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test("sample-1", async (t) => {
{
field: "code | 1 | type",
message:
'"code | 1 | type" value "c" is not one of the allowed values: "cpt", "hcpcs", "icd", "ms-drg", "r-drg", "s-drg", "aps-drg", "ap-drg", "apr-drg", "apc", "ndc", "hipps", "local", "eapg", "cdt", "rc", "cdm"',
'"code | 1 | type" value "c" is not one of the allowed values: "CPT", "HCPCS", "ICD", "MS-DRG", "R-DRG", "S-DRG", "APS-DRG", "AP-DRG", "APR-DRG", "APC", "NDC", "HIPPS", "LOCAL", "EAPG", "CDT", "RC", "CDM"',
path: "C4",
warning: true,
},
Expand All @@ -34,7 +34,7 @@ test("sample-1 maxErrors", async (t) => {
{
field: "code | 1 | type",
message:
'"code | 1 | type" value "c" is not one of the allowed values: "cpt", "hcpcs", "icd", "ms-drg", "r-drg", "s-drg", "aps-drg", "ap-drg", "apr-drg", "apc", "ndc", "hipps", "local", "eapg", "cdt", "rc", "cdm"',
'"code | 1 | type" value "c" is not one of the allowed values: "CPT", "HCPCS", "ICD", "MS-DRG", "R-DRG", "S-DRG", "APS-DRG", "AP-DRG", "APR-DRG", "APC", "NDC", "HIPPS", "LOCAL", "EAPG", "CDT", "RC", "CDM"',
path: "C4",
warning: true,
},
Expand Down

0 comments on commit 194603b

Please sign in to comment.