0

Is there a way to create a customized validator to validate the data that is imported from csv file in REDCap?

wibeasley
  • 5,000
  • 3
  • 34
  • 62
Tri Vi
  • 33
  • 1
  • 5

1 Answers1

1

I'm not entirely sure what you mean but I will try to answer your question as best as possible.

To begin with, you can customize what validation is used on a per-field level in REDCap, by simply editing a field and selecting a field type. E. g. if it's a 'text' field with the 'integer' constraint activated, data for that field in uploaded .csv files will be checked to ensure that only integer values are imported. You can add some extra constraints as well, using e. g. min/max values or action tags (link to PDF document about action tags). Note that if you use 'multiple choice'/'checkboxes' type fields, where you manually specify a limited number of possible field choices, uploaded data will be checked to make sure that all values for the field are in the list of allowed field choices.

If you mean that you want to bypass REDCap's validation process so that it allows some normally invalid values to be uploaded (say a value of 2.5 for a 'text' field with the 'integer' constraint), I don't think that's possible, and I don't think there's any good reason for wanting to do that. If you want a field to be less 'lax' about validation, then you can change its type to a more general one. So if you have a 'text' field with the 'integer' constraint, you can simply remove the 'integer' constraint and have it be a plain 'text' field. But be careful if you do this. Think about whether you are removing constraints because actually valid data aren't allowed to be uploaded, or if you are trying to upload invalid data that ought to be removed or fixed. If it's the latter you should definitely leave the validation as it is, because then it's doing its job and letting you know what needs to be corrected.

If you want to add additional validation, making it stricter than what REDCap does at the moment, then you can of course change the field types to be more narrow, e. g. adding an 'integer' constraint to a 'text' field, or changing a 'text' field to be a 'multiple choice' field. That's the solution in REDCap. If you want to add additional constraints/validation, that REDCap doesn't support, I think you'll have to pre-process the data before upload. If you want to automate the validation process then you could write a script in R or Python that:

  1. Imports the .csv data (e. g. with read.csv/read_csv)
  2. Filters the data the way you want (e.g. if you want to exclude certain strings that have a pattern to them, you could use R's 'stringr' package or Python's 're' package)
  3. Uploads the data to REDCap using the REDCap API (for R there's the 'redcapAPI' package, and for Python there's the 'PyCap' package) Note that you would need an API key, which you can ask your institution's REDCap administrators for, if you'd want your script to upload the data directly. You can of course also create a script that, instead of uploading the data directly, produces .csv files for upload.

If you're not very familiar with R, Python or other programming languages/tools that enable you to craft validation scripts it's probably best to work with what REDCap itself offers you.

Arboc
  • 11
  • 1