Files
intc-cloud/intc-modules/intc-health/src/main/resources/mapper/health/StatisticAnalysisMapper.xml
2026-06-20 22:06:25 +08:00

1092 lines
42 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.intc.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
inner join health_person hp on
hp.id = hmr.person_id and hp.del_flag = '0'
left join health_record hr on
hr.id = hmr.health_record_id
<where>
hmr.del_flag = '0'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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="selectStaticPersonList" parameterType="HealthRecordDto" resultType="com.intc.health.domain.vo.HealthStaticPersonVo">
select
hp."name" as personName,
coalesce(hr.healthRecordCount, 0) as healthRecordCount,
coalesce(hdr.hospitalCount, 0) as hospitalCount,
coalesce(hdr.doctorTotalCount, 0) as doctorTotalCount,
coalesce(hdr.doctorCount, 0) as doctorCount,
coalesce(hdr.doctorCost, 0) as doctorCost,
coalesce(hmr.marDayCount, 0) as marDayCount,
coalesce(hmr.marCount, 0) as marCount,
coalesce(hmr.marTypeCount, 0) as marTypeCount,
coalesce(htr.feverDayCount, 0) as feverDayCount
from
health_person hp
left join (
select
person_id,
count(*) as healthRecordCount
from health_record
where del_flag = '0'
group by person_id
) hr on hr.person_id = hp.id
left join (
select
person_id,
count(distinct hospital_name) as hospitalCount,
count(distinct doctor) as doctorTotalCount,
count(*) as doctorCount,
coalesce(sum(total_cost), 0) as doctorCost
from health_doctor_record
where del_flag = '0'
group by person_id
) hdr on hdr.person_id = hp.id
left join (
select
person_id,
count(distinct to_char(dosing_time, 'yyyy-MM-dd')) as marDayCount,
count(*) as marCount,
count(distinct medicine_id) as marTypeCount
from health_mar_record
where del_flag = '0'
group by person_id
) hmr on hmr.person_id = hp.id
left join (
select
person_id,
count(distinct to_char(measure_time, 'yyyy-MM-dd')) as feverDayCount
from health_temperature_record
where del_flag = '0'
and temperature >= 37
group by person_id
) htr on htr.person_id = hp.id
where hp.del_flag = '0'
<if test="personId != null "> and hp.id = #{personId}</if>
<!-- 数据范围过滤 -->
${params.dataScope}
order by hp.ranking
</select>
<select id="selectHealthScreenDoctorSummary" parameterType="HealthDoctorRecordDto" resultType="java.util.HashMap">
select
count(*) as "doctorCount",
coalesce(sum(a.total_cost), 0) as "doctorCost",
count(distinct a.hospital_name) as "hospitalCount",
count(distinct a.doctor) as "doctorTotalCount"
from health_doctor_record a
inner join health_person hp on hp.id = a.person_id and hp.del_flag = '0'
<where>
a.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and a.visiting_time &lt;= to_date(#{endTime}, 'yyyy-MM-dd') + interval '1 day' - interval '1 second'
</if>
<if test="startTime!=null and startTime !=''">
and a.visiting_time &gt;= to_date(#{startTime}, 'yyyy-MM-dd')
</if>
<if test="healthRecordId != null"> and a.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and a.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectHealthScreenPersonRankList" parameterType="HealthRecordDto" resultType="com.intc.health.domain.vo.HealthStaticPersonVo">
select
hp."name" as personName,
coalesce(hr.healthRecordCount, 0) as healthRecordCount,
coalesce(hdr.hospitalCount, 0) as hospitalCount,
coalesce(hdr.doctorTotalCount, 0) as doctorTotalCount,
coalesce(hdr.doctorCount, 0) as doctorCount,
coalesce(hdr.doctorCost, 0) as doctorCost,
coalesce(hmr.marDayCount, 0) as marDayCount,
coalesce(hmr.marCount, 0) as marCount,
coalesce(hmr.marTypeCount, 0) as marTypeCount,
coalesce(htr.feverDayCount, 0) as feverDayCount
from health_person hp
left join (
select person_id, count(*) as healthRecordCount
from health_record
where del_flag = '0'
group by person_id
) hr on hr.person_id = hp.id
left join (
select
person_id,
count(distinct hospital_name) as hospitalCount,
count(distinct doctor) as doctorTotalCount,
count(*) as doctorCount,
coalesce(sum(total_cost), 0) as doctorCost
from health_doctor_record
where del_flag = '0'
group by person_id
) hdr on hdr.person_id = hp.id
left join (
select
person_id,
count(distinct to_char(dosing_time, 'yyyy-MM-dd')) as marDayCount,
count(*) as marCount,
count(distinct medicine_id) as marTypeCount
from health_mar_record
where del_flag = '0'
group by person_id
) hmr on hmr.person_id = hp.id
left join (
select
person_id,
count(distinct to_char(measure_time, 'yyyy-MM-dd')) as feverDayCount
from health_temperature_record
where del_flag = '0'
and temperature >= 37
group by person_id
) htr on htr.person_id = hp.id
where hp.del_flag = '0'
<if test="personId != null "> and hp.id = #{personId}</if>
<!-- 数据范围过滤 -->
${params.dataScope}
order by
(
least(round(coalesce(htr.feverDayCount, 0) * 1.2), 35)
+ least(round(coalesce(hdr.doctorCount, 0) * 2.5), 30)
+ least(round(coalesce(hmr.marCount, 0) * 0.15), 12)
+ least(coalesce(hr.healthRecordCount, 0) * 2, 10)
+ least(round(coalesce(hdr.doctorCost, 0) / 1000), 13)
) desc,
hp.ranking
limit 12
</select>
<select id="selectHealthScreenMedicineSummary" parameterType="HealthMarRecordDto" resultType="java.util.HashMap">
select
count(*) as "marCount",
count(distinct a.medicine_id) as "medicalTypeCount",
count(distinct to_char(a.dosing_time, 'yyyy-MM-dd')) as "marDayCount"
from health_mar_record a
inner join health_person hp on hp.id = a.person_id and hp.del_flag = '0'
<where>
a.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and a.dosing_time &lt;= to_date(#{endTime}, 'yyyy-MM-dd') + interval '1 day' - interval '1 second'
</if>
<if test="startTime!=null and startTime !=''">
and a.dosing_time &gt;= to_date(#{startTime}, 'yyyy-MM-dd')
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and a.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and a.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectHealthScreenTemperatureSummary" parameterType="HealthTemperatureRecordDto" resultType="java.util.HashMap">
select
count(*) as "temperatureTotalCount",
count(case when a.temperature &lt; 36.9 then 1 end) as "normalTempCount",
count(case when a.temperature &gt;= 36.9 and a.temperature &lt;= 37.5 then 1 end) as "lowerTempCount",
count(case when a.temperature &gt; 37.5 and a.temperature &lt; 38.5 then 1 end) as "middleTempCount",
count(case when a.temperature &gt;= 38.5 then 1 end) as "higherTempCount",
count(distinct case when a.temperature &gt;= 37 then to_char(a.measure_time, 'yyyy-MM-dd') end) as "feverDayCount"
from health_temperature_record a
inner join health_person hp on hp.id = a.person_id and hp.del_flag = '0'
<where>
a.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and a.measure_time &lt;= to_date(#{endTime}, 'yyyy-MM-dd') + interval '1 day' - interval '1 second'
</if>
<if test="startTime!=null and startTime !=''">
and a.measure_time &gt;= to_date(#{startTime}, 'yyyy-MM-dd')
</if>
<if test="healthRecordId != null "> and a.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and a.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectHealthScreenActivitySummary" parameterType="HealthActivityDto" resultType="java.util.HashMap">
select
count(*) as "activityCount",
coalesce(sum(a.total_cost), 0) as "activityCost"
from health_activity a
<where>
a.del_flag = '0'
<if test="endTime != null "> and a.start_time &lt;= #{endTime}</if>
<if test="startTime != null "> and a.start_time &gt;= #{startTime}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
</select>
<select id="selectHealthScreenActivityList" parameterType="HealthActivityDto" resultType="com.intc.health.domain.vo.HealthActivityVo">
select
a.id,
a.name,
a.type,
a.place,
a.activity_volume as activityVolume,
a.exercise_time as exerciseTime,
a.start_time as startTime,
a.end_time as endTime,
a.harvest,
a.foods,
a.total_cost as totalCost,
a.partner,
a.cost_detail as costDetail
from health_activity a
<where>
a.del_flag = '0'
<if test="endTime != null "> and a.start_time &lt;= #{endTime}</if>
<if test="startTime != null "> and a.start_time &gt;= #{startTime}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
order by a.start_time desc
limit 50
</select>
<select id="selectHealthScreenDoctorList" parameterType="HealthDoctorRecordDto" resultType="com.intc.health.domain.vo.HealthDoctorRecordVo">
select
a.id,
a.hospital_name as hospitalName,
a.departments,
a.doctor,
a.type,
a.health_record_id as healthRecordId,
a.visiting_time as visitingTime,
a.prescribe,
a.diagnosis,
a.person_id as personId,
a.total_cost as totalCost,
hp."name" as personName,
hr."name" as healthRecordName
from health_doctor_record a
inner join health_person hp on hp.id = a.person_id and hp.del_flag = '0'
left join health_record hr on hr.id = a.health_record_id
<where>
a.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and a.visiting_time &lt;= to_date(#{endTime}, 'yyyy-MM-dd') + interval '1 day' - interval '1 second'
</if>
<if test="startTime!=null and startTime !=''">
and a.visiting_time &gt;= to_date(#{startTime}, 'yyyy-MM-dd')
</if>
<if test="healthRecordId != null"> and a.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and a.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
order by a.visiting_time desc
limit 50
</select>
<select id="selectHealthScreenMedicineList" parameterType="HealthMarRecordDto" resultType="com.intc.health.domain.vo.HealthMarRecordVo">
select
a.id,
a.type,
a.health_record_id as healthRecordId,
a.dosing_time as dosingTime,
a.dosage,
a.person_id as personId,
a.resource,
a.place,
a.medicine_id as medicineId,
a.unit,
a.content,
a.content_unit as contentUnit,
hp."name" as personName,
hr."name" as healthRecordName,
hmb.short_name || '-' || hmb.brand || '(' || hmb.packaging || ')' as name
from health_mar_record a
inner join health_person hp on hp.id = a.person_id and hp.del_flag = '0'
left join health_record hr on hr.id = a.health_record_id
left join health_medicine_basic hmb on hmb.id = a.medicine_id
<where>
a.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and a.dosing_time &lt;= to_date(#{endTime}, 'yyyy-MM-dd') + interval '1 day' - interval '1 second'
</if>
<if test="startTime!=null and startTime !=''">
and a.dosing_time &gt;= to_date(#{startTime}, 'yyyy-MM-dd')
</if>
<if test="healthRecordId != null and healthRecordId != ''"> and a.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and a.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
order by a.dosing_time desc
limit 50
</select>
<select id="selectHealthScreenTemperatureList" parameterType="HealthTemperatureRecordDto" resultType="com.intc.health.domain.vo.HealthTemperatureRecordVo">
select
a.id,
a.health_record_id as healthRecordId,
a.measure_time as measureTime,
a.temperature,
a.person_id as personId,
hp."name" as personName,
hr."name" as healthRecordName
from health_temperature_record a
inner join health_person hp on hp.id = a.person_id and hp.del_flag = '0'
left join health_record hr on hr.id = a.health_record_id
<where>
a.del_flag = '0'
<if test="endTime!=null and endTime !=''">
and a.measure_time &lt;= to_date(#{endTime}, 'yyyy-MM-dd') + interval '1 day' - interval '1 second'
</if>
<if test="startTime!=null and startTime !=''">
and a.measure_time &gt;= to_date(#{startTime}, 'yyyy-MM-dd')
</if>
<if test="healthRecordId != null "> and a.health_record_id = #{healthRecordId}</if>
<if test="personId != null "> and a.person_id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
order by a.measure_time desc
limit 1000
</select>
<select id="selectHealthRecordCostList" parameterType="HealthRecordDto" resultType="com.intc.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'
and exists (select 1 from health_person hp where hp.id = hr.person_id and hp.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.intc.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'
and exists (select 1 from health_person hp where hp.id = hr.person_id and hp.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.intc.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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.intc.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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.intc.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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.intc.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'
and exists (select 1 from health_person hp where hp.id = hmr.person_id and hp.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>
<select id="selectMilkPowderStatistic" parameterType="HealthMilkPowderRecordDto" resultType="com.intc.health.domain.vo.HealthMilkPowderStatisticVo">
select
hp.id as personId ,
hp.name as personName,
(
select
count(*)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and to_char(hmpr.suckles_time,
'yyyy-MM-dd') = to_char(CURRENT_DATE,
'yyyy-MM-dd')
) as todayCount,
(
select
sum(hmpr.consumption)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and to_char(hmpr.suckles_time,
'yyyy-MM-dd') = to_char(CURRENT_DATE,
'yyyy-MM-dd')
) as todayConsumption,
(
select
count(*)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '7 days'
) as sevenDayCount,
(
select
sum(hmpr.consumption)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '7 days'
) as sevenDayConsumption,
(
select
count(*)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '1 months'
) as oneMonthCount,
(
select
sum(hmpr.consumption)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '1 months'
) as oneMonthConsumption,
(
select
count(*)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '3 months'
) as threeMonthCount,
(
select
sum(hmpr.consumption)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '3 months'
) as threeMonthConsumption,
(
select
count(*)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '6 months'
) as sixMonthCount,
(
select
sum(hmpr.consumption)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '6 months'
) as sixMonthConsumption,
(
select
count(*)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '1 years'
) as oneYearCount,
(
select
sum(hmpr.consumption)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '1 years'
) as oneYearConsumption,
(
select
count(*)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '2 years'
) as twoYearCount,
(
select
sum(hmpr.consumption)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '2 years'
) as twoYearConsumption,
(
select
count(*)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '3 years'
) as threeYearCount,
(
select
sum(hmpr.consumption)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '3 years'
) as threeYearConsumption,
(
select
count(*)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '5 years'
) as fiveYearCount,
(
select
sum(hmpr.consumption)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
and hmpr.suckles_time >= CURRENT_DATE - interval '5 years'
) as fiveYearConsumption,
(
select
count(*)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
) as totalCount,
(
select
sum(hmpr.consumption)
from
health_milk_powder_record hmpr
where
hmpr.person_id = hp.id
) as totalConsumption
from
health_person hp
<where>
hp.del_flag = '0'
<if test="personId != null "> and hp.id = #{personId}</if>
</where>
<!-- 数据范围过滤 -->
${params.dataScope}
limit 1
</select>
<select id="selectMilkPowderDayStatistic" parameterType="HealthMilkPowderRecordDto" resultType="com.intc.health.domain.vo.HealthMilkPowderRecordVo">
select
to_char(hmpr.suckles_time,
'yyyy-MM-dd') as sucklesTime,
sum (hmpr.consumption) as consumption
from
health_milk_powder_record hmpr
where hmpr.del_flag ='0'
and exists (select 1 from health_person hp where hp.id = hmpr.person_id and hp.del_flag = '0')
<if test="personId != null "> and hmpr.person_id = #{personId}</if>
<if test="endTime!=null and endTime !=''">
and #{endTime}>=to_char(hmpr.suckles_time, 'yyyy-MM-dd')
</if>
<if test="startTime!=null and startTime !=''">
and to_char(hmpr.suckles_time, 'yyyy-MM-dd')>=#{startTime}
</if>
<!-- 数据范围过滤 -->
${params.dataScope}
group by
to_char(hmpr.suckles_time,
'yyyy-MM-dd')
order by
to_char(hmpr.suckles_time,
'yyyy-MM-dd') desc
</select>
</mapper>