<?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="cn.iocoder.yudao.module.system.dal.mysql.biz.ElderlyMedicalRecordMapper">
    <select id="queryPage" resultType="cn.iocoder.yudao.module.system.dal.dataobject.biz.ElderlyMedicalRecordDO">
        SELECT mr.*,ei.elder_name as 'elder.elderName',ei.elder_sex as 'elder.elderSex',ei.bed_name as
        'elder.bedName',ei.room_name as 'elder.roomName',
        ei.floor_name as 'elder.floorName',ei.build_name as 'elder.buildName'
        FROM elderly_medical_record mr LEFT JOIN elderly_info ei ON ei.id = mr.elder_id
        where 1 = 1
        <if test="null != params.elderName and '' != params.elderName">
            and ei.elder_name like concat('%',#{params.elderName} ,'%')
        </if>
        <if test="null != params.bedName and params.bedName != ''">
            and ei.bed_name like concat('%',#{params.bedName} ,'%') or ei.room_name like concat('%',#{params.bedName}
            ,'%')
        </if>
        <if test="params.createTime != null">
            and mr.create_date between #{params.createTime[0]} and #{params.createTime[1]}
        </if>
        <if test="params.healthGuidance != null and params.healthGuidance != '' ">
            and mr.health_guidance = #{params.healthGuidance}
        </if>
        <if test="params.orgType != null">
            and ei.org_type = #{params.orgType}
        </if>
        <if test="params.tenantIds != null">
            and ei.tenant_id in
            <foreach item="id" collection="params.tenantIds" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        order by mr.create_date desc
    </select>
</mapper>
