package thyyxxk.webserver.dao.his.medicalinsurance;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.medicalinsurance.emrupload.Adminfo;
import thyyxxk.webserver.entity.medicalinsurance.emrupload.HeightWeight;
import thyyxxk.webserver.entity.medicalinsurance.emrupload.SimpleEmrPatientData;

import java.util.List;

@Mapper
public interface EmrUploadDao {

    @Select("select id,create_id,create_date,emr_category_code," +
            "refer_physician,consult_physician,dept_director,emr_data_element," +
            "createName=(select rtrim(d.name) from a_employee_mi d where d.code=create_id)," +
            "referPhysicianName=(select rtrim(d.name) from a_employee_mi d where d.code=refer_physician), " +
            "consultPhysicianName=(select rtrim(d.name) from a_employee_mi d where d.code=consult_physician), " +
            "deptDirectorName=(select rtrim(d.name) from a_employee_mi d where d.code=dept_director) " +
            "from emr_patient_data where pat_no=#{patNo} and times=#{times} and del_flag=0 " +
            "and emr_category_code in " +
            "('ruyuanjiluzhuanyong','shoucibingchengjilu','chuyuanjilu','siwangjilu'," +
            "'shoushujilu','qiangjiujilu')")
    List<SimpleEmrPatientData> getEmrList(String patNo, int times);
    
    @Select("select " +
            "mdtrtSn=rtrim(a.inpatient_no)+'_'+cast(a.admiss_times as varchar), " +
            "b.mdtrt_id,b.psn_no,mdtrtsn=rtrim(a.inpatient_no),name=rtrim(a.name), " +
            "gend=a.sex,b.age,admRecNo=rtrim(a.inpatient_no)+'_'+cast(a.admiss_times as varchar), " +
            "wardareaName=(select d.name from zd_unit_code d where d.code=a.dis_dept), " +
            "deptCode=a.zk_ward,bedno=a.bed_no,admTime=a.admiss_date, " +
            "deptName=(select d.name from zd_unit_code d where d.code=a.zk_ward) " +
            "from zy_inactpatient a left join t_si_setlinfo b  " +
            "on b.pat_no=a.inpatient_no and b.times=a.admiss_times and b.revoked=0 " +
            "where a.inpatient_no=#{patNo} and a.admiss_times=#{times}")
    Adminfo selectAdminfo(String patNo, int times);

    @Select("select max(si_caty) from zd_unit_code where name=#{name} ")
    String getSiCaty(String name);

    @Select("select isnull(max(body_length),0) as height,isnull(min(body_weight), 0) as weight " +
            "from yz_temperature_sum where inpatient_no=#{patNo} and admiss_times=#{times}")
    HeightWeight getHeightWeight(String patNo, int times);
}
