diff --git a/cdisc_rules_engine/check_operators/dataframe_operators.py b/cdisc_rules_engine/check_operators/dataframe_operators.py index 5bb527dc9..011835f65 100644 --- a/cdisc_rules_engine/check_operators/dataframe_operators.py +++ b/cdisc_rules_engine/check_operators/dataframe_operators.py @@ -998,8 +998,19 @@ def split_parts_have_unequal_length(self, other_value: dict): @type_operator(FIELD_DATAFRAME) def empty(self, other_value: dict): target = self.replace_prefix(other_value.get("target")) + series = self.value[target] + + def check_empty(x): + return isinstance(x, (set, list, dict)) and len(x) == 0 + + if hasattr(series, "map_partitions"): + is_empty_collection = series.map(check_empty, meta=("x", "bool")) + else: + is_empty_collection = series.map(check_empty) results = np.where( - self.value[target].isin(NULL_FLAVORS) | pd.isna(self.value[target]), + self.value[target].isin(NULL_FLAVORS) + | pd.isna(self.value[target]) + | is_empty_collection, True, False, ) diff --git a/resources/schema/Operations.json b/resources/schema/Operations.json index 988ba28c3..ea439a54d 100644 --- a/resources/schema/Operations.json +++ b/resources/schema/Operations.json @@ -87,14 +87,7 @@ "properties": { "operator": { "const": "get_codelist_attributes" } }, - "required": [ - "id", - "operator", - "name", - "ct_attribute", - "version", - "target" - ], + "required": ["id", "operator", "name", "ct_attribute", "version"], "type": "object" }, { @@ -557,9 +550,6 @@ "type": "string", "enum": ["code", "value", "pref_term"] }, - "target": { - "type": "string" - }, "term_value": { "type": "string" }, diff --git a/resources/schema/Operations.md b/resources/schema/Operations.md index 0c56dcb99..e7b553a09 100644 --- a/resources/schema/Operations.md +++ b/resources/schema/Operations.md @@ -152,12 +152,12 @@ Returns a list of valid extensible codelist term's submission values. Used for e ### get_codelist_attributes -Fetches controlled terminology attribute values from CT packages based on row-specific CT package and version references. +Fetches controlled terminology attribute values from CT packages based on row-specific CT package and version references. The operation constructs CT package names based on the standard being validated and the values in the `name` and `version` columns (e.g., SDTMIG → "sdtmct-{version}"). When the `name` column contains "CDISC" or "CDISC CT", it uses the validation run's standard to determine the package prefix and the version found in the cell of the specified column. The operation extracts all codes matching the specified ct_attribute from the package. **Required Parameters:** - `ct_attribute`: Attribute to extract - `"Term CCODE"`, `"Codelist CCODE"`, `"Term Value"`, `"Codelist Value"`, or `"Term Preferred Term"` -- `target`: Column containing CT reference (e.g., "TSVCDREF") +- `name`: Column containing CT reference (e.g., "TSVCDREF") - identifies which terminology system is referenced - `version`: Column containing CT version (e.g., "TSVCDVER") ```yaml @@ -166,9 +166,10 @@ Fetches controlled terminology attribute values from CT packages based on row-sp operator: get_codelist_attributes ct_attribute: Term CCODE version: TSVCDVER - target: TSVCDREF ``` +**Note:** due to editor not containing the cache, if using this operator in rule editor, you must put the ctpackage versions contained within your data in the library tab for it work properly in editor. + ### valid_codelist_dates Returns the valid terminology package dates for a given standard. diff --git a/tests/resources/COREIssue329/rule-286.json b/tests/resources/COREIssue329/rule-286.json index 2cb25a38c..f000509c2 100644 --- a/tests/resources/COREIssue329/rule-286.json +++ b/tests/resources/COREIssue329/rule-286.json @@ -1,101 +1,96 @@ { - "Authorities": [ + "Authorities": [ + { + "Organization": "CDISC", + "Standards": [ { - "Organization": "CDISC", - "Standards": [ - { - "Name": "SDTMIG", - "Version": "3.2", - "References": [ - { - "Origin": "SDTM and SDTMIG Conformance Rules", - "Version": "2.0", - "Citations": [ - { - "Document": "IG v3.2", - "Item": "Assumption 3", - "Section": "7.4", - "Cited_Guidance": "Further information about the parameters is included below in Table 1. TSVAL may have controlled terminology depending on the value of TSPARMCD" - } - ], - "Rule_Identifier": { - "Id": "CG0286", - "Version": "1" - } - } - ] - }, + "Name": "SDTMIG", + "Version": "3.2", + "References": [ + { + "Origin": "SDTM and SDTMIG Conformance Rules", + "Version": "2.0", + "Citations": [ { - "Name": "SDTMIG", - "Version": "3.3", - "References": [ - { - "Origin": "SDTM and SDTMIG Conformance Rules", - "Version": "2.0", - "Citations": [ - { - "Document": "IG v3.3", - "Item": "Assumption 3", - "Section": "7.4", - "Cited_Guidance": "Further information about the parameters is included Appendix C1, Trial Summary Codes. TSVAL may have controlled terminology depending on the value of TSPARMCD. Conditions for including parameters are included in Appendix C1, Trial Summary Codes." - } - ], - "Rule_Identifier": { - "Id": "CG0286", - "Version": "1" - } - } - ] + "Document": "IG v3.2", + "Item": "Assumption 3", + "Section": "7.4", + "Cited_Guidance": "Further information about the parameters is included below in Table 1. TSVAL may have controlled terminology depending on the value of TSPARMCD" } - ] - } - ], - "Core": { - "Id": "CDISC.SDTMIG.CG0286", - "Version": "1", - "Status": "Draft" - }, - "Description": "", - "Outcome": { - "Message": "" - }, - "Sensitivity": "Record", - "Scope": { - "Classes": { - "Include": [ - "TRIAL DESIGN" - ] + ], + "Rule_Identifier": { + "Id": "CG0286", + "Version": "1" + } + } + ] }, - "Domains": { - "Include": [ - "TS" - ] - } - }, - "Executability": "Fully Executable", - "Check": { - "all": [ - { - "name": "TSVCDREF", - "operator": "equal_to", - "value": "CDISC", - "value_is_literal": true - }, + { + "Name": "SDTMIG", + "Version": "3.3", + "References": [ { - "name": "TSVALCD", - "operator": "is_not_contained_by", - "value": "$all_ct_term_codes" + "Origin": "SDTM and SDTMIG Conformance Rules", + "Version": "2.0", + "Citations": [ + { + "Document": "IG v3.3", + "Item": "Assumption 3", + "Section": "7.4", + "Cited_Guidance": "Further information about the parameters is included Appendix C1, Trial Summary Codes. TSVAL may have controlled terminology depending on the value of TSPARMCD. Conditions for including parameters are included in Appendix C1, Trial Summary Codes." + } + ], + "Rule_Identifier": { + "Id": "CG0286", + "Version": "1" + } } - ] - }, - "Rule_Type": "Record Data", - "Operations": [ - { - "id": "$all_ct_term_codes", - "name": "TSVCDREF", - "operator": "get_codelist_attributes", - "version": "TSVCDVER", - "attribute": "TSVALCD" + ] } + ] + } + ], + "Core": { + "Id": "CDISC.SDTMIG.CG0286", + "Version": "1", + "Status": "Draft" + }, + "Description": "", + "Outcome": { + "Message": "" + }, + "Sensitivity": "Record", + "Scope": { + "Classes": { + "Include": ["TRIAL DESIGN"] + }, + "Domains": { + "Include": ["TS"] + } + }, + "Executability": "Fully Executable", + "Check": { + "all": [ + { + "name": "TSVCDREF", + "operator": "equal_to", + "value": "CDISC", + "value_is_literal": true + }, + { + "name": "TSVALCD", + "operator": "is_not_contained_by", + "value": "$all_ct_term_codes" + } ] + }, + "Rule_Type": "Record Data", + "Operations": [ + { + "id": "$all_ct_term_codes", + "name": "TSVCDREF", + "operator": "get_codelist_attributes", + "version": "TSVCDVER" + } + ] }