TrialPath / app /components /gap_card.py
yakilee's picture
feat: enhance UI with evidence links, journey guards, and gap phrasing
28604f7
"""Gap analysis action card component."""
from __future__ import annotations
from trialpath.models import GapItem
_IMPORTANCE_COLORS = {
"high": "red",
"medium": "orange",
"low": "grey",
}
def render_gap_card(
gap: GapItem,
affected_trials: list[str] | None = None,
trial_titles: dict[str, str] | None = None,
) -> dict:
"""Produce a render-spec dict for a single gap item.
*trial_titles* maps nct_id -> trial title for "would match IF" phrasing.
"""
titles = trial_titles or {}
match_statements = []
for nct_id in affected_trials or []:
title = titles.get(nct_id, nct_id)
match_statements.append(
{
"nct_id": nct_id,
"trial_title": title,
"statement": f"You would match {title} IF you had: {gap.recommended_action}",
}
)
return {
"description": gap.description,
"recommended_action": gap.recommended_action,
"clinical_importance": gap.clinical_importance,
"importance_color": _IMPORTANCE_COLORS.get(gap.clinical_importance, "grey"),
"affected_trials": affected_trials or [],
"match_statements": match_statements,
}