package thyyxxk.webserver.dao.his.examinations;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.*;
import thyyxxk.webserver.entity.examinations.bookablemanage.ExamItem;
import thyyxxk.webserver.entity.examinations.inspections.request.ReportIndexInquiry;
import thyyxxk.webserver.entity.examinations.inspections.response.TestReport;
import thyyxxk.webserver.entity.yiji.YjReqIndex;

import java.util.List;

/**
 * @author dj
 */
@Mapper
public interface InspectionsDao {

    @Select("select rtrim(max(tj_no)) from mz_patient_mi with(nolock) where social_no=#{socialNo}")
    String selectTjNo(@Param("socialNo") String socialNo);

    @Select("select rtrim(code) as code, rtrim(name) as name, rtrim(exec_unit) as execUnit, " +
            "execUnitName=(select rtrim(name) from zd_unit_code with(nolock) where code=exec_unit), " +
            "rtrim(py_code) as pyCode, rtrim(d_code) as wbCode, wx_bookable_flag, book_tip " +
            "from ${tableName} with(nolock) where isnull(del_flag,0)!=1")
    IPage<ExamItem> searchItems(IPage<ExamItem> iPage,
                                @Param("tableName") String tableName);

    @Select("select rtrim(code) as code, rtrim(name) as name, rtrim(exec_unit) as execUnit, " +
            "execUnitName=(select rtrim(name) from zd_unit_code with(nolock) where code=exec_unit), " +
            "rtrim(py_code) as pyCode, rtrim(d_code) as wbCode, wx_bookable_flag, book_tip " +
            "from ${tableName} with(nolock) where isnull(del_flag,0)!=1 and ${method} like #{content}")
    IPage<ExamItem> searchItemsByCondition(IPage<ExamItem> iPage,
                                           @Param("tableName") String tableName,
                                           @Param("method") String method,
                                           @Param("content") String content);

    @Update("update ${tableName} set wx_bookable_flag=#{wxBookableFlag},book_tip=#{bookTip} where code=#{code}")
    void updateWxBookableFlag(ExamItem item);

    @Select("select rtrim(social_no) from a_patient_mi where inpatient_no=#{patNo}")
    String selectInpatientSocialNo(String patNo);

    @Select("select rtrim(social_no) from mz_patient_mi where patient_id=#{patNo}")
    String selectOutpatientSocialNo(String patNo);

    @Insert("delete from t_check_data where patient_uid=#{uid};" +
            "insert into t_check_data (patient_uid,patient_name,pat_no,times,examin_eparts,room_code, " +
            "examination_see,examinationre_sult,doctor_code,check_doctor_code,check_time,report_time, " +
            "patient_from,report_url,top_req_no) " +
            "values (#{uid},#{patName},#{patNo},#{times},#{groupName},#{staffDept},'','',#{reqDoctor},'', " +
            "'','',#{patientFrom},#{reportUrl},#{reqNo})")
    void insertNewCheckData(YjReqIndex index);

    @Insert("delete from patient_archive where pat_no=#{patNo} and times=#{times} and document_id=#{uid};" +
            "insert into patient_archive (id,pat_no,times,document_id,create_id,name,path,type) " +
            "values (#{archiveId},#{patNo},#{times},#{uid},#{staffId},#{patName},#{suffixDir},5)")
    void insertArchive(YjReqIndex index);
}
