From c96318516eef1bf0838d9cb11f8fcd3188ea4e8b Mon Sep 17 00:00:00 2001 From: Samuel Johnson Date: Wed, 18 Feb 2026 18:42:20 -0500 Subject: [PATCH 1/3] new metadata --- .../dataset_builders/base_dataset_builder.py | 2 ++ .../define_variables_with_library_metadata.py | 1 + ...es_metadata_with_define_and_library_dataset_builder.py | 2 ++ .../variables_metadata_with_library_metadata.py | 2 ++ resources/schema/rule/MetaVariables.json | 1 + resources/schema/rule/MetaVariables.md | 8 ++++++++ resources/schema/rule/Rule_Type.md | 3 +++ ...es_metadata_with_define_and_library_dataset_builder.py | 3 +++ ...bles_metadata_with_library_metadata_dataset_builder.py | 4 ++++ 9 files changed, 26 insertions(+) diff --git a/cdisc_rules_engine/dataset_builders/base_dataset_builder.py b/cdisc_rules_engine/dataset_builders/base_dataset_builder.py index ae67c499e..3718b65e4 100644 --- a/cdisc_rules_engine/dataset_builders/base_dataset_builder.py +++ b/cdisc_rules_engine/dataset_builders/base_dataset_builder.py @@ -215,12 +215,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 0faf1ad84..2cd772705 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 @@ -35,6 +35,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 """ @@ -73,6 +74,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 9c224b551..9a2201d5d 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 @@ -19,6 +19,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 @@ -49,6 +50,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 2e3a690a7..ee12e8cdd 100644 --- a/resources/schema/rule/MetaVariables.json +++ b/resources/schema/rule/MetaVariables.json @@ -133,6 +133,7 @@ }, { "const": "filename" }, { "const": "library_variable_core" }, + { "const": "library_variable_has_codelist" }, { "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 91945918d..bcb5e3599 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 bbf184d8f..551084579 100644 --- a/resources/schema/rule/Rule_Type.md +++ b/resources/schema/rule/Rule_Type.md @@ -160,6 +160,7 @@ Attach variable codelist and codelist terms - `library_variable_data_type` - `library_variable_role` - `library_variable_core` +- `library_variable_has_codelist` - `library_variable_ccode` #### Rule Macro @@ -561,6 +562,7 @@ Attach define xml metadata at variable level - `library_variable_core` - `library_variable_order_number` - `library_variable_data_type` +- `library_variable_has_codelist` - `library_variable_ccode` ## Variables Metadata Check against Define XML and Library Metadata @@ -596,6 +598,7 @@ Attach define xml metadata at variable level - `library_variable_core` - `library_variable_order_number` - `library_variable_data_type` +- `library_variable_has_codelist` - `library_variable_ccode` - `variable_has_empty_values` 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 0810892c4..156363a47 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 @@ -79,6 +79,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) @@ -182,6 +183,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", } @@ -247,3 +249,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 424161286..5815f0850 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", ] @@ -215,6 +217,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) @@ -386,6 +389,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", ] ) From 528a036a0bfeb4e8e18d55adde8ae1c90e2c3d88 Mon Sep 17 00:00:00 2001 From: Samuel Johnson Date: Thu, 26 Feb 2026 10:46:59 -0500 Subject: [PATCH 2/3] added missing meta --- resources/schema/rule/MetaVariables.json | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/schema/rule/MetaVariables.json b/resources/schema/rule/MetaVariables.json index 9be718eb7..e8e097be8 100644 --- a/resources/schema/rule/MetaVariables.json +++ b/resources/schema/rule/MetaVariables.json @@ -134,6 +134,7 @@ { "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" }, From dc408c3f81268aa2fb6d807b2c36aacfcc7a6e5a Mon Sep 17 00:00:00 2001 From: Samuel Johnson Date: Thu, 26 Feb 2026 10:51:40 -0500 Subject: [PATCH 3/3] tests --- .../test_define_variables_with_library_metadata.py | 2 ++ 1 file changed, 2 insertions(+) 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"}