Write a SQL query using window functions to rank patients within each cohort by outcome date and compute a running total of events.