package thyyxxk.webserver.dao.his.zhuyuanyisheng;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.inpatient.patient.Patient;

import java.util.List;

public interface PatientCriticalValuesDao {

    @Select("select inpatient_no, admiss_times, zk_ward as deptCode, rtrim(name) as name, bed_no " +
            "from zy_actpatient " +
            "where inpatient_no = #{patNo} ")
    Patient selectPatientInfoByPatNo(String patNo);

    @Insert("insert t_patient_critical_value (pat_no, times, message) " +
            "values (#{patNo}, #{times}, #{message} )")
    void insertAMessage(String patNo,
                        Integer times,
                        String message);

    @Select("select code " +
            "from a_employee_mi " +
            "where dept_code = #{deptCode} " +
            "  and isnull(del_flag, 0) = 0")
    List<String> selectDoctorByDept(String deptCode);


    @Select("select rtrim(inpatient_no) + '_' + cast(admiss_times as varchar(3)) as patNo, " +
            "       rtrim(name)                                                  as name, " +
            "       rtrim(bed_no)                                                as bedNo, " +
            "       a.message " +
            "from t_patient_critical_value a " +
            "         left join " +
            "     zy_actpatient b on (a.pat_no = b.inpatient_no " +
            "         and a.times = b.admiss_times) " +
            " ${ew.customSqlSegment} " +
            " order by a.creation_time desc ")
    List<JSONObject> selectCriticalValuePatientList(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);

    @Select("select message from t_patient_critical_value where pat_no = #{patNo} and times =#{times}")
    List<String> selectCriticalValueByPatInfo(String patNo, Integer times);

}
