-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvent Log for BuparR - Elective 2.sql
79 lines (54 loc) · 3.37 KB
/
Event Log for BuparR - Elective 2.sql
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
--DROP TABLE div_perf.dbo.CPG_Elective_EventLog2
select * into div_perf.dbo.CPG_Elective_EventLog21
from (
SELECT distinct J.*,
CPG_PrimaryDiagnosis, Site
FROM
div_perf.dbo.CPG_Elective_EventLog k
right join
(select * from(
SELECT referral_id as Case_ID, 'Referral Date' as Activity, 'Referral Date' as [Detailed Activity], Consultant_At_Episode as Resource, Specialty_At_Discharge as Specialty,
referral_request_received_date as timestamp
FROM div_perf.dbo.CPG_Elective_EventLog
where referral_request_received_date between '01/01/2018' and '31/12/2018'
UNION ALL
SELECT referral_id
as Case_ID, 'First Outpatient appointment' as Activity, Appointment_Type AS [Detailed Activity], Appointment_Resource as Resource, Specialty_OP_Discharge as Specialty,
attendance_date as timestamp
FROM div_perf.dbo.CPG_Elective_EventLog
where First_Attendance = 1 and
attendance_date between '01/01/2018' and '01/10/2019'
UNION ALL
SELECT referral_id
as Case_ID, 'Subsequent Outpatient appointment' as Activity, Appointment_Type AS [Detailed Activity], Appointment_Resource as Resource, Specialty_OP_Discharge as Specialty,
attendance_date as timestamp
FROM div_perf.dbo.CPG_Elective_EventLog
where First_Attendance = 2 and Outcome_of_Attendance <> 1 and
attendance_date between '01/01/2018' and '01/10/2019'
UNION ALL
SELECT referral_id as Case_ID, 'Final Outpatient Appointment' as Activity, Appointment_Type as [Detailed Activity], Specialty_OP_Discharge as Specialty,
Appointment_Resource as Resource,
attendance_date as timestamp
FROM div_perf.dbo.CPG_Elective_EventLog
where Outcome_of_Attendance = 1 and attendance_date between '01/01/2018' and '01/10/2019'
UNION ALL
SELECT referral_id as Case_ID, 'Decision to Admit' as Activity, 'Decision to Admit' as [Detailed Activity], Consultant_At_Episode as Resource, Specialty_At_Discharge as Specialty,
Decided_to_Admit_Date as timestamp
FROM div_perf.dbo.CPG_Elective_EventLog
where Decided_to_Admit_Date between '01/01/2018' and '01/10/2019'
UNION ALL
SELECT referral_id as Case_ID, 'Inpatient Spell' as Activity, 'Inpatient Spell' as [Detailed Activity], Consultant_At_Episode as Resource, Specialty_At_Discharge as Specialty,
[Admission_Date] as timestamp
FROM div_perf.dbo.CPG_Elective_EventLog
where [Admission_Date] between '01/01/2018' and '01/10/2019'
) a) J
on k.referral_id = J.Case_ID
) a
where a.Case_ID is not null
--AND timestamp >= '01/01/2019'
-------
Select * from div_perf.dbo.CPG_Elective_EventLog
Select * from div_perf.dbo.CPG_Elective_EventLog2
Select * from div_perf.dbo.CPG_Elective_EventLog3
Select * from div_perf.dbo.CPG_Elective_EventLog21
where CASE_ID <> ' '