forked from lewisschmidt/CCL
-
Notifications
You must be signed in to change notification settings - Fork 1
/
OrdersCount
68 lines (58 loc) · 1.87 KB
/
OrdersCount
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
; count orders and show the order and facility where it was ordered
select
Count = count(o.order_id)
,CPOE_Order = o.order_mnemonic
;,uar_get_code_display(o.catalog_cd)
,Order_type = uar_get_code_display(ocs.mnemonic_type_cd)
,Facility_Display = uar_get_code_display(e.loc_facility_cd)
from
orders o
, order_catalog_synonym ocs
, encounter e
Plan o
where o.orig_order_dt_tm > sysdate - 7 ;integer determines the date back in days (sysdate)
and o.order_status_cd in (2543.00); cs 6004, Future 2546.00, Ordered 2550.00, Completed 2543.00
and o.catalog_type_cd = 2516.00; cs 6000, pharmacy
and o.activity_type_cd = 705.00; cs 106, pharmacy = 705.00
and o.template_order_id = 0; child orders are > 0
Join OCS
where o.catalog_cd = ocs.catalog_cd
/*and ocs.mnemonic_type_cd in(
;CODE_VALUE DISPLAY
2580 ;Brand Name
2581 ;Direct Care Provider
614542 ;C - Dispensable Drug Names
2582 ;Generic Name
614548 ;Y - Generic Products
614544 ;M - Generic Miscellaneous Products
614543 ;E - IV Fluids and Nicknames
;614546 ;Outreach
;614547 ;PathLink
2583 ;Primary
2584 ;Rx Mnemonic
2585 ;Surgery Med
614549 ;Z - Trade Products
614545 ;N - Trade Miscellaneous Products
*/
join e
where e.encntr_id = o.encntr_id
and e.loc_facility_cd in(
;CODE_VALUE DISPLAY
21198290 ;location
,271998575 ;location
,271998583 ;location
,271998479 ;location
,276041517 ;location
,276497813 ;location
,344062579 ;location
,349503863 ;location
,499091795 ;location
,516280427 ;location
,416024841 ;location
,428514323 ;location
,275964153 ;location
,275964173 ;location
)
group by o.catalog_type_cd, o.catalog_cd, o.order_mnemonic, ocs.mnemonic_type_cd,e.loc_facility_cd
order by count(o.order_id) desc
with maxrec = 500, time = 300