You are on page 1of 36

Structured Query Language (SQL): Pharmacy

Data, Up Close and Personal


Patrick Spoutz
Pain Clinical Pharmacy Specialist & Data Manager

March 20th, 2018


Objectives

• Understand the types of information that available via SQL

• Describe the syntax of a basic query

• Become familiar with techniques to write efficient code on the Field Reporting
Enclave (FRE)

• Become familiar with viewing SQL query cost

VETERANS HEALTH ADMINISTRATION


Background

• Completed PGY1 Residency at the Ann Arbor VA


– Worked with Allison Brenner (Pharmacy CAC) designing order menus, reminder dialogs

• Completed PGY1 Residency at the VISN 15 PBM Office in Kansas City


– Pharmacy Outcomes and Healthcare Analytics
– Learned SQL, reporting services, Pyramid

• Population Health Specialist


– Designing dashboards, reports, clinical processes on VISN Data Warehouse (VDW)
– Anticoagulation, Cost Savings, Hepatitis C, Chronic Disease Management (DM, hypertension,
hyperlipidemia)

• Pain Clinical Pharmacy Specialist


– 75% of time in pain clinic
– Now coding on the Field Reporting Enclave (FRE) instead of the VDW

VETERANS HEALTH ADMINISTRATION 2


Corporate Data Warehouse (CDW) Overview – slide 1

• Updated once daily (overnight)

• Primary data source is VISTA


• There are some non-VISTA data sources

• Per the CDW Guide Introduction and Policies


• “The data comes from the source systems (mostly Vista) without “scrubbing”,
filtering and without business logic applied. The data is not optimized for any
particular use but rather it is fairly normalized to allow its use by varied types of
queries for analyses and reports.”

VETERANS HEALTH ADMINISTRATION 3


Corporate Data Warehouse (CDW) Overview – slide 2

VETERANS HEALTH ADMINISTRATION 4


Corporate Data Warehouse (CDW) Overview

VETERANS HEALTH ADMINISTRATION 5


Data Available

• Structured Query Language (SQL)


– Lab values
– Problem lists
– Vital signs
– Encounters / workload
– Visit diagnoses
– Prescriptions
– Many more….
• Non-structured data is more difficult to access or query
– Free text of notes
– Imaging
– Typically stored in other databases

VETERANS HEALTH ADMINISTRATION


Interacting with VA Data

VETERANS HEALTH ADMINISTRATION


Microsoft SQL Server Reporting Services (SSRS) – slide 1

VETERANS HEALTH ADMINISTRATION


Microsoft SQL Server Reporting Services (SSRS) – slide 2

VETERANS HEALTH ADMINISTRATION


Pyramid Analytics

VETERANS HEALTH ADMINISTRATION


Microsoft SQL Server Management Studio (SMSS)

VETERANS HEALTH ADMINISTRATION 11


TOAD

VETERANS HEALTH ADMINISTRATION 12


Reporting Services vs. Pyramid vs. SQL: Choosing the Right
Tool for the Job

VETERANS HEALTH ADMINISTRATION


Project Example Using SQL: AHA/ACC Heart Risk
Calculator - 1

VETERANS HEALTH ADMINISTRATION


Project Example Using SQL: AHA/ACC Heart Risk
Calculator - 2

VETERANS HEALTH ADMINISTRATION 15


Project Example Using SQL: AHA/ACC Heart Risk
Calculator-3

VETERANS HEALTH ADMINISTRATION


Project Example Using SQL: AHA/ACC Heart Risk
Calculator -4

VETERANS HEALTH ADMINISTRATION 17


Other Projects

• Various ways of obtaining customized lists of patients


– Example: All patients on etodolac who have not previously tried meloxicam

• Complex patient cohorts


– Example: All patients with a specific disease state diagnosis and not receiving a specific
medication within the last year

• Complex dashboards that present data with SSRS


– Example: All Academic Detailing reports are built on SQL code with an SSRS interface

VETERANS HEALTH ADMINISTRATION 18


Basic SQL Queries-1

Select [stuff that you want!]

From [where should the computer look]

Where [restrictions to filter to what you want]

Order by [orders the output]

Regular Life Analogy: “Honey, please get the milk from the store, but not the 2% kind, and
put it on the top shelf”

[Exercise for the reader: match the select, from, where, and order by clauses with relevant
part of sentence]

VETERANS HEALTH ADMINISTRATION


Basic SQL Queries-2

VETERANS HEALTH ADMINISTRATION


Getting Started with SQL-1
• Obtain necessary software
– Microsoft SQL Server Management Studio; Toad for SQL Server Software generally obtained
through the VISN Database Administrator
– SSMS installation on your desktop/laptop is requested through your local software installation
request process (refer to applications section in table at https://vaww.cdw.va.gov/Regions/fr/
for installation files/information)
– Some VISNs have Citrix-based SSMS/TOAD; contact your VISN Data Warehouse POC for more
information (https://vaww.cdw.va.gov/Regions/fr/SitePages/VISN_POCs.aspx).

• Learn the programming language


– Moodle courses link: https://vapharmacytraining.remote-
learner.net/course/index.php?categoryid=39
– Kathi Kellenberger book (available through TMS Skillsoft Books).

VETERANS HEALTH ADMINISTRATION


Getting Started with SQL-2
• CDW Support
– https://vaww.cdw.va.gov/support/Training/
– Sign up for CDW Training Announcements
– Frequently Asked Questions link: https://vaww.cdw.va.gov/support/cdwcs/Pages/CDW-
Frequently-Asked-Questions.aspx
– Attend CDW Insights, SQL Office Hours
– CDW Introduction and Policies link: https://vaww.cdw.va.gov/Pages/CDWHome.aspx

VETERANS HEALTH ADMINISTRATION 22


Switching Gears to Efficient Coding on the Field Reporting
Enclave (FRE)

VETERANS HEALTH ADMINISTRATION 23


Introduction to Efficient FRE Coding-1

• Querying on the FRE is not free


– Heavy data loads, complex queries, multiple users slow processing down
– Poorly or inefficiently written code adds to the backlog
– Adopting best practices can improve performance (or at least prevent performance
degradation)

• LSV vs. CDWWork


– Users initially receive access to LSV tables
– Contains data for last three years ONLY (data >= 10-1-2014)
– If access needed for older data or national data due to role, file a VHA NDS Access Form
Health Operations Request form link:
http://vaww.vhadataportal.med.va.gov/DataAccess/HealthcareOperationsRequestProce
ss.aspx
• Recommend only requesting CDW_FULL and using LSV for SPatient/SStaff needs

VETERANS HEALTH ADMINISTRATION


Introduction to Efficient FRE Coding-2

• Developed by Samantha McClelland [formerly Samantha Wright] and LeAnn Radcliffe


• Available at https://vaww.cdw.va.gov/Regions/fr/

VETERANS HEALTH ADMINISTRATION


MetaData – “Data about data”

• Detailed MetaData information available at:


https://vaww.cdw.va.gov/metadata/default.aspx#
• Spreadsheet version available at:
https://vaww.dev.fre.cdw.va.gov/sites/D03_VISN12/Documents/Metadata_Table_
with_Queries.xlsx

VETERANS HEALTH ADMINISTRATION


More MetaData: Identifying Indexes

VETERANS HEALTH ADMINISTRATION 27


Improving Efficiency Example-1

1 Minute and 39 Seconds


VETERANS HEALTH ADMINISTRATION
Improving Efficiency Example-2

<1 Second
VETERANS HEALTH ADMINISTRATION 29
Query Plans

VETERANS HEALTH ADMINISTRATION 30


Query Plans: A Comparison-1

In depth education on query plans available at


https://vaww.cdw.va.gov/support/Training/
“Bad Query” “Less Bad Query”

VETERANS HEALTH ADMINISTRATION


Query Plans: A Comparison-2

“Bad Query” “Less Bad Query”

VETERANS HEALTH ADMINISTRATION


Incremental Loads

• Advanced technique
• Uses
– Scanning large fact tables daily
– Processing data for entire VA

• Downsides
– Complex to construct
– Break easily
– May inadvertently create copy of
entire CDW

VETERANS HEALTH ADMINISTRATION 33


Acknowledgements

• CDW Insights Presentations on MetaData & CDW Support in general

• Samantha McClelland (Wright) and LeAnn Radcliffe’s Query Efficiency Tool

• Spencer Schaefer, Eric Wagner, Samantha McClelland, and Linda Chia for feedback
on presentation slides

• Monica Schaefer for mentorship

VETERANS HEALTH ADMINISTRATION


Questions?

VETERANS HEALTH ADMINISTRATION 35

You might also like