LEFT JOIN(SELECT amfa.id ,amfa.master_id, amfa.following_type num FROM Archive_Master_Following amfa left join
(SELECT amfb.master_id ida,max(handle_time) t FROM Archive_Master_Following amfb GROUP BY master_id) amfc
@ -855,12 +855,6 @@
on m.id=sDoctor.archive_detail_id
LEFT JOIN(select archive_detail_id,count(*) numb from emr_fault_detail where 1=1 and back_flag in ('2','6') GROUP BY archive_detail_id) sNurse
on m.id=sNurse.archive_detail_id
LEFT JOIN (select code,name from emr_dictionary where parent_id=(select id from emr_dictionary where
typeCode='dept_code' )) d
on m.dept_admission_to=d.code
LEFT JOIN (select code,name from emr_dictionary where parent_id=(select id from emr_dictionary where
typeCode='dept_code' )) f
on m.dept_name=f.code
LEFT JOIN(select archive_detail_id,count(*) numb from emr_fault_detail where 1=1 and back_flag is not null GROUP BY archive_detail_id) s
on m.id=s.archive_detail_id
LEFT JOIN (select MasterID,COUNT(*) num from archive_printInfo group by MasterID) printTable
@ -871,9 +865,9 @@
<iftest="printNum != null and printNum != ''">
<choose>
<whentest="printNum == 1">
and printTable.MasterID is not null
and m.print_flag is not null
</when>
<otherwise>and printTable.MasterID is null</otherwise>
<otherwise>and m.print_flag is null</otherwise>
</choose>
</if>
<iftest="inpNo != null and inpNo != ''">
@ -1802,43 +1796,13 @@
VARCHAR (10),
f1.handle_time,
120
) and flag= 1 order by date asc) as b) as overTime1,
<iftest="overdueDays != null and overdueDays != ''">
case
when ISNULL( datediff(day,convert(varchar(100),f2.mid_date,23),convert(varchar(100),f1.handle_time,23)),0)<=0
then '0'
when ISNULL( datediff(day,convert(varchar(100),f2.mid_date,23),convert(varchar(100),f1.handle_time,23)),0)+ISNULL(f2.dayOne,0)-1-cast(#{overdueDays,jdbcType=NCHAR} as int)<0
then '0'
when ISNULL(f2.dayOne,0)>=0 and ISNULL( datediff(day,convert(varchar(100),f2.mid_date,23),convert(varchar(100),f1.handle_time,23)),0)>=0
then ISNULL( datediff(day,convert(varchar(100),f2.mid_date,23),convert(varchar(100),f1.handle_time,23)),0)+ISNULL(f2.dayOne,0)-1-cast(#{overdueDays,jdbcType=NCHAR} as int)
else '0'
end overdue
</if>
<iftest="overdueDays == null or overdueDays == ''">
case
when ISNULL( datediff(day,convert(varchar(100),f2.mid_date,23),convert(varchar(100),f1.handle_time,23)),0)<=0
then '0'
when ISNULL( datediff(day,convert(varchar(100),f2.mid_date,23),convert(varchar(100),f1.handle_time,23)),0)+ISNULL(f2.dayOne,0)-1-3<0
then '0'
when ISNULL(f2.dayOne,0)>=0 and ISNULL( datediff(day,convert(varchar(100),f2.mid_date,23),convert(varchar(100),f1.handle_time,23)),0)>=0
then ISNULL( datediff(day,convert(varchar(100),f2.mid_date,23),convert(varchar(100),f1.handle_time,23)),0)+ISNULL(f2.dayOne,0)-1-3
select id,master_id,following_type,following_content,handle_name,handle_time,ROW_NUMBER() OVER (partition by master_id ORDER BY master_id,handle_time) as rowNumb from Archive_Master_Following where following_type='9'
)f1
LEFT JOIN (
select *,
<iftest="overdueDays != null and overdueDays != ''">
convert(varchar(10),(DATEADD(DAY,cast(#{overdueDays,jdbcType=NCHAR} as int)-1,convert(varchar(10),handle_time,23))),23) mid_date
,ISNULL(dbo.getWorkday(convert(varchar(10),handle_time,23),convert(varchar(10),(DATEADD(DAY,cast(#{overdueDays,jdbcType=NCHAR} as int),convert(varchar(10),handle_time,23))),23)) , 0) dayOne
</if>
<iftest="overdueDays == null or overdueDays == ''">
convert(varchar(10),(DATEADD(DAY,cast('2' as int),convert(varchar(10),handle_time,23))),23) mid_date
,ISNULL(dbo.getWorkday(convert(varchar(10),handle_time,23),convert(varchar(10),(DATEADD(DAY,cast('3' as int),convert(varchar(10),handle_time,23))),23)) , 0) dayOne
</if>
select *
from(
select *,ROW_NUMBER() OVER (partition by master_id ORDER BY master_id,handle_time) as rowNumb from Archive_Master_Following where following_type='5'
)a
@ -1849,10 +1813,6 @@
from archive_master where 1=1 and ArchiveState not in('作废','已封存','取消入院') and Is_Valid!=1
) m
on f1.master_id=m.master_id
LEFT JOIN (select code,name from emr_dictionary where parent_id=(select id from emr_dictionary where typeCode='dept_code' )) c
on m.dept_name=c.code
LEFT JOIN (select code,name from emr_dictionary where parent_id=(select id from emr_dictionary where typeCode='dept_code' )) e
on m.dept_admission_to=e.code
<where> 1=1 and m.master_id!='' and m.master_id is not null and f2.handle_time is not null
<!--<if test="(overdueDaysTwo != null and overdueDaysTwo != '') ">-->
select m.id as archive_detail_id,ISNULL(f.state, '未召回') state,f.recall_reason,m.inp_no,m.visit_id,m.name,m.dept_name,CONVERT(VARCHAR(20),m.discharge_date_time,120) discharge_date_time,m.ArchiveState,m.sex,m.ID_NO,m.dept_admission_to,CONVERT(VARCHAR(20),m.admission_date_time,120) admission_date_time,m.DISCHARGE_DISPOSITION,
p.id as v_printinfo_id
from archive_master m
left join(select * from emr_fault_detail t where id = (select top 1 id from emr_fault_detail where archive_detail_id = t.archive_detail_id order by create_time desc )
and state in('已召回','未召回')) f
ON f.archive_detail_id=m.id
left join archive_printinfo p ON m.id=p.MasterID
where 1=1 and m.Is_Valid!=1
<iftest="archiveDetailId != null">
and f.archive_detail_id = #{archiveDetailId,jdbcType=NVARCHAR}
</if>
<iftest="assortId != null">
and f.assort_id = #{assortId,jdbcType=NVARCHAR}
</if>
<iftest="parentId != null">
and m.parent_id = #{parentId,jdbcType=INTEGER}
</if>
<iftest="content != null">
and f.content = #{content,jdbcType=NVARCHAR}
</if>
<iftest="score != null">
and f.score = #{score,jdbcType=DECIMAL}
</if>
<iftest="backContent != null">
and f.back_content = #{backContent,jdbcType=NVARCHAR}
</if>
<iftest="firstTrial != null">
and f.first_trial = #{firstTrial,jdbcType=NVARCHAR}
</if>
<iftest="creater != null">
and f.creater = #{creater,jdbcType=NVARCHAR}
</if>
<iftest="createTime != null">
and f.create_time = #{createTime,jdbcType=NCHAR}
</if>
<iftest="updater != null">
and f.updater = #{updater,jdbcType=NVARCHAR}
</if>
<iftest="updateTime != null">
and f.update_time = #{updateTime,jdbcType=NCHAR}
</if>
<iftest="inpNo != null and inpNo != ''">
and m.inp_no = #{inpNo,jdbcType=NCHAR}
</if>
<iftest="visitId != null and visitId != ''">
and m.visit_id=#{visitId,jdbcType=NCHAR}
</if>
<iftest="name != null and name != ''">
and m.name like '%'+#{name,jdbcType=NCHAR}+'%'
</if>
<iftest="archivestate!= null and archivestate!= ''">
<!-- select m.id as archive_detail_id,ISNULL(f.state, '未召回') state,f.recall_reason,m.inp_no,m.visit_id,m.name,m.dept_name,CONVERT(VARCHAR(20),m.discharge_date_time,120) discharge_date_time,m.ArchiveState,m.sex,m.ID_NO,m.dept_admission_to,CONVERT(VARCHAR(20),m.admission_date_time,120) admission_date_time,m.DISCHARGE_DISPOSITION,-->
<!-- p.id as v_printinfo_id-->
<!-- from archive_master m-->
<!-- left join(select t.state,t.recall_reason,t.archive_detail_id from emr_fault_detail t where id = (select top 1 id from emr_fault_detail where archive_detail_id = t.archive_detail_id order by create_time desc )-->
<!-- and state in('已召回','未召回')) f-->
<!-- ON f.archive_detail_id=m.id-->
<!-- left join archive_printinfo p ON m.id=p.MasterID-->
<!-- where 1=1 and m.Is_Valid!=1-->
<!-- <if test="archiveDetailId != null">-->
<!-- and f.archive_detail_id = #{archiveDetailId,jdbcType=NVARCHAR}-->
<!-- </if>-->
<!-- <if test="assortId != null">-->
<!-- and f.assort_id = #{assortId,jdbcType=NVARCHAR}-->
<!-- </if>-->
<!-- <if test="parentId != null">-->
<!-- and m.parent_id = #{parentId,jdbcType=INTEGER}-->
<!-- </if>-->
<!-- <if test="content != null">-->
<!-- and f.content = #{content,jdbcType=NVARCHAR}-->
<!-- </if>-->
<!-- <if test="score != null">-->
<!-- and f.score = #{score,jdbcType=DECIMAL}-->
<!-- </if>-->
<!-- <if test="backContent != null">-->
<!-- and f.back_content = #{backContent,jdbcType=NVARCHAR}-->
<!-- </if>-->
<!-- <if test="firstTrial != null">-->
<!-- and f.first_trial = #{firstTrial,jdbcType=NVARCHAR}-->
<!-- </if>-->
<!-- <if test="creater != null">-->
<!-- and f.creater = #{creater,jdbcType=NVARCHAR}-->
<!-- </if>-->
<!-- <if test="createTime != null">-->
<!-- and f.create_time = #{createTime,jdbcType=NCHAR}-->
<!-- </if>-->
<!-- <if test="updater != null">-->
<!-- and f.updater = #{updater,jdbcType=NVARCHAR}-->
<!-- </if>-->
<!-- <if test="updateTime != null">-->
<!-- and f.update_time = #{updateTime,jdbcType=NCHAR}-->
<!-- </if>-->
<!-- <if test="inpNo != null and inpNo != ''">-->
<!-- and m.inp_no = #{inpNo,jdbcType=NCHAR}-->
<!-- </if>-->
<!-- <if test="visitId != null and visitId != ''">-->
<!-- and m.visit_id=#{visitId,jdbcType=NCHAR}-->
<!-- </if>-->
<!-- <if test="name != null and name != ''">-->
<!-- and m.name like '%'+#{name,jdbcType=NCHAR}+'%'-->
<!-- </if>-->
<!-- <if test="archivestate!= null and archivestate!= ''">-->
s.T2,s.T3,s.IsFullText,s.operateName,m.inp_no,m.visit_id,m.name,CONVERT(varchar(10),m.admission_date_time, 120) admissionDateTime,m.dept_name, m.isscaned,m.dept_admission_to,(select COUNT(1) from archive_other where archive_other.masterID=s.masterID and archive_other.sysFlag = 1)as num
from archive_other s
left join archive_master m
on s.masterID=m.id
where s.id in(
(select top 1 id from archive_other a where a.pid=s.pid and a.masterID=s.masterID ORDER BY createdtime desc)
)
and m.is_sign =1
<iftest="id != null and id != ''"> and s.ID = #{id}</if>
<iftest="pid != null and pid != ''"> and s.pid = #{pid}</if>
<choose>
<whentest="startSignDate != null and startSignDate != '' and endSignDate != null and endSignDate != ''">