digital-preservation / csv-schema

CSV Schema
http://digital-preservation.github.io/csv-schema
Mozilla Public License 2.0
98 stars 33 forks source link

Custom Validation for CSV Fields #49

Closed megin1989 closed 2 weeks ago

megin1989 commented 2 weeks ago

How can I perform custom validation on a CSV file?

Example: Validate that all combinations of the ENCOUNTER_CLASS_CODE and ENCOUNTER_CLASS_CODE_DESCRIPTION fields in the primary CSV file exactly match the data given in the validation file. The check should ensure that each pair of ENCOUNTER_CLASS_CODE and ENCOUNTER_CLASS_CODE_DESCRIPTION in the primary CSV exists in the validation .CSVS file using regular expressions.

version 1.0 @totalColumns 2 @Separator ',' ENCOUNTER_CLASS_CODE: regex("(?i)^(AMB|EMER|FLD|HH|IMP|ACUTE|NONAC|OBSENC|PRENC|SS|VR)$") ENCOUNTER_CLASS_CODE_DESCRIPTION: regex("(?i)^(ambulatory|emergency|field|home health|inpatient encounter|inpatient acute|inpatient non-acute|observation encounter|pre-admission|short stay|virtual)$")

adamretter commented 2 weeks ago

I don't really understand your question, as the example you have provided seems to solve it. Are you looking to say if the value scope of one field conditionally depends on the value of another field? If so this may help - https://digital-preservation.github.io/csv-schema/csv-schema-1.2.html#if-expressions

DavidUnderdown commented 2 weeks ago

See digital-preservation/csv-validator/issues/502 for suggested schema that should achieve the desired result