cidgoh / DataHarmonizer

A standardized browser-based spreadsheet editor and validator that can be run offline and locally, and which includes templates for SARS-CoV-2 and Monkeypox sampling data. This project, created by the Centre for Infectious Disease Genomics and One Health (CIDGOH), at Simon Fraser University, is now an open-source collaboration with contributions from the National Microbiome Data Collaborative (NMDC), the LinkML development team, and others.
MIT License
94 stars 27 forks source link

Feature: Optional column becomes mandatory based on other column value #153

Closed Takadonet closed 11 months ago

Takadonet commented 3 years ago

Is it possible that a column B is default optional but is mandatory after Column A has a certain value.

Example: Column Sequenced : Value : ['yes','no','failed']

Column Reason_Failed: Value: Free form text ; Mandatory only when value 'failed' is given to Column Sequenced.

ddooley commented 3 years ago

This would be a welcome feature. It suggests that one could have a bit of a conditional language in addition to just marking a field as required or recommended. E.g. "required if [field x] value is [value y]".

Takadonet commented 1 year ago

Is there any movement on this feature request? If not, we will implement some backend validation.

ddooley commented 1 year ago

LinkML now has a rule language that enables this functionality so next steps are for the DH project to get that implemented to some extent in https://github.com/cidgoh/DataHarmonizer/issues/370 . We have hired a developer that will be able to take on DH development but have him dedicated on another task for one month. I'll try to scope out the task of implementing portions of the rule language in the next week; perhaps this is something we can collaborate on.

A first move would be if you could see what the rules you need look like in one of your LinkML schemas, so we can test against that as a priority? The LinkML specs for rules: https://linkml.io/linkml/schemas/advanced.html#rules

ddooley commented 1 year ago

By the way, is your DH/LinkML incoming data in JSON format? If so, LinkML's generated JSON-Schema will apparently have the LinkML rules compiled into JSON schema rules, and that is a way to validate such things. Stated here: https://linkml.io/linkml/generators/json-schema.html#rules

Takadonet commented 1 year ago

It will at the layer where we hit valid button. Our hosted version does not allow end user to submit data if it is not valid.

To my understanding then it will need to be implemented in DH layer in the template (schema_*) files.

ddooley commented 1 year ago

For sure the rules should be expressed in schema.yaml , then when DH loads them, javascript will enable Validate (button) to detect / report required but empty fields. But that aside, LinkML comand line tool ability to output json schema could then be used via jason schema validator to check for required fields, and conditionally required fields, as far as I can tell, via if-then-else https://json-schema.org/understanding-json-schema/reference/conditionals.html but I'll have to verify that LinkML rules flow through to this json schema expressivity.

Takadonet commented 1 year ago

Sounds good. Our hope is to reduce lots of manually checking with scripts/humans.

ddooley commented 11 months ago

@Takadonet We'll address this functionality in newer https://github.com/cidgoh/DataHarmonizer/issues/370 so will close it here.