<!-- ,case when emr_fault_detail.archive_detail_id is not null then '是' else '否' end isFault,ISNULL(printTable.num, 0) printNum-->
<!-- from archive_master m-->
<!-- left join (select distinct archive_detail_id from emr_fault_detail where back_flag in ('6','5')) emr_fault_detail-->
<!-- on emr_fault_detail.archive_detail_id = m.ID-->
<!-- 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 distinct masterID,C5 FROM archive_other where sysFlag = '1') ao-->
<!-- on m.id=ao.masterID-->
<!-- 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 archive_detail_id,count(*) numb from emr_fault_detail where 1=1 and back_flag in ('1','5') GROUP BY archive_detail_id) sDoctor-->
<!-- on m.id=sDoctor.archive_detail_id-->
<!-- LEFT JOIN (select MasterID,COUNT(*) num from archive_printInfo group by MasterID) printTable-->
<!-- on m.id=printTable.MasterID-->
<!-- where 1=1 and ArchiveState in('初审') and m.Is_Valid!=1-->
<!-- and patindex('%B%',m.inp_no) = 0 and inp_no not like 'LG%'-->
<!-- <if test="isFault != null and isFault != ''">-->
<!-- <if test="isFault == 1">-->
<!-- AND emr_fault_detail.archive_detail_id is not null-->
<!-- </if>-->
<!-- <if test="isFault == 0">-->
<!-- AND emr_fault_detail.archive_detail_id is null-->
<!-- </if>-->
<!-- </if>-->
<!-- <if test="printNum != null and printNum != ''">-->
<!-- <choose>-->
<!-- <when test="printNum == 1">-->
<!-- and printTable.MasterID is not null-->
<!-- </when>-->
<!-- <otherwise>and printTable.MasterID is null</otherwise>-->
<!-- </choose>-->
<!-- </if>-->
<!-- <if test="inpNo != null and inpNo != ''">-->
<!-- and m.inp_no like '%'+#{inpNo,jdbcType=NCHAR}+'%'-->
<!-- </if>-->
<!-- <if test="bedNumber != null and bedNumber != ''">-->
<!-- and m.bed_number like '%'+#{bedNumber,jdbcType=NVARCHAR}+'%'-->
<!-- </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 != ''">-->
<!-- and m.ArchiveState in(#{archivestate,jdbcType=NVARCHAR})-->
<!-- </if>-->
<!-- <if test="idNo != null and idNo != ''">-->
<!-- and m.ID_NO like '%'+#{idNo,jdbcType=NCHAR}+'%'-->
<!-- </if>-->
<!-- <if test="sex != null">-->
<!-- and m.sex = #{sex,jdbcType=NVARCHAR}-->
<!-- </if>-->
<!-- <if test="deptName!= null and deptName!= ''">-->