Skip to content

Commit

Permalink
Add tests for remaining CSV errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-thompson committed Jan 6, 2025
1 parent d9eb601 commit e0cf580
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
16 changes: 16 additions & 0 deletions test/fixtures/sample-bad-header.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
hospital_name,last_updated_on,version,hospital_location,hospital_address,license_number|CA,"To the best of its knowledge and belief, the hospital has included all applicable standard charge information in accordance with the requirements of 45 CFR 180.50, and the information encoded is true, accurate, and complete as of the date indicated.",,,,,,,,,,,,,,
West Mercy Hospital,July 1 2024,2.0,West Mercy Hospital|West Mercy Surgical Center,"12 Main Street, Fullerton, CA 92832|23 Ocean Ave, San Jose, CA 94088",50056,true,,,,,,,,,,,,,,
Description,code|1,code|1|type,code|2,code|2|type,modifiers,setting,drug_unit_of_measurement,drug_type_of_measurement,standard_charge|gross,standard_charge|discounted_cash,payer_name,plan_name,standard_charge|negotiated_dollar,standard_charge|negotiated_percentage,standard_charge|negotiated_algorithm,estimated_amount,standard_charge|methodology,standard_charge|min,standard_charge|max,additional_generic_notes
Major hip and knee joint replacement or reattachment of lower extremity without mcc,470,MS-DRG,175869,LOCAL,,inpatient,,,,,Platform Health Insurance,PPO,20000,,MS-DRG,22243.34,case rate,20000,20000,
Major hip and knee joint replacement or reattachment of lower extremity without mcc,470,MS-DRG,175869,LOCAL,,inpatient,,,,,Platform Health Insurance,PPO,20000,,https://www.cms.gov/Outreach-and-Education/Medicare-Learning-Network-MLN/MLNProducts/html/images/OP.jpg,22243.34,case rate,20000,20000,
Major hip and knee joint replacement or reattachment of lower extremity without mcc,470,MS-DRG,175869,LOCAL,,inpatient,,,,,Platform Health Insurance,PPO,20000,,The adjusted base payment rate indicated in the standard_charge|negotiated_dollar data element may be further adjusted for additional factors including transfers and outliers.,22243.34,case rate,20000,20000,
Major hip and knee joint replacement or reattachment of lower extremity without mcc,470,MS-DRG,175869,LOCAL,,inpatient,,,,,Region Health Insurance,HMO,,50,,23145.98,percent of total billed charges,20000,20000,
"Evaluation of hearing function to determine candidacy for, or postoperative status of, surgically implanted hearing device; first hour",92626,CPT,,,,outpatient,,,150,125,Platform Health Insurance,PPO,98.98,,,,fee schedule,98.98,98.98,110% of the Medicare fee schedule
"Evaluation of hearing function to determine candidacy for, or postoperative status of, surgically implanted hearing device; first hour",92626,CPT,,,,outpatient,,,150,125,Region Health Insurance,HMO,,115,,105.34,fee schedule,98.98,98.98,115% of the state's workers' compensation amount
"Behavioral health; residential (hospital residential treatment program), without room and board, per diem",H0017,HCPCS,,,,inpatient,,,2500,2250,Platform Health Insurance,PPO,1500,,,,per diem,1500,1500,
"Behavioral health; residential (hospital residential treatment program), without room and board, per diem, days 1-3",H0017,hcpcs,,,,inpatient,,,2500,2250,Region Health Insurance,HMO,2000,,,,per diem,2000,2000,
"Behavioral health; residential (hospital residential treatment program), without room and board, per diem, days 4-5",H0017,HCPCS,,,,inpatient,,,2500,2250,Region Health Insurance,HMO,1800,,,,per diem,1800,1800,
"Behavioral health; residential (hospital residential treatment program), without room and board, per diem, days 6+",H0017,HCPCS,,,,inpatient,,,2500,2250,Region Health Insurance,HMO,1200,,,,per diem,1200,1200,
Treatment or observation room — observation room,762,RC,,,,outpatient,,,13000,12000,Platform Health Insurance,PPO,8000,,,,case rate,8000,10000,Negotiated standard charge without surgery and without rule out myocardial infarction
Treatment or observation room — observation room,762,RC,,,,outpatient,,,13000,12000,Platform Health Insurance,PPO,10000,,,,case rate,8000,10000,Negotiated standard charge without surgery and with rule out myocardial infarction
Treatment or observation room — observation room,762,RC,,,,outpatient,,,13000,12000,Region Health Insurance,HMO,9000,,,,case rate,8000,10000,
17 changes: 17 additions & 0 deletions test/fixtures/sample-blank-header.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
hospital_name,last_updated_on,version,hospital_location,hospital_address,license_number|CA,"To the best of its knowledge and belief, the hospital has included all applicable standard charge information in accordance with the requirements of 45 CFR 180.50, and the information encoded is true, accurate, and complete as of the date indicated.",,,,,,,,,,,,,,
West Mercy Hospital,2024-07-01,2.0,West Mercy Hospital|West Mercy Surgical Center,"12 Main Street, Fullerton, CA 92832|23 Ocean Ave, San Jose, CA 94088",50056,true,,,,,,,,,,,,,,

Description,code|1,code|1|type,code|2,code|2|type,modifiers,setting,drug_unit_of_measurement,drug_type_of_measurement,standard_charge|gross,standard_charge|discounted_cash,payer_name,plan_name,standard_charge|negotiated_dollar,standard_charge|negotiated_percentage,standard_charge|negotiated_algorithm,estimated_amount,standard_charge|methodology,standard_charge|min,standard_charge|max,additional_generic_notes
Major hip and knee joint replacement or reattachment of lower extremity without mcc,470,MS-DRG,175869,LOCAL,,inpatient,,,,,Platform Health Insurance,PPO,20000,,MS-DRG,22243.34,case rate,20000,20000,
Major hip and knee joint replacement or reattachment of lower extremity without mcc,470,MS-DRG,175869,LOCAL,,inpatient,,,,,Platform Health Insurance,PPO,20000,,https://www.cms.gov/Outreach-and-Education/Medicare-Learning-Network-MLN/MLNProducts/html/images/OP.jpg,22243.34,case rate,20000,20000,
Major hip and knee joint replacement or reattachment of lower extremity without mcc,470,MS-DRG,175869,LOCAL,,inpatient,,,,,Platform Health Insurance,PPO,20000,,The adjusted base payment rate indicated in the standard_charge|negotiated_dollar data element may be further adjusted for additional factors including transfers and outliers.,22243.34,case rate,20000,20000,
Major hip and knee joint replacement or reattachment of lower extremity without mcc,470,MS-DRG,175869,LOCAL,,inpatient,,,,,Region Health Insurance,HMO,,50,,23145.98,percent of total billed charges,20000,20000,
"Evaluation of hearing function to determine candidacy for, or postoperative status of, surgically implanted hearing device; first hour",92626,CPT,,,,outpatient,,,150,125,Platform Health Insurance,PPO,98.98,,,,fee schedule,98.98,98.98,110% of the Medicare fee schedule
"Evaluation of hearing function to determine candidacy for, or postoperative status of, surgically implanted hearing device; first hour",92626,CPT,,,,outpatient,,,150,125,Region Health Insurance,HMO,,115,,105.34,fee schedule,98.98,98.98,115% of the state's workers' compensation amount
"Behavioral health; residential (hospital residential treatment program), without room and board, per diem",H0017,HCPCS,,,,inpatient,,,2500,2250,Platform Health Insurance,PPO,1500,,,,per diem,1500,1500,
"Behavioral health; residential (hospital residential treatment program), without room and board, per diem, days 1-3",H0017,hcpcs,,,,inpatient,,,2500,2250,Region Health Insurance,HMO,2000,,,,per diem,2000,2000,
"Behavioral health; residential (hospital residential treatment program), without room and board, per diem, days 4-5",H0017,HCPCS,,,,inpatient,,,2500,2250,Region Health Insurance,HMO,1800,,,,per diem,1800,1800,
"Behavioral health; residential (hospital residential treatment program), without room and board, per diem, days 6+",H0017,HCPCS,,,,inpatient,,,2500,2250,Region Health Insurance,HMO,1200,,,,per diem,1200,1200,
Treatment or observation room — observation room,762,RC,,,,outpatient,,,13000,12000,Platform Health Insurance,PPO,8000,,,,case rate,8000,10000,Negotiated standard charge without surgery and without rule out myocardial infarction
Treatment or observation room — observation room,762,RC,,,,outpatient,,,13000,12000,Platform Health Insurance,PPO,10000,,,,case rate,8000,10000,Negotiated standard charge without surgery and with rule out myocardial infarction
Treatment or observation room — observation room,762,RC,,,,outpatient,,,13000,12000,Region Health Insurance,HMO,9000,,,,case rate,8000,10000,
3 changes: 3 additions & 0 deletions test/fixtures/sample-no-data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hospital_name,last_updated_on,version,hospital_location,hospital_address,license_number|CA,"To the best of its knowledge and belief, the hospital has included all applicable standard charge information in accordance with the requirements of 45 CFR 180.50, and the information encoded is true, accurate, and complete as of the date indicated.",,,,,,,,,,,,,,
West Mercy Hospital,2024-07-01,2.0,West Mercy Hospital|West Mercy Surgical Center,"12 Main Street, Fullerton, CA 92832|23 Ocean Ave, San Jose, CA 94088",50056,true,,,,,,,,,,,,,,
Description,code|1,code|1|type,code|2,code|2|type,modifiers,setting,drug_unit_of_measurement,drug_type_of_measurement,standard_charge|gross,standard_charge|discounted_cash,payer_name,plan_name,standard_charge|negotiated_dollar,standard_charge|negotiated_percentage,standard_charge|negotiated_algorithm,estimated_amount,standard_charge|methodology,standard_charge|min,standard_charge|max,additional_generic_notes
66 changes: 66 additions & 0 deletions test/validators/CsvValidator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import * as fs from "fs";
import * as path from "path";
import { CsvValidator } from "../../src/validators/CsvValidator.js";
import {
HeaderBlankError,
InvalidVersionError,
MinRowsError,
ProblemsInHeaderError,
} from "../../src/errors/csv/index.js";

describe("CsvValidator", () => {
describe("constructor", () => {
Expand All @@ -25,4 +33,62 @@ describe("CsvValidator", () => {
expect(validator.dataCallback).toBe(valueCallback);
});
});

describe("#validate", () => {
it("should return an error when attempting to validate against an invalid version", async () => {
const validator = new CsvValidator("x.y.z");
const input = fs.createReadStream(
new URL(
path.join("..", "fixtures", "sample-tall-valid.csv"),
import.meta.url
)
);
const results = await validator.validate(input);
expect(results.valid).toBe(false);
expect(results.errors).toHaveLength(1);
expect(results.errors[0]).toBeInstanceOf(InvalidVersionError);
});

it("should return an error when a header row is blank", async () => {
const validator = new CsvValidator("v2.2.0");
const input = fs.createReadStream(
new URL(
path.join("..", "fixtures", "sample-blank-header.csv"),
import.meta.url
)
);
const results = await validator.validate(input);
expect(results.valid).toBe(false);
expect(results.errors).toHaveLength(1);
expect(results.errors[0]).toBeInstanceOf(HeaderBlankError);
});

it("should return an error when there are no data rows", async () => {
const validator = new CsvValidator("v2.2.0");
const input = fs.createReadStream(
new URL(
path.join("..", "fixtures", "sample-no-data.csv"),
import.meta.url
)
);
const results = await validator.validate(input);
expect(results.valid).toBe(false);
expect(results.errors).toHaveLength(1);
expect(results.errors[0]).toBeInstanceOf(MinRowsError);
});

it("should stop validation when there are problems in the header", async () => {
const validator = new CsvValidator("v2.2.0");
const input = fs.createReadStream(
new URL(
path.join("..", "fixtures", "sample-bad-header.csv"),
import.meta.url
)
);
const results = await validator.validate(input);
expect(results.valid).toBe(false);
expect(results.errors).toHaveLength(2);
expect(results.errors[1]).toBeInstanceOf(ProblemsInHeaderError);
});
});
});
3 changes: 2 additions & 1 deletion test/validators/JsonValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ describe("JsonValidator", () => {
});

it("should limit the number of errors returned when the maxErrors option is used", async () => {
const input = createFixtureStream("sample-empty.json");
// this file normally could produce 3 errors when not limited
const input = createFixtureStream("sample-no-min-max.json");
const result = await validator.validate(input, { maxErrors: 2 });
expect(result.valid).toBe(false);
expect(result.errors).toHaveLength(2);
Expand Down

0 comments on commit e0cf580

Please sign in to comment.