package thyyxxk.webserver.dao.adicon;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.examinations.adicon.ItemMatch;
import thyyxxk.webserver.entity.examinations.adicon.ReportDetail;

import java.util.List;

@Mapper
public interface AdiconDao {

    @Select("select CHECKITEMID as matchCode,CHECKITEMNAME as matchName from T_CHECKITEM \n" +
            "where CHECKITEMNAME in (${statement})")
    List<ItemMatch> selectAutoMatchableItems(String statement);

    @Select("select item_code from t_checkitem_match where item_code in (${statement})")
    List<String> selectMatchedItems(String statement);

    @Select("select CHECKITEMID as itemCode,CHECKITEMNAME as itemName from T_CHECKITEM")
    List<ItemMatch> selectZdItems();

    @Insert({"<script>" +
            "insert into t_checkitem_match (item_code,item_name,match_code,match_name) " +
            "values " +
            "<foreach collection='list' item='item' separator=','> " +
            "(#{item.itemCode},#{item.itemName},#{item.matchCode},#{item.matchName})" +
            "</foreach>" +
            "</script>"})
    void insertMatchItem(List<ItemMatch> list);

    @Select("select CHECKITEMID from T_SINGLE_RESULT where SGLCHECKID=#{id} " +
            "and CHECKITEMID in (${statement})")
    List<String> selectExistCheckItem(String id, String statement);

    @Select("select item_code,match_code from t_checkitem_match where item_code in (${statement})")
    List<ItemMatch> selectMatchedItems2(String statement);

    @Insert({"<script>" +
            "insert into T_SINGLE_RESULT (SGLCHECKID,CHECKITEMID,ITEMRESULT,UNIT," +
            "LOWCRITICAL,HIGHCRITICAL,CRITICALNAME,CREATEDATE,UPDATEDATE,ISABANDON," +
            "RSLTFLAG,REGISTDEPT,OPERATEDATE,MYROWID,HINT) " +
            "values " +
            "<foreach collection='list' item='item' separator=','> " +
            "(#{item.patientNumber},#{item.itemCode},#{item.result},#{item.resultUnit}," +
            "#{item.str4},#{item.str5},#{item.resultReference},#{item.receivedDate}," +
            "#{item.reportDate},'0',#{item.str2},#{item.department},getdate()," +
            "#{item.str3},#{item.resultHint})" +
            "</foreach>" +
            "</script>"})
    void insertNewResult(List<ReportDetail> list);
}
