Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json format 2.0 #6

Merged
merged 7 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
JsonValidatorOptions,
} from "./types.js"
import { JsonValidatorOneOne } from "./versions/1.1/json.js"
import { JsonValidatorTwoZero } from "./versions/2.0/json.js"

/**
*
Expand All @@ -18,6 +19,8 @@ export async function validateJson(
): Promise<ValidationResult> {
if (version === "v1.1") {
return JsonValidatorOneOne.validateJson(jsonInput, options)
} else if (version === "v2.0") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mint-thompson I'm thinking that we'll probably want to update this to support major, minor, and patch versioning, but keeping it consistent with the previous implementation for now.

return JsonValidatorTwoZero.validateJson(jsonInput, options)
}
return new Promise((resolve) => {
resolve({
Expand Down
14 changes: 7 additions & 7 deletions src/versions/2.0/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {
BillingCodeType,
CHARGE_BILLING_CLASSES,
CHARGE_SETTINGS,
CONTRACTING_METHODS,
STANDARD_CHARGE_METHODOLOGY,
ChargeBillingClass,
ChargeSetting,
ContractingMethod,
StandardChargeMethod,
DRUG_UNITS,
DrugUnit,
} from "./types"
Expand Down Expand Up @@ -354,7 +354,7 @@ export function validateWideFields(
Object.entries(row).forEach(([field, value], columnIndex) => {
if (
field.includes("contracting_method") &&
!CONTRACTING_METHODS.includes(value as ContractingMethod)
!STANDARD_CHARGE_METHODOLOGY.includes(value as StandardChargeMethod)
) {
errors.push(
csvErr(
Expand All @@ -364,7 +364,7 @@ export function validateWideFields(
ERRORS.ALLOWED_VALUES(
field,
value,
CONTRACTING_METHODS as unknown as string[]
STANDARD_CHARGE_METHODOLOGY as unknown as string[]
)
)
)
Expand Down Expand Up @@ -458,8 +458,8 @@ export function validateTallFields(
}

if (
!CONTRACTING_METHODS.includes(
row["standard_charge | methodology"] as ContractingMethod
!STANDARD_CHARGE_METHODOLOGY.includes(
row["standard_charge | methodology"] as StandardChargeMethod
)
) {
errors.push(
Expand All @@ -471,7 +471,7 @@ export function validateTallFields(
ERRORS.ALLOWED_VALUES(
"standard_charge | methodology",
row["standard_charge | methodology"],
CONTRACTING_METHODS as unknown as string[]
STANDARD_CHARGE_METHODOLOGY as unknown as string[]
)
)
)
Expand Down
124 changes: 93 additions & 31 deletions src/versions/2.0/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
CHARGE_BILLING_CLASSES,
CHARGE_SETTINGS,
DRUG_UNITS,
CONTRACTING_METHODS,
STANDARD_CHARGE_METHODOLOGY,
} from "./types.js"
import { errorObjectToValidationError, parseJson } from "../common/json.js"

const STANDARD_CHARGE_DEFINITIONS = {
billing_code_information: {
code_information: {
type: "object",
properties: {
code: { type: "string" },
Expand All @@ -37,6 +37,7 @@ const STANDARD_CHARGE_DEFINITIONS = {
},
required: ["unit", "type"],
},

standard_charges: {
type: "object",
properties: {
Expand All @@ -48,11 +49,6 @@ const STANDARD_CHARGE_DEFINITIONS = {
enum: CHARGE_SETTINGS,
type: "string",
},
modifiers: {
type: "array",
items: { type: "string" },
uniqueItems: true,
},
payers_information: {
type: "array",
items: { $ref: "#/definitions/payers_information" },
Expand All @@ -71,9 +67,9 @@ const STANDARD_CHARGE_DEFINITIONS = {
properties: {
description: { type: "string" },
drug_information: { $ref: "#/definitions/drug_information" },
billing_code_information: {
code_information: {
type: "array",
items: { $ref: "#/definitions/billing_code_information" },
items: { $ref: "#/definitions/code_information" },
minItems: 1,
},
standard_charges: {
Expand All @@ -82,29 +78,24 @@ const STANDARD_CHARGE_DEFINITIONS = {
minItems: 1,
},
},
required: ["description", "billing_code_information", "standard_charges"],
required: ["description", "code_information", "standard_charges"],
},
payers_information: {
type: "object",
properties: {
payer_name: { type: "string" },
plan_name: { type: "string" },
additional_payer_notes: { type: "string" },
standard_charge: { type: "number", exclusiveMinimum: 0 },
standard_charge_percent: { type: "number", exclusiveMinimum: 0 },
contracting_method: {
enum: CONTRACTING_METHODS,
standard_charge_dollar: { type: "number", exclusiveMinimum: 0 },
standard_charge_algorithm: { type: "string" },
standard_charge_percentage: { type: "number", exclusiveMinimum: 0 },
estimated_amount: { type: "number", exclusiveMinimum: 0 },
methodology: {
enum: STANDARD_CHARGE_METHODOLOGY,
type: "string",
},
},
required: ["payer_name", "plan_name", "contracting_method"],
if: {
properties: {
contracting_method: { const: "percent of total billed charges" },
},
},
then: { required: ["standard_charge_percent"] },
else: { required: ["standard_charge"] },
required: ["payer_name", "plan_name", "methodology"],
},
}

Expand All @@ -113,9 +104,9 @@ const STANDARD_CHARGE_PROPERTIES = {
properties: {
description: { type: "string" },
drug_information: { $ref: "#/definitions/drug_information" },
billing_code_information: {
code_information: {
type: "array",
items: { $ref: "#/definitions/billing_code_information" },
items: { $ref: "#/definitions/code_information" },
minItems: 1,
},
standard_charges: {
Expand All @@ -124,7 +115,7 @@ const STANDARD_CHARGE_PROPERTIES = {
minItems: 1,
},
},
required: ["description", "billing_code_information", "standard_charges"],
required: ["description", "code_information", "standard_charges"],
}

export const STANDARD_CHARGE_SCHEMA = {
Expand All @@ -145,22 +136,92 @@ export const METADATA_DEFINITIONS = {
},
required: ["license_number", "state"],
},
affirmation: {
type: "object",
properties: {
affirmation: {
const:
"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.",
},
confirm_affirmation: {
type: "boolean",
},
shaselton-usds marked this conversation as resolved.
Show resolved Hide resolved
},
required: ["affirmation", "confirm_affirmation"],
},
modifier_information: {
type: "object",
properties: {
description: {
type: "string",
},
code: {
type: "string",
},
shaselton-usds marked this conversation as resolved.
Show resolved Hide resolved
modifier_payer_information: {
type: "array",
items: {
$ref: "#/definitions/modifier_payer_information",
},
minItems: 1,
},
},
required: ["description", "modifier_payer_information", "code"],
},
modifier_payer_information: {
type: "object",
properties: {
payer_name: {
type: "string",
},
plan_name: {
type: "string",
},
description: {
type: "string",
},
},
required: ["payer_name", "plan_name", "description"],
},
}

export const METADATA_PROPERTIES = {
hospital_name: { type: "string" },
last_updated_on: { type: "string", format: "date" },
license_information: {
type: "array",
items: { $ref: "#/definitions/license_information" },
minItems: 1,
$ref: "#/definitions/license_information",
},
version: { type: "string" },
hospital_location: { type: "string" },
financial_aid_policy: { type: "string" },
hospital_address: {
type: "array",
items: { type: "string" },
},
hospital_location: {
type: "array",
items: {
type: "string",
},
},
affirmation: {
$ref: "#/definitions/affirmation",
},
modifier_information: {
type: "array",
items: {
$ref: "#/definitions/modifier_information",
},
},
}

export const METADATA_REQUIRED = ["hospital_name", "last_updated_on", "version"]
export const METADATA_REQUIRED = [
"hospital_name",
"last_updated_on",
"hospital_location",
"hospital_address",
"license_information",
"version",
"affirmation",
]

export const METADATA_SCHEMA = {
$schema: "http://json-schema.org/draft-07/schema#",
Expand Down Expand Up @@ -213,6 +274,7 @@ export async function validateJson(
if (typeof key === "string") {
metadata[key] = value
} else {
// is this where I need to put another check for the modifier information?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right spot for that. These checks that collect values into the local metadata object may have to get updated, since modifiers are part of the METADATA_SCHEMA. It might be useful for us to take a closer look at some of this code to make sure that we get the right approach here. Then, we can add some modifiers to the test fixtures.

hasCharges = true
if (!validator.validate(STANDARD_CHARGE_SCHEMA, value)) {
valid = false
Expand Down
6 changes: 3 additions & 3 deletions src/versions/2.0/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export const CHARGE_BILLING_CLASSES = [
type ChargeBillingClassTuple = typeof CHARGE_BILLING_CLASSES
export type ChargeBillingClass = ChargeBillingClassTuple[number]

export const CONTRACTING_METHODS = [
export const STANDARD_CHARGE_METHODOLOGY = [
"case rate",
"fee schedule",
"percent of total billed charges",
"per diem",
"other",
] as const
type ContractingMethodTuple = typeof CONTRACTING_METHODS
export type ContractingMethod = ContractingMethodTuple[number]
type StandardChargeTuple = typeof STANDARD_CHARGE_METHODOLOGY
export type StandardChargeMethod = StandardChargeTuple[number]
15 changes: 9 additions & 6 deletions test/json.spec.ts → test/1.1/json.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import test from "ava"
import { loadFixtureStream } from "./utils"
import { validateJson } from "../src/json.js"
import { loadFixtureStream } from "../utils.js"
import { validateJson } from "../../src/json.js"

test("validateJson", async (t) => {
const result = await validateJson(loadFixtureStream("sample-1.json"), "v1.1")
const result = await validateJson(
loadFixtureStream("/1.1/sample-1.json"),
"v1.1"
)
t.is(result.valid, false)
t.is(result.errors.length, 1)
})

test("validateJson empty", async (t) => {
const result = await validateJson(
loadFixtureStream("sample-empty.json"),
loadFixtureStream("/1.1/sample-empty.json"),
"v1.1"
)
t.is(result.valid, false)
Expand All @@ -19,7 +22,7 @@ test("validateJson empty", async (t) => {

test("validateJson maxErrors", async (t) => {
const result = await validateJson(
loadFixtureStream("sample-empty.json"),
loadFixtureStream("/1.1/sample-empty.json"),
"v1.1",
{
maxErrors: 1,
Expand All @@ -31,7 +34,7 @@ test("validateJson maxErrors", async (t) => {

test("validateJson valid", async (t) => {
const result = await validateJson(
loadFixtureStream("sample-valid.json"),
loadFixtureStream("/1.1/sample-valid.json"),
"v1.1"
)
t.is(result.valid, true)
Expand Down
59 changes: 59 additions & 0 deletions test/2.0/json.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import test from "ava"
import { loadFixtureStream } from "../utils.js"
import { validateJson } from "../../src/json.js"

test("validateJson", async (t) => {
const result = await validateJson(
loadFixtureStream("/2.0/sample-valid.json"),
"v2.0"
)
t.is(result.valid, true)
t.deepEqual(result.errors.length, 0)
})

test("validateJson empty", async (t) => {
const result = await validateJson(
loadFixtureStream("/2.0/sample-empty.json"),
"v2.0"
)
t.is(result.valid, false)
t.deepEqual(result.errors.length, 8)
})

test("validateJson maxErrors", async (t) => {
const result = await validateJson(
loadFixtureStream("/2.0/sample-empty.json"),
"v2.0",
{
maxErrors: 1,
}
)
t.is(result.valid, false)
t.deepEqual(result.errors.length, 1)
})

test("validateJson errorFile", async (t) => {
const result = await validateJson(
loadFixtureStream("/2.0/sample-errors.json"),
"v2.0"
)
t.is(result.valid, false)
t.deepEqual(result.errors.length, 3)
t.deepEqual(result.errors, [
{
path: "/standard_charges/0/payers_information/0/standard_charge_dollar",
field: "standard_charge_dollar",
message: "must be number",
},
{
path: "/standard_charges/3/payers_information/2",
field: "2",
message: "must have required property 'methodology'",
},
{
path: "/affirmation/affirmation",
field: "affirmation",
message: "must be equal to constant",
},
])
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading