package thyyxxk.webserver.dao.his.examinations;

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.examinations.BloodSugar.BgNursingTestSync;
import thyyxxk.webserver.entity.inpatient.patient.Patient;

import java.util.List;

@Mapper
public interface BloodSugarQueryDao {
    @Select("select bed_no, " +
            "       rtrim(a.name) name, " +
            "       birth_date, " +
            "       a.inpatient_no, " +
            "       admiss_date," +
            "      b.sex," +
            "     zk_ward_name = (select rtrim(name) from zd_unit_code where code = zk_ward) " +
            "from ${tableName} a, " +
            "     a_patient_mi b " +
            "where a.inpatient_no = b.inpatient_no " +
            "  and a.inpatient_no = #{patNo} " +
            "and a.admiss_times = #{times}")
    Patient getPatientInfo(@Param("tableName") String tableName,
                           @Param("patNo") String patNo,
                           @Param("times") Integer times);

    @Select("select id, " +
            "       inpatient_no, " +
            "       admiss_times, " +
            "       nurse_id, " +
            "       nurse_id_name = (select rtrim(name) from a_employee_mi where code = nurse_id)," +
            "       test_time, " +
            "       bed_no, " +
            "       timecode_id, " +
            "       timecode_name, " +
            "       rtrim(test_result) test_result, " +
            "       rtrim(result_unit) result_unit " +
            "from data_blood_glouse " +
            "where inpatient_no = #{patNo}" +
            " and admiss_times = #{times}" +
            " order by test_time ")
    List<BgNursingTestSync> getPatientLoodSugar(@Param("patNo") String patNo,
                                                @Param("times") Integer times);

    @Select("select admiss_times " +
            "from zy_actpatient " +
            "where inpatient_no = #{patNo} ")
    Integer getPatientTimes(@Param("patNo") String patNo);

    @Update("update bg_nursing_test_sync " +
            "set nurse_id  = #{nurseId}, " +
            "    test_time = #{testTime}, " +
            "    test_result = #{testResult}  " +
            "where id = #{id}")
    void modifyPatientBloodGlucoseInfo(BgNursingTestSync param);

}
