Remote Subscriber Database (RSD) SQL guide (Compass 1): Difference between revisions

From Discovery Data Service
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 8: Line 8:
[[File:Dataset algorithm.jpg|600x600px|The algorithm followed to generate datasets]]
[[File:Dataset algorithm.jpg|600x600px|The algorithm followed to generate datasets]]


== Creating the patient cohort ==
== Patient cohort ==
 
=== Creating the patient cohort ===
The first step, when a list of patients marked for observational study is received, is to create a patient cohort. Patient data usually comes into the DDS in the form of pseudonymised personal data. Additional information about the patient can be obtained from the Discovery database using the pseudo identifier or the pseudo NHS identifier.
The first step, when a list of patients marked for observational study is received, is to create a patient cohort. Patient data usually comes into the DDS in the form of pseudonymised personal data. Additional information about the patient can be obtained from the Discovery database using the pseudo identifier or the pseudo NHS identifier.


Line 17: Line 19:
Patients are linked to the Discovery database using pseudo patient identifiers. However, if only pseudo NHS numbers are provided, the corresponding pseudo identifiers can be derived from the '''link distributor''' table. Patients are filtered by organisation ODS codes to ensure that only the patients of the required GP practices are selected.
Patients are linked to the Discovery database using pseudo patient identifiers. However, if only pseudo NHS numbers are provided, the corresponding pseudo identifiers can be derived from the '''link distributor''' table. Patients are filtered by organisation ODS codes to ensure that only the patients of the required GP practices are selected.


 
=== Building the patient cohort SQL with pseudo NHS numbers ===
The following example SQL shows how a patient cohort is built using pseudo NHS numbers:
The following example SQL shows how a patient cohort is built using pseudo NHS numbers:


Line 30: Line 32:
Patients can be selected with a specific set of observations using a lookup table of relevant&nbsp;SNOMED codes.<br /> Some patients prefer to withhold consent and are therefore are excluded from the cohort;&nbsp;the relevant SNOMED consent code can be checked in the observation table.<br /> Patients are usually only select if they have registration type 2&nbsp;(Regular/GMS).<br /> Sometimes patients are also based on their age in years.
Patients can be selected with a specific set of observations using a lookup table of relevant&nbsp;SNOMED codes.<br /> Some patients prefer to withhold consent and are therefore are excluded from the cohort;&nbsp;the relevant SNOMED consent code can be checked in the observation table.<br /> Patients are usually only select if they have registration type 2&nbsp;(Regular/GMS).<br /> Sometimes patients are also based on their age in years.


==<span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations.5Bedit.5D"><span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations">Building patient cohort SQL with filtered observations</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[Edit|edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>==
===<span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations.5Bedit.5D"><span class="mw-headline" id="Building_patient_cohort_SQL_with_filtered_observations">Building patient cohort SQL with filtered observations</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>===


[[File:Building patient cohort SQL with filtered observations.png|Building patient cohort SQL with filtered observations]]
[[File:Building patient cohort SQL with filtered observations.png|Building patient cohort SQL with filtered observations]]


==<span class="mw-headline" id="Creating_the_observation_cohort.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_observation_cohort.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_observation_cohort.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_observation_cohort.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_observation_cohort.5Bedit.5D"><span class="mw-headline" id="Creating_the_observation_cohort">Creating the observation cohort</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[Edit|edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>==
== Observation cohort ==
 
===<span class="mw-headline" id="Creating_the_observation_cohort.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_observation_cohort.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_observation_cohort.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_observation_cohort.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_observation_cohort.5Bedit.5D"><span class="mw-headline" id="Creating_the_observation_cohort">Creating the observation cohort</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>===


Observation&nbsp;cohort are created to improve query performance;&nbsp;instead of scanning through the entire observation table, a sub-set of the observation table is created, based on the patient cohort.
Observation&nbsp;cohort are created to improve query performance;&nbsp;instead of scanning through the entire observation table, a sub-set of the observation table is created, based on the patient cohort.


&nbsp;
=== &nbsp;<span class="mw-headline" id="Building_the_observation_cohort_SQL_.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_observation_cohort_SQL_.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_observation_cohort_SQL_.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_observation_cohort_SQL_.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_observation_cohort_SQL_.5Bedit.5D"><span class="mw-headline" id="Building_the_observation_cohort_SQL">Building the observation cohort SQL&nbsp;</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span> ===
 
[[File:Building observation cohort SQL.png|Building observation cohort SQL]]
==<span class="mw-headline" id="Building_the_observation_cohort_SQL_.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_observation_cohort_SQL_.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_observation_cohort_SQL_.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_observation_cohort_SQL_.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_observation_cohort_SQL_.5Bedit.5D"><span class="mw-headline" id="Building_the_observation_cohort_SQL">Building the observation cohort SQL&nbsp;</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[Edit|edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>==


[[File:Building observation cohort SQL.png|Building observation cohort SQL]]
== Medications cohort ==


==<span class="mw-headline" id="Creating_the_medications_cohort.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_medications_cohort.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_medications_cohort.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_medications_cohort.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_medications_cohort.5Bedit.5D"><span class="mw-headline" id="Creating_the_medications_cohort">Creating the medications cohort</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[Edit|edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>==
===<span class="mw-headline" id="Creating_the_medications_cohort.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_medications_cohort.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_medications_cohort.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_medications_cohort.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_the_medications_cohort.5Bedit.5D"><span class="mw-headline" id="Creating_the_medications_cohort">Creating the medications cohort</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>===


Medications cohort are created to improve query performance;&nbsp;instead of scanning through the entire observation table, a sub-set of the medication statement table is created, based on the patient cohort.
Medications cohort are created to improve query performance;&nbsp;instead of scanning through the entire observation table, a sub-set of the medication statement table is created, based on the patient cohort.
Line 50: Line 53:
[[File:Patient, medication statement and organization.png|Patient, medication statement and organisation]]
[[File:Patient, medication statement and organization.png|Patient, medication statement and organisation]]


&nbsp;
=== &nbsp;<span class="mw-headline" id="Building_the_medication_cohort_SQL.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_medication_cohort_SQL.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_medication_cohort_SQL.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_medication_cohort_SQL.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_medication_cohort_SQL.5Bedit.5D"><span class="mw-headline" id="Building_the_medication_cohort_SQL">Building the medication cohort SQL</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span> ===
 
[[File:Building medication cohort SQL.png|Building medication cohort SQL]]
==<span class="mw-headline" id="Building_the_medication_cohort_SQL.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_medication_cohort_SQL.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_medication_cohort_SQL.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_medication_cohort_SQL.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_medication_cohort_SQL.5Bedit.5D"><span class="mw-headline" id="Building_the_medication_cohort_SQL">Building the medication cohort SQL</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[Edit|edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>==


[[File:Building medication cohort SQL.png|Building medication cohort SQL]]
== Other cohorts ==


==<span class="mw-headline" id="Creating_other_cohorts.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_other_cohorts.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_other_cohorts.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Creating_other_cohorts.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_other_cohorts.5Bedit.5D"><span class="mw-headline" id="Creating_other_cohorts">Creating other cohorts</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[Edit|edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>==
===<span class="mw-headline" id="Creating_other_cohorts.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_other_cohorts.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_other_cohorts.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Creating_other_cohorts.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Creating_other_cohorts.5Bedit.5D"><span class="mw-headline" id="Creating_other_cohorts">Creating other cohorts</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>===


This step can apply to any large tables to support improved query performance. For example, the encounter_raw table is a good candidate to create a separate cohort for SQL query; you can query this table if you want information such as the number of face to face encounters, or the number of home visits.
This step can apply to any large tables to support improved query performance. For example, the encounter_raw table is a good candidate to create a separate cohort for SQL query; you can query this table if you want information such as the number of face to face encounters, or the number of home visits.
Line 62: Line 64:
[[File:Encounter.png|Encounter raw entity]]
[[File:Encounter.png|Encounter raw entity]]


&nbsp;
=== &nbsp;<span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL.5Bedit.5D"><span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL">Building the encounter raw cohort SQL</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span> ===
 
==<span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL.5Bedit.5D"><span class="mw-headline" id="Building_the_encounter_raw_cohort_SQL">Building the encounter raw cohort SQL</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>==
 
[[File:Building encounter raw cohort SQL.png|Building encounter raw cohort SQL]]
[[File:Building encounter raw cohort SQL.png|Building encounter raw cohort SQL]]


&nbsp;
== &nbsp;<span class="mw-headline" id="Building_datasets.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_datasets.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_datasets.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Building_datasets.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_datasets.5Bedit.5D"><span class="mw-headline" id="Building_datasets">Building datasets</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span> ==
 
==<span class="mw-headline" id="Building_datasets.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_datasets.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_datasets.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Building_datasets.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Building_datasets.5Bedit.5D"><span class="mw-headline" id="Building_datasets">Building datasets</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>==
 
This involves creating a number of tables in the database.
This involves creating a number of tables in the database.


==<span class="mw-headline" id="Patient_demographic_dataset.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Patient_demographic_dataset.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Patient_demographic_dataset.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Patient_demographic_dataset.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Patient_demographic_dataset.5Bedit.5D"><span class="mw-headline" id="Patient_demographic_dataset">Patient demographic dataset</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>==
===<span class="mw-headline" id="Patient_demographic_dataset.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Patient_demographic_dataset.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Patient_demographic_dataset.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Patient_demographic_dataset.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Patient_demographic_dataset.5Bedit.5D"><span class="mw-headline" id="Patient_demographic_dataset">Patient demographic dataset</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>===


A typical patient demographic dataset includes the following information: [[File:Patient demographic dataset.png|Patient demographic dataset]] This information is translated into a 'create table' script, which is then run to create the dataset table in the database.
A typical patient demographic dataset includes the following information: [[File:Patient demographic dataset.png|Patient demographic dataset]] This information is translated into a 'create table' script, which is then run to create the dataset table in the database.


&nbsp;
=== &nbsp;<span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table.5Bedit.5D"><span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table">Create&nbsp;table script for a patient demographic dataset table</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span> ===
 
&nbsp;
 
==<span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table.5Bedit.5D.5Bedit.5D.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table.5Bedit.5D.5B.5B.5B.7Cedit.5D.5D.5D.5Bedit.5D"><span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table.5Bedit.5D.5Bedit.5D"><span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table.5Bedit.5D"><span class="mw-headline" id="Create_table_script_for_a_patient_demographic_dataset_table">Create&nbsp;table script for a patient demographic dataset table</span><span class="mw-editsection"><span class="mw-editsection-bra">[</span>[[edit]]<span class="mw-editsection-bra">]</span></span></span></span></span></span></span>==
 
[[File:Create table script.png|Create table script for patient demographic dataset]]
[[File:Create table script.png|Create table script for patient demographic dataset]]



Revision as of 14:02, 15 May 2020

Introduction

This article describes the steps needed to create, and analyse, patient data selections from the Discovery database.

Datasets are needed to add patient data to a report. Each dataset represents the results gained from running a combination of SQL commands and stored procedures on a data source.

The following diagram shows the algorithm that is followed to generate these datasets:

The algorithm followed to generate datasets

Patient cohort

Creating the patient cohort

The first step, when a list of patients marked for observational study is received, is to create a patient cohort. Patient data usually comes into the DDS in the form of pseudonymised personal data. Additional information about the patient can be obtained from the Discovery database using the pseudo identifier or the pseudo NHS identifier.

The following entity diagram shows the relationships between patient and organisation:

General patient cohort

Patients are linked to the Discovery database using pseudo patient identifiers. However, if only pseudo NHS numbers are provided, the corresponding pseudo identifiers can be derived from the link distributor table. Patients are filtered by organisation ODS codes to ensure that only the patients of the required GP practices are selected.

Building the patient cohort SQL with pseudo NHS numbers

The following example SQL shows how a patient cohort is built using pseudo NHS numbers:

Patient cohort SQL with pseudo NHS numbers

Sometimes, the cohort is created with filtered observations.

The example below filters patients who are registered, alive, and have had diabetes. They belong to the age 12 years and over. Two additional tables are introduced for the query: observation(patients who have had diabetes) and episode of care (patients who are registered and have the appropriate registration type for this study).

Cohorts with filtered observations

Patients can be selected with a specific set of observations using a lookup table of relevant SNOMED codes.
Some patients prefer to withhold consent and are therefore are excluded from the cohort; the relevant SNOMED consent code can be checked in the observation table.
Patients are usually only select if they have registration type 2 (Regular/GMS).
Sometimes patients are also based on their age in years.

Building patient cohort SQL with filtered observations[edit]

Building patient cohort SQL with filtered observations

Observation cohort

Creating the observation cohort[edit]

Observation cohort are created to improve query performance; instead of scanning through the entire observation table, a sub-set of the observation table is created, based on the patient cohort.

 Building the observation cohort SQL [edit]

Building observation cohort SQL

Medications cohort

Creating the medications cohort[edit]

Medications cohort are created to improve query performance; instead of scanning through the entire observation table, a sub-set of the medication statement table is created, based on the patient cohort.

Patient, medication statement and organisation

 Building the medication cohort SQL[edit]

Building medication cohort SQL

Other cohorts

Creating other cohorts[edit]

This step can apply to any large tables to support improved query performance. For example, the encounter_raw table is a good candidate to create a separate cohort for SQL query; you can query this table if you want information such as the number of face to face encounters, or the number of home visits.

Encounter raw entity

 Building the encounter raw cohort SQL[edit]

Building encounter raw cohort SQL

 Building datasets[edit]

This involves creating a number of tables in the database.

Patient demographic dataset[edit]

A typical patient demographic dataset includes the following information: Patient demographic dataset This information is translated into a 'create table' script, which is then run to create the dataset table in the database.

 Create table script for a patient demographic dataset table[edit]

Create table script for patient demographic dataset

 

 

 

 

In this example, the age and LSOA code are derived from the patient table. The demographic dataset table is updated with those values when there is a match on the pseudo identifier.
If the update is large, it might be possible to optimise the update process by using batches as shown in the following example: