package thyyxxk.webserver.dao.his.datamodify;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
import thyyxxk.webserver.entity.datamodify.YzTemperature;

import java.util.List;

/**
 * <p>
 * 描述
 * </p>
 *
 * @author xc
 * @date 2021-04-12 17:43
 */
@Mapper
public interface YzTemperatureDao {

    /**
     * 查询住院 护理记录单 这个很坑爹一条记录在别的地方会很多
     *
     * @param toStringRecDate 日期
     * @param toStringRecTime 时间
     * @param inpatientNo     住院号
     * @param admissTimes     住院次数
     * @return 返回指定的护理记录单
     */
    @Select("select patientName=(select rtrim(name) name from a_patient_mi where a_patient_mi.inpatient_no= yz_temperature.inpatient_no), " +
            "inpatient_no,rec_date,rec_time,temperature_1,pulse_1,breathe_1,pressure_1_am,pressure_1_pm," +
            "spo2,mind,skin,tubes_name,tubes_status,other_info,ward,admiss_times,detail_no, " +
            "userid=(select rtrim(name) name from a_employee_mi where code = userid) " +
            "from yz_temperature " +
            "where inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes} and scd_flag='0' " +
            "and rec_date=#{toStringRecDate} and rec_time=#{toStringRecTime} " +
            "order by detail_no")
    List<YzTemperature> queryDetails(@Param("toStringRecDate") String toStringRecDate,
                                     @Param("toStringRecTime") String toStringRecTime,
                                     @Param("inpatientNo") String inpatientNo,
                                     @Param("admissTimes") Integer admissTimes);

    /**
     * 获取病区
     *
     * @return 科室 code 和 名字
     */
    @Select("select code,rtrim(name) name from zy_ward_code")
    List<GetDropdownBox> getWard();

    /**
     * 更新重要的数据
     *
     * @param param 根据 住院号 住院次数 日期 时间
     *              现在能修改的字段有 体温：temperature1 脉搏：pulse1 呼吸：breathe1
     *              血压am： pressure1Am， 血压pm：pressure1Pm  spo2：spo2 意识：mind 皮肤：skin
     *              管道名称：tubesName 管道状态：tubesStatus  病区：ward
     */
    @Update("<script>" +
            "update yz_temperature set " +
            "modify_userid=#{modifyUserid},modify_time=#{modifyTime}  " +
            "<if test=\"temperature1!=null\">" +
            ",temperature_1=#{temperature1}" +
            "</if>" +
            "<if test=\"pulse1!=null\">" +
            ",pulse_1=#{pulse1}" +
            "</if>" +
            "<if test=\"breathe1!=null\">" +
            ",breathe_1=#{breathe1}" +
            "</if>" +
            "<if test=\"pressure1Am!=null\">" +
            ",pressure_1_am=#{pressure1Am}" +
            "</if>" +
            "<if test=\"pressure1Pm!=null\">" +
            ",pressure_1_pm=#{pressure1Pm}" +
            "</if>" +
            "<if test=\"spo2!=null\">" +
            ",spo2=#{spo2}" +
            "</if>" +
            "<if test=\"mind!=null\">" +
            ",mind=#{mind}" +
            "</if>" +
            "<if test=\"skin!=null\">" +
            ",skin=#{skin}" +
            "</if>" +
            "<if test=\"tubesName!=null\">" +
            ",tubes_name=#{tubesName}" +
            "</if>" +
            "<if test=\"tubesStatus!=null\">" +
            ",tubes_status=#{tubesStatus}" +
            "</if>" +
            "<if test=\"ward!=null\">" +
            ",ward=#{ward}" +
            "</if>" +
            "where " +
            "inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes} and scd_flag='0' " +
            "and rec_date=#{toStringRecDate} and rec_time=#{toStringRecTime} and detail_no=#{detailNo}" +
            "</script>")
    void teperatureHead(YzTemperature param);


    /**
     * 更新 剩下的地方 主要是更新 病室和 修改人 修改时间
     *
     * @param param        更新条件以及更新的字段
     * @param detailNoList 下面这个是很坑爹的东西需要很多个这个才能锁定唯一的一条
     */
    @Update("<script>" +
            "update yz_temperature set modify_userid=#{param.modifyUserid},modify_time=#{param.modifyTime}" +
            "<if test=\"param.ward!=null\">" +
            ",ward=#{param.ward}" +
            "</if>" +
            "where " +
            "inpatient_no=#{param.inpatientNo} and admiss_times=#{param.admissTimes} and scd_flag='0' " +
            "and rec_date=#{param.toStringRecDate} and rec_time=#{param.toStringRecTime} and detail_no in " +
            "<foreach collection=\"detailNoList\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">" +
            "#{item.detailNo}" +
            "</foreach>" +
            "</script>")
    void teperatureBody(@Param("param") YzTemperature param,
                        @Param("detailNoList") List<YzTemperature> detailNoList);
}
