diff --git a/cdisc_rules_engine/dataset_builders/base_dataset_builder.py b/cdisc_rules_engine/dataset_builders/base_dataset_builder.py index ad1bc81c4..517f00739 100644 --- a/cdisc_rules_engine/dataset_builders/base_dataset_builder.py +++ b/cdisc_rules_engine/dataset_builders/base_dataset_builder.py @@ -217,12 +217,14 @@ def get_library_variables_metadata(self) -> DatasetInterface: ) for variable in variables: variable["ccode"] = "" + variable["has_codelist"] = False variable_metadata: Optional[dict] = variables_metadata.get(variable["name"]) if variable_metadata: if "_links" in variable and "codelist" in variable["_links"]: first_codelist = variable["_links"]["codelist"][0] codelist_code = first_codelist["href"].split("/")[-1] variable["ccode"] = codelist_code + variable["has_codelist"] = True if "role" not in variable: variable["role"] = "" if "core" not in variable: diff --git a/cdisc_rules_engine/dataset_builders/define_variables_with_library_metadata.py b/cdisc_rules_engine/dataset_builders/define_variables_with_library_metadata.py index 5dbc2b05d..45f5c8cb0 100644 --- a/cdisc_rules_engine/dataset_builders/define_variables_with_library_metadata.py +++ b/cdisc_rules_engine/dataset_builders/define_variables_with_library_metadata.py @@ -29,6 +29,7 @@ def build(self): "library_variable_data_type", "library_variable_role", "library_variable_core", + "library_variable_has_codelist", "library_variable_ccode", "library_variable_order_number" """ diff --git a/cdisc_rules_engine/dataset_builders/variables_metadata_with_define_and_library_dataset_builder.py b/cdisc_rules_engine/dataset_builders/variables_metadata_with_define_and_library_dataset_builder.py index 6151530a1..ee00d2cad 100644 --- a/cdisc_rules_engine/dataset_builders/variables_metadata_with_define_and_library_dataset_builder.py +++ b/cdisc_rules_engine/dataset_builders/variables_metadata_with_define_and_library_dataset_builder.py @@ -36,6 +36,7 @@ def build(self): library_variable_data_type, library_variable_role, library_variable_core, + library_variable_has_codelist, library_variable_ccode, library_variable_order_number """ @@ -74,6 +75,7 @@ def build(self): "library_variable_data_type", "library_variable_role", "library_variable_core", + "library_variable_has_codelist", "library_variable_ccode", "library_variable_order_number", ] diff --git a/cdisc_rules_engine/dataset_builders/variables_metadata_with_library_metadata.py b/cdisc_rules_engine/dataset_builders/variables_metadata_with_library_metadata.py index 1d99c9e99..81dbb9894 100644 --- a/cdisc_rules_engine/dataset_builders/variables_metadata_with_library_metadata.py +++ b/cdisc_rules_engine/dataset_builders/variables_metadata_with_library_metadata.py @@ -20,6 +20,7 @@ def build(self): library_variable_role, library_variable_core, library_variable_ccode, + library_variable_has_codelist library_variable_order_number """ # get dataset metadata and execute the rule @@ -50,6 +51,7 @@ def build(self): "library_variable_role", "library_variable_core", "library_variable_ccode", + "library_variable_has_codelist", "library_variable_order_number", ] ], diff --git a/resources/schema/rule/MetaVariables.json b/resources/schema/rule/MetaVariables.json index 3b3f8d753..85c873e3a 100644 --- a/resources/schema/rule/MetaVariables.json +++ b/resources/schema/rule/MetaVariables.json @@ -139,6 +139,8 @@ }, { "const": "filename" }, { "const": "library_variable_core" }, + { "const": "library_variable_has_codelist" }, + { "const": "library_variable_ccode" }, { "const": "library_variable_data_type" }, { "const": "library_variable_label" }, { "const": "library_variable_name" }, diff --git a/resources/schema/rule/MetaVariables.md b/resources/schema/rule/MetaVariables.md index e15193cfa..d25e53de0 100644 --- a/resources/schema/rule/MetaVariables.md +++ b/resources/schema/rule/MetaVariables.md @@ -222,6 +222,14 @@ ordinal attribute of a variable from the CDISC Library role attribute of a variable from the CDISC Library +## library_variable_ccode + +ccode attribute of a variable from the CDISC Library + +## library_variable_has_codelist + +Indicates whether a variable has an associated codelist in the CDISC Library + ## row_number 1-based index of record number diff --git a/resources/schema/rule/Rule_Type.md b/resources/schema/rule/Rule_Type.md index 6f76f560f..fa8e46eda 100644 --- a/resources/schema/rule/Rule_Type.md +++ b/resources/schema/rule/Rule_Type.md @@ -315,6 +315,7 @@ all: - `library_variable_data_type` - `library_variable_role` - `library_variable_core` +- `library_variable_has_codelist` - `library_variable_ccode` #### Rule Macro diff --git a/tests/unit/test_dataset_builders/test_define_variables_with_library_metadata.py b/tests/unit/test_dataset_builders/test_define_variables_with_library_metadata.py index 64f839d31..3c36c1478 100644 --- a/tests/unit/test_dataset_builders/test_define_variables_with_library_metadata.py +++ b/tests/unit/test_dataset_builders/test_define_variables_with_library_metadata.py @@ -55,6 +55,7 @@ def test_define_variables_metadata_with_library_metadata_dataset_builder( "library_variable_core": ["Req", "Req", "Req", "Req"], "library_variable_order_number": ["1", "2", "8", "9"], "library_variable_data_type": ["Char", "Char", "Num", "Char"], + "library_variable_has_codelist": [False, False, False, False], } ) mock_get_library_variables_metadata.return_value = PandasDataset(library_vars_data) @@ -232,6 +233,7 @@ def test_define_variables_metadata_with_library_metadata_dataset_builder( "library_variable_core", "library_variable_order_number", "library_variable_data_type", + "library_variable_has_codelist", ] intersection = {"STUDYID", "USUBJID", "AESEQ", "AETERM"} diff --git a/tests/unit/test_dataset_builders/test_variables_metadata_with_define_and_library_dataset_builder.py b/tests/unit/test_dataset_builders/test_variables_metadata_with_define_and_library_dataset_builder.py index 4f6244e02..430ad609e 100644 --- a/tests/unit/test_dataset_builders/test_variables_metadata_with_define_and_library_dataset_builder.py +++ b/tests/unit/test_dataset_builders/test_variables_metadata_with_define_and_library_dataset_builder.py @@ -78,6 +78,7 @@ def test_build_combined_metadata( "library_variable_order_number": ["1", "2", "9", "8"], "library_variable_data_type": ["Char", "Char", "Char", "Num"], "library_variable_ccode": ["C49487", "C69256", "C41331", "C25364"], + "library_variable_has_codelist": [True, True, True, True], } ) mock_get_library_variables_metadata.return_value = PandasDataset(library_vars_data) @@ -181,6 +182,7 @@ def test_build_combined_metadata( "library_variable_role", "library_variable_core", "library_variable_ccode", + "library_variable_has_codelist", "library_variable_order_number", "variable_has_empty_values", "variable_is_empty", @@ -228,3 +230,4 @@ def test_build_combined_metadata( assert row["library_variable_role"] in ["Identifier", "Topic"] assert row["library_variable_core"] == "Req" assert row["library_variable_ccode"] in ["C49487", "C69256", "C41331"] + assert row["library_variable_has_codelist"] in [True, True, True] diff --git a/tests/unit/test_dataset_builders/test_variables_metadata_with_library_metadata_dataset_builder.py b/tests/unit/test_dataset_builders/test_variables_metadata_with_library_metadata_dataset_builder.py index f24568005..eb889e460 100644 --- a/tests/unit/test_dataset_builders/test_variables_metadata_with_library_metadata_dataset_builder.py +++ b/tests/unit/test_dataset_builders/test_variables_metadata_with_library_metadata_dataset_builder.py @@ -55,6 +55,7 @@ def test_variable_metadata_with_library_metadata_dataset_builder( "library_variable_order_number": ["1", "2", "9", "8"], "library_variable_data_type": ["Char", "Char", "Char", "Num"], "library_variable_ccode": ["C49487", "C69256", "C41331", "C25364"], + "library_variable_has_codelist": [True, True, True, True], } ) mock_get_library_variables_metadata.return_value = PandasDataset(library_vars_data) @@ -164,6 +165,7 @@ def test_variable_metadata_with_library_metadata_dataset_builder( "library_variable_role", "library_variable_core", "library_variable_ccode", + "library_variable_has_codelist", "library_variable_order_number", "variable_has_empty_values", "variable_is_empty", @@ -217,6 +219,7 @@ def test_variable_metadata_with_library_metadata_dataset_builder_variable_only_i "library_variable_order_number": ["1", "2", "9", "2000"], "library_variable_data_type": ["Char", "Char", "Char", "Num"], "library_variable_ccode": ["C49487", "C69256", "C41331", "C25364"], + "library_variable_has_codelist": [True, True, True, True], } ) mock_get_library_variables_metadata.return_value = PandasDataset(library_vars_data) @@ -388,6 +391,7 @@ def test_variable_metadata_with_library_metadata_dataset_builder_variable_only_i "library_variable_core", "library_variable_data_type", "library_variable_ccode", + "library_variable_has_codelist", "variable_has_empty_values", "variable_is_empty", ]