Skill Tracer
Skills › Scientific Agent Skills › treatment-plans › validate_treatment_plan.py

validate_treatment_plan.py

95 lines · skills/treatment-plans/scripts/validate_treatment_plan.py at 5f2bc03

1#!/usr/bin/env python3
2"""Validate strict JSON structure without evaluating clinical content."""
3
4from __future__ import annotations
5
6import argparse
7import sys
8
9from _common import (
10 TEMPLATE_FILES,
11 Issue,
12 ValidationError,
13 error_report,
14 load_target,
15 print_report,
16 report_payload,
17 validate_document,
18 validate_package_structure,
22def validate_target(raw_path: str) -> dict:
23 documents, _ = load_target(raw_path)
24 if set(documents) == set(TEMPLATE_FILES):
25 issues = validate_package_structure(documents)
26 else:
27 issues: list[Issue] = []
28 for document_type, document in documents.items():
29 for issue in validate_document(document):
30 issues.append(
31 Issue(
32 issue.code,
33 f"{document_type if document_type in TEMPLATE_FILES else 'unknown_document_type'}:{issue.path}",
34 issue.level,
35 )
36 )
37 issues.sort(key=lambda item: (item.path, item.code))
39 record_count = 0
40 for document in documents.values():
41 for field in (
42 "facts",
43 "interventions",
44 "goals",
45 "monitoring_items",
46 "checkpoints",
47 "entries",
48 "handoff_items",
49 "unresolved_items",
50 ):
51 value = document.get(field)
52 if isinstance(value, list):
53 record_count += len(value)
55 return report_payload(
56 "structural_validation",
57 issues,
58 counts={
59 "documents_checked": len(documents),
60 "records_checked": record_count,
61 "structural_issues": len(issues),
62 },
63 extra={
64 "clinical_content_evaluated": False,
65 "unknown_fields_allowed": False,
66 },
67 )
70def build_parser() -> argparse.ArgumentParser:
71 parser = argparse.ArgumentParser(
72 description=(
73 "Validate one local JSON record or a complete six-file package. "
74 "Checks only schema, types, enums, bounds, and ISO dates."
75 )
76 )
77 parser.add_argument(
78 "path",
79 help="Local .json file or complete package directory",
80 )
81 return parser
84def main() -> int:
85 args = build_parser().parse_args()
86 try:
87 report = validate_target(args.path)
88 except ValidationError as exc:
89 report = error_report("structural_validation", exc)
90 print_report(report)
91 return 1 if report["status"] == "fail" else 0
94if __name__ == "__main__":
95 sys.exit(main())