cdisc-org / cdisc-rules-engine

Open source offering of the cdisc rules engine
MIT License
46 stars 12 forks source link

Allow use of `within` parameter with `is_unique_relationship` and `is_not_unique_relationship` operators #685

Open ASL-rmarshall opened 8 months ago

ASL-rmarshall commented 8 months ago

We need to check for 1-to-1 relationships between the following pairs of variables:

However, the requirement for a 1-to-1 relationship is usually within the scope of a parent entity/class. For example, it would be acceptable for the same name value to be associated with different description values for StudyArm, StudyEpoch, StudyElement, etc. if the combinations appeared within different instances of the parent StudyDesign class.

At the moment, the is_unique_relationship and is_not_unique_relationship operators check for unique relationships within the whole dataset. In order to support checking of unique relationships within an instance of a parent class, the operators should be updated to support use of the within parameter. The within parameter should accept a list of 1 or more variable names, which (if present) would then be used to group the input dataset (e.g., using groupby) before checking for unique relationships. For example, the following would check for non-unique relationship of name and description within parent_id:

Check:
  all:
    - name: 'name'
      operator: non_empty
    - name: description
      operator: non_empty
    - name: 'name'
      operator: is_not_unique_relationship
      value: description
      within:
        - parent_id