Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cdisc_rules_engine/dataset_builders/base_dataset_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing updates to test_define_variables_with_library_metadata

Original file line number Diff line number Diff line change
Expand Up @@ -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"
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -50,6 +51,7 @@ def build(self):
"library_variable_role",
"library_variable_core",
"library_variable_ccode",
"library_variable_has_codelist",
"library_variable_order_number",
]
],
Expand Down
2 changes: 2 additions & 0 deletions resources/schema/rule/MetaVariables.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
8 changes: 8 additions & 0 deletions resources/schema/rule/MetaVariables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions resources/schema/rule/Rule_Type.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ all:
- `library_variable_data_type`
- `library_variable_role`
- `library_variable_core`
- `library_variable_has_codelist`
- `library_variable_ccode`

#### Rule Macro
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
]
Expand Down
Loading