# opensafely/post-covid-neurodegenerative architecture

> Architecture diagram of the GitHub repository opensafely/post-covid-neurodegenerative, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/opensafely/post-covid-neurodegenerative
- Repository: https://github.com/opensafely/post-covid-neurodegenerative

## Overview

This repository contains an OpenSAFELY observational-study analysis: it defines patient cohorts and outcomes from primary- and secondary-care records, then cleans and analyses extracted datasets and produces study outputs. The README documents the main workflow and capabilities; the sampled source confirms dataset-definition dependencies and an archived REM-sleep-disorder cohort variant. Most downstream analysis scripts were not sampled, so those relationships are included only where explicitly documented.

Main entry points: [`analysis/dataset_clean/dataset_clean.R`](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_clean/dataset_clean.R) (Dataset cleaning), [`analysis/dataset_definition/variables_cohorts.py`](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/variables_cohorts.py) (Cohort variables), [`analysis/dataset_definition/variables_dates.py`](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/variables_dates.py) (Study date variables), [`analysis/dataset_definition/dataset_definition_dates.py`](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/dataset_definition_dates.py) (Cohort dates)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cohort["Cohort definition"]
  node_codelists["Clinical codelists<br/>[codelists.py]"]
  node_var_helpers["ehrQL helpers"]
  node_cohort_vars["Cohort variables"]
  node_date_vars["Study date variables<br/>[variables_dates.py]"]
  node_date_dataset["Cohort dates"]
  node_cohort_dataset["Cohort datasets"]
  node_cohort_variants["Exposure cohorts"]
end

subgraph group_clean["Data preparation"]
  node_cleaning["Dataset cleaning<br/>[dataset_clean.R]"]
end

subgraph group_analysis["Analysis"]
  node_table1["Patient characteristics<br/>[table1.R]"]
  node_table1_hosp["Hospitalisation summary"]
  node_table2["Event counts<br/>[table2.R]"]
  node_venn["Outcome sources<br/>[venn.R]"]
  node_model_input["Model inputs<br/>[make_model_input.R]"]
  node_cox["Cox analysis"]
  node_stata["Stata reruns<br/>[cox_model.do]"]
end

subgraph group_outputs["Study outputs"]
  node_model_output["Model summaries"]
  node_other_output["Other summaries"]
  node_aer["Excess-risk inputs<br/>[make_aer_input.R]"]
end

subgraph group_archive["Archived RSD variant"]
  node_rsd_cohort["Archived RSD dataset"]
  node_rsd_vars["RSD outcome variables<br/>[variables_rsd.py]"]
  node_rsd_helpers["RSD query helpers"]
  node_rsd_codes["RSD codelists<br/>[codelists_rsd.py]"]
  node_rsd_variants["Archived exposure cohorts"]
end

node_analyst(("Study analyst"))
node_cox_action["cox-ipw action"]

node_analyst -->|"runs study"| node_date_dataset
node_date_dataset -->|"imports variables"| node_date_vars
node_date_vars -->|"imports codes"| node_codelists
node_date_vars -->|"uses helpers"| node_var_helpers
node_date_dataset -->|"provides dates"| node_cohort_dataset
node_cohort_dataset -->|"imports variables"| node_cohort_vars
node_cohort_vars -->|"imports codes"| node_codelists
node_cohort_vars -->|"uses helpers"| node_var_helpers
node_cohort_variants -->|"generates cohorts"| node_cohort_dataset
node_cohort_variants -.->|"extracts data for"| node_cleaning
node_cleaning -->|"supplies data"| node_table1
node_cleaning -->|"supplies data"| node_table1_hosp
node_cleaning -->|"supplies data"| node_table2
node_cleaning -->|"supplies data"| node_venn
node_cleaning -->|"supplies data"| node_model_input
node_model_input -->|"provides inputs"| node_cox_action
node_cox_action -->|"fits models"| node_cox
node_cox -->|"reruns failures"| node_stata
node_cox -->|"provides results"| node_model_output
node_model_input -->|"provides inputs"| node_aer
node_table1 -->|"contributes outputs"| node_other_output
node_rsd_cohort -->|"imports variables"| node_rsd_vars
node_rsd_vars -->|"uses helpers"| node_rsd_helpers
node_rsd_vars -->|"imports codes"| node_rsd_codes
node_rsd_variants -->|"calls generator"| node_rsd_cohort

click node_codelists "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/codelists.py"
click node_var_helpers "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/variable_helper_functions.py"
click node_cohort_vars "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/variables_cohorts.py"
click node_date_vars "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/variables_dates.py"
click node_date_dataset "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/dataset_definition_dates.py"
click node_cohort_dataset "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/dataset_definition_cohorts.py"
click node_cohort_variants "https://github.com/opensafely/post-covid-neurodegenerative/tree/main/analysis/dataset_definition"
click node_cleaning "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_clean/dataset_clean.R"
click node_table1 "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/table1/table1.R"
click node_table1_hosp "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/table1/table1_hospitalised.R"
click node_table2 "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/table2/table2.R"
click node_venn "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/venn/venn.R"
click node_model_input "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/model/make_model_input.R"
click node_stata "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/model/cox_model.do"
click node_model_output "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/make_output/make_model_output.R"
click node_other_output "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/make_output/make_other_output.R"
click node_aer "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/make_output/make_aer_input.R"
click node_rsd_cohort "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/archive/dataset_definition_rsd/dataset_definition_rsd_cohorts.py"
click node_rsd_vars "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/archive/dataset_definition_rsd/variables_rsd.py"
click node_rsd_helpers "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/archive/dataset_definition_rsd/variable_rsd_helper_functions.py"
click node_rsd_codes "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/archive/dataset_definition_rsd/codelists_rsd.py"
click node_rsd_variants "https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/archive/dataset_definition_rsd/dataset_definition_rsd_prevax.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_codelists,node_var_helpers,node_cohort_vars,node_date_vars,node_date_dataset,node_cohort_dataset,node_cohort_variants toneBlue
class node_cleaning toneAmber
class node_table1,node_table1_hosp,node_table2,node_venn,node_model_input,node_cox,node_stata toneMint
class node_model_output,node_other_output,node_aer toneRose
class node_rsd_cohort,node_rsd_vars,node_rsd_helpers,node_rsd_codes,node_rsd_variants,node_analyst,node_cox_action toneIndigo
```

## Components

### Cohort definition

- [Clinical codelists](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/codelists.py): `analysis/dataset_definition/codelists.py`
- [ehrQL helpers](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/variable_helper_functions.py): `analysis/dataset_definition/variable_helper_functions.py`
- [Cohort variables](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/variables_cohorts.py): `analysis/dataset_definition/variables_cohorts.py`
- [Study date variables](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/variables_dates.py): `analysis/dataset_definition/variables_dates.py`
- [Cohort dates](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/dataset_definition_dates.py): `analysis/dataset_definition/dataset_definition_dates.py`
- [Cohort datasets](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_definition/dataset_definition_cohorts.py): `analysis/dataset_definition/dataset_definition_cohorts.py`
- [Exposure cohorts](https://github.com/opensafely/post-covid-neurodegenerative/tree/main/analysis/dataset_definition): `analysis/dataset_definition`

### Data preparation

- [Dataset cleaning](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/dataset_clean/dataset_clean.R): `analysis/dataset_clean/dataset_clean.R`

### Analysis

- [Patient characteristics](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/table1/table1.R): `analysis/table1/table1.R`
- [Hospitalisation summary](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/table1/table1_hospitalised.R): `analysis/table1/table1_hospitalised.R`
- [Event counts](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/table2/table2.R): `analysis/table2/table2.R`
- [Outcome sources](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/venn/venn.R): `analysis/venn/venn.R`
- [Model inputs](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/model/make_model_input.R): `analysis/model/make_model_input.R`
- **Cox analysis**
- [Stata reruns](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/model/cox_model.do): `analysis/model/cox_model.do`

### Study outputs

- [Model summaries](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/make_output/make_model_output.R): `analysis/make_output/make_model_output.R`
- [Other summaries](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/make_output/make_other_output.R): `analysis/make_output/make_other_output.R`
- [Excess-risk inputs](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/make_output/make_aer_input.R): `analysis/make_output/make_aer_input.R`

### Archived RSD variant

- [Archived RSD dataset](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/archive/dataset_definition_rsd/dataset_definition_rsd_cohorts.py): `analysis/archive/dataset_definition_rsd/dataset_definition_rsd_cohorts.py`
- [RSD outcome variables](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/archive/dataset_definition_rsd/variables_rsd.py): `analysis/archive/dataset_definition_rsd/variables_rsd.py`
- [RSD query helpers](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/archive/dataset_definition_rsd/variable_rsd_helper_functions.py): `analysis/archive/dataset_definition_rsd/variable_rsd_helper_functions.py`
- [RSD codelists](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/archive/dataset_definition_rsd/codelists_rsd.py): `analysis/archive/dataset_definition_rsd/codelists_rsd.py`
- [Archived exposure cohorts](https://github.com/opensafely/post-covid-neurodegenerative/blob/main/analysis/archive/dataset_definition_rsd/dataset_definition_rsd_prevax.py): `analysis/archive/dataset_definition_rsd/dataset_definition_rsd_prevax.py`

### Other components

- **Study analyst**
- **cox-ipw action**

## Connections

- Study analyst → Cohort dates: runs study (evidence: `README.md`)
- Cohort dates → Study date variables: imports variables (evidence: `analysis/dataset_definition/dataset_definition_dates.py`)
- Study date variables → Clinical codelists: imports codes (evidence: `analysis/dataset_definition/variables_dates.py`)
- Study date variables → ehrQL helpers: uses helpers (evidence: `analysis/dataset_definition/variables_dates.py`)
- Cohort dates → Cohort datasets: provides dates (evidence: `README.md`)
- Cohort datasets → Cohort variables: imports variables (evidence: `analysis/dataset_definition/dataset_definition_cohorts.py`)
- Cohort variables → Clinical codelists: imports codes (evidence: `analysis/dataset_definition/variables_cohorts.py`)
- Cohort variables → ehrQL helpers: uses helpers (evidence: `analysis/dataset_definition/variables_cohorts.py`)
- Exposure cohorts → Cohort datasets: generates cohorts (evidence: `README.md`)
- Exposure cohorts → Dataset cleaning: extracts data for
- Dataset cleaning → Patient characteristics: supplies data (evidence: `README.md`)
- Dataset cleaning → Hospitalisation summary: supplies data (evidence: `README.md`)
- Dataset cleaning → Event counts: supplies data (evidence: `README.md`)
- Dataset cleaning → Outcome sources: supplies data (evidence: `README.md`)
- Dataset cleaning → Model inputs: supplies data (evidence: `README.md`)
- Model inputs → cox-ipw action: provides inputs (evidence: `README.md`)
- cox-ipw action → Cox analysis: fits models (evidence: `README.md`)
- Cox analysis → Stata reruns: reruns failures (evidence: `README.md`)
- Cox analysis → Model summaries: provides results (evidence: `README.md`)
- Model inputs → Excess-risk inputs: provides inputs (evidence: `README.md`)
- Patient characteristics → Other summaries: contributes outputs (evidence: `README.md`)
- Archived RSD dataset → RSD outcome variables: imports variables (evidence: `analysis/archive/dataset_definition_rsd/dataset_definition_rsd_cohorts.py`)
- RSD outcome variables → RSD query helpers: uses helpers (evidence: `analysis/archive/dataset_definition_rsd/variables_rsd.py`)
- RSD outcome variables → RSD codelists: imports codes (evidence: `analysis/archive/dataset_definition_rsd/variables_rsd.py`)
- Archived exposure cohorts → Archived RSD dataset: calls generator (evidence: `analysis/archive/dataset_definition_rsd/dataset_definition_rsd_prevax.py`)
