From 272620b94cc936321f9360a1c69fbc9b0f49e47f Mon Sep 17 00:00:00 2001 From: Richard Williams Date: Thu, 18 Sep 2025 17:05:54 +0100 Subject: [PATCH 1/2] SQL to get vaccine reference data We want every combination of VaccinationName and VaccinationContent (target disease) --- analysis/vaccination_reference_query.sql | 7 +++++++ project.yaml | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 analysis/vaccination_reference_query.sql diff --git a/analysis/vaccination_reference_query.sql b/analysis/vaccination_reference_query.sql new file mode 100644 index 0000000..a84250c --- /dev/null +++ b/analysis/vaccination_reference_query.sql @@ -0,0 +1,7 @@ +-- We don't query either patient-level or event-level data, so we need not +-- exclude T1OOs using the AllowedPatientsWithTypeOneDissent table. +SELECT DISTINCT + VaccinationName, + VaccinationContent +FROM VaccinationReference +ORDER BY VaccinationContent, VaccinationName; diff --git a/project.yaml b/project.yaml index 1110595..ac86c62 100644 --- a/project.yaml +++ b/project.yaml @@ -37,6 +37,17 @@ actions: rows: output/decision_support_value_reference.csv log: output/decision_support_value_reference_log.json + vaccination_reference_query: + run: > + sqlrunner:latest + --output output/vaccination_reference.csv + --log-file output/vaccination_reference_log.json + analysis/vaccination_reference_query.sql + outputs: + moderately_sensitive: + rows: output/vaccination_reference.csv + log: output/vaccination_reference_log.json + make-html-reports: # --execute # execute notebooks before converting them to HTML reports @@ -58,6 +69,7 @@ actions: analysis/*.ipynb needs: - query + - vaccination_reference_query outputs: moderately_sensitive: reports: output/*.html From 1342d18ca2435a83400f7075cd29cebbf01385c8 Mon Sep 17 00:00:00 2001 From: Richard Williams Date: Thu, 18 Sep 2025 17:06:54 +0100 Subject: [PATCH 2/2] Add a notebook to display the report Currently this is just for vaccine name/target disease combos, but could in theory be extended to other similar things. --- analysis/vaccination_reference_report.ipynb | 399 ++++++++++++++++++++ 1 file changed, 399 insertions(+) create mode 100644 analysis/vaccination_reference_report.ipynb diff --git a/analysis/vaccination_reference_report.ipynb b/analysis/vaccination_reference_report.ipynb new file mode 100644 index 0000000..ab6217a --- /dev/null +++ b/analysis/vaccination_reference_report.ipynb @@ -0,0 +1,399 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import dateutil\n", + "from IPython.display import Markdown\n", + "import json\n", + "import pandas\n", + "import pathlib" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "pandas.set_option(\"display.max_columns\", None)\n", + "pandas.set_option(\"display.max_rows\", None)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "OUTPUT_DIR = pathlib.Path(\"../output\")" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "rows = pandas.read_csv(\n", + " OUTPUT_DIR / \"vaccination_reference.csv\",\n", + " names=[\n", + " \"Vaccine name (column name: VaccinationName)\",\n", + " \"Target disease (column name: VaccinationContent)\",\n", + " ],\n", + " header=1,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "log = {\n", + " d[\"event\"]: d\n", + " for d in (\n", + " json.loads(line)\n", + " for line in (OUTPUT_DIR / \"vaccination_reference_log.json\")\n", + " .read_text()\n", + " .splitlines()\n", + " )\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "# Although a misnomer, the report run date is the date the query was executed\n", + "# rather than the date the report was rendered.\n", + "report_run_date = dateutil.parser.parse(\n", + " log.get(\"finish_executing_sql_query\", {}).get(\"timestamp\", \"9999-01-01T00:00:00\")\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# OpenSAFELY-TPP Database Reference Values\n", + "\n", + "This report displays the reference values of the OpenSAFELY-TPP database.\n", + "It is part of the OpenSAFELY platform's technical documentation\n", + "and is published at .\n", + "\n", + "Currently this report only shows the possible combinations of \"vaccine name\" and \"target disease\" in the `VaccinationReference` table, but could be extended to include other tables in future.\n", + "\n", + "If you would like to use the OpenSAFELY platform, then you should read\n", + "our [documentation](https://docs.opensafely.org/),\n", + "our [principles](https://www.opensafely.org/about/),\n", + "and our process for [onboarding new users](https://www.opensafely.org/onboarding-new-users/).\n", + "If you would like to see the code we used to create this report,\n", + "then you can [view it on GitHub](https://github.com/opensafely/tpp-database-schema).\n", + "\n", + "## Report Run Date" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "\n", + "This report was run on 1 October 2024.\n", + "It reflects the state of the database on this date.\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Markdown(\n", + " f\"\"\"\n", + "This report was run on {report_run_date:%-d %B %Y}.\n", + "It reflects the state of the database on this date.\n", + "\"\"\"\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## VaccinationReference Table\n", + "\n", + "The `VaccinationReference` table contains the following information:\n", + "\n", + "* `VaccinationName`, the name of the vaccine\n", + "* `VaccinationContent`, the disease that the vaccine targets\n", + "\n", + "The table below shows all the possible combinations of `VaccinationName` and `VaccinationContent` in the OpenSAFELY-TPP database." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Vaccine nameTarget disease (column Vaccination)
Abrysvo vaccine powder and solvent for solution for injection 0.5ml vials (Pfizer)MENINGOCOCCAL A
Abrysvo vaccine powder and solvent for solution for injection 0.5ml vials (Pfizer)TETANUS
AC VaxANTI-D IMMUNOGLOBULIN
AC VaxMENINGOCOCCAL B
AC VaxTETANUS SPECIAL
ACT - HIBBCG
ACT - HIBMENINGOCOCCAL C
ACT - HIBTICK BORNE ENCEPHALITIS
ACT-HIB DTPCHOLERA
ACT-HIB DTPMENINGOCOCCAL W135
ACT-HIB DTPTUBERCULIN PPD
ACWY VaxDENGUE
ACWY VaxMENINGOCOCCAL Y
ACWY VaxTULARAEMIA
Adacel vaccine suspension for injection 0.5ml pre-filled syringesDIPHTHERIA
Adacel vaccine suspension for injection 0.5ml pre-filled syringesMUMPS
Adacel vaccine suspension for injection 0.5ml pre-filled syringesTYPHOID
Adjuvanted quadrivalent flu vacc (SA, inact) inj 0.5ml pfs (Seqirus UK Ltd)DIPHTHERIA ANTITOXIN
Adjuvanted quadrivalent flu vacc (SA, inact) inj 0.5ml pfs (Seqirus UK Ltd)NORMAL IMMUNOGLOBULIN
Adjuvanted quadrivalent flu vacc (SA, inact) inj 0.5ml pfs (Seqirus UK Ltd)VARICELLA-ZOSTER
Adjuvanted trivalent influenza vaccine (Seqirus)H1N1 Swine Flu
Adjuvanted trivalent influenza vaccine (Seqirus)OTHER
Adjuvanted trivalent influenza vaccine (Seqirus)VARICELLA-ZOSTER IMMUNOGLOBULIN
Agrippal S1HEAF TEST
Agrippal S1PALIVIZUMAB
Agrippal S1YELLOW FEVER
Agrippal vaccine prefilled syringeHEPATITIS A
Agrippal vaccine prefilled syringePERTUSSIS
AlmevaxHEPATITIS B
AlmevaxPHYTOMENADIONE
AmbirixHEPATITIS B IMMUNOGLOBULIN
AmbirixPNEUMOCOCCAL
AnthraxHIB
AnthraxPOLIO
Anti-D ImmunoglobulinHUMAN NORMAL IMMUNOGLOBULIN
Anti-D ImmunoglobulinRABIES
Apexxnar vaccine suspension for injection 0.5ml pre-filled syringes (Pfizer Ltd)HUMAN PAPILLOMAVIRUS
Apexxnar vaccine suspension for injection 0.5ml pre-filled syringes (Pfizer Ltd)RABIES IMMUNOGLOBULIN
Arexvy vaccine inj 0.5ml vials (GlaxoSmithKline UK Ltd)HUMAN RESPIRATORY SYNCYTIAL VIRUS
Arexvy vaccine inj 0.5ml vials (GlaxoSmithKline UK Ltd)ROTAVIRUS
ArilvaxINFLUENZA
ArilvaxRUBELLA
Avaxim JuniorMEASLES
Avaxim JuniorSMALLPOX
AvaximJAPANESE B ENCEPHALITIS
AvaximSARS-2 Coronavirus
" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Markdown(rows.to_html(index=False))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.10" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}