-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHealthcare_db.sql
More file actions
289 lines (246 loc) · 8.62 KB
/
Healthcare_db.sql
File metadata and controls
289 lines (246 loc) · 8.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
-- 1 How many rows of data are in the FactTable that include a Gross Charge greater than $100?
SELECT
COUNT(*) AS Rows_Count
FROM
FactTable
WHERE
FactTable.GrossCharge > 100;
-- 2 How many unique patients exist is the Healthcare_DB?
SELECT
COUNT(DISTINCT dimPatientPK) AS UniquePatients
FROM
dimPatient;
-- 3 How many CptCodes are in each CptGrouping?
SELECT
CptGrouping, COUNT(DISTINCT CptCode) AS Total_CptCode
FROM
dimCptCode
GROUP BY CptGrouping
ORDER BY Total_CptCode DESC;
-- 4 How many physicians have submitted a Medicare insurance claim?
SELECT
COUNT(DISTINCT f.dimphysicianPK) AS Physicians_Medicare_Claims
FROM
FactTable f
JOIN
Dimpayer p ON f.dimpayerpk = p.dimpayerpk
WHERE
p.payername = 'Medicare';
-- 5 Calculate the Gross Collection Rate (GCR) for each LocationName -
-- See Below GCR = Payments divided GrossCharge Which LocationName has the highest GCR?--
SELECT l.LocationName,
SUM(f.payment) AS Total_Payments,
SUM(f.GrossCharge) AS Total_GrossCharge,
CASE
WHEN SUM(f.GrossCharge)=0 THEN 0
ELSE CAST(SUM(f.payment) AS DECIMAL (18,4))/SUM(f.GrossCharge)
END AS GrossCollectionRate
From FactTable f
JOIN Dimlocation l
ON f.dimlocationPK = l.dimlocationPK
GROUP BY l.locationName
ORDER BY GrossCollectionRate DESC;
-- 6 How many CptCodes have more than 100 units?
SELECT
COUNT(*) AS CPTCodes_Above_100_Units
FROM
(SELECT
dimCPTCodePK, SUM(CPTUnits) AS TotalUnits
FROM
FactTable
GROUP BY dimCPTCodePK
HAVING SUM(CPTUnits) > 100) AS SubQuery;
-- 7 Find the physician specialty that has received the highest
-- amount of payments. Then show the payments by month for this group of physicians.
SELECT
p.ProviderSpecialty,
SUM(f.Payment) AS TotalPayments
FROM FactTable f
JOIN dimPhysician p
ON f.dimPhysicianPK = p.dimPhysicianPK
GROUP BY p.ProviderSpecialty
ORDER BY SUM(f.Payment) DESC;
-- 8 How many CptUnits by DiagnosisCodeGroup are assigned to a
-- "J code" Diagnosis (these are diagnosis codes with
-- the letter J in the code)?
SELECT
d.DiagnosisCodeGroup, SUM(f.CPTUnits) AS TotalCPTUnits
FROM
FactTable f
JOIN
dimDiagnosisCode d ON f.dimDiagnosisCodePK = d.dimDiagnosisCodePK
WHERE
d.DiagnosisCode LIKE 'J%'
GROUP BY d.DiagnosisCodeGroup
ORDER BY TotalCPTUnits DESC;
-- 9 You've been asked to put together a report that details Patient demographics. The report should group patients into three buckets- Under 18, between 18-65, & over 65
-- Please include the following columns:
-- -First and Last name in the same column
-- -Email
-- -Patient Age
-- -City and State in the same column
SELECT
CONCAT(FirstName, ' ', LastName),
Email,
PatientAge,
CASE
WHEN PatientAGE < 18 THEN 'Under 18'
WHEN PatientAGE BETWEEN 18 AND 65 THEN '18-65'
ELSE 'OVER 65'
END AS AgeBucket,
CONCAT(City, ' ', State)
FROM
dimpatient
ORDER BY AgeBucket , PatientAge;
-- 10 How many dollars have been written off (adjustments) due to credentialing (AdjustmentReason)?
SELECT
SUM(f.Adjustment) AS TotalCredentialing
FROM FactTable f
JOIN dimTransaction t
ON f.dimTransactionPK = t.dimTransactionPK
WHERE t.AdjustmentReason = 'Credentialing';
-- Which location has the highest number of credentialing adjustments?
SELECT
l.LocationName,
SUM(f.Adjustment) AS TotalCredentialingWriteOff
FROM FactTable f
JOIN dimTransaction t
ON f.dimTransactionPK = t.dimTransactionPK
JOIN dimLocation l
ON f.dimLocationPK = l.dimLocationPK
WHERE t.AdjustmentReason = 'Credentialing'
GROUP BY l.LocationName
ORDER BY TotalCredentialingWriteOff DESC;
-- How many physicians at this location have been impacted by credentialing adjustments? What does this mean?
SELECT
COUNT(DISTINCT f.dimPhysicianPK) AS PhysiciansImpacted
FROM FactTable f
JOIN dimTransaction t
ON f.dimTransactionPK = t.dimTransactionPK
JOIN dimLocation l
ON f.dimLocationPK = l.dimLocationPK
WHERE t.AdjustmentReason = 'Credentialing'
AND l.LocationName = '<<Top Location From Previous Query>>';
-- 11 What is the average patientage by gender for patients seen at Big Heart Community Hospital with a Diagnosisthat included Type 2 diabetes? And how many Patients are included in that average?
SELECT
p.PatientGender,
AVG(CAST(p.PatientAge AS DECIMAL(10,2))) AS AvgPatientAge,
COUNT(DISTINCT p.dimPatientPK) AS PatientCount
FROM FactTable f
JOIN dimPatient p
ON f.dimPatientPK = p.dimPatientPK
JOIN dimLocation l
ON f.dimLocationPK = l.dimLocationPK
JOIN dimDiagnosisCode d
ON f.dimDiagnosisCodePK = d.dimDiagnosisCodePK
WHERE l.LocationName = 'Big Heart Community Hospital'
AND d.DiagnosisCodeDescription LIKE '%Type 2%'
GROUP BY p.PatientGender
ORDER BY p.PatientGender;
-- 12 There are a two visit types that you have been asked to compare (use CptDesc).
-- - Office/outpatient visit est
-- - Office/outpatient visit new
-- Show each CptCode, CptDesc and the assocaited CptUnits.
-- What is the Charge per CptUnit? (Reduce to two decimals)
-- What does this mean?
SELECT
c.CptCode,
c.CptDesc,
SUM(f.CPTUnits) AS TotalCPTUnits,
ROUND(SUM(f.GrossCharge) / NULLIF(SUM(f.CPTUnits), 0),
2) AS ChargePerCptUnit
FROM
FactTable f
JOIN
dimCptCode c ON f.dimCPTCodePK = c.dimCPTCodePK
WHERE
c.CptDesc LIKE '%Office/outpatient visit est%'
OR c.CptDesc LIKE '%Office/outpatient visit new%'
GROUP BY c.CptCode , c.CptDesc
ORDER BY c.CptDesc;
-- 13 Similar to Question 12, you've been asked to analysis the PaymentperUnit (NOT ChargeperUnit). You've been tasked with finding the PaymentperUnit by PayerName.
-- Do this analysis on the following visit type (CptDesc)- Initial hospital care
-- Show each CptCode, CptDesc and associated CptUnits.
-- **Note you will encounter a zero value error. If you can't remember what to do find the ifnull lecture in
-- Section 8.
-- What does this mean?
SELECT
p.PayerName,
c.CptCode,
c.CptDesc,
SUM(f.CPTUnits) AS TotalCPTUnits,
ROUND(SUM(f.Payment) / NULLIF(SUM(f.CPTUnits), 0),
2) AS PaymentPerUnit
FROM
FactTable f
JOIN
dimCptCode c ON f.dimCPTCodePK = c.dimCPTCodePK
JOIN
dimPayer p ON f.dimPayerPK = p.dimPayerPK
WHERE
c.CptDesc = 'Initial hospital care'
GROUP BY p.PayerName , c.CptCode , c.CptDesc
ORDER BY p.PayerName;
-- Within the FactTable we are able to see GrossCharges. You've been asked to find the NetCharge, which means Contractual adjustments need to be subtracted from the
-- GrossCharge (GrossCharges - Contractual Adjustments).After you've found the NetCharge then calculate the Net Collection Rate (Payments/NetCharge) for each physician specialty. Which physician specialty has the worst Net Collection Rate with a NetCharge greater than $25,000? What is happening here? Where are the other dollars and why aren't they being collected?
-- What does this mean?
SELECT
p.ProviderSpecialty,
SUM(f.GrossCharge) AS TotalGrossCharge,
SUM(CASE
WHEN t.AdjustmentReason = 'Contractual'
THEN f.Adjustment
ELSE 0
END) AS ContractualAdjustments,
SUM(f.GrossCharge)
- SUM(CASE
WHEN t.AdjustmentReason = 'Contractual'
THEN f.Adjustment
ELSE 0
END) AS NetCharge,
SUM(f.Payment) AS TotalPayments,
ROUND(
SUM(f.Payment) /
NULLIF(
SUM(f.GrossCharge)
- SUM(CASE
WHEN t.AdjustmentReason = 'Contractual'
THEN f.Adjustment
ELSE 0
END),
0),
4) AS NetCollectionRate
FROM FactTable f
JOIN dimPhysician p
ON f.dimPhysicianPK = p.dimPhysicianPK
JOIN dimTransaction t
ON f.dimTransactionPK = t.dimTransactionPK
GROUP BY p.ProviderSpecialty
HAVING
SUM(f.GrossCharge)
- SUM(CASE
WHEN t.AdjustmentReason = 'Contractual'
THEN f.Adjustment
ELSE 0
END) > 25000
ORDER BY NetCollectionRate ASC;
-- Question 15
-- Build a Table that includes the following elements:
-- - LocationName
-- - CountofPhysicians
-- - CountofPatients
-- - GrossCharge
-- - AverageChargeperPatients
SELECT
l.LocationName,
COUNT(DISTINCT f.dimPhysicianPK) AS CountOfPhysicians,
COUNT(DISTINCT f.dimPatientPK) AS CountOfPatients,
SUM(f.GrossCharge) AS TotalGrossCharge,
ROUND(SUM(f.GrossCharge) / NULLIF(COUNT(DISTINCT f.dimPatientPK), 0),
2) AS AverageChargePerPatient
FROM
FactTable f
JOIN
dimLocation l ON f.dimLocationPK = l.dimLocationPK
GROUP BY l.LocationName
ORDER BY TotalGrossCharge DESC;