Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ def get_condition_composite(
)

if key == AllowedConditionsKeys.NOT.value:
# "not" composite wraps a regular composite
return NotConditionComposite(
not_inner = cls.get_condition_composite(condition_list)
not_composite = NotConditionComposite(
key=key,
condition_composite=cls.get_condition_composite(conditions["not"]),
condition_composite=not_inner,
)
composite.add_conditions(
AllowedConditionsKeys.ALL.value,
[not_composite],
)
continue
else:
# create a regular composite
conditions_to_add = []
Expand Down
234 changes: 234 additions & 0 deletions tests/QARegressionTests/test_Issues/test_CoreIssue1348.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
import os
import subprocess

import pytest
import json
from conftest import get_python_executable

_message = (
"The study version's study phase is not specified according to the extensible Trial Phase Response"
' (C66737) SDTM codelist - codeSystem is not "http://www.cdisc.org", codeSystemVersion is not a valid'
" terminology package date, and/or the code or decode is found in the codelist (case insensitive)"
" but the corresponding decode or code does not match the codelist value (case sensitive)."
)
_summary = [
{
"dataset": "StudyVersion.xpt",
"core_id": "CORE-000409",
"message": _message,
"issues": 7,
}
]
_issue_details = [
{
"core_id": "CORE-000409",
"message": _message,
"executability": "fully executable",
"dataset": "StudyVersion.xpt",
"USUBJID": "",
"row": 1,
"SEQ": "",
"variables": [
"$code_for_pref_term",
"$code_for_value",
"$pref_term_for_code",
"$value_for_code",
"studyPhase.standardCode.code",
"studyPhase.standardCode.decode",
],
"values": [
"C199989",
"C199989",
"Phase II Trial",
"PHASE II TRIAL",
"C15601",
"Phase Ib Trial",
],
},
{
"core_id": "CORE-000409",
"message": _message,
"executability": "fully executable",
"dataset": "StudyVersion.xpt",
"USUBJID": "",
"row": 2,
"SEQ": "",
"variables": [
"$code_for_pref_term",
"$code_for_value",
"$pref_term_for_code",
"$value_for_code",
"studyPhase.standardCode.code",
"studyPhase.standardCode.decode",
],
"values": ["null", "null", "Not Applicable", "NOT APPLICABLE", "C48660", "N/A"],
},
{
"core_id": "CORE-000409",
"message": _message,
"executability": "fully executable",
"dataset": "StudyVersion.xpt",
"USUBJID": "",
"row": 3,
"SEQ": "",
"variables": [
"$code_for_pref_term",
"$code_for_value",
"$pref_term_for_code",
"$value_for_code",
"studyPhase.standardCode.code",
"studyPhase.standardCode.decode",
],
"values": [
"C198366",
"C198366",
"null",
"null",
"C198366xx",
"Phase I/II/III Trial",
],
},
{
"core_id": "CORE-000409",
"message": _message,
"executability": "fully executable",
"dataset": "StudyVersion.xpt",
"USUBJID": "",
"row": 4,
"SEQ": "",
"variables": [
"$code_for_pref_term",
"$code_for_value",
"$pref_term_for_code",
"$value_for_code",
"studyPhase.standardCode.code",
"studyPhase.standardCode.decode",
],
"values": ["C15600", "C15600", "null", "null", "C00001x", "Phase I Trial"],
},
{
"core_id": "CORE-000409",
"message": _message,
"executability": "fully executable",
"dataset": "StudyVersion.xpt",
"USUBJID": "",
"row": 5,
"SEQ": "",
"variables": [
"$code_for_pref_term",
"$code_for_value",
"$pref_term_for_code",
"$value_for_code",
"studyPhase.standardCode.code",
"studyPhase.standardCode.decode",
],
"values": [
"C198366",
"C198366",
"Phase II Trial",
"PHASE II TRIAL",
"C15601",
"Phase I/II/III Trial",
],
},
{
"core_id": "CORE-000409",
"message": _message,
"executability": "fully executable",
"dataset": "StudyVersion.xpt",
"USUBJID": "",
"row": 6,
"SEQ": "",
"variables": [
"$code_for_pref_term",
"$code_for_value",
"$pref_term_for_code",
"$value_for_code",
"studyPhase.standardCode.code",
"studyPhase.standardCode.decode",
],
"values": ["C199989", "C199989", "null", "null", "C198366xx", "PHASE IB TRIAL"],
},
{
"core_id": "CORE-000409",
"message": _message,
"executability": "fully executable",
"dataset": "StudyVersion.xpt",
"USUBJID": "",
"row": 7,
"SEQ": "",
"variables": [
"$code_for_pref_term",
"$code_for_value",
"$pref_term_for_code",
"$value_for_code",
"studyPhase.standardCode.code",
"studyPhase.standardCode.decode",
],
"values": [
"null",
"null",
"Phase Ib Trial",
"PHASE IB TRIAL",
"C199989",
"PHASE 2 TRIAL",
],
},
]


@pytest.mark.regression
class TestCoreIssue1348:
@pytest.mark.parametrize(
"rule_name, dataset, issue_summary, details",
[
("DDF00015_not.yaml", "data_pos", [], []),
("DDF00015_not.yaml", "data_neg", _summary, _issue_details),
("DDF00015_all.yaml", "data_pos", [], []),
("DDF00015_all.yaml", "data_neg", _summary, _issue_details),
],
)
def test_not_as_first_condition_same_errors_as_all_condition(
self, rule_name, dataset, issue_summary, details
):
# Run the command in the terminal
command = [
f"{get_python_executable()}",
"-m",
"core",
"validate",
"-s",
"sdtmig",
"-v",
"3-4",
"-lr",
os.path.join("tests", "resources", "CoreIssue1348", rule_name),
"-of",
"json",
"--data",
os.path.join("tests", "resources", "CoreIssue1348", dataset),
]
subprocess.run(command, check=True)

# Get the latest created Excel file
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]
# Open the JSON report file
json_report = json.load(open(json_report_path))
assert {
"Conformance_Details",
"Dataset_Details",
"Issue_Summary",
"Issue_Details",
"Rules_Report",
}.issubset(json_report.keys())

assert details == json_report["Issue_Details"]
assert issue_summary == json_report["Issue_Summary"]
if os.path.exists(json_report_path):
os.remove(json_report_path)
117 changes: 117 additions & 0 deletions tests/resources/CoreIssue1348/DDF00015_all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Authorities:
- Organization: CDISC
Standards:
- Name: USDM
References:
- Citations:
- Cited Guidance:
"A study version's study phase must be specified according to
the extensible Trial Phase Response (C66737) SDTM codelist
(e.g. an entry with a code or decode used from the codelist
should be consistent with the full entry in the codelist)."
Document: "USDM_CORE_Rules.xlsx"
Origin: "USDM Conformance Rules"
Rule Identifier:
Id: "DDF00015"
Version: "1"
Version: "1.0"
Version: "3.0"
Check:
all:
- not:
any:
- all:
- name: $code_for_pref_term
operator: empty
- name: $code_for_value
operator: empty
- name: $pref_term_for_code
operator: empty
- name: $value_for_code
operator: empty
- all:
- name: $pref_term_for_code
operator: non_empty
- name: $value_for_code
operator: non_empty
- any:
- name: $code_for_pref_term
operator: non_empty
- name: $code_for_value
operator: non_empty
- any:
- name: studyPhase.standardCode.code
operator: equal_to
value: $code_for_pref_term
- name: studyPhase.standardCode.code
operator: equal_to
value: $code_for_value
- any:
- name: studyPhase.standardCode.decode
operator: equal_to
value: $pref_term_for_code
- name: studyPhase.standardCode.decode
operator: equal_to
value: $value_for_code
Core:
Id: "CORE-000409"
Status: Draft
Version: "1"
Description: "A study version's study phase must be specified according to the
extensible Trial Phase Response (C66737) SDTM codelist (e.g. an entry with a
code or decode used from the codelist should be consistent with the full entry
in the codelist)."
Executability: Fully Executable
Operations:
- id: $codelist_code
map:
- output: C66737
operator: map
- codelist_code: $codelist_code
ct_package_type: SDTM
id: $value_for_code
operator: codelist_terms
term_code: studyPhase.standardCode.code
version: studyPhase.standardCode.codeSystemVersion
returntype: value
- codelist_code: $codelist_code
ct_package_type: SDTM
id: $pref_term_for_code
operator: codelist_terms
term_code: studyPhase.standardCode.code
version: studyPhase.standardCode.codeSystemVersion
returntype: pref_term
- codelist_code: $codelist_code
ct_package_type: SDTM
id: $code_for_pref_term
operator: codelist_terms
term_pref_term: studyPhase.standardCode.decode
version: studyPhase.standardCode.codeSystemVersion
returntype: code
- codelist_code: $codelist_code
ct_package_type: SDTM
id: $code_for_value
operator: codelist_terms
term_value: studyPhase.standardCode.decode
version: studyPhase.standardCode.codeSystemVersion
returntype: code
Outcome:
Message: 'The study version''s study phase is not specified according to the
extensible Trial Phase Response (C66737) SDTM codelist - codeSystem is not
"http://www.cdisc.org", codeSystemVersion is not a valid terminology package
date, and/or the code or decode is found in the codelist (case insensitive)
but the corresponding decode or code does not match the codelist value (case
sensitive).'
Output Variables:
- $code_for_pref_term
- $code_for_value
- $pref_term_for_code
- $value_for_code
- studyPhase.standardCode.code
- studyPhase.standardCode.decode
Rule Type: Record Data
Scope:
Entities:
Include:
- "StudyVersion"
Sensitivity: Record
Loading
Loading