cdisc-org / cdisc-org/cdisc-rules-engine
Rule blocked: SEND310 - need to be able to have a count on distinct values
- Dominant language
- Python
- Stars
- 113
- Forks
- 43
- Avg merge
- 14h 51m
- Merged PRs (30d)
- 14
Description
In SEND310 (but also applicable to some other SEND rules), we have "DM: Subjects with different values for SPECIES and/or **STRAIN** cannot have the same SETCD value."
So we need to group the rows by SETCD (not by USUBJID), and then count how many distinct values of "STRAIN" there are in each group. If there is more than 1 distinct value per group, a violation must be reported.
So we use:
Check:
all:
# Only apply when the "STRAIN" column (as "permissible") is present
- name: 'STRAIN'
operator: 'exists'
# just for testing, assuring a violation is report
- name: 'STRAIN'
operator: not_equal_to
value: 'whale'
#- name: $distinct_strain_count
# operator: greater_than
# value: 1
The second part, checking for "whale", just for testing right now, to ensure a violation is triggered
We also define in "Operations":
Operations:
- domain: DM
id: $distinct_strain_count
group:
- SETCD
// within the group with identical values for SETCD. count the number of records
name: STRAIN
// todo: we need something like "distinct_count" here
operator: distinct
grouping the rows by value of STRAIN, and then taking the distinct values, which leads to an array, that is returned.
We do however need to count the number of members in the array.
I think this can be solved by a new operator like "distinct_count", not returning the array itself, but the number of members in the array.
Remark that record_count cannot be used here, as were are not counting records (I tried with "filter", but "filter" needs to have a literal value, which we can of course not foresee).
An alternative (more generic) would be that in the "Check" part, we have an operator, or a set of operators that work on arrays:
like:
- name: $distinct_strain # array with the distinct values of "STRAIN" within a group
operator: count_greater_than # counts the values in the array, and applies and "greater_than" on it
value: 1
This however has the disadvantage that we than also need operators lijke
- count_less_than
- count_equal_to
- count_greater_or_equal
- count_less_or_equal
I attach the test file.
[unit-test-coreid-SENDIG310_negative.xlsx](https://github.com/user-attachments/files/20790365/unit-test-coreid-SENDIG310_negative.xlsx)

Contributor guide
Assessment
This issue has not been assessed yet.