<?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.kcim.dao.mapper.ComputePatientCostAccountMapper">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.kcim.dao.model.ComputePatientCostAccount" id="computePatientCostAccountMap">
        <result property="id" column="id"/>
        <result property="hospId" column="hosp_id"/>
        <result property="computeDate" column="compute_date"/>
        <result property="patientCostId" column="patient_cost_id"/>
        <result property="costType" column="cost_type"/>
        <result property="accountType" column="account_type"/>
        <result property="computeResult" column="compute_result"/>
        <result property="standComputeResult" column="stand_compute_result"/>
        <result property="createUser" column="create_user"/>
        <result property="createTime" column="create_time"/>
        <result property="updateUser" column="update_user"/>
        <result property="updateTime" column="update_time"/>
        <result property="deleteUser" column="delete_user"/>
        <result property="deleteTime" column="delete_time"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>

    <select id="getDiseaseCostDetailList" resultType="com.kcim.vo.DiseaseCostDetailVO">
        SELECT
            SUBSTR(c.`primary_diag_code`,1,3) as itemCode,
            c.`primary_diag_name` as itemName ,
            b.cost_type as costTypeCode,
            COUNT(1) AS serviceVolume,
            SUM( b.compute_result ) AS hospitalFullCost
        FROM
            compute_patient_cost a
                INNER JOIN compute_patient_cost_account b ON a.id = b.patient_cost_id
                AND b.del_flag = 0
                AND b.hosp_id = #{hospId,jdbcType=BIGINT}
                INNER JOIN import_patient_info c on a.visit_no=c.visit_no
                AND c.hosp_id = #{hospId,jdbcType=BIGINT}
                AND c.del_flag = 0
                AND c.compute_date = #{computeDate,jdbcType=VARCHAR}
                AND IFNULL(c.`primary_diag_code`,'')!=''
        WHERE
            a.del_flag = 0
          AND a.hosp_id = #{hospId,jdbcType=BIGINT}
          AND a.compute_date = #{computeDate,jdbcType=VARCHAR}
          <if test="diseaseFilter != null and diseaseFilter != ''">
            AND (c.`primary_diag_code` LIKE CONCAT('%', #{diseaseFilter,jdbcType=VARCHAR}, '%') 
                 OR c.`primary_diag_name` LIKE CONCAT('%', #{diseaseFilter,jdbcType=VARCHAR}, '%'))
          </if>
        GROUP BY
--             c.`primary_diag_code`,
            SUBSTR(c.`primary_diag_code`,1,3),
            b.cost_type
    </select>
    <select id="getDiseaseCostCompositionDetail" resultType="com.kcim.vo.DiseaseCostDetailVO">
        SELECT
            SUBSTR(c.`primary_diag_code`,1,3) as itemCode,
            c.`primary_diag_name` as itemName ,
            b.account_type as costTypeCode,
            COUNT(1) AS serviceVolume,
            SUM( b.compute_result ) AS hospitalFullCost
        FROM
            compute_patient_cost a
                INNER JOIN compute_patient_cost_account b ON a.id = b.patient_cost_id
                AND b.del_flag = 0
                AND b.hosp_id = #{hospId,jdbcType=BIGINT}
                INNER JOIN import_patient_info c on a.visit_no=c.visit_no
                AND c.hosp_id = #{hospId,jdbcType=BIGINT}
                AND c.del_flag = 0
                AND c.compute_date = #{computeDate,jdbcType=VARCHAR}
                AND IFNULL(c.`primary_diag_code`,'')!=''
        WHERE
            a.del_flag = 0
          AND a.hosp_id = #{hospId,jdbcType=BIGINT}
          AND a.compute_date = #{computeDate,jdbcType=VARCHAR}
          <if test="diseaseFilter != null and diseaseFilter != ''">
            AND (c.`primary_diag_code` LIKE CONCAT('%', #{diseaseFilter,jdbcType=VARCHAR}, '%') 
                 OR c.`primary_diag_name` LIKE CONCAT('%', #{diseaseFilter,jdbcType=VARCHAR}, '%'))
          </if>
        GROUP BY
--             c.`primary_diag_code`,
            SUBSTR(c.`primary_diag_code`,1,3),
            b.account_type
    </select>
    <select id="getDeptDiseaseCostCompositionDetail" resultType="com.kcim.vo.DiseaseCostDetailVO">
        SELECT
            SUBSTR(c.`primary_diag_code`,1,3) as itemCode,
            c.`primary_diag_name` as itemName ,
            a.department_code as departmentCode,
            a.department_name as departmentName,
            COUNT(1) AS serviceVolume,
            SUM( b.compute_result ) AS hospitalFullCost
        FROM
            compute_patient_cost a
                INNER JOIN compute_patient_cost_account b ON a.id = b.patient_cost_id
                AND b.del_flag = 0
                AND b.hosp_id = #{hospId,jdbcType=BIGINT}
                INNER JOIN import_patient_info c on a.visit_no=c.visit_no
                AND c.hosp_id = #{hospId,jdbcType=BIGINT}
                AND c.del_flag = 0
                AND c.compute_date = #{computeDate,jdbcType=VARCHAR}
                AND IFNULL(c.`primary_diag_code`,'')!=''
        WHERE
            a.del_flag = 0
          AND a.hosp_id = #{hospId,jdbcType=BIGINT}
          AND a.compute_date = #{computeDate,jdbcType=VARCHAR}
          <if test="diseaseFilter != null and diseaseFilter != ''">
            AND (c.`primary_diag_code` LIKE CONCAT('%', #{diseaseFilter,jdbcType=VARCHAR}, '%') 
                 OR c.`primary_diag_name` LIKE CONCAT('%', #{diseaseFilter,jdbcType=VARCHAR}, '%'))
          </if>
        GROUP BY
--             c.`primary_diag_code`,
            SUBSTR(c.`primary_diag_code`,1,3),
            a.department_code
    </select>
    <select id="getDrgCostDetailList" resultType="com.kcim.vo.DiseaseCostDetailVO">
        SELECT
            c.`group_code` as itemCode,
            c.`group_name` as itemName ,
            b.cost_type as costTypeCode,
            COUNT(1) AS serviceVolume,
            SUM( b.compute_result ) AS hospitalFullCost
        FROM
            compute_patient_cost a
                INNER JOIN compute_patient_cost_account b ON a.id = b.patient_cost_id
                AND b.del_flag = 0
                AND b.hosp_id = #{hospId,jdbcType=BIGINT}
                INNER JOIN import_patient_info c on a.visit_no=c.visit_no
                AND c.hosp_id = #{hospId,jdbcType=BIGINT}
                AND c.del_flag = 0
                AND c.compute_date = #{computeDate,jdbcType=VARCHAR}
                AND IFNULL(c.`group_code`,'')!=''
        WHERE
            a.del_flag = 0
          AND a.hosp_id = #{hospId,jdbcType=BIGINT}
          AND a.compute_date = #{computeDate,jdbcType=VARCHAR}
        GROUP BY
            c.`group_code`,
            b.cost_type
    </select>
    <select id="getDrgCostCompositionDetail" resultType="com.kcim.vo.DiseaseCostDetailVO">
        SELECT
            c.`group_code` as itemCode,
            c.`group_name` as itemName ,
            b.account_type as costTypeCode,
            COUNT(1) AS serviceVolume,
            SUM( b.compute_result ) AS hospitalFullCost
        FROM
            compute_patient_cost a
                INNER JOIN compute_patient_cost_account b ON a.id = b.patient_cost_id
                AND b.del_flag = 0
                AND b.hosp_id = #{hospId,jdbcType=BIGINT}
                INNER JOIN import_patient_info c on a.visit_no=c.visit_no
                AND c.hosp_id = #{hospId,jdbcType=BIGINT}
                AND c.del_flag = 0
                AND c.compute_date = #{computeDate,jdbcType=VARCHAR}
                AND IFNULL(c.`group_code`,'')!=''
        WHERE
            a.del_flag = 0
          AND a.hosp_id = #{hospId,jdbcType=BIGINT}
          AND a.compute_date = #{computeDate,jdbcType=VARCHAR}
        GROUP BY
            c.`group_code`,
            b.account_type
    </select>
    <select id="getDeptDrgCostCompositionDetail" resultType="com.kcim.vo.DiseaseCostDetailVO">
        SELECT
            c.`group_code` as itemCode,
            c.`group_name` as itemName ,
            a.department_code as departmentCode,
            a.department_name as departmentName,
            COUNT(1) AS serviceVolume,
            SUM( b.compute_result ) AS hospitalFullCost
        FROM
            compute_patient_cost a
                INNER JOIN compute_patient_cost_account b ON a.id = b.patient_cost_id
                AND b.del_flag = 0
                AND b.hosp_id = #{hospId,jdbcType=BIGINT}
                INNER JOIN import_patient_info c on a.visit_no=c.visit_no
                AND c.hosp_id = #{hospId,jdbcType=BIGINT}
                AND c.del_flag = 0
                AND c.compute_date = #{computeDate,jdbcType=VARCHAR}
                AND IFNULL(c.`group_code`,'')!=''
        WHERE
            a.del_flag = 0
          AND a.hosp_id = #{hospId,jdbcType=BIGINT}
          AND a.compute_date = #{computeDate,jdbcType=VARCHAR}
        GROUP BY
            c.`group_code`,
            a.department_code
    </select>
</mapper>