|
select 核算医师,费用类别,round(sum(核算金额)+0,2) as 金额
from
(
(
select f.登记时间,
f.id,
a.住院号,
a.姓名,
s.编码,
s.名称 as 项目名称,
s.规格,
f.标准单价 as 单价,
f.数次 as 数量,
f.计算单位 as 单位,
f.实收金额,
f.实收金额 as 核算金额,
decode(f.住院医师, null, 开单人, f.住院医师) as 核算医师,
'普通费用' as 费用类别
from 病人信息 a, 病人费用记录 f, 收费项目目录 s
where a.病人id = f.病人id
and f.收费细目id = s.id
and f.登记时间 between to_date('2007-02-01', 'yyyy-mm-dd') and
to_date('2007-02-28', 'yyyy-mm-dd') + 1 - 1 / 24 / 60 / 60
and f.开单部门id = 69
and f.门诊标志 = 2
)
union all
(
select f.登记时间,
f.id,
a.住院号,
a.姓名,
s.编码,
s.名称 as 项目名称,
s.规格,
f.标准单价 as 单价,
f.数次 as 数量,
f.计算单位 as 单位,
f.实收金额,
f.实收金额 / m.医师数 as 核算金额,
m.医师 as 核算医师,
'手术费用' as 费用类别
from 病人信息 a,
(select A.病人id, A.主页ID, A.手术日期, 医师, 医师数
from (select 病人id, 主页ID, 手术日期, 医师
from (select t.手术日期,
t.病人id,
t.主页ID,
t.主刀医师 as 医师
from 病人手麻记录 t
where t.主刀医师 is not null
and not(t.已行手术 like '8%' or t.已行手术 like '9%')
union
select t.手术日期,
t.病人id,
t.主页ID,
t.第一助手 as 医师 from 病人手麻记录 t
where t.第一助手 is not null
and not(t.已行手术 like '8%' or t.已行手术 like '9%')
union
select t.手术日期,
t.病人id,
t.主页ID,
t.第二助手 as 医师 from 病人手麻记录 t
where t.第二助手 is not null
and not(t.已行手术 like '8%' or t.已行手术 like '9%'))
group by 病人id, 主页ID, 手术日期, 医师) A,
(select 病人id, 主页ID, 手术日期, count(*) as 医师数
from (select 病人id, 主页ID, 手术日期, 医师
from (select t.手术日期,
t.病人id,
t.主页ID,
t.主刀医师 as 医师
from 病人手麻记录 t
where t.主刀医师 is not null
and not(t.已行手术 like '8%' or t.已行手术 like '9%')
union
select t.手术日期,
t.病人id,
t.主页ID,
t.第一助手 as 医师 from 病人手麻记录 t
where t.第一助手 is not null
and not(t.已行手术 like '8%' or t.已行手术 like '9%')
union
select t.手术日期,
t.病人id,
t.主页ID,
t.第二助手 as 医师 from 病人手麻记录 t
where t.第二助手 is not null
and not(t.已行手术 like '8%' or t.已行手术 like '9%'))
group by 病人id, 主页ID, 手术日期, 医师)
group by 病人id, 主页ID, 手术日期) B
where a.病人id = b.病人id
and a.主页ID = b.主页ID
and a.手术日期 = b.手术日期) m,
病人费用记录 f,
部门表 b,
收费项目目录 s,
(select t.已行手术 as 材料编码
from 病人手麻记录 t
where (t.已行手术 like '8%' or t.已行手术 like '9%')
and t.手术日期 between to_date('2006-02-01', 'yyyy-mm-dd') and
to_date('2007-02-28', 'yyyy-mm-dd') + 1 - 1 / 24 / 60 / 60
group by t.已行手术) c
where a.病人id = m.病人id
and f.病人id = m.病人id
and f.主页id = m.主页id
and trunc(f.发生时间) = m.手术日期
and b.id = f.开单部门id
and f.收费细目id = s.id
and s.编码 = c.材料编码(+)
and c.材料编码 is null
and f.登记时间 between to_date('2006-02-01', 'yyyy-mm-dd') and
to_date('2007-02-28', 'yyyy-mm-dd') + 1 - 1 / 24 / 60 / 60
and f.开单部门id = 69
)
union all
(
select f.登记时间,
f.id,
a.住院号,
a.姓名,
s.编码,
s.名称 as 项目名称,
s.规格,
f.标准单价 as 单价,
f.数次 as 数量,
f.计算单位 as 单位,
f.实收金额,
f.实收金额 / m.医师数 as 核算金额,
m.医师 as 核算医师,
'特殊材料' as 费用类别
from 病人信息 a,
(select A.病人id, A.主页ID, A.手术日期, 医师, 医师数
from (select 病人id, 主页ID, 手术日期, 医师
from (select t.手术日期,
t.病人id,
t.主页ID,
t.主刀医师 as 医师
from 病人手麻记录 t
where t.主刀医师 is not null
and (t.已行手术 like '8%' or t.已行手术 like '9%')
union
select t.手术日期,
t.病人id,
t.主页ID,
t.第一助手 as 医师 from 病人手麻记录 t
where t.第一助手 is not null
and (t.已行手术 like '8%' or t.已行手术 like '9%')
union
select t.手术日期,
t.病人id,
t.主页ID,
t.第二助手 as 医师 from 病人手麻记录 t
where t.第二助手 is not null
and (t.已行手术 like '8%' or t.已行手术 like '9%'))
group by 病人id, 主页ID, 手术日期, 医师) A,
(select 病人id, 主页ID, 手术日期, count(*) as 医师数
from (select 病人id, 主页ID, 手术日期, 医师
from (select t.手术日期,
t.病人id,
t.主页ID,
t.主刀医师 as 医师
from 病人手麻记录 t
where t.主刀医师 is not null
and (t.已行手术 like '8%' or t.已行手术 like '9%')
union
select t.手术日期,
t.病人id,
t.主页ID,
t.第一助手 as 医师 from 病人手麻记录 t
where t.第一助手 is not null
and (t.已行手术 like '8%' or t.已行手术 like '9%')
union
select t.手术日期,
t.病人id,
t.主页ID,
t.第二助手 as 医师 from 病人手麻记录 t
where t.第二助手 is not null
and (t.已行手术 like '8%' or t.已行手术 like '9%'))
group by 病人id, 主页ID, 手术日期, 医师)
group by 病人id, 主页ID, 手术日期) B
where a.病人id = b.病人id
and a.主页ID = b.主页ID
and a.手术日期 = b.手术日期) m,
病人费用记录 f,
部门表 b,
收费项目目录 s,
(select t.已行手术 as 材料编码
from 病人手麻记录 t
where (t.已行手术 like '8%' or t.已行手术 like '9%')
and t.手术日期 between to_date('2006-02-01', 'yyyy-mm-dd') and
to_date('2007-02-28', 'yyyy-mm-dd') + 1 - 1 / 24 / 60 / 60
group by t.已行手术) c
where a.病人id = m.病人id
and f.病人id = m.病人id
and f.主页id = m.主页id
and trunc(f.发生时间) = m.手术日期
and b.id = f.开单部门id
and f.收费细目id = s.id
and s.编码 = c.材料编码
and f.登记时间 between to_date('2006-02-01', 'yyyy-mm-dd') and
to_date('2007-02-28', 'yyyy-mm-dd') + 1 - 1 / 24 / 60 / 60
and f.开单部门id = 69
)
)
group by 核算医师,费用类别 |
|