Recommendation service¶
The application orchestrator: cohort fetch → scoring pipeline → engine →
persistence, for one or many patients. Wires the CohortRepository,
DataPipeline, and PrescriptionStore collaborators.
Naming
The class is RecommendationService. CDSS is kept as a back-compat
alias for pre-existing callers — both import from ai_cdss.
RecommendationService
¶
RecommendationService(
repository: Optional[CohortRepository] = None,
pipeline: Optional[DataPipeline] = None,
store: Optional[PrescriptionStore] = None,
debug: bool = False,
)
Application orchestrator: cohort fetch → scoring pipeline → engine → persistence, for one or many patients.
Wires three injected collaborators (all default to production implementations, all swappable for tests / backtests):
repository(CohortRepository) — reads the inputCohort.pipeline(DataPipeline) — Cohort → scored frame.store(PrescriptionStore) — idempotency check + writes the recommendation output.
The per-patient recommendation itself is delegated to Recommender
(engine locally). Note the layering: this class is the service;
Recommender is the engine. They are distinct — don't conflate.
Source code in src\ai_cdss\interface\cdss.py
recommend_for_patients
¶
recommend_for_patients(
patient_ids: List[int],
n: int = N,
days: int = N_DAYS,
protocols_per_day: int = PROTOCOLS_PER_DAY,
scoring_date: Optional[Timestamp] = None,
force: bool = False,
) -> Dict[str, Any]
Run recommendations for one or many patients. Returns the same structure as recommend_for_study, with 'per_patient' detailing each patient's result.
force=False (default) skips any patient who already has rows in
prescription_staging for the week we would be recommending for
(regardless of STATUS). Set force=True to rerun anyway.
Source code in src\ai_cdss\interface\cdss.py
recommend_for_study
¶
recommend_for_study(
study_id: List[int],
n: int,
days: int,
protocols_per_day: int,
scoring_date: Optional[Timestamp] = None,
force: bool = False,
) -> Dict[str, Any]
Cohort/study run. See recommend_for_patients for force.
Source code in src\ai_cdss\interface\cdss.py
compute_patient_fit
¶
Compute + persist PPF for one or more patients.
Delegates to compute.compute_ppf_for_patients + persist_ppf.
Requires the repository to expose patient_subscales +
protocol_attributes (production-only accessors —
RGSCohortRepository has them).
Source code in src\ai_cdss\interface\cdss.py
compute_protocol_similarity
¶
Compute + persist the protocol similarity matrix.
Delegates to compute.compute_protocol_similarity_matrix +
persist_similarity.