Refine study controls and slice rail
This commit is contained in:
@@ -317,6 +317,7 @@ def ensure_study_summary_table() -> None:
|
||||
completed boolean NOT NULL DEFAULT false,
|
||||
completed_by text,
|
||||
completed_at timestamptz,
|
||||
completion_updated_at timestamptz,
|
||||
refreshed_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
ALTER TABLE public.pacs_dicom_study_summaries
|
||||
@@ -327,6 +328,8 @@ def ensure_study_summary_table() -> None:
|
||||
ADD COLUMN IF NOT EXISTS completed_by text;
|
||||
ALTER TABLE public.pacs_dicom_study_summaries
|
||||
ADD COLUMN IF NOT EXISTS completed_at timestamptz;
|
||||
ALTER TABLE public.pacs_dicom_study_summaries
|
||||
ADD COLUMN IF NOT EXISTS completion_updated_at timestamptz;
|
||||
"""
|
||||
pg_scalar(sql)
|
||||
|
||||
@@ -511,7 +514,8 @@ def annotation_overview_by_study() -> dict[str, dict[str, Any]]:
|
||||
COALESCE(
|
||||
jsonb_agg(DISTINCT part.value) FILTER (WHERE part.value IS NOT NULL),
|
||||
'[]'::jsonb
|
||||
) AS body_parts
|
||||
) AS body_parts,
|
||||
max(a.updated_at) FILTER (WHERE COALESCE(a.updated_by, '') <> 'system') AS annotation_updated_at
|
||||
FROM public.pacs_dicom_series_annotations a
|
||||
LEFT JOIN LATERAL jsonb_array_elements_text(a.body_parts) AS part(value) ON true
|
||||
GROUP BY a.ct_number
|
||||
@@ -530,7 +534,7 @@ def summary_rows_by_study() -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
SELECT
|
||||
ct_number, series_count, annotated_series, unannotated_series,
|
||||
body_parts, completed, completed_by, completed_at, refreshed_at
|
||||
body_parts, completed, completed_by, completed_at, completion_updated_at, refreshed_at
|
||||
FROM public.pacs_dicom_study_summaries
|
||||
""",
|
||||
timeout=8,
|
||||
@@ -545,7 +549,7 @@ def study_completion_fields(ct_number: str) -> dict[str, Any]:
|
||||
ensure_study_summary_table()
|
||||
rows = pg_json_rows(
|
||||
f"""
|
||||
SELECT completed, completed_by, completed_at
|
||||
SELECT completed, completed_by, completed_at, completion_updated_at
|
||||
FROM public.pacs_dicom_study_summaries
|
||||
WHERE ct_number = {sql_literal(ct_number)}
|
||||
LIMIT 1
|
||||
@@ -559,6 +563,7 @@ def study_completion_fields(ct_number: str) -> dict[str, Any]:
|
||||
"completed": bool(row.get("completed", False)),
|
||||
"completed_by": row.get("completed_by", ""),
|
||||
"completed_at": row.get("completed_at", ""),
|
||||
"completion_updated_at": row.get("completion_updated_at", ""),
|
||||
}
|
||||
|
||||
|
||||
@@ -593,6 +598,12 @@ def studies(_: str = Depends(require_auth), q: str = "", limit: int = 200) -> li
|
||||
row["completed"] = bool((summary or {}).get("completed", False))
|
||||
row["completed_by"] = (summary or {}).get("completed_by", "")
|
||||
row["completed_at"] = (summary or {}).get("completed_at", "")
|
||||
row["completion_updated_at"] = (summary or {}).get("completion_updated_at", "")
|
||||
row["annotation_updated_at"] = annotation_summary.get("annotation_updated_at", "")
|
||||
row["modified_at"] = max(
|
||||
str(row.get("annotation_updated_at") or ""),
|
||||
str(row.get("completion_updated_at") or ""),
|
||||
)
|
||||
row["summary_updated_at"] = (summary or {}).get("refreshed_at", "")
|
||||
return rows
|
||||
|
||||
@@ -1218,19 +1229,21 @@ def update_study_completion(ct_number: str, data: StudyCompletionIn, user: str =
|
||||
pg_scalar(
|
||||
f"""
|
||||
INSERT INTO public.pacs_dicom_study_summaries (
|
||||
ct_number, completed, completed_by, completed_at, refreshed_at
|
||||
ct_number, completed, completed_by, completed_at, completion_updated_at, refreshed_at
|
||||
)
|
||||
VALUES (
|
||||
{sql_literal(ct_number)},
|
||||
{'true' if data.completed else 'false'},
|
||||
{sql_literal(user)},
|
||||
{'now()' if data.completed else 'NULL'},
|
||||
now(),
|
||||
now()
|
||||
)
|
||||
ON CONFLICT (ct_number) DO UPDATE SET
|
||||
completed = EXCLUDED.completed,
|
||||
completed_by = EXCLUDED.completed_by,
|
||||
completed_at = EXCLUDED.completed_at
|
||||
completed_at = EXCLUDED.completed_at,
|
||||
completion_updated_at = EXCLUDED.completion_updated_at
|
||||
"""
|
||||
)
|
||||
return {"ok": True, "ct_number": ct_number, **study_completion_fields(ct_number)}
|
||||
@@ -1593,7 +1606,9 @@ def save_annotation_payload(
|
||||
"skipped": skipped,
|
||||
"ai_skipped": ai_skipped,
|
||||
"notes": notes,
|
||||
"updated_at": time.strftime("%Y-%m-%dT%H:%M:%S"),
|
||||
"ai_model": ai_model or series_row.get("annotation", {}).get("ai_model", ""),
|
||||
"updated_by": user,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user