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: 1 addition & 1 deletion .github/scripts/run_validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fi
echo "Rule file: $RULE_YML"

# ---------------------------------------------------------------------------
# Initialise report
# Initialize report
# ---------------------------------------------------------------------------
{
echo "# Rule Validation Report"
Expand Down
1 change: 0 additions & 1 deletion Published/CORE-000929/negative/01/data/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
PRODUCT=SDTMIG
VERSION=3-3
CT=sdtmct2020-12-18
DEFINE_XML=define_negative1.xml
9 changes: 4 additions & 5 deletions Published/CORE-000929/negative/01/results/results.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Dataset,Record,Variable,Value
zb.csv,,,
fa.csv,2,$domain_lib_ccode,"['C49563', 'C49562', 'C117755', 'C147168', 'C147169', 'C147170', 'C132354', 'C147171', 'C147172', 'C147173', 'C147174', 'C147175', 'C147176', 'C147177', 'C147178', 'C147179', 'C111282', 'C111138', 'C111137', 'C85441', 'C49568', 'C49569', 'C102605', 'C49578', 'C95087', 'C102616', 'C102618', 'C49572', 'C102619', 'C102620', 'C49576', 'C102621', 'C102622', 'C49585', 'C102617', 'C117466', 'C102630', 'C49626', 'C49587', 'C85442', 'C117756', 'C102640', 'C102641', 'C117757', 'C61536', 'C102651', 'C112320', 'C49592', 'C49602', 'C49603', 'C95095', 'C102674', 'C49604', 'C102671', 'C61531', 'C102677', 'C147180', 'C161329', 'C106552', 'C49606', 'C49608', 'C111289', 'C61529', 'C147181', 'C49607', 'C102700', 'C49609', 'C95098', 'C147182', 'C147183', 'C102707', 'C107097', 'C106571', 'C49610', 'C49616', 'C147184', 'C112420', 'C117655', 'C49615', 'C147185', 'C147186', 'C147187', 'C147189', 'C147191', 'C147193', 'C147195', 'C147196', 'C147197', 'C147198', 'C147200', 'C147201', 'C147203', 'C147204', 'C147205', 'C147206', 'C147207', 'C147208', 'C147209', 'C147210', 'C147211', 'C147212', 'C147216', 'C147218', 'C147219', 'C147220', 'C147222', 'C147223', 'C147224', 'C147225', 'C147226', 'C165871', 'C147227', 'C147228', 'C147229', 'C147232', 'C147233', 'C147234', 'C147235', 'C147236', 'C147238', 'C147239', 'C147240', 'C147241', 'C147242', 'C147243', 'C147244', 'C147245', 'C147246', 'C147249', 'C147250', 'C147251', 'C147252', 'C147261', 'C147264', 'C147267', 'C147268', 'C147269', 'C49617', 'C49618', 'C117699', 'C49619', 'C49620', 'C147270', 'C106578', 'C53483', 'C106577', 'C49621', 'C95103', 'C102726', 'C49622']"
fa.csv,2,define_variable_codelist_coded_codes,['C00002']
vs.csv,2,$domain_lib_ccode,"['C49563', 'C49562', 'C117755', 'C147168', 'C147169', 'C147170', 'C132354', 'C147171', 'C147172', 'C147173', 'C147174', 'C147175', 'C147176', 'C147177', 'C147178', 'C147179', 'C111282', 'C111138', 'C111137', 'C85441', 'C49568', 'C49569', 'C102605', 'C49578', 'C95087', 'C102616', 'C102618', 'C49572', 'C102619', 'C102620', 'C49576', 'C102621', 'C102622', 'C49585', 'C102617', 'C117466', 'C102630', 'C49626', 'C49587', 'C85442', 'C117756', 'C102640', 'C102641', 'C117757', 'C61536', 'C102651', 'C112320', 'C49592', 'C49602', 'C49603', 'C95095', 'C102674', 'C49604', 'C102671', 'C61531', 'C102677', 'C147180', 'C161329', 'C106552', 'C49606', 'C49608', 'C111289', 'C61529', 'C147181', 'C49607', 'C102700', 'C49609', 'C95098', 'C147182', 'C147183', 'C102707', 'C107097', 'C106571', 'C49610', 'C49616', 'C147184', 'C112420', 'C117655', 'C49615', 'C147185', 'C147186', 'C147187', 'C147189', 'C147191', 'C147193', 'C147195', 'C147196', 'C147197', 'C147198', 'C147200', 'C147201', 'C147203', 'C147204', 'C147205', 'C147206', 'C147207', 'C147208', 'C147209', 'C147210', 'C147211', 'C147212', 'C147216', 'C147218', 'C147219', 'C147220', 'C147222', 'C147223', 'C147224', 'C147225', 'C147226', 'C165871', 'C147227', 'C147228', 'C147229', 'C147232', 'C147233', 'C147234', 'C147235', 'C147236', 'C147238', 'C147239', 'C147240', 'C147241', 'C147242', 'C147243', 'C147244', 'C147245', 'C147246', 'C147249', 'C147250', 'C147251', 'C147252', 'C147261', 'C147264', 'C147267', 'C147268', 'C147269', 'C49617', 'C49618', 'C117699', 'C49619', 'C49620', 'C147270', 'C106578', 'C53483', 'C106577', 'C49621', 'C95103', 'C102726', 'C49622']"
vs.csv,2,define_variable_codelist_coded_codes,['C00004']
FA,2,$domain_lib_ccode,"['C49563', 'C49562', 'C117755', 'C147168', 'C147169', 'C147170', 'C132354', 'C147171', 'C147172', 'C147173', 'C147174', 'C147175', 'C147176', 'C147177', 'C147178', 'C147179', 'C111282', 'C111138', 'C111137', 'C85441', 'C49568', 'C49569', 'C102605', 'C49578', 'C95087', 'C102616', 'C102618', 'C49572', 'C102619', 'C102620', 'C49576', 'C102621', 'C102622', 'C49585', 'C102617', 'C117466', 'C102630', 'C49626', 'C49587', 'C85442', 'C117756', 'C102640', 'C102641', 'C117757', 'C61536', 'C102651', 'C112320', 'C49592', 'C49602', 'C49603', 'C95095', 'C102674', 'C49604', 'C102671', 'C61531', 'C102677', 'C147180', 'C161329', 'C106552', 'C49606', 'C49608', 'C111289', 'C61529', 'C147181', 'C49607', 'C102700', 'C49609', 'C95098', 'C147182', 'C147183', 'C102707', 'C107097', 'C106571', 'C49610', 'C49616', 'C147184', 'C112420', 'C117655', 'C49615', 'C147185', 'C147186', 'C147187', 'C147189', 'C147191', 'C147193', 'C147195', 'C147196', 'C147197', 'C147198', 'C147200', 'C147201', 'C147203', 'C147204', 'C147205', 'C147206', 'C147207', 'C147208', 'C147209', 'C147210', 'C147211', 'C147212', 'C147216', 'C147218', 'C147219', 'C147220', 'C147222', 'C147223', 'C147224', 'C147225', 'C147226', 'C165871', 'C147227', 'C147228', 'C147229', 'C147232', 'C147233', 'C147234', 'C147235', 'C147236', 'C147238', 'C147239', 'C147240', 'C147241', 'C147242', 'C147243', 'C147244', 'C147245', 'C147246', 'C147249', 'C147250', 'C147251', 'C147252', 'C147261', 'C147264', 'C147267', 'C147268', 'C147269', 'C49617', 'C49618', 'C117699', 'C49619', 'C49620', 'C147270', 'C106578', 'C53483', 'C106577', 'C49621', 'C95103', 'C102726', 'C49622']"
FA,2,define_variable_codelist_coded_codes,['C00002']
VS,2,$domain_lib_ccode,"['C49563', 'C49562', 'C117755', 'C147168', 'C147169', 'C147170', 'C132354', 'C147171', 'C147172', 'C147173', 'C147174', 'C147175', 'C147176', 'C147177', 'C147178', 'C147179', 'C111282', 'C111138', 'C111137', 'C85441', 'C49568', 'C49569', 'C102605', 'C49578', 'C95087', 'C102616', 'C102618', 'C49572', 'C102619', 'C102620', 'C49576', 'C102621', 'C102622', 'C49585', 'C102617', 'C117466', 'C102630', 'C49626', 'C49587', 'C85442', 'C117756', 'C102640', 'C102641', 'C117757', 'C61536', 'C102651', 'C112320', 'C49592', 'C49602', 'C49603', 'C95095', 'C102674', 'C49604', 'C102671', 'C61531', 'C102677', 'C147180', 'C161329', 'C106552', 'C49606', 'C49608', 'C111289', 'C61529', 'C147181', 'C49607', 'C102700', 'C49609', 'C95098', 'C147182', 'C147183', 'C102707', 'C107097', 'C106571', 'C49610', 'C49616', 'C147184', 'C112420', 'C117655', 'C49615', 'C147185', 'C147186', 'C147187', 'C147189', 'C147191', 'C147193', 'C147195', 'C147196', 'C147197', 'C147198', 'C147200', 'C147201', 'C147203', 'C147204', 'C147205', 'C147206', 'C147207', 'C147208', 'C147209', 'C147210', 'C147211', 'C147212', 'C147216', 'C147218', 'C147219', 'C147220', 'C147222', 'C147223', 'C147224', 'C147225', 'C147226', 'C165871', 'C147227', 'C147228', 'C147229', 'C147232', 'C147233', 'C147234', 'C147235', 'C147236', 'C147238', 'C147239', 'C147240', 'C147241', 'C147242', 'C147243', 'C147244', 'C147245', 'C147246', 'C147249', 'C147250', 'C147251', 'C147252', 'C147261', 'C147264', 'C147267', 'C147268', 'C147269', 'C49617', 'C49618', 'C117699', 'C49619', 'C49620', 'C147270', 'C106578', 'C53483', 'C106577', 'C49621', 'C95103', 'C102726', 'C49622']"
VS,2,define_variable_codelist_coded_codes,['C00004']
1 change: 0 additions & 1 deletion Published/CORE-000929/negative/02/data/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
PRODUCT=SDTMIG
VERSION=3-4
CT=sdtmct2020-12-18
DEFINE_XML=define_negative2.xml
1 change: 0 additions & 1 deletion Published/CORE-000929/positive/01/data/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
PRODUCT=SDTMIG
VERSION=3-3
CT=sdtmct2020-12-18
DEFINE_XML=define_positive1.xml
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Unpublished/
**`.env`**

Specifies the standard and version to validate against. `PRODUCT` and `VERSION` are required; `SUBSTANDARD`, `USE_CASE`, `CT`, and `DEFINE_XML` are optional depending on the rule.

See [`.env.example`](./engine/.env.example) for example env environment variables.
```
PRODUCT=TIG
VERSION=1-0
Expand All @@ -179,14 +179,14 @@ Unpublished/

```
dataset,variable,label,type,length
cm,STUDYID,Study Identifier,Char,50
cm,DOMAIN,Domain Abbreviation,Char,50
cm,USUBJID,Unique Subject Identifier,Char,50
cm,CMTRT,"Reported Name of Drug, Med, or Therapy",Char,50
dm,STUDYID,Study Identifier,Char,50
dm,DOMAIN,Domain Abbreviation,Char,50
dm,USUBJID,Unique Subject Identifier,Char,50
dm,AGE,Age,Num,8
CM,STUDYID,Study Identifier,Char,50
CM,DOMAIN,Domain Abbreviation,Char,50
CM,USUBJID,Unique Subject Identifier,Char,50
CM,CMTRT,"Reported Name of Drug, Med, or Therapy",Char,50
DM,STUDYID,Study Identifier,Char,50
DM,DOMAIN,Domain Abbreviation,Char,50
DM,USUBJID,Unique Subject Identifier,Char,50
DM,AGE,Age,Num,8
...
```

Expand Down
81 changes: 71 additions & 10 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
and writes results.json into each case's results/ directory.
"""

import os
import sys
import subprocess
from pathlib import Path
Expand All @@ -13,6 +14,8 @@
ENGINE_DIR = Path("engine")
CONVERT_SCRIPT = Path(".github/scripts/convert_results.py")

LOG_LEVELS = ["info", "debug", "error", "critical", "disabled", "warn"]

# ---------------------------------------------------------------------------
# Rule folder helpers
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -83,7 +86,13 @@ def next_results_path(results_dir: Path) -> Path:
# Engine invocation
# ---------------------------------------------------------------------------

def run_engine(rule_yml: Path, data_dir: Path, output_path: Path) -> tuple[bool, str]:
def run_engine(
rule_yml: Path,
data_dir: Path,
output_path: Path,
log_level: str,
capture_logs: bool,
) -> tuple[bool, str]:
env_file = find_env_file(data_dir)
if env_file is None:
return False, f"No .env file found in {data_dir}"
Expand All @@ -96,11 +105,36 @@ def run_engine(rule_yml: Path, data_dir: Path, output_path: Path) -> tuple[bool,
"-of", "JSON",
"-o", str(output_path.resolve()),
"-p", "disabled",
"-l", log_level,
]

try:
proc = subprocess.run(cmd, cwd=ENGINE_DIR, capture_output=True, text=True)
output = (proc.stdout + proc.stderr).strip()
env = os.environ.copy()

stream_output = log_level != "disabled"
lines: list[str] = []
with subprocess.Popen(
cmd,
cwd=ENGINE_DIR,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
) as proc:
for line in proc.stdout:
if stream_output:
print(f" {line}", end="")
lines.append(line)
proc.wait()

output = "".join(lines).strip()

if capture_logs and output:
log_path = output_path.parent / f"{output_path.name}_engine.log.txt"
log_path.write_text(output, encoding="utf-8")
print(f" Log captured — {log_path}")

return proc.returncode == 0, output
except Exception as e:
return False, str(e)
Expand All @@ -111,7 +145,12 @@ def run_engine(rule_yml: Path, data_dir: Path, output_path: Path) -> tuple[bool,
# ---------------------------------------------------------------------------


def run_rule(rule_path: Path, specific_case: Optional[str] = None):
def run_rule(
rule_path: Path,
specific_case: Optional[str],
log_level: str,
capture_logs: bool,
):
rule_yml = find_rule_yml(rule_path)
all_cases = get_test_cases(rule_path)

Expand All @@ -134,7 +173,7 @@ def run_rule(rule_path: Path, specific_case: Optional[str] = None):
output_path = next_results_path(case["results_dir"])

print(f"\n Running {test_type}/{case_id}...")
ok, output = run_engine(rule_yml, data_dir, output_path)
ok, output = run_engine(rule_yml, data_dir, output_path, log_level, capture_logs)

json_path = Path(str(output_path) + ".json")
if ok and json_path.exists():
Expand Down Expand Up @@ -212,20 +251,42 @@ def prompt_case(cases: Dict[str, List[dict]]) -> Optional[str]:
print("Invalid — try again.")


def prompt_log_level() -> str:
print("\nLog level options:")
for i, level in enumerate(LOG_LEVELS, 1):
print(f" {i}. {level}")
while True:
choice = input("Select log level (default: disabled): ").strip().lower()
if not choice:
return "disabled"
if choice in LOG_LEVELS:
return choice
if choice.isdigit() and 1 <= int(choice) <= len(LOG_LEVELS):
return LOG_LEVELS[int(choice) - 1]
print("Invalid — try again.")


def prompt_capture_logs() -> bool:
choice = input("Capture engine logs to results folder? (y/N): ").strip().lower()
return choice == "y"


# ---------------------------------------------------------------------------
# Entry point
# ---------------------------------------------------------------------------

def main():
rule_path = prompt_rule_path()
cases = get_test_cases(rule_path)
specific = prompt_case(cases)
run_rule(rule_path, specific)
rule_path = prompt_rule_path()
cases = get_test_cases(rule_path)
specific = prompt_case(cases)
log_level = prompt_log_level()
capture_logs = prompt_capture_logs()
run_rule(rule_path, specific, log_level, capture_logs)


if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\nInterrupted.")
sys.exit(1)
sys.exit(1)