<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.diagbot.mapper.QcCasesMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.diagbot.entity.QcCases">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="prefix" property="prefix" />
        <result column="order_no" property="orderNo" />
        <result column="remark" property="remark" />
        <result column="is_deleted" property="isDeleted" />
        <result column="gmt_create" property="gmtCreate" />
        <result column="gmt_modified" property="gmtModified" />
        <result column="creator" property="creator" />
        <result column="modifier" property="modifier" />
    </resultMap>

    <select id="getQcCases" resultType="com.diagbot.dto.QcCasesDTO">
        SELECT
            qch.*,
            qc.`name` AS NAME,
            qc.prefix AS prefix
        FROM
            `qc_cases_hospital` qch,
            qc_cases qc
        WHERE
            qch.cases_id = qc.id
        AND qch.is_deleted = 'N'
        AND qc.is_deleted = 'N'
        <if test="hospitalId != null and hospitalId != ''">
            and qch.hospital_id = #{hospitalId}
        </if>
    </select>

    <!-- 按模块统计条目数 -->
    <select id="entryGroupByCase" resultType="com.diagbot.dto.NumDTO">
        SELECT
        a.id,
        a.NAME,
        count(*) AS num
        FROM
        qc_cases a,
        qc_cases_entry b
        WHERE
        a.is_deleted = 'N'
        AND b.is_deleted = 'N'
        AND a.id = b.cases_id
        GROUP BY
        a.id,
        a.`name`
    </select>
</mapper>
