d.*,[dbo].[getWorkday](m.discharge_date_time,d.create_time) overdue from archive_master m
LEFT JOIN(select master_id archive_detail_id,handle_time create_time,handle_name first_instance from (
select ROW_NUMBER() over(partition by master_id order by handle_time asc) RowNum
,Archive_Master_Following.*
from Archive_Master_Following where 1=1 and following_type ='5' ) as t1 where 1=1 and RowNum = 1
) d
on m.id=d.archive_detail_id
LEFT JOIN (select code,name from emr_dictionary where parent_id=(select id from emr_dictionary where
typeCode='dept_code' )) t
on m.dept_admission_to=t.code
@ -1201,11 +1204,7 @@
typeCode='dept_code' )) g
on m.dept_name=g.code
where 1=1
--判断初审以及状态为null
and d.archive_state in ('初审', null)
--或者初审时间,时间最小
and d.create_time in (select create_time from emr_fault_detail A where create_time=(select min(create_time) from emr_fault_detail B where A.[archive_detail_id]=B.[archive_detail_id]))
<iftest="id != null and id != ''">
<iftest="id != null and id != ''">
and m.id = #{id,jdbcType=NVARCHAR}
</if>
<iftest="inpNo != null and inpNo != ''">
@ -1269,7 +1268,7 @@
</if>
</if>
<iftest="overdueDays != null and overdueDays != ''">
and [dbo].[getWorkday](m.discharge_date_time,d.create_time)>=#{overdueDays,jdbcType=NCHAR}
and convert(int,[dbo].[getWorkday](m.discharge_date_time,d.create_time))-convert(int,#{overdueDays,jdbcType=INTEGER})>0