您的位置:首页 > 其它

创建存储过程,包及包体

2016-01-17 15:07 218 查看
--创建包
create or replace package PAK_ExecuteAttendingDoctor is
type cp_results is ref cursor;
procedure ExecuteAttendingDoctor(start_time  in varchar2,end_time in  varchar2,cp_results  out cp_results);
end PAK_ExecuteAttendingDoctor;


--创建包体
create or replace package body PAK_ExecuteAttendingDoctor is
procedure ExecuteAttendingDoctor(start_time in varchar2,
end_time   in varchar2,
cp_results out cp_results) is
begin
open cp_results for
select distinct *
from (select t.dept_code, t.dept_name
from dcp_sys_user t
where t.dept_code > 0
and t.dept_code is not null
group by t.dept_code, t.dept_name) mm,
(select a.execute_dept,
a.attending_doctor,
nvl(a.fhrs, 0) fhrs,
nvl(b.nrrs, 0) nrrs,
nvl(c.wcrs, 0) wcrs,
round(nvl(b.nrrs  / a.fhrs, 0), 4) nrl,
round(nvl(c.wcrs  / b.nrrs, 0), 4) wcl,
nvl(d.xdyzzs, 0) xdyzzs,
nvl(xdlcljyzs, 0) xdlcljyzs,
round(nvl(xdlcljyzs / d.xdyzzs, 0), 4) xdl
from --按医生统计符合人数
(select execute_dept, attending_doctor, count(patient_no) fhrs
from lcp_patient_visit v
where v.conform_master_id > 0
and v.admission_date >=
to_date(start_time, 'yyyy-mm-dd')
and v.admission_date <=
to_date(end_time, 'yyyy-mm-dd hh24:mi:ss')
group by v.execute_dept, v.attending_doctor) a,
----纳入人数---
(select execute_dept,
v1.attending_doctor,
count(patient_no) nrrs
from lcp_patient_visit v1
where v1.cp_master_id > 0
and v1.admission_date >=
to_date(start_time, 'yyyy-mm-dd')
and v1.admission_date <=
to_date(end_time, 'yyyy-mm-dd hh24:mi:ss')
group by v1.execute_dept, v1.attending_doctor) b,
----完成人数-----
(select execute_dept,
v2.attending_doctor,
count(patient_no) wcrs
from lcp_patient_visit v2
where v2.cp_master_id > 0
and v2.cp_state = 11
and v2.admission_date >=
to_date(start_time, 'yyyy-mm-dd')
and v2.admission_date <=
to_date(end_time, 'yyyy-mm-dd hh24:mi:ss')
group by v2.execute_dept, v2.attending_doctor) c,
----下达医嘱总数-----
(select count(*) xdyzzs, v.execute_dept, v.attending_doctor
from lcp_patient_log_order t, lcp_patient_visit v
where t.patient_no in
(select t.patient_no
from lcp_patient_visit t
where t.cp_state in (1, 11, 21)
and t.admission_date >=
to_date(start_time, 'yyyy-mm-dd')
and t.admission_date <=
to_date(end_time, 'yyyy-mm-dd hh24:mi:ss'))
and t.patient_no = v.patient_no
group by v.execute_dept, v.attending_doctor) d,
----下达临床路径医嘱数-----
(select count(*) xdlcljyzs, v.execute_dept, v.attending_doctor
from lcp_patient_log_order t, lcp_patient_visit v
where t.patient_no in
(select t.patient_no
from lcp_patient_visit t
where t.cp_state in (1, 11, 21)
and t.admission_date >=
to_date(start_time, 'yyyy-mm-dd')
and t.admission_date <=
to_date(end_time, 'yyyy-mm-dd hh24:mi:ss'))
and t.cp_node_order_item_id > 0
and t.patient_no = v.patient_no
group by v.execute_dept, v.attending_doctor) e

where a.execute_dept = b.execute_dept(+)
and a.attending_doctor = b.attending_doctor(+)
and a.execute_dept = c.execute_dept(+)
and a.attending_doctor = c.attending_doctor(+)
and a.execute_dept = d.execute_dept(+)
and a.attending_doctor = d.attending_doctor(+)
and a.execute_dept = e.execute_dept(+)
and a.attending_doctor = e.attending_doctor(+)) aa
where mm.dept_name = aa.execute_dept
order by aa.execute_dept, nrrs desc;
end ExecuteAttendingDoctor;

end PAK_ExecuteAttendingDoctor;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: