Note
Go to the end to download the full example code.
Basic usage of CDSS to generate a protocol recommendation.#
This example demonstrates how to use the DataLoader, DataProcessor, and CDSS to load data and generate a 7-day protocol plan.
scoring 2025-06-16 00:00:00
/home/runner/work/ai-cdss/ai-cdss/src/ai_cdss/data_processor.py:303: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
df = df.groupby(by=[PATIENT_ID, 'SESSION_DATE'], group_keys=False).apply(day_skip_to_nan)
PATIENT_ID PROTOCOL_ID PPF \
0 1 1 0.562178
1 1 2 0.965500
2 1 3 0.812396
3 1 4 0.719061
4 1 5 0.409213
CONTRIB ADHERENCE_RECENT \
0 [0.252232, 0.03653, 0.118418, 0.147197, 0.007801] 0.673392
1 [0.119867, 0.02396, 0.00862, 0.381091, 0.431962] 0.700176
2 [0.34855, 0.076633, 0.02168, 0.243166, 0.122367] 0.746217
3 [0.026373, 0.13851, 0.007091, 0.486407, 0.06068] 0.718749
4 [0.139366, 0.047926, 0.094186, 0.101513, 0.026... 0.762258
DELTA_DM USAGE USAGE_WEEK DAYS GAME_SCORE
0 -0.058395 10 0 [0, 1, 2, 3, 4, 6] 1.177175
1 -0.064327 10 0 [0, 3, 4, 5, 6] 1.601349
2 -0.048376 10 0 [0, 2, 3, 4, 5, 6] 1.510237
3 0.042883 10 0 [0, 1, 4, 5] 1.480693
4 0.018059 10 0 [0, 1, 2, 4, 5, 6] 1.189530
import sys
sys.path.append("..")
from ai_cdss.cdss import CDSS
from ai_cdss.data_loader import DataLoaderMock
from ai_cdss.data_processor import DataProcessor
import pandas as pd
from IPython.display import display
print(__doc__)
PATIENT_LIST = [
775, 787, 788
]
# Parameters
rgs_mode = "app"
weights = [1,1,1]
alpha = 0.5
n = 12
days = 7
protocols_per_day = 5
# Services
loader = DataLoaderMock(
num_patients=5,
num_protocols=5,
num_sessions=10
)
processor = DataProcessor(
weights=weights,
alpha=alpha
)
# Execution
session = loader.load_session_data(patient_list=PATIENT_LIST)
timeseries = loader.load_timeseries_data(patient_list=PATIENT_LIST)
ppf = loader.load_ppf_data(patient_list=PATIENT_LIST)
init_metrics = loader.load_protocol_init()
protocol_similarity = loader.load_protocol_similarity()
scores = processor.process_data(
session_data=session,
timeseries_data=timeseries,
ppf_data=ppf,
init_data=init_metrics)
# CDSS
cdss = CDSS(
scoring=scores,
n=n,
days=days,
protocols_per_day=protocols_per_day
)
# Results
# patient_id = PATIENT_LIST[0]
patient_id = 1
recommendation = cdss.recommend(patient_id=patient_id, protocol_similarity=protocol_similarity)
recommendation.to_csv(f"recommendation_{patient_id}_new.csv", index=False)
with pd.option_context('display.max_columns', None):
display(recommendation)
Total running time of the script: (0 minutes 1.194 seconds)