-
Notifications
You must be signed in to change notification settings - Fork 36
1316: New rule - value against library metadata #1680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bdb439b
#1316 dataset builder for new rule
alexfurmenkov f4343a2
Merge branch 'main' into 1316
alexfurmenkov 6383a72
Merge branch 'main' into 1316
alexfurmenkov b26f306
test for ContentsLibraryVariablesDatasetBuilder
alexfurmenkov 76662cc
rule description added to schema
alexfurmenkov 38c291c
Update merged schema files with markdown descriptions
adb6af7
simple regression test for new rule
alexfurmenkov 7e2cd04
test_dataset.json copied(for prettier)
alexfurmenkov e311841
test_dataset.json copied(for prettier)
alexfurmenkov f9bedc1
Merge remote-tracking branch 'origin/1316' into 1316
alexfurmenkov e6b4893
Merge branch 'main' into 1316
gerrycampion bcf6933
added rule type to json schema
alexfurmenkov c3a759a
Update merged schema files with markdown descriptions
77bc929
Merge branch 'main' into 1316
alexfurmenkov bc5cc32
changed outer to left join in dataset build method
alexfurmenkov 5e9e008
Revert "changed outer to left join in dataset build method"
alexfurmenkov 26733e7
Merge branch 'main' into 1316
SFJohnson24 b8ed267
Merge branch 'main' into 1316
SFJohnson24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
cdisc_rules_engine/dataset_builders/contents_library_variables_dataset_builder.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from cdisc_rules_engine.dataset_builders.values_dataset_builder import ( | ||
| ValuesDatasetBuilder, | ||
| ) | ||
|
|
||
|
|
||
| class ContentsLibraryVariablesDatasetBuilder(ValuesDatasetBuilder): | ||
| def build(self): | ||
| """ | ||
| Returns a long dataset where each value in each row of the original dataset is | ||
| a row in the new dataset. | ||
| Library metadata corresponding to each row's variable is | ||
| attached to each row. | ||
| Columns available in the dataset are: | ||
| "row_number", | ||
| "variable_name", | ||
| "variable_value", | ||
| "library_variable_name", | ||
| "library_variable_label", | ||
| "library_variable_role", | ||
| "library_variable_ccode", | ||
| ..., | ||
| """ | ||
| # get dataset contents and convert it from wide to long | ||
| data_contents_long_df = ValuesDatasetBuilder.build(self) | ||
| variables_metadata = self.get_library_variables_metadata() | ||
| # merge dataset contents with library variable metadata | ||
| merged = data_contents_long_df.merge( | ||
| variables_metadata.data, | ||
| how="outer", | ||
| left_on="variable_name", | ||
| right_on="library_variable_name", | ||
| ) | ||
| return merged |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import os | ||
| import subprocess | ||
| import unittest | ||
|
|
||
| import pytest | ||
| import json | ||
| from conftest import get_python_executable | ||
|
|
||
|
|
||
| @pytest.mark.regression | ||
| class TestCoreIssue1316(unittest.TestCase): | ||
| def test_new_rule(self): | ||
| # Run the command in the terminal | ||
| command = [ | ||
| f"{get_python_executable()}", | ||
| "-m", | ||
| "core", | ||
| "validate", | ||
| "-s", | ||
| "sdtmig", | ||
| "-v", | ||
| "3-4", | ||
| "-dp", | ||
| os.path.join( | ||
| "tests", | ||
| "resources", | ||
| "CoreIssue1316", | ||
| "test_dataset.json", | ||
| ), | ||
| "-lr", | ||
| os.path.join("tests", "resources", "CoreIssue1316", "rule_new.yml"), | ||
| "-ps", | ||
| "1", | ||
| "-of", | ||
| "json", | ||
| ] | ||
| subprocess.run(command, check=True) | ||
|
|
||
| files = os.listdir() | ||
| json_files = [ | ||
| file | ||
| for file in files | ||
| if file.startswith("CORE-Report-") and file.endswith(".json") | ||
| ] | ||
| json_report_path = sorted(json_files)[-1] | ||
| json_report = json.load(open(json_report_path)) | ||
| assert { | ||
| "Conformance_Details", | ||
| "Dataset_Details", | ||
| "Issue_Summary", | ||
| "Issue_Details", | ||
| "Rules_Report", | ||
| }.issubset(json_report.keys()) | ||
| assert json_report["Issue_Summary"][0]["issues"] == 591 | ||
| assert json_report["Rules_Report"][0]["status"] == "ISSUE REPORTED" | ||
|
|
||
| if os.path.exists(json_report_path): | ||
| os.remove(json_report_path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| Authorities: | ||
| - Organization: CDISC | ||
| Standards: | ||
| - Name: SDTMIG | ||
| References: | ||
| - Citations: | ||
| - Cited Guidance: | ||
| Each domain dataset is distinguished by a unique, two-character | ||
| code | ||
| Document: IG v3.4 | ||
| Section: "2.2" | ||
| Origin: SDTM and SDTMIG Conformance Rules | ||
| Rule Identifier: | ||
| Id: CORE-EX-ROUTE-001 | ||
| Version: "1" | ||
| Version: "2.0" | ||
| Version: "3.4" | ||
| Check: | ||
| all: | ||
| - name: variable_name | ||
| operator: equal_to | ||
| value: EXROUTE | ||
| - name: library_variable_ccode | ||
| operator: non_empty | ||
|
|
||
| Core: | ||
| Id: CORE-EX-ROUTE-001 | ||
| Status: Draft | ||
| Version: "1" | ||
| Description: test. | ||
| Executability: Fully Executable | ||
|
|
||
| Outcome: | ||
| Message: test. | ||
| Output Variables: | ||
| - EXROUTE | ||
| Rule Type: Value Check against Library Metadata | ||
| Scope: | ||
| Classes: | ||
| Include: | ||
| - ALL | ||
| Domains: | ||
| Include: | ||
| - ALL | ||
| Sensitivity: Record |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to also add this rule type to
Rule_Type.json. This is why the merge script is not finding anything.