Select d.门诊号,
null 住院号,
n.病人id,
n.主页id 住院次数,
n.姓名,
n.性别,
n.年龄,
c.身份证号,
n.医嘱内容,
e.接收日期 检查时间,
a.内容文本 As 标题,
b.内容文本 As 正文
From 电子病历内容 a,
电子病历内容 b,
病人医嘱报告 m,
病人医嘱记录 n,
病人信息 c,
病人挂号记录 d,
影像检查记录 e
Where a.对象类型 = 3
And a.Id = b.父ID
and n.病人来源 = 1
and a.文件id = m.病历id
and m.医嘱id = n.id
and n.病人id = c.病人id
and n.挂号单 = d.no
and m.医嘱id = e.医嘱id
And b.对象类型 = 2
And b.终止版 = 0
and (e.接收日期 > sysdate - 3 or d.门诊号 = '' or n.姓名 = '' or c.身份证号 = '')
union all
Select null 门诊号,
d.住院号,
n.病人id,
n.主页id 住院次数,
n.姓名,
n.性别,
n.年龄,
c.身份证号,
n.医嘱内容,
e.接收日期 检查时间,
a.内容文本 As 标题,
b.内容文本 As 正文
From 电子病历内容 a,
电子病历内容 b,
病人医嘱报告 m,
病人医嘱记录 n,
病人信息 c,
病案主页 d,
影像检查记录 e
Where a.对象类型 = 3
And a.Id = b.父ID
and n.病人来源 = 2
and a.文件id = m.病历id
and m.医嘱id = n.id
and n.病人id = c.病人id
and n.病人id = d.病人id
and n.主页id = d.主页id
and m.医嘱id = e.医嘱id
And b.对象类型 = 2
And b.终止版 = 0
and (e.接收日期 > sysdate - 3 or d.住院号 = '' or n.姓名 = '' or c.身份证号 = '')
--and n.id = 17454038