You are given a dataset with a lot of patient information and you want to look at patients' blood pressure measurement for medication adherence purposes. You may be inerested in who pays for theses visits for the management of bloood pressure.
We can look inot the data and look at patients with uncontrolled hypertension (HTN), BP 140/90 mmHg or higher.
observations is the table that we will explore using the SQL Server Management Studio (SSMS).
Between the years 2018 and 2019, how many patients had uncontrolled HTN?
SELECT * FROM observations
SELECT * FROM observations
WHERE ((DESCRIPTION = 'Diastolic Blood Pressure' AND VALUE > 90)
OR (DESCRIPTION = 'Systolic Blood Pressure' AND VALUE > 140))
Can do DISCTINCT function and be more specific with dates, this gives a list of the different patients that meet the criteria:
SELECT DISTINCT PATIENT FROM observations
WHERE ((DESCRIPTION = 'Diastolic Blood Pressure' AND VALUE > 90)
OR (DESCRIPTION = 'Systolic Blood Pressure' AND VALUE > 140))
AND DATE >= '2018-01-01'
and DATE <'2020-01-01'
Additionally, we can display the total number of patients:
SELECT COUNT(distinct PATIENT) AS 'Total Number'
FROM observations
WHERE ((DESCRIPTION = 'Diastolic Blood Pressure' AND VALUE > 90)
OR (DESCRIPTION = 'Systolic Blood Pressure' AND VALUE > 140))
AND DATE >= '2018-01-01'
and DATE <'2020-01-01'
Which providers treated patients with uncontrolled HTN between 2018-2019?
We will need to use JOIN function to join encounters table with providers table:
SELECT DISTINCT BP.PATIENT, PROV.name as 'Provider Name'
FROM observations BP
join encounters ENC ON BP.encounter=ENC.id
join providers PROV ON ENC.provider=PROV.id
WHERE (
(BP.DESCRIPTION = 'Diastolic Blood Pressure' AND BP.VALUE > 90)
OR (BP.DESCRIPTION = 'Systolic Blood Pressure' AND BP.VALUE > 140)
)
AND BP.DATE >= '2018-01-01'
and BP.DATE < '2020-01-01'
Finding out the providers' specialty:
SELECT DISTINCT BP.PATIENT
, PROV.name as 'Provider Name'
, PROV.speciality
FROM observations BP
join encounters ENC ON BP.encounter=ENC.id
join providers PROV ON ENC.provider=PROV.id
WHERE (
(BP.DESCRIPTION = 'Diastolic Blood Pressure' AND BP.VALUE > 90)
OR (BP.DESCRIPTION = 'Systolic Blood Pressure' AND BP.VALUE > 140)
)
AND BP.DATE >= '2018-01-01'
and BP.DATE <'2020-01-01'
What medications were given to patients with uncontrolled HTN?
SELECT DISTINCT BP.PATIENT , MED.DESCRIPTION as MEDICATION
FROM observations BP
join medications MED ON BP.PATIENT = MED.PATIENT
AND MED.START >= BP.DATE
WHERE (
(BP.DESCRIPTION = 'Diastolic Blood Pressure' AND BP.VALUE > 90)
OR (BP.DESCRIPTION = 'Systolic Blood Pressure' AND BP.VALUE > 140)
)
AND BP.DATE >= '2018-01-01'
and BP.DATE <'2020-01-01'
Dataset source: https://synthetichealth.github.io/synthea/
Github repository: https://github.com/ib99