SummaryBackgroundAs the COVID-19 pandemic continues, national-level surveillance platforms with real-time individual person-level data are required to monitor and predict the epidemiological and clinical profile of COVID-19 and inform public health policy. We aimed to create a national dataset of patient-level data in Scotland to identify temporal trends and COVID-19 risk factors, and to develop a novel statistical prediction model to forecast COVID-19-related deaths and hospitalisations during the second wave.MethodsWe established a surveillance platform to monitor COVID-19 temporal trends using person-level primary care data (including age, sex, socioeconomic status, urban or rural residence, care home residence, and clinical risk factors) linked to data on SARS-CoV-2 RT-PCR tests, hospitalisations, and deaths for all individuals resident in Scotland who were registered with a general practice on Feb 23, 2020. A Cox proportional hazards model was used to estimate the association between clinical risk groups and time to hospitalisation and death. A survival prediction model derived from data from March 1 to June 23, 2020, was created to forecast hospital admissions and deaths from October to December, 2020. We fitted a generalised additive spline model to daily SARS-CoV-2 cases over the previous 10 weeks and used this to create a 28-day forecast of the number of daily cases. The age and risk group pattern of cases in the previous 3 weeks was then used to select a stratified sample of individuals from our cohort who had not previously tested positive, with future cases in each group sampled from a multinomial distribution. We then used their patient characteristics (including age, sex, comorbidities, and socioeconomic status) to predict their probability of hospitalisation or death.FindingsOur cohort included 5 384 819 people, representing 98·6% of the entire estimated population residing in Scotland during 2020. Hospitalisation and death among those testing positive for SARS-CoV-2 between March 1 and June 23, 2020, were associated with several patient characteristics, including male sex (hospitalisation hazard ratio [HR] 1·47, 95% CI 1·38–1·57; death HR 1·62, 1·49–1·76) and various comorbidities, with the highest hospitalisation HR found for transplantation (4·53, 1·87–10·98) and the highest death HR for myoneural disease (2·33, 1·46–3·71). For those testing positive, there were decreasing temporal trends in hospitalisation and death rates. The proportion of positive tests among older age groups (>40 years) and those with at-risk comorbidities increased during October, 2020. On Nov 10, 2020, the projected number of hospitalisations for Dec 8, 2020 (28 days later) was 90 per day (95% prediction interval 55–125) and the projected number of deaths was 21 per day (12–29).InterpretationThe estimated incidence of SARS-CoV-2 infection based on positive tests recorded in this unique data resource has provided forecasts of hospitalisation and death rates for the whole of Scotland. These findings were used by the Scottish Government to inform their response to reduce COVID-19-related morbidity and mortality.FundingMedical Research Council, National Institute for Health Research Health Technology Assessment Programme, UK Research and Innovation Industrial Strategy Challenge Fund, Health Data Research UK, Scottish Government Director General Health and Social Care.