Browse Source

31天再入院

zhaops 4 years ago
parent
commit
f333debef2

+ 1 - 0
src/main/java/com/diagbot/config/ResourceServerConfigurer.java

@@ -103,6 +103,7 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
                 .antMatchers("/console/resultStatisticsByDeptPage").permitAll()
                 .antMatchers("/console/homePageMRCount").permitAll()
                 .antMatchers("/console/qcCheckStatistics").permitAll()
+                .antMatchers("/console/reHos31DaysPage").permitAll()
                 .antMatchers("/consoleByDept/entryCountGroupByCaseAndDept").permitAll()
                 .antMatchers("/consoleByDept/entryCountGroupByCaseAndDeptPage").permitAll()
                 .antMatchers("/consoleByDept/entryCountGroupByEntryAndDept").permitAll()

+ 1 - 0
src/main/java/com/diagbot/config/security/UrlAccessDecisionManager.java

@@ -146,6 +146,7 @@ public class UrlAccessDecisionManager implements AccessDecisionManager {
                 || matchers("/console/resultStatisticsByDeptPage", request)
                 || matchers("/console/homePageMRCount", request)
                 || matchers("/console/qcCheckStatistics", request)
+                || matchers("/console/reHos31DaysPage", request)
                 || matchers("/consoleByDept/entryCountGroupByCaseAndDept", request)
                 || matchers("/consoleByDept/entryCountGroupByCaseAndDeptPage", request)
                 || matchers("/consoleByDept/entryCountGroupByEntryAndDept", request)

+ 42 - 0
src/main/java/com/diagbot/dto/ReBeHosDTO.java

@@ -0,0 +1,42 @@
+package com.diagbot.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/7/16 13:43
+ */
+@Getter
+@Setter
+public class ReBeHosDTO {
+    /**
+     * 病案号
+     */
+    private String fileCode;
+    /**
+     * 病人姓名
+     */
+    private String name;
+    /**
+     * 性别
+     */
+    private String sex;
+    /**
+     * 主诊断
+     */
+    private String diagnose;
+    /**
+     * 间隔天数
+     */
+    private Integer diffDay;
+    /**
+     * 比较病历组
+     */
+    private List<ReBeHosDetailDTO> details;
+}

+ 48 - 0
src/main/java/com/diagbot/dto/ReBeHosDetailDTO.java

@@ -0,0 +1,48 @@
+package com.diagbot.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/7/16 15:17
+ */
+@Getter
+@Setter
+public class ReBeHosDetailDTO {
+    /**
+     * 病人住院号
+     */
+    private String behospitalCode;
+    /**
+     * 病历等级
+     */
+    private String level;
+    /**
+     * 病历得分
+     */
+    private Double scoreRes;
+    /**
+     * 科室编码
+     */
+    private String behDeptId;
+    /**
+     * 科室
+     */
+    private String behDeptName;
+
+    /**
+     * 出院日期
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    private Date leaveHospitalDate;
+    /**
+     * 入院日期
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    private Date behospitalDate;
+}

+ 40 - 0
src/main/java/com/diagbot/dto/ReBeHosMergeDTO.java

@@ -0,0 +1,40 @@
+package com.diagbot.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/7/16 14:49
+ */
+@Getter
+@Setter
+public class ReBeHosMergeDTO {
+    private String fileCode;
+    private String diagnose;
+    private String name;
+    private String sex;
+    private String behDeptId;
+    private String behDeptName;
+    private String behospitalCode;
+    private Double scoreRes;
+    private String level;
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    private Date behospitalDate;
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    private Date leaveHospitalDate;
+    private String lastBehDeptId;
+    private String lastBehDeptName;
+    private String lastBehospitalCode;
+    private Double lastScoreRes;
+    private String lastLevel;
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    private Date lastBehospitalDate;
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    private Date lastLeaveHospitalDate;
+    private Integer diffDays;
+}

+ 44 - 0
src/main/java/com/diagbot/facade/ConsoleFacade.java

@@ -1,6 +1,7 @@
 package com.diagbot.facade;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.diagbot.aggregate.AverageStatisticsAggregate;
 import com.diagbot.aggregate.MrStatisticsAggregate;
 import com.diagbot.aggregate.ResultStatisticsAggregate;
@@ -17,8 +18,12 @@ import com.diagbot.dto.LevelStatisticsTZDTO;
 import com.diagbot.dto.NumDTO;
 import com.diagbot.dto.QcResultPercentDTO;
 import com.diagbot.dto.QcResultShortDTO;
+import com.diagbot.dto.ReBeHosDTO;
+import com.diagbot.dto.ReBeHosDetailDTO;
+import com.diagbot.dto.ReBeHosMergeDTO;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
+import com.diagbot.util.BeanUtil;
 import com.diagbot.util.ListUtil;
 import com.diagbot.util.StringUtil;
 import com.diagbot.vo.EntryStatisticsVO;
@@ -27,6 +32,7 @@ import com.diagbot.vo.FilterPageByAverageVO;
 import com.diagbot.vo.FilterPageVO;
 import com.diagbot.vo.FilterVO;
 import com.diagbot.vo.QcResultShortPageVO;
+import com.diagbot.vo.ReBeHosPageVO;
 import com.google.common.collect.Lists;
 import io.github.lvyahui8.spring.aggregate.facade.DataBeanAggregateQueryFacade;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -961,4 +967,42 @@ public class ConsoleFacade {
         item.setImproveToFullPercentStr(improveToFullPercentStr);
         return item;
     }
+
+    /**
+     * 31天再入院详情页
+     *
+     * @param reBeHosPageVO
+     * @return
+     */
+    public IPage<ReBeHosDTO> reHos31DaysPage(ReBeHosPageVO reBeHosPageVO) {
+        filterFacade.reBeHosPageVOSet(reBeHosPageVO);
+        IPage<ReBeHosMergeDTO> page = behospitalInfoFacade.reHos31DaysPage(reBeHosPageVO);
+        List<ReBeHosMergeDTO> records = page.getRecords();
+        IPage<ReBeHosDTO> retPage = new Page<>();
+        BeanUtil.copyProperties(page, retPage);
+        List<ReBeHosDTO> retRecords = Lists.newLinkedList();
+        if (ListUtil.isNotEmpty(records)) {
+            for (ReBeHosMergeDTO record : records) {
+                ReBeHosDTO retRecord = new ReBeHosDTO();
+                BeanUtil.copyProperties(record, retRecord);
+                List<ReBeHosDetailDTO> details = Lists.newLinkedList();
+                ReBeHosDetailDTO detailRecord = new ReBeHosDetailDTO();
+                BeanUtil.copyProperties(record, detailRecord);
+                details.add(detailRecord);
+                ReBeHosDetailDTO lastDetailRecord = new ReBeHosDetailDTO();
+                lastDetailRecord.setBehDeptId(record.getLastBehDeptId());
+                lastDetailRecord.setBehDeptName(record.getBehDeptName());
+                lastDetailRecord.setBehospitalCode(record.getLastBehospitalCode());
+                lastDetailRecord.setBehospitalDate(record.getLastBehospitalDate());
+                lastDetailRecord.setLeaveHospitalDate(record.getLastLeaveHospitalDate());
+                lastDetailRecord.setLevel(record.getLastLevel());
+                lastDetailRecord.setScoreRes(record.getLastScoreRes());
+                details.add(lastDetailRecord);
+                retRecord.setDetails(details);
+                retRecords.add(retRecord);
+            }
+        }
+        retPage.setRecords(retRecords);
+        return retPage;
+    }
 }

+ 13 - 0
src/main/java/com/diagbot/facade/FilterFacade.java

@@ -12,6 +12,7 @@ import com.diagbot.vo.FilterPageByDeptVO;
 import com.diagbot.vo.FilterPageVO;
 import com.diagbot.vo.FilterVO;
 import com.diagbot.vo.QcResultShortPageVO;
+import com.diagbot.vo.ReBeHosPageVO;
 import org.springframework.stereotype.Component;
 
 import java.util.Date;
@@ -265,4 +266,16 @@ public class FilterFacade {
         /*long interval = entryStatisticsVO.getEndDate().getTime() + 1000;
         entryStatisticsVO.setEndDate(new Date(Long.valueOf(interval)));*/
     }
+
+    /**
+     * 31天再入院参数拼接
+     *
+     * @param reBeHosPageVO
+     */
+    public void reBeHosPageVOSet(ReBeHosPageVO reBeHosPageVO) {
+        String hospitalId = SysUserUtils.getCurrentHospitalID();
+        String userId = SysUserUtils.getCurrentPrincipleID();
+        reBeHosPageVO.setHospitalId(hospitalId);
+        reBeHosPageVO.setUserId(Long.valueOf(userId));
+    }
 }

+ 10 - 0
src/main/java/com/diagbot/mapper/BehospitalInfoMapper.java

@@ -13,6 +13,7 @@ import com.diagbot.dto.LevelStatisticsTZDTO;
 import com.diagbot.dto.MsgDTO;
 import com.diagbot.dto.NumDTO;
 import com.diagbot.dto.QcResultShortDTO;
+import com.diagbot.dto.ReBeHosMergeDTO;
 import com.diagbot.entity.BehospitalInfo;
 import com.diagbot.vo.AnalyzeCodeVO;
 import com.diagbot.vo.AnalyzeVO;
@@ -25,6 +26,7 @@ import com.diagbot.vo.FilterPageByDeptVO;
 import com.diagbot.vo.FilterPageVO;
 import com.diagbot.vo.FilterVO;
 import com.diagbot.vo.QcResultShortPageVO;
+import com.diagbot.vo.ReBeHosPageVO;
 import com.diagbot.vo.TaskVO;
 import org.apache.ibatis.annotations.Param;
 
@@ -327,4 +329,12 @@ public interface BehospitalInfoMapper extends BaseMapper<BehospitalInfo> {
      * @return
      */
     public List<ExportExcelDTO> qcResultShortPageExport(@Param("qcResultShortPageVO") QcResultShortPageVO qcResultShortPageVO);
+
+    /**
+     * 31天再入院详情页
+     *
+     * @param reBeHosPageVO
+     * @return
+     */
+    public IPage<ReBeHosMergeDTO> reHos31DaysPage(@Param("reBeHosPageVO") ReBeHosPageVO reBeHosPageVO);
 }

+ 10 - 0
src/main/java/com/diagbot/service/BehospitalInfoService.java

@@ -13,6 +13,7 @@ import com.diagbot.dto.LevelStatisticsTZDTO;
 import com.diagbot.dto.MsgDTO;
 import com.diagbot.dto.NumDTO;
 import com.diagbot.dto.QcResultShortDTO;
+import com.diagbot.dto.ReBeHosMergeDTO;
 import com.diagbot.entity.BehospitalInfo;
 import com.diagbot.vo.AnalyzeCodeVO;
 import com.diagbot.vo.AnalyzeVO;
@@ -25,6 +26,7 @@ import com.diagbot.vo.FilterPageByDeptVO;
 import com.diagbot.vo.FilterPageVO;
 import com.diagbot.vo.FilterVO;
 import com.diagbot.vo.QcResultShortPageVO;
+import com.diagbot.vo.ReBeHosPageVO;
 import com.diagbot.vo.TaskVO;
 import org.apache.ibatis.annotations.Param;
 
@@ -320,4 +322,12 @@ public interface BehospitalInfoService extends IService<BehospitalInfo> {
      * @return
      */
     public List<ExportExcelDTO> qcResultShortPageExport(@Param("qcResultShortPageVO") QcResultShortPageVO qcResultShortPageVO);
+
+    /**
+     * 31天再入院详情页
+     *
+     * @param reBeHosPageVO
+     * @return
+     */
+    public IPage<ReBeHosMergeDTO> reHos31DaysPage(@Param("reBeHosPageVO") ReBeHosPageVO reBeHosPageVO);
 }

+ 13 - 0
src/main/java/com/diagbot/service/impl/BehospitalInfoServiceImpl.java

@@ -13,6 +13,7 @@ import com.diagbot.dto.LevelStatisticsTZDTO;
 import com.diagbot.dto.MsgDTO;
 import com.diagbot.dto.NumDTO;
 import com.diagbot.dto.QcResultShortDTO;
+import com.diagbot.dto.ReBeHosMergeDTO;
 import com.diagbot.entity.BehospitalInfo;
 import com.diagbot.mapper.BehospitalInfoMapper;
 import com.diagbot.service.BehospitalInfoService;
@@ -27,6 +28,7 @@ import com.diagbot.vo.FilterPageByDeptVO;
 import com.diagbot.vo.FilterPageVO;
 import com.diagbot.vo.FilterVO;
 import com.diagbot.vo.QcResultShortPageVO;
+import com.diagbot.vo.ReBeHosPageVO;
 import com.diagbot.vo.TaskVO;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Service;
@@ -436,4 +438,15 @@ public class BehospitalInfoServiceImpl extends ServiceImpl<BehospitalInfoMapper,
     public List<ExportExcelDTO> qcResultShortPageExport(@Param("qcResultShortPageVO") QcResultShortPageVO qcResultShortPageVO) {
         return baseMapper.qcResultShortPageExport(qcResultShortPageVO);
     }
+
+    /**
+     * 31天再入院详情页
+     *
+     * @param reBeHosPageVO
+     * @return
+     */
+    @Override
+    public IPage<ReBeHosMergeDTO> reHos31DaysPage(@Param("reBeHosPageVO") ReBeHosPageVO reBeHosPageVO) {
+        return baseMapper.reHos31DaysPage(reBeHosPageVO);
+    }
 }

+ 35 - 0
src/main/java/com/diagbot/vo/ReBeHosPageVO.java

@@ -0,0 +1,35 @@
+package com.diagbot.vo;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotNull;
+import java.util.Date;
+
+/**
+ * @Description:
+ * @Author:zhaops
+ * @time: 2020/7/16 13:29
+ */
+@Getter
+@Setter
+public class ReBeHosPageVO extends Page {
+    @ApiModelProperty(hidden = true)
+    private Long userId;
+    @ApiModelProperty(hidden = true)
+    private String hospitalId;
+    @NotNull(message = "请输入起始时间")
+    private Date startDate;
+    @NotNull(message = "请输入截止时间")
+    private Date endDate;
+    /**
+     * 病案号
+     */
+    private String fileCode;
+    /**
+     * 病人姓名
+     */
+    private String name;
+}

+ 19 - 0
src/main/java/com/diagbot/web/ConsoleController.java

@@ -14,6 +14,7 @@ import com.diagbot.dto.LevelStatisticsDTO;
 import com.diagbot.dto.LevelStatisticsTZDTO;
 import com.diagbot.dto.NumDTO;
 import com.diagbot.dto.QcResultShortDTO;
+import com.diagbot.dto.ReBeHosDTO;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.facade.ConsoleFacade;
 import com.diagbot.vo.EntryStatisticsVO;
@@ -22,6 +23,7 @@ import com.diagbot.vo.FilterPageByAverageVO;
 import com.diagbot.vo.FilterPageVO;
 import com.diagbot.vo.FilterVO;
 import com.diagbot.vo.QcResultShortPageVO;
+import com.diagbot.vo.ReBeHosPageVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -548,4 +550,21 @@ public class ConsoleController {
     public RespDTO<List<HomePageImproveDTO>> qcCheckStatistics(@RequestBody @Valid FilterOrderVO filterOrderVO) {
         return RespDTO.onSuc(consoleFacade.qcCheckStatistics(filterOrderVO));
     }
+
+    /**
+     * 31天再入院人数(内页)
+     *
+     * @param reBeHosPageVO
+     * @return
+     */
+    @ApiOperation(value = "31天再入院人数(内页)[by:zhaops]",
+            notes = "name: 病人名称 <br>" +
+                    "fileCode: 病案号 <br>" +
+                    "startDate: 起始时间 <br>" +
+                    "endDate: 截止时间 <br>")
+    @PostMapping("/reHos31DaysPage")
+    @SysLogger("reHos31DaysPage")
+    public RespDTO<IPage<ReBeHosDTO>> reHos31DaysPage(@RequestBody @Valid ReBeHosPageVO reBeHosPageVO) {
+        return RespDTO.onSuc(consoleFacade.reHos31DaysPage(reBeHosPageVO));
+    }
 }

+ 258 - 1
src/main/resources/mapper/BehospitalInfoMapper.xml

@@ -3529,7 +3529,7 @@
         r2.behospital_code AS lastBehospitalCode,
         r2.behospital_date AS lastBehospitalDate,
         r2.leave_hospital_date AS lastLeaveHospitalDate,
-        TIMESTAMPDIFF( DAY, DATE( r2.leave_hospital_date ), DATE( r1.behospital_date ) ) AS diffDay
+        TIMESTAMPDIFF( DAY, DATE( r2.leave_hospital_date ), DATE( r1.behospital_date ) ) AS diffDays
         FROM
         (
         SELECT
@@ -5088,4 +5088,261 @@
         f1.behDeptId = f2.behDeptId
         AND f1.behDeptName = f2.behDeptName
     </select>
+
+    <!-- 31天再入院详情页-->
+    <select id="reHos31DaysPage" resultType="com.diagbot.dto.ReBeHosMergeDTO">
+        SELECT
+        t.fileCode,
+        t.diagnose,
+        t.NAME,
+        t.sex,
+        t.hospitalId,
+        t.behDeptId,
+        t.behDeptName,
+        t.behospitalCode,
+        t.behospitalDate,
+        t.leaveHospitalDate,
+        t.lastBehDeptId,
+        t.lastBehDeptName,
+        t.lastBehospitalCode,
+        t.lastBehospitalDate,
+        t.lastLeaveHospitalDate,
+        t.diffDays,
+        mqi.score_res AS scoreRes,
+        mqi.LEVEL AS LEVEL,
+        mqi_last.score_res AS lastScoreRes,
+        mqi_last.LEVEL AS lastLevel
+        FROM
+        (
+        SELECT
+        be.fileCode,
+        be.diagnose,
+        be.NAME,
+        be.sex,
+        be.hospitalId,
+        be.behDeptId,
+        be.behDeptName,
+        be.behospitalCode,
+        be.behospitalDate,
+        be.leaveHospitalDate,
+        be.lastBehDeptId,
+        be.lastBehDeptName,
+        be.lastBehospitalCode,
+        be.lastBehospitalDate,
+        be.lastLeaveHospitalDate,
+        be.diffDays
+        FROM
+        (
+        SELECT
+        r1.file_code AS fileCode,
+        r1.diagnose,
+        r1.NAME,
+        r1.sex,
+        r1.hospital_id AS hospitalId,
+        r1.beh_dept_id AS behDeptId,
+        r1.beh_dept_name AS behDeptName,
+        r1.behospital_code AS behospitalCode,
+        r1.behospital_date AS behospitalDate,
+        r1.leave_hospital_date AS leaveHospitalDate,
+        r2.beh_dept_id AS lastBehDeptId,
+        r2.beh_dept_name AS lastBehDeptName,
+        r2.behospital_code AS lastBehospitalCode,
+        r2.behospital_date AS lastBehospitalDate,
+        r2.leave_hospital_date AS lastLeaveHospitalDate,
+        TIMESTAMPDIFF( DAY, DATE( r2.leave_hospital_date ), DATE( r1.behospital_date ) ) AS diffDays
+        FROM
+        (
+        SELECT
+        ( @rownum := @rownum + 1 ) AS rownum,
+        t1.file_code,
+        t1.diagnose,
+        t1.NAME,
+        t1.sex,
+        t1.hospital_id,
+        t1.beh_dept_id,
+        t1.beh_dept_name,
+        t1.behospital_code,
+        t1.behospital_date,
+        t1.leave_hospital_date
+        FROM
+        (
+        SELECT
+        tt1.file_code,
+        tt1.diagnose,
+        tt2.NAME,
+        tt2.sex,
+        tt2.hospital_id,
+        tt2.beh_dept_id,
+        tt2.beh_dept_name,
+        tt2.behospital_code,
+        tt2.behospital_date,
+        tt2.leave_hospital_date
+        FROM
+        (
+        SELECT
+        a.file_code,
+        a.diagnose
+        FROM
+        med_behospital_info a
+        WHERE
+        a.is_deleted = 'N'
+        AND a.is_placefile = 1
+        AND a.qc_type_id != 0
+        AND IFNULL( a.diagnose, '' )!= ''
+        AND IFNULL( a.file_code, '' )!= ''
+        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
+            AND a.hospital_id = #{reBeHosPageVO.hospitalId}
+        </if>
+        <if test="reBeHosPageVO.startDate != null">
+            <![CDATA[ AND a.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
+        </if>
+        <if test="reBeHosPageVO.endDate != null">
+            <![CDATA[ AND a.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
+        </if>
+        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
+            AND a.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
+        </if>
+        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
+            AND a.name like concat('%', #{reBeHosPageVO.name},'%')
+        </if>
+        GROUP BY
+        a.file_code,
+        a.diagnose
+        HAVING
+        count(*)> 1
+        ) tt1,
+        med_behospital_info tt2
+        WHERE
+        tt2.is_deleted = 'N'
+        AND tt2.is_placefile = 1
+        AND tt2.qc_type_id != 0
+        AND tt1.file_code = tt2.file_code
+        AND tt1.diagnose = tt2.diagnose
+        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
+            AND tt2.hospital_id = #{reBeHosPageVO.hospitalId}
+        </if>
+        <if test="reBeHosPageVO.startDate != null">
+            <![CDATA[ AND tt2.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
+        </if>
+        <if test="reBeHosPageVO.endDate != null">
+            <![CDATA[ AND tt2.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
+        </if>
+        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
+            AND tt2.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
+        </if>
+        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
+            AND tt2.name like concat('%', #{reBeHosPageVO.name},'%')
+        </if>
+        ORDER BY
+        tt1.file_code,
+        tt1.diagnose,
+        tt2.behospital_date DESC
+        ) t1,
+        ( SELECT @rownum := 0 ) r
+        ) r1
+        LEFT JOIN (
+        SELECT
+        ( @INDEX := @INDEX + 1 ) AS rownum,
+        t1.file_code,
+        t1.diagnose,
+        t1.NAME,
+        t1.sex,
+        t1.hospital_id,
+        t1.beh_dept_id,
+        t1.beh_dept_name,
+        t1.behospital_code,
+        t1.behospital_date,
+        t1.leave_hospital_date
+        FROM
+        (
+        SELECT
+        tt1.file_code,
+        tt1.diagnose,
+        tt2.NAME,
+        tt2.sex,
+        tt2.hospital_id,
+        tt2.beh_dept_id,
+        tt2.beh_dept_name,
+        tt2.behospital_code,
+        tt2.behospital_date,
+        tt2.leave_hospital_date
+        FROM
+        (
+        SELECT
+        a.file_code,
+        a.diagnose
+        FROM
+        med_behospital_info a
+        WHERE
+        a.is_deleted = 'N'
+        AND a.is_placefile = 1
+        AND a.qc_type_id != 0
+        AND IFNULL( a.diagnose, '' )!= ''
+        AND IFNULL( a.file_code, '' )!= ''
+        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
+            AND a.hospital_id = #{reBeHosPageVO.hospitalId}
+        </if>
+        <if test="reBeHosPageVO.startDate != null ">
+            <![CDATA[ AND a.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
+        </if>
+        <if test="reBeHosPageVO.endDate != null ">
+            <![CDATA[ AND a.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
+        </if>
+        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
+            AND a.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
+        </if>
+        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
+            AND a.name like concat('%', #{reBeHosPageVO.name},'%')
+        </if>
+        GROUP BY
+        a.file_code,
+        a.diagnose
+        HAVING
+        count(*)> 1
+        ) tt1,
+        med_behospital_info tt2
+        WHERE
+        tt2.is_deleted = 'N'
+        AND tt2.is_placefile = 1
+        AND tt2.qc_type_id != 0
+        AND tt1.file_code = tt2.file_code
+        AND tt1.diagnose = tt2.diagnose
+        <if test="reBeHosPageVO.hospitalId != null and reBeHosPageVO.hospitalId != ''">
+            AND tt2.hospital_id = #{reBeHosPageVO.hospitalId}
+        </if>
+        <if test="reBeHosPageVO.startDate != null ">
+            <![CDATA[ AND tt2.leave_hospital_date >= #{reBeHosPageVO.startDate}]]>
+        </if>
+        <if test="reBeHosPageVO.endDate != null ">
+            <![CDATA[ AND tt2.leave_hospital_date <= #{reBeHosPageVO.endDate}]]>
+        </if>
+        <if test="reBeHosPageVO.fileCode != null and reBeHosPageVO.fileCode != ''">
+            AND tt2.file_code like concat('%', #{reBeHosPageVO.fileCode},'%')
+        </if>
+        <if test="reBeHosPageVO.name != null and reBeHosPageVO.name != ''">
+            AND tt2.name like concat('%', #{reBeHosPageVO.name},'%')
+        </if>
+        ORDER BY
+        tt1.file_code,
+        tt1.diagnose,
+        tt2.behospital_date DESC
+        ) t1,(
+        SELECT
+        @INDEX := 0
+        ) r
+        ) r2 ON r1.file_code = r2.file_code
+        AND r1.rownum = r2.rownum - 1
+        ) be
+        WHERE
+        be.diffDays IS NOT NULL
+        AND be.diffDays BETWEEN 0
+        AND 31
+        ) t
+        LEFT JOIN med_qcresult_info mqi ON mqi.is_deleted = 'N'
+        AND t.hospitalId = mqi.hospital_id
+        AND t.behospitalCode = mqi.behospital_code
+        LEFT JOIN med_qcresult_info mqi_last ON mqi_last.is_deleted = 'N'
+        AND t.hospitalId = mqi_last.hospital_id
+        AND t.lastBehospitalCode = mqi_last.behospital_code
+    </select>
 </mapper>