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

Refactor and restructure validation functions. #63

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

mint-thompson
Copy link
Collaborator

This is a large restructuring of the CSV and JSON validation logic into two new classes: JsonValidator and CsvValidator. These classes replace the previously defined types in order to facilitate reuse and extension.

The main change to JSON validation is the use of schemas defined in files. Previously, the schemas were defined as variables in the code. This means there are some new preparatory steps to get the subschemas out of the main schema. But, the overall implementation, where the metadata is checked last, is the same.

CSV validation is now significantly different. It still makes use of some helper functions for typical types of checks (required values, enums, etc.), but instead of an explicit function definition for validating rows, the validation checks are created by binding some variables to base validation functions, then adding those checks to a tree. This allows for sets of checks to occur conditionally based on the results of other checks or defined predicates. It also allows for the set of checks to vary depending on the version option. Errors now exist as specific error classes, which allows for easier analysis or modification by code that uses this module.

The current implementation removes the previous concept of the warning flag for validation errors. Instead, the expectation is that validation is performed against a specific version of the requirements without regard for any future requirements. This allows for easier analysis of files published before certain requirements took effect.

The jest module is now used for tests. The previous set of tests are rewritten, and there are some new tests specific to the new implementation.

While reviewing these changes, please keep in mind the organization of constants, functions, and classes. I tried to get things organized reasonably well, but I may not have moved everything to the right places.

The current state of this branch is a work-in-progress: lots of
incomplete implementations and tests. Use this branch to work towards a
complete implementation of the refactored validator classes.
Fix OBOB for code count. Add tests for incorrect use of code columns.

Start filling out tests for validateRow tall

Adding "normalized columns" so that we can easily find the location of
elements, but keep the original formatting for message purposes.

Define some of the tests for validating a row in tall mode. Fields
tested are description, setting, and the drug information fields.

Add tests for code pairs and non-payer specific charges

add tests for payer specific negotiated charge

Add "other" methodology conditional

Still messing around a bit with types and the structure of the
validation tree.

Add tests for requiring at least one charge

I'm starting to feel uneasy about some of these implementations. Might
try to change up how they go so I have less actual logic in the
predicate functions.

Change up validation types and partial function application

Individual validation functions are redefined so that the arguments are
listed in a useful order for binding. This means that when actually
validating the row, the only values to pass in are the data object and
the row index.

Add tests for dollar amount requiring min and max

Remove reset method, since it's really just for convenience, and it
doesn't actually make things that much more convenient.
Add tests for modifier-only rows.
Add tests for requiring estimated allowed amount when payer-specific
percentage or algorithm, but not dollar amount, are present.
Add tests for requiring drug information when NDC code type is used.
Add tests for payer specific negotiated charge conditional.
Add tests for "other" methodology conditional.
Add tests for requiring at least one charge.
Add tests for payer-specific dollar amount requiring a min and max.
Add tests for modifier row additional information.
Add tests for requiring an estimated allowed amount for a percentage or
algorithm.
Add tests for requiring drug information when code type is NDC.
Build row validators after rows are determined.
Add list of available versions to InvalidVersionError.
Tests that depend on a specific version of the requirements are split
into separate files, since the main test file was growing too large.

For pre-v2.2.0 versions, there are no modifier rows. Therefore, code
information is always required.
Many constants are moved around so that there's fewer total definitions
in the CsvValidator file.
Bind the CsvValidator instance to the data callback so that the function
will have access to any other properties it needs.
Fill out todo tests for JsonValidator. Make JsonValidator's schema
properties public, both for testing and because it might be useful to be
able to modify them in an inherited class.
Delete some unused constants and types.
@mint-thompson mint-thompson marked this pull request as ready for review January 6, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant