select
case when ss.cyrq is null then 0 else 1 end status,
cast(ss.zyh as VARCHAR2(20))+ ‘46356378221050411A1001’ pid,
ss.brxm name,
ss.bahm caseid,
ss.csny birthday,
ss.zyh inpno,
CASE
WHEN (
datediff(YEAR, ss.csny, getdate()) <> 0
) THEN
(
ltrim(
datediff(YEAR, ss.csny, getdate())
)
)
ELSE
(
CASE
WHEN (
datediff(MONTH, ss.csny, getdate()) <> 0
) THEN
(
ltrim(
convert(decimal(18,2),convert(DECIMAL,datediff(MONTH, ss.csny, getdate()))/12)
)
)
ELSE
(
CASE
WHEN (
datediff(DAY, ss.csny, getdate()) <> 0
) THEN
(
ltrim(
convert(decimal(18,2),convert(DECIMAL,datediff(day, ss.csny, getdate()))/365)
)
)
ELSE
‘’
END
)
END
)
END age,
case when ss.brxb=‘1’ THEN ‘男’
when ss.brxb=‘2’ THEN ‘女’
else ‘未知’ end sex,
ss.brks admiss_dept_code,
ss.brch curr_bed_code,
isnull(zzys.ygbh,‘-’) attending_doctor_code,
ss.ryrq admiss_date,
ss.cyrq discharge_date,
hh.jssj settle_date,
zy.lyfs way_discharge_code,
case when zy.lyfs=‘1’ THEN ‘医嘱离院’
when zy.lyfs=‘2’ THEN ‘医嘱转院’
when zy.lyfs=‘3’ THEN ‘医嘱转社区卫生服务机构/乡镇卫生院’
when zy.lyfs=‘4’ THEN ‘非医嘱离院’
when zy.lyfs=‘5’ THEN ‘死亡’
else ‘其他’ end way_discharge_name,
datediff(day, ss.ryrq, isnull(ss.cyrq,getdate())) indays,
ss.bahm empiid,
ss.brks discharge_dept_code,
ss.zlxz team_code,
‘46356378221050411A1001’ hos_code,
‘本溪’ medical_division_name,
COALESCE(cyjs.tczf,ynjs.tczf) AS fee_ins_coordinated,
COALESCE(cyjs.jmdbzf,ynjs.jmdbzf) AS fee_ins_diag,
COALESCE(cyjs.qtzf,ynjs.qtzf) AS fee_ins_other,
COALESCE(cyjs.zhzf + cyjs.xjzf ,ynjs.zhzf + ynjs.xjzf ,0) AS fee_zifei,
‘’ AS fee_zifu,
‘’ AS fee_zili,
‘’ AS drg_type
from zy_brry ss
left join(select max(zz.jsrq)jssj,zz.zyh from zy_zyjs zz where zz.FPHM is not null and zz.zfpb=0 group by zz.zyh,zz.fyhj,zz.zfhj) hh on hh.zyh=ss.zyh
left join yb_jsqd cc on cc.jsxh=ss.zyh
left join yb_jsqd_zyxx zy on zy.jlxh = cc.jlxh
left join gy_ygdm zzys on zzys.ygdm = ss.zzys
LEFT JOIN zlhis.yb_yjxx_gj ynjs ON ynjs.jsxh=cc.jsxh AND ynjs.zfpb<>1
LEFT JOIN zlhis.yb_jsxx_gj cyjs ON cyjs.jsxh=cc.jsxh AND cyjs.zfpb<>1
where ss.zyh=‘200838173’