|  |  | 
 |  |  |         pmo.hpi, | 
 |  |  |         pmo.fuflag, | 
 |  |  |         pmo.patname, | 
 |  |  |         CONCAT(pa.age,pa.age_unit,pa.age2,pa.age_unit2) AS age, | 
 |  |  |         pa.telcode, | 
 |  |  |         pmo.mainsuit, | 
 |  |  |         pa.idcardno | 
 |  |  |         from pat_med_outhosp pmo left join pat_archive pa on pmo.patid = pa.id | 
 |  |  |         pmo.mainsuit | 
 |  |  |         from pat_med_outhosp pmo | 
 |  |  |         <where> | 
 |  |  |             pmo.del_flag=0 | 
 |  |  |             <if test="orgid != null ">and pmo.orgid = #{orgid}</if> | 
 |  |  | 
 |  |  |                 #{hospitalname}, | 
 |  |  |                 '%') | 
 |  |  |             </if> | 
 |  |  |             <if test="deptcodes != null and deptcodes.size()>0"> | 
 |  |  |                 AND  pmo.deptcode IN | 
 |  |  |                 <foreach collection="deptcodes" item="deptcode" open="(" separator="," | 
 |  |  |                          close=")"> | 
 |  |  |                     #{deptcode} | 
 |  |  |                 </foreach> | 
 |  |  |             </if> | 
 |  |  |  | 
 |  |  |  | 
 |  |  |             <if test="deptname != null  and deptname != ''">and pmo.deptname like concat('%', #{deptname}, '%')</if> | 
 |  |  |             <if test="drname != null  and drname != ''">and pmo.drname like concat('%', #{drname}, '%')</if> | 
 |  |  |             <if test="patname != null  and patname != ''">and pmo.patname like concat('%', #{patname}, '%')</if> | 
 |  |  | 
 |  |  |             <if test="patno != null ">and pmo.patno = #{patno}</if> | 
 |  |  |             <if test="outhospno != null  and outhospno != ''">and pmo.outhospno = #{outhospno}</if> | 
 |  |  |             <if test="diagcheckFlag != null  and diagcheckFlag != ''">and pmo.diagcheck_flag = #{diagcheckFlag}</if> | 
 |  |  |             <if test="diagname != null  and diagname != ''">and pmo.diagname like concat('%',#{diagname}, '%')</if> | 
 |  |  |         </where> | 
 |  |  |         order by pmo.update_time desc | 
 |  |  |     </select> | 
 |  |  | 
 |  |  |  | 
 |  |  |     <select id="selectPatMedOuthospCount" parameterType="com.smartor.domain.PatMedReq" | 
 |  |  |             resultType="com.smartor.domain.PatMedRes"> | 
 |  |  |         SELECT SUM( rs ) AS rs, | 
 |  |  |         SUM( rc ) AS rc | 
 |  |  |         FROM ( | 
 |  |  |         SELECT | 
 |  |  |         COUNT(id) AS rc, | 
 |  |  |         COUNT(DISTINCT patid) AS rs | 
 |  |  |         0 AS rs | 
 |  |  |         FROM | 
 |  |  |         pat_med_outhosp | 
 |  |  |         <where> | 
 |  |  |             del_flag=0 | 
 |  |  |             <if test="orgid != null"> | 
 |  |  |                 and orgid = #{orgid} | 
 |  |  |             </if> | 
 |  |  |             and date_format(admitdate,'%y%m%d') >= date_format(#{startDate},'%y%m%d') | 
 |  |  |             and date_format(admitdate,'%y%m%d') <= date_format(#{endDate},'%y%m%d') | 
 |  |  |             <if test="deptcodeList != null and deptcodeList.size()>0"> | 
 |  |  | 
 |  |  |                 </foreach> | 
 |  |  |             </if> | 
 |  |  |         </where> | 
 |  |  |         union all | 
 |  |  |         select | 
 |  |  |         0 AS rc, | 
 |  |  |         count(1) AS rs | 
 |  |  |         FROM | 
 |  |  |         service_subtask | 
 |  |  |         <where> | 
 |  |  |             del_flag = 0 | 
 |  |  |             and service_type=3 | 
 |  |  |             <if test="orgid != null"> | 
 |  |  |                 and orgid = #{orgid} | 
 |  |  |             </if> | 
 |  |  |             <if test="startDate != null"> | 
 |  |  |                 AND date_format( visit_time, '%y%m%d' ) >= date_format( #{startDate}, '%y%m%d' ) | 
 |  |  |             </if> | 
 |  |  |             <if test="endDate != null"> | 
 |  |  |                 AND date_format( visit_time, '%y%m%d' ) <= date_format(#{endDate},'%y%m%d') | 
 |  |  |             </if> | 
 |  |  |             <if test="deptcodeList != null and deptcodeList.size()>0"> | 
 |  |  |                 and deptcode in | 
 |  |  |                 <foreach collection="deptcodeList" item="deptcode" open="(" separator="," close=")"> | 
 |  |  |                     #{deptcode} | 
 |  |  |                 </foreach> | 
 |  |  |             </if> | 
 |  |  |         </where> | 
 |  |  |         ) AS combined_data | 
 |  |  |     </select> | 
 |  |  |  | 
 |  |  |     <select id="getDeptRanking" parameterType="com.smartor.domain.PatMedReq" resultType="com.smartor.domain.PatMedRes"> |