Files
intc-cloud/ruoyi-modules/intc-health/src/main/resources/mapper/health/StatisticAnalysisMapper.xml

603 lines
22 KiB
XML

<?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.ruoyi.health.mapper.StatisticAnalysisMapper">
<resultMap type="HealthMarRecordVo" id="HealthMarRecordResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="type" column="type" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="delFlag" column="del_flag" />
<result property="remark" column="remark" />
<result property="healthRecordId" column="health_record_id" />
<result property="dosingTime" column="dosing_time" />
<result property="dosage" column="dosage" />
<result property="personId" column="person_id" />
<result property="resource" column="resource" />
<result property="place" column="place" />
<result property="medicineId" column="medicine_id" />
<result property="unit" column="unit" />
<result property="content" column="content" />
<result property="contentUnit" column="content_unit" />
<result property="personName" column="person_name" />
<result property="healthRecordName" column="health_record_name" />
<result property="useDays" column="useDays" />
<result property="count" column="count" />
<result property="dosingTimeStr" column="dosingTimeStr" />
</resultMap>
<select id="selectMarRecordList" parameterType="HealthMarRecordDto" resultMap="HealthMarRecordResult">
select
count(*) as count,
sum(hmr.dosage) as dosage,
hmr.medicine_id,
hmb."short_name"||'-'||hmb."brand"||'('||hmb.packaging||')' as name,
hmr.unit ,
hmr.person_id ,
hp."name" as person_name,
hmr.health_record_id as health_record_id,
hr."name" as health_record_name,
(
select
count(distinct to_char(t.dosing_time, 'yyyy-MM-dd'))
from
health_mar_record t
where
t.person_id = hmr.person_id
and t.health_record_id = hmr.health_record_id
and t.medicine_id = hmr.medicine_id
) as useDays
from
health_mar_record hmr
left join health_medicine_basic hmb on
hmb.id = hmr.medicine_id
left join health_person hp on
hp.id = hmr.person_id
left join health_record hr on
hr.id = hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hmr.dosing_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hmr.dosing_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hmr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
group by
hmr.medicine_id,
hmb."short_name" ,
hmr.person_id ,
hp.name ,
hmr.health_record_id,
hr."name",
hmr.unit ,
hmb."brand",
hmb.packaging
order by hmb."short_name" desc
</select>
<select id="selectHospitalCount" parameterType="HealthMarRecordDto" resultType="int">
select
count(distinct hospital_name)
from
health_doctor_record hmr
left join health_record hr on hr.id=hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hmr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectDoctorCount" parameterType="HealthMarRecordDto" resultType="int">
select
count(distinct doctor )
from
health_doctor_record hmr
left join health_record hr on hr.id=hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hmr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectDistinctMedicalCount" parameterType="HealthMarRecordDto" resultType="int">
select
count(distinct medicine_id )
from
health_mar_record hmr
left join health_record hr on hr.id=hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hmr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectMarTypeList" parameterType="HealthMarRecordDto" resultMap="HealthMarRecordResult">
select
hmr."type" ,
count(hmr."type" ) as count
from
health_mar_record hmr
left join health_record hr on hr.id=hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hmr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
group by
hmr."type"
order by count(hmr."type" ) desc
</select>
<select id="selectMarDayCountList" parameterType="HealthMarRecordDto" resultMap="HealthMarRecordResult">
select
to_char(hmr.dosing_time, 'yyyy-MM-dd') as dosingTimeStr,
count(to_char(hmr.dosing_time, 'yyyy-MM-dd')) as count
from
health_mar_record hmr
left join health_record hr on hr.id=hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hmr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
group by
to_char(hmr.dosing_time, 'yyyy-MM-dd')
order by to_char(hmr.dosing_time, 'yyyy-MM-dd')
</select>
<select id="selectMarDayCount" parameterType="HealthMarRecordDto" resultType="int">
select
count(distinct to_char(hmr.dosing_time, 'yyyy-MM-dd') )
from
health_mar_record hmr
left join health_record hr on hr.id=hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hmr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectFeverDayCount" parameterType="HealthRecordDto" resultType="int">
select
count(distinct to_char(hmr.measure_time, 'yyyy-MM-dd') )
from
health_temperature_record hmr
left join health_record hr on hr.id=hmr.health_record_id
<where>
hmr.del_flag = '0' and hmr.temperature>=37
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hmr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectStaticPersonList" parameterType="HealthRecordDto" resultType="com.ruoyi.health.domain.vo.HealthStaticPersonVo">
select
hp."name" as personName,
(
select
count(*)
from
health_record hr
where
hr.person_id = hp.id
and hr.del_flag = '0') as healthRecordCount,
(
select
count(distinct hdr.hospital_name)
from
health_doctor_record hdr
where
hdr.person_id = hp.id
and hdr.del_flag = '0') as hospitalCount,
(
select
count(distinct hdr.doctor)
from
health_doctor_record hdr
where
hdr.person_id = hp.id
and hdr.del_flag = '0') as doctorTotalCount,
(
select
count(*)
from
health_doctor_record hdr
where
hdr.person_id = hp.id
and hdr.del_flag = '0') as doctorCount,
(
select
case when sum(hdr.total_cost) is null then 0
else sum(hdr.total_cost)
end
from
health_doctor_record hdr
where
hdr.person_id = hp.id
and hdr.del_flag = '0') as doctorCost,
(
select
count(distinct to_char(hmr.dosing_time, 'yyyy-MM-dd') )
from
health_mar_record hmr
where
hmr.person_id = hp.id
and hmr.del_flag = '0') as marDayCount,
(
select
count(*)
from
health_mar_record hmr
where
hmr.person_id = hp.id
and hmr.del_flag = '0') as marCount,
(
select
count(distinct hmr."medicine_id")
from
health_mar_record hmr
where
hmr.person_id = hp.id
and hmr.del_flag = '0') as marTypeCount,
(
select
count(distinct to_char(hmr.measure_time, 'yyyy-MM-dd') )
from
health_temperature_record hmr
where
hmr.person_id = hp.id
and hmr.temperature >= 37) as feverDayCount
from
health_person hp
where 1=1
<!-- 数据范围过滤 -->
${params.dataScope}
order by hp.ranking
</select>
<select id="selectHealthRecordCostList" parameterType="HealthRecordDto" resultType="com.ruoyi.health.domain.vo.HealthRecordVo">
select
(
select
case
when sum(hdr.total_cost) is null then 0
else sum(hdr.total_cost)
end
from
health_doctor_record hdr
where
hdr.health_record_id = hr.id
and hdr.del_flag = '0') as doctorCost,
hr.id ,
hr."name",
hr.person_id
from
health_record hr
<where>
hr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hr.id = #{healthRecordId}</if>
<if test="personId != null "> and hr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
order by hr.occur_time
</select>
<select id="selectHealthRecordList" parameterType="HealthRecordDto" resultType="com.ruoyi.health.domain.vo.HealthRecordVo">
select
(
select
count(distinct hdr.hospital_name)
from
health_doctor_record hdr
where
hdr.health_record_id = hr.id
and hdr.del_flag = '0') as hospitalCount,
(
select
count(distinct hdr.doctor)
from
health_doctor_record hdr
where
hdr.health_record_id = hr.id
and hdr.del_flag = '0') as doctorTotalCount,
(
select
count(*)
from
health_doctor_record hdr
where
hdr.health_record_id = hr.id
and hdr.del_flag = '0') as doctorCount,
(
select
case
when sum(hdr.total_cost) is null then 0
else sum(hdr.total_cost)
end
from
health_doctor_record hdr
where
hdr.health_record_id = hr.id
and hdr.del_flag = '0') as doctorCost,
(
select
count(distinct to_char(hmr.dosing_time, 'yyyy-MM-dd') )
from
health_mar_record hmr
where
hmr.health_record_id = hr.id
and hmr.del_flag = '0') as marDayCount,
(
select
count(*)
from
health_mar_record hmr
where
hmr.health_record_id = hr.id
and hmr.del_flag = '0') as marCount,
(
select
count(*)
from
health_process_record hmr
where
hmr.health_record_id = hr.id
and hmr.del_flag = '0') as processCount,
(
select
count(distinct hmr."medicine_id")
from
health_mar_record hmr
where
hmr.health_record_id = hr.id
and hmr.del_flag = '0') as marTypeCount,
(
select
count(distinct to_char(hmr.measure_time, 'yyyy-MM-dd') )
from
health_temperature_record hmr
where
hmr.health_record_id = hr.id
and hmr.temperature >= 37) as feverDayCount,
hr.id ,
hr."name",
hr.occur_time as occurTime,
hr.rehabilitation_time as rehabilitationTime,
hr.person_id as personId
from
health_record hr
<where>
hr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hr.id = #{healthRecordId}</if>
<if test="personId != null "> and hr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
order by hr.occur_time desc
</select>
<select id="selectDoctorRecordList" parameterType="HealthDoctorRecordDto" resultType="com.ruoyi.health.domain.vo.HealthDoctorRecordVo">
select
hmr.id,
hmr.health_record_id as healthRecordId,
hmr.total_cost as totalCost
from
health_doctor_record hmr
left join health_record hr on
hr.id = hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hr.id = #{healthRecordId}</if>
<if test="personId != null "> and hr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectMarCount" parameterType="HealthMarRecordDto" resultType="int">
select
count(*)
from
health_mar_record hmr
left join health_record hr on hr.id=hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hmr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectProcessCount" parameterType="HealthMarRecordDto" resultType="int">
select
count(*)
from
health_process_record hmr
left join health_record hr on hr.id=hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hr.occur_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hr.occur_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hmr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectHospitalStaticList" parameterType="HealthDoctorRecordDto" resultType="com.ruoyi.health.domain.vo.HealthDoctorRecordVo">
select
count(hmr.hospital_name) as count,
hmr.hospital_name as hospitalName
from
health_doctor_record hmr
left join health_record hr on
hr.id = hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hmr.visiting_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hmr.visiting_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
group by hmr.hospital_name
order by count(hmr.hospital_name) desc
</select>
<select id="selectDoctorStaticList" parameterType="HealthDoctorRecordDto" resultType="com.ruoyi.health.domain.vo.HealthDoctorRecordVo">
select
count(hmr.doctor) as count,
hmr.doctor,
hmr.hospital_name as hospitalName
from
health_doctor_record hmr
left join health_record hr on
hr.id = hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hmr.visiting_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hmr.visiting_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
group by hmr.hospital_name,hmr.doctor
order by count(hmr.doctor) desc
</select>
<select id="selectDepartStaticList" parameterType="HealthDoctorRecordDto" resultType="com.ruoyi.health.domain.vo.HealthDoctorRecordVo">
select
count(hmr.departments) as count,
hmr.departments as departments
from
health_doctor_record hmr
left join health_record hr on
hr.id = hmr.health_record_id
<where>
hmr.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hmr.visiting_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hmr.visiting_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<if test="healthRecordId != null"> and hmr.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and hr.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
group by hmr.departments
order by count(hmr.departments) desc
</select>
</mapper>