package thyyxxk.webserver.dao.his.zhuyuanyisheng;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;
import thyyxxk.webserver.entity.CodeName;
import thyyxxk.webserver.entity.casefrontsheet.YshHzRecord;
import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
import thyyxxk.webserver.entity.dictionary.CyComboGrid;
import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.*;
import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.dto.JyJcCheckItemDto;
import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.vo.JcJyPartOrSample;
import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.vo.ViewInspectionItemDetailsVo;
import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.PatientTemp;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 描述： 检查申请
 * </p>
 *
 * @author xc
 * @date 2022-02-10 15:42
 */
@Mapper
public interface JianYanJianChaDao {

    @Select("select order_name,req_no,act_order_no, " +
            "start_time,inpatient_no,admiss_times,receive_flag," +
            "patient_uid,inspect_stuff_name = (select rtrim(name) from ysh_zd_part_code where code = inspect_stuff)," +
            "       (select rtrim(name)\n" +
            "        from ysh_zd_part_code\n" +
            "        where code = inspect_part)         inspect_part_name " +
            "from ysh_yj_req with (NOLOCK) " +
            " ${ew.customSqlSegment} ")
    List<YshYjReq> huoQuJianChaShenQingV2(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);


    @Select("select req_no,\n" +
            "       inpatient_no,\n" +
            "       p_name,\n" +
            "       p_age,\n" +
            "       admiss_times,\n" +
            "       bed_no,\n" +
            "       p_bar_code,\n" +
            "       group_name,\n" +
            "       act_order_no,\n" +
            "       order_code,\n" +
            "       order_name,\n" +
            "       page_no,\n" +
            "       req_comment,\n" +
            "       req_doctor,\n" +
            "       req_dept,\n" +
            "       req_ward,\n" +
            "       exec_dept,\n" +
            "       req_date,\n" +
            "       sample_status,\n" +
            "       print_flag,\n" +
            "       receive_flag,\n" +
            "       req_type,\n" +
            "       result_comment,\n" +
            "       sys_date,\n" +
            "       start_time,\n" +
            "       isnull(diag_text,\n" +
            "              (select name\n" +
            "               from zd_icd_code_new\n" +
            "               where code = diag_code)) as diag_text,\n" +
            "       order_type,\n" +
            "       report_no,\n" +
            "       jz_flag,\n" +
            "       req_studyid,\n" +
            "       req_tz_comment,\n" +
            "       req_other_result,\n" +
            "       receive_jc,\n" +
            "       diag_code,\n" +
            "       confirm_flag,\n" +
            "       confirm_time,\n" +
            "       confirm_id,\n" +
            "       quantity,\n" +
            "       inspect_part,\n" +
            "       inspect_stuff,\n" +
            "       (select rtrim(name)\n" +
            "        from jy_zd_sample with (NOLOCK)\n" +
            "        where code = inspect_stuff)        inspect_stuff_name,\n" +
            "       (select rtrim(name)\n" +
            "        from ysh_zd_part_code\n" +
            "        where code = inspect_part)         inspect_part_name,\n" +
            "       (select rtrim(name)\n" +
            "        from zd_unit_code\n" +
            "        where code = req_dept)          as req_dept_name,\n" +
            "       (select rtrim(name)\n" +
            "        from zd_unit_code\n" +
            "        where code = req_ward)          as req_ward_name,\n" +
            "       (select rtrim(name)\n" +
            "        from a_employee_mi\n" +
            "        where code = req_doctor)        as req_doctor_name,\n" +
            "       case\n" +
            "           when req_type = '2' then (select rtrim(class)\n" +
            "                                     from jy_zd_item c\n" +
            "                                     where c.zy_order_code = order_code)\n" +
            "           else '00'\n" +
            "           end                             classes\n" +
            "from ysh_yj_req with (NOLOCK)" +
            "${ew.customSqlSegment}")
    List<YshYjReq> huoQuShengQingXiangQing(@Param("ew") QueryWrapper<YshYjReq> reqNo);

    @Select("select top 1 sex, " +
            "       rtrim(home_street) as  home_street," +
            "       rtrim(home_tel) as home_tel," +
            "       responceTypeName = (select responce_type_name = (select rtrim(name) from zy_zd_responce_type where code = responce_type) \n" +
            "from zy_actpatient with (NOLOCK) \n" +
            "where inpatient_no = #{patNo}) " +
            "from a_patient_mi with (NOLOCK) " +
            "where inpatient_no = #{patNo}")
    PatientTemp huoQuHuanZheXinXi(@Param("patNo") String patNo);

    @Select("select rtrim(comm) comm, " +
            "       comment1, " +
            "       comment2, " +
            "       comment3, " +
            "       comment4, " +
            "       comment5, " +
            "       comment6, " +
            "       comment7, " +
            "       comment8 " +
            "from jc_zd_class with (NOLOCK) " +
            "where code = #{code}")
    JcZdClass daYingXiangQing(@Param("code") String code);

    @Select("select tc_name as name," +
            "       rtrim(tc_no) as code," +
            "       '1' as isTheParentNode " +
            "from zy_tc_yj c with (NOLOCK)" +
            "where isnull(del_flag, '0') = '0' and " +
            "${ew.sqlSegment}")
    List<JcZdClass> getTemplate(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);

    @Select("select op_id,tc_exec " +
            "from zy_tc_yj with (NOLOCK) " +
            "where tc_no = #{code}")
    ZyTcYj jianChaLuRuRen(String code);

    @Delete("delete zy_tc_yj " +
            "where tc_no = #{code}; " +
            "delete zy_tc_detail_yj " +
            "where tc_no = #{code};")
    void shanChuJianChaMuBan(String code);

    @Select("SELECT rtrim(a.order_code) as                                          orderCode, " +
            "       rtrim(a.order_name) as                                          orderName, " +
            "       rtrim(a.order_code) as                                          code, " +
            "       rtrim(a.order_name) as                                          name, " +
            "       rtrim(a.yb_comment)                                             ybComment, " +
            "       '0'                 as                                          checkFlag, " +
            "       a.exec_dept         as                                          execDept, " +
            "       a.order_type        as                                          orderType, " +
            "       (select rtrim(name) from zd_unit_code with (NOLOCK) where code = a.exec_dept) execDeptName, " +
            "       CONVERT(varchar(100), GETDATE(), 20)           as               startTime," +
            "       inspect_stuff as inspectStuff , " +
            "       inspectStuffName = (select rtrim(name) from jy_zd_sample with (NOLOCK) where code = inspect_stuff)," +
            "       rtrim(c.tc_no) as tc_no," +
            "       '2' as isTheParentNode, " +
            "      case when c.req_type = '2' then (select rtrim(class) from jy_zd_item yj where yj.zy_order_code = a.order_code) " +
            "      else (select rtrim(class) from jc_zd_item yj where yj.zy_order_code = a.order_code) end  as classes " +
            "FROM yz_order_item a with (NOLOCK), " +
            "     zy_tc_detail_yj b with (NOLOCK), " +
            "     zy_tc_yj c with (NOLOCK) " +
            "where b.tc_no = c.tc_no " +
            "  and a.order_code = b.order_code " +
            "  and isnull(a.del_flag, '') <> '1'" +
            "  and isnull(c.del_flag, '') <> '1' " +
            "  and ${ew.sqlSegment} " +
            "  order by sort_no desc ")
    List<Map<String, String>> selectTemplateContent(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);


    @Select("SELECT                 rtrim(a.order_code) as        orderCode,\n" +
            "                       rtrim(a.order_name) as        orderName,\n" +
            "                       rtrim(a.order_code) as        code,\n" +
            "                       rtrim(a.order_name) as        name,\n" +
            "                       rtrim(a.yb_comment)           ybComment,\n" +
            "                       '0'                 as        checkFlag,\n" +
            "                       jyjc.exec_unit      as        execDept,\n" +
            "                       a.order_type        as        orderType,\n" +
            "                       (select rtrim(name)\n" +
            "                        from zd_unit_code with (NOLOCK)\n" +
            "                        where code = jyjc.exec_unit) execDeptName,\n" +
            "                       CONVERT(varchar(100),\n" +
            "                               GETDATE(),\n" +
            "                               20)         as        startTime,\n" +
            "                       b.inspect_stuff     as        inspectStuff,\n" +
            "    inspectStuffName = (select rtrim(name)\n" +
            "                        from jy_zd_sample with (NOLOCK)\n" +
            "                        where code = b.inspect_stuff),\n" +
            "                       b.inspect_part      AS        inspectPart,\n" +
            "                       (select rtrim(name)\n" +
            "                        from ysh_zd_part_code\n" +
            "                        where code = b.inspect_part) inspectPartName,\n" +
            "                       rtrim(c.tc_no)      as        tc_no,\n" +
            "                       '2'                 as        isTheParentNode,\n" +
            "                       class               as        classes,\n" +
            "                       note,\n" +
            "                       collection_info as collectionInfo,\n" +
            "                       a.gender_restriction AS genderRestriction,\n" +
            "                       a.min_age_restriction AS minAgeRestriction,\n" +
            "                       a.max_age_restriction AS maxAgeRestriction\n" +
            "FROM yz_order_item a with (NOLOCK),\n" +
            "     zy_tc_detail_yj b with (NOLOCK),\n" +
            "     zy_tc_yj c with (NOLOCK),\n" +
            "     ${tableName} jyjc\n" +
            "where b.tc_no = c.tc_no\n" +
            "  and a.order_code = b.order_code\n" +
            "  and isnull(a.del_flag, '') <> '1'\n" +
            "  and isnull(c.del_flag, '') <> '1'\n" +
            "  and jyjc.zy_order_code = a.order_code\n" +
            "  and isnull(jyjc.zy_flag, '0') != '1'\n" +
            "  and c.tc_no = #{code}\n" +
            "  and c.req_type = #{type}\n" +
            "order by item_no;")
    List<Map<String, String>> getTemplateByCodeAndType(@Param("code") String code,
                                                       @Param("type") String type,
                                                       @Param("tableName") String tableName);

    @Select("<script>" +
            "SELECT jc_text,name,code,wh_flag,op_id " +
            "FROM ysh_zd_yj_template with (NOLOCK) " +
            "WHERE (py_code like #{name} or d_code like #{name} or name like #{name}) " +
            "<if test=\"leiXing == 1\">" +
            "  and op_id = #{userCode} " +
            "</if>" +
            "<if test=\"leiXing == 2\">" +
            "  and dept_code = (select rtrim(dept_code) from a_employee_mi where code = #{userCode}) and wh_flag = '2' " +
            "</if>" +
            "<if test=\"leiXing == 3\">" +
            "  and wh_flag = '3' " +
            "</if>" +
            "</script>")
    Page<YshZdYjTemplate> huoQuShuoMingMuBan(IPage<YshZdYjTemplate> page,
                                             @Param("name") String name,
                                             @Param("leiXing") Integer leiXing,
                                             @Param("userCode") String userCode);

    @Select("select * from ysh_zd_yj_template with (NOLOCK) where code = #{code}")
    YshZdYjTemplate muBanShuJu(String code);

    @Update("update ysh_zd_yj_template " +
            "set jc_text  = #{jcText}, " +
            "    name     = #{name}, " +
            "    py_code  = #{pyCode}, " +
            "    d_code   = #{dCode}, " +
            "    sys_date = getdate() " +
            "where code = #{code} ")
    void genXingShouMingMuBan(@Param("jcText") String jcText,
                              @Param("name") String name,
                              @Param("pyCode") String pyCode,
                              @Param("dCode") String dCode,
                              @Param("code") String code);

    @Delete("delete from ysh_zd_yj_template where code = #{code} ")
    void shanChuShouMingMuBan(String code);

    @Insert("insert into ysh_zd_yj_template (code, name, py_code, d_code, jc_text, jc_type, dept_code, op_id, sys_date, wh_flag) " +
            "values (#{code}, #{name}, #{pyCode}, #{dCode}, #{jcText}, 3, " +
            "(select rtrim(a_employee_mi.dept_code) from a_employee_mi where a_employee_mi.code = #{opId}), #{opId}, getdate(), #{whFlag})")
    void xinZengShouMingMuBan(YshZdYjTemplate param);


    @Select("select rtrim(code) as code, rtrim(name) as name " +
            "from zd_icd_code_new with (NOLOCK) where del_flag=0 " +
            "and (yb_code like #{name} or yb_name like #{name} or yb_py_code like #{name})")
    List<GetDropdownBox> diagnosisInOurHospital(String name);

    @Select("select tc_no " +
            "from zy_tc_yj with (NOLOCK) " +
            "where op_id = #{code} " +
            "  and tc_name = #{name}" +
            "  and req_type = #{reqType} ")
    List<String> huoQuJianChaJianYanChongFuMuBanMing(@Param("name") String name,
                                                     @Param("code") String code,
                                                     @Param("reqType") String reqType);

    /**
     * 插入检查或检验模板
     */
    @Insert("INSERT INTO zy_tc_yj (tc_no, tc_name, tc_exec, del_flag, py_code, d_code, n_code, order_type/*1个人 2-科室*/,op_id, " +
            "                                    req_type, tc_flag/*录入方式 1-手工选择 0-自动选择*/, create_date, sort_no) " +
            "VALUES (#{tcNo}, #{tcName}, #{tcExec}, N'0',#{pyCode}, #{dCode}, null, #{orderType}, #{opId}, #{reqType}, #{tcFlag}, getdate(), #{sortNo});")
    void chaRuJCJYMuBan(ZyTcYj param);

    @Insert("<script>" +
            "insert into zy_tc_detail_yj (tc_no, order_code,  inspect_part, inspect_stuff, item_no) " +
            "values " +
            "<foreach collection='list' item='item' index='index' separator=','>" +
            "(#{tcNo}, #{item.orderCode}, #{item.inspectPart}, #{item.inspectStuff}" +
            ", ${index} + 1)" +
            "</foreach>" +
            "</script>")
    void chaRuJCJYMuBanNeiRong(List<YshHzRecord> list,
                               @Param("tcNo") String tcNo,
                               @Param("reqType") String reqType);

    @Insert("<script>" +
            "insert into ysh_yj_req (req_no, inpatient_no, p_name, p_age, admiss_times, bed_no, group_name/* order_name一样*/, " +
            "                        act_order_no, order_code, order_name, page_no/* req_no */, req_comment, req_doctor, " +
            "                        req_dept, req_ward, exec_dept, req_date,/*getdate*/ " +
            "                        receive_flag/*1*/, req_type/*2检验3检查*/, sys_date/*getdate*/, start_time , diag_code, " +
            "                        diag_text, " +
            "                        order_type, jz_flag/*1 和 null*/, req_tz_comment/*体征信息*/, req_other_result/*相关辅检结果*/," +
            "inspect_stuff,inspect_part,quantity, charge_fee) " +
            "values " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.reqNo}, #{inpatientNo}, #{name}, #{age}, #{admissTimes}, #{bedNo}, #{item.orderName}, " +
            "        #{item.actOrderNo}, #{item.orderCode}, cast(#{item.orderName} as varchar(60)) , #{item.reqNo}, #{item.reqComment}, #{userCode}, " +
            "        #{deptCode}, #{wardCode}, #{item.execDept}, #{reqDate}, '1', #{reqType}, #{reqDate}, #{reqDate},#{item.diagCode},#{item.diagText}, " +
            "        (select class from ${orderTypeTable} where zy_order_code = #{item.orderCode})," +
            "       #{item.jzFlag},#{item.reqTzComment},#{item.reqOtherResult}," +
            "       #{item.inspectStuff}, #{item.inspectPart},#{item.quantity},#{item.chargeFee})" +
            "</foreach>" +
            "</script>")
    void chaRuShenQing(@Param("list") List<YshYjReq> list,
                       @Param("inpatientNo") String inpatientNo,
                       @Param("name") String name,
                       @Param("age") String age,
                       @Param("admissTimes") Integer admissTimes,
                       @Param("bedNo") String bedNo,
                       @Param("userCode") String userCode,
                       @Param("deptCode") String deptCode,
                       @Param("wardCode") String wardCode,
                       @Param("reqType") String reqType,
                       @Param("orderTypeTable") String orderTypeTable,
                       @Param("reqDate") Date reqDate);

    @Insert("<script>" +
            "INSERT INTO yz_act_order (order_code, order_name, frequ_code, infant_flag/*婴儿标志*/, order_time, physician, start_time, " +
            "                          act_order_no, inpatient_no, admiss_times, drug_flag/*o*/, enter_oper/*录入人*/, enter_time/*录时间*/, " +
            "                          status_flag/*2*/, confirm_time, signer,/*在我这里保存了医嘱就直接确定了*/ " +
            "                          self_buy/*0*/, pay_self/*0*/, serial/*00*/, group_no/*00*/, doctor_flag, exec_unit, dept_code, " +
            "                          ward_code, reg_flag/*1*/,emergency_flag,yb_self_flag, dose,drug_quan) " +
            "VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.orderCode}, #{item.orderName}, 'ONCE', #{infantFlag}, #{item.startTime}, #{userCode}, #{item.startTime}, " +
            "        #{item.actOrderNo}, #{inpatientNo}, " +
            "        #{admissTimes}, 'o', #{userCode}, #{reqDate}, '2', #{reqDate}, #{userCode}, '0', '0', '00', '00', '1', " +
            "        #{item.execDept}, " +
            "        #{deptCode}, #{wardCode}, '1',#{item.jzFlag},#{item.ybSelfFlag},#{item.quantity},#{item.quantity})" +
            "</foreach>" +
            "</script>")
    void chaRuShenQingYiZhu(@Param("list") List<YshYjReq> list,
                            @Param("inpatientNo") String inpatientNo,
                            @Param("admissTimes") Integer admissTimes,
                            @Param("userCode") String userCode,
                            @Param("deptCode") String deptCode,
                            @Param("wardCode") String wardCode,
                            @Param("infantFlag") Integer infantFlag,
                            @Param("reqDate") Date reqDate);


    @Select("select req_no," +
            "       inpatient_no," +
            "       admiss_times, " +
            "       group_name," +
            "       order_name, " +
            "       act_order_no, " +
            "       order_code, " +
            "       req_comment, " +
            "       req_doctor, " +
            "       req_doctor_name= (select rtrim(name) from a_employee_mi with (NOLOCK) where code = req_doctor), " +
            "       req_dept, " +
            "       req_dept_name = (select rtrim(name) from zd_unit_code with (NOLOCK) where code = req_dept)," +
            "       req_ward_name      = (select rtrim(name) from zd_unit_code where code = req_ward), " +
            "       exec_dept, " +
            "       exec_dept_name = (select rtrim(name) from zd_unit_code with (NOLOCK) where code = exec_dept), " +
            "       req_date, " +
            "       inspect_stuff, " +
            "       inspect_stuff_name = (select rtrim(name) from jy_zd_sample with (NOLOCK) where code = inspect_stuff), " +
            "       jz_flag," +
            "       receive_flag " +
            " from ysh_yj_req with (NOLOCK) " +
            " ${ew.customSqlSegment} ")
    List<YshYjReq> huoQuJianYanV2(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);

    @Select("SELECT rtrim(a.code) as code, " +
            "       rtrim(a.name) as name " +
            "FROM jy_zd_class a with (NOLOCK), " +
            "     yz_order_item b with (NOLOCK) " +
            "where a.code = b.jy_type " +
            "  and isnull(b.del_flag, '') <> '1' " +
            "group by a.code, a.name ")
    IPage<JcZdClass> jianYanFenLei(IPage<JcZdClass> page);

    @Select("select rtrim(code) as code,name from ${tableName} with (NOLOCK) " +
            "where isnull(del_flag, '0') = '0' and (name like #{name} " +
            "    or py_code like #{name} " +
            "    or code like #{name} or d_code like #{name} )")
    List<GetDropdownBox> biaoBenOrBuWei(String name, String tableName);

    @Select("select rtrim(code) as code,rtrim(name) as name,py_code,d_code as wb_code from jy_zd_sample with (NOLOCK) " +
            "where isnull(del_flag, '0') = '0'")
    List<JcJyPartOrSample> getJySample();


    @Select("select rtrim(code) as code,rtrim(name) as name,py_code,d_code as wb_code,parent_code from ysh_zd_part_code with (NOLOCK) " +
            "where isnull(del_flag, '0') = '0'")
    List<JcJyPartOrSample> getJcPartCode();

    @Select("select * " +
            "from ysh_yj_req with (NOLOCK) where req_no = #{reqNo} and inpatient_no = #{patNo} and admiss_times = #{times}")
    YshYjReq huoQuJianYanJianCha(@Param("reqNo") Integer reqNo,
                                 @Param("patNo") String patNo,
                                 @Param("times") Integer times);

    @Select("select count(1) " +
            "from yz_zy_patient_fee " +
            "where act_order_no = #{yj.actOrderNo} " +
            "  and inpatient_no = #{yj.inpatientNo} " +
            "  and admiss_times = #{yj.admissTimes} " +
            "  and charge_status not in ('3','2') ")
    int selecePatientFee(@Param("yj") YshYjReq yj);

    @Delete("delete from ysh_yj_req where req_no = #{reqNo} and inpatient_no = #{patNo} and admiss_times = #{times}")
    void shanChuJianYanJianCha(@Param("reqNo") Integer reqNo,
                               @Param("patNo") String patNo,
                               @Param("times") Integer times);

    @Update("update yz_zy_patient_fee " +
            "set charge_status = '2', " +
            "    op_id         = #{userCode}, " +
            "    op_date       = getdate() " +
            "where inpatient_no = #{yj.inpatientNo} " +
            "  and admiss_times = #{yj.admissTimes} " +
            "  and act_order_no = #{yj.actOrderNo} " +
            "  and charge_status = '3'")
    void cancellationOfConfirmedFees(@Param("yj") YshYjReq yj,
                                     @Param("userCode") String userCode);

    @Update("update yz_act_order " +
            "set status_flag = '-1', " +
            "    instruction = N'作废'," +
            "    order_name = N'作废' + order_name " +
            "where act_order_no = #{orderNo} ")
    void shanChuYiZhu(@Param("orderNo") BigDecimal orderNo);


    @Select("select a.order_code, " +
            "       a.occ_code, " +
            "       b.name, " +
            "       a.amount, " +
            "       cast(a.amount * b.charge_amount as varchar) as charge_amount, " +
            "       cast(b.charge_amount as varchar)            as unit_price," +
            "       national_code, " +
            "       national_name " +
            "from yz_order_occurence a, " +
            "     zd_charge_item b " +
            "where a.occ_code = b.code " +
            "  and a.order_code = #{orderCode}")
    List<ViewInspectionItemDetailsVo.Item> viewInspectionItemDetails(String orderCode);

    @Select("select top 1 jc_id from yj_jc_patient where ba_no = #{patNo} ")
    String getJcIdByPatNo(String patNo);

    @Select("select count(1) from zy_detail_charge where order_no = #{yj.actOrderNo} and inpatient_no = #{yj.inpatientNo} and admiss_times = #{yj.admissTimes}  ")
    int selectedFeeCount(@Param("yj") YshYjReq yj);

    @Select("select fs_icd_text,report_no,check_date,his_req_no,report_id," +
            "report_name  = (select name from a_employee_mi where code = report_id)," +
            "report_date,confirm_id,confirm_name = (select name from a_employee_mi where code = confirm_id),confirm_date " +
            "from yj_jc_record where his_req_no = #{reqNo} and jc_id = #{jcId}")
    YjJcRecord getJcRecord(String reqNo, String jcId);

    @Select("select text_zd,text_jc from " +
            "yj_jc_record_report where report_no = #{report} and title_code = '01' ")
    Map<String, String> selectTextJc(String report);


    @Select("select time_limit, note, collection_info\n" +
            "from ${tableName}\n" +
            "where zy_order_code = #{code}\n")
    ViewInspectionItemDetailsVo selectJcJyItem(@Param("tableName") String tableName, @Param("code") String code);

    /**
     * 获取检验大类
     *
     * @return
     */
    @Select("select rtrim(code) as code,name as name  from jy_zd_class")
    List<JyJcItem> queryInspectionClassification();

    /**
     * 获取详细的检验项目
     *
     * @return
     */
    @Select("select                 rtrim(a.zy_order_code)          as code,\n" +
            "                       rtrim(a.name)                   as name,\n" +
            "                       rtrim(a.class)                  as classes,\n" +
            "                       exec_unit,\n" +
            "    exec_unit_name   = (select name from zd_unit_code where code = a.exec_unit),\n" +
            "                       '2'                             as type,\n" +
            "                       isnull(b.sample, a.sample_code) as inspectStuff,\n" +
            "    inspectStuffName = (select rtrim(name)\n" +
            "                        from jy_zd_sample with (NOLOCK)\n" +
            "                        where code = isnull(b.sample, a.sample_code)),\n" +
            "                       note,\n" +
            "                       collection_info,\n" +
            "                       a.gender_restriction,\n" +
            "                       a.min_age_restriction,\n" +
            "                       a.max_age_restriction,\n" +
            "                       rtrim(a.py_code)                as py_code,\n" +
            "                       rtrim(a.d_code)                 as d_code,a.code as id " +
            "from jy_zd_item a\n" +
            "         left join yz_order_item b on (a.zy_order_code = b.order_code)\n" +
            "where isnull(a.del_flag, '0') != '1' and isnull(a.zy_flag, '0') != '1' " +
            "  and isnull(b.del_flag, '0') <> '1'")
    List<JyJcItem> getJyDetailedItems();


    @Select("select rtrim(code) as code,rtrim(name) as name from jc_zd_class")
    List<JyJcItem> queryCheckClassification();


    @Select("select a.zy_order_code as code,a.code as id, " +
            "       isnull(b.name,'') as bw,bw_code as part_code, rtrim(b.name) as part_name," +
            "       rtrim(a.name) name, " +
            "       rtrim(class)  as classes, " +
            "       exec_unit," +
            "       exec_unit_name = (select name from zd_unit_code where zd_unit_code.code = exec_unit)," +
            "       note , collection_info , a.gender_restriction , a.min_age_restriction, a.max_age_restriction, rtrim(a.py_code) as py_code , rtrim(a.d_code) as d_code   " +
            "from jc_zd_item a " +
            "         left join ysh_zd_part_code b on (a.bw_code = b.code)" +
            "         left join yz_order_item c on (c.order_code = a.zy_order_code) " +
            "where isnull(a.del_flag, '0')<> '1' " +
            "  and isnull(zy_flag, '0') <> '1'" +
            "  and isnull(c.del_flag, '0') <> '1'  " +
            "order by class")
    List<JyJcItem> selectJcDetailItems();


    @Select("select top 1 req_comment,req_tz_comment,req_other_result,diag_code,diag_text " +
            "from ysh_yj_req where inpatient_no = #{patNo} and admiss_times = #{times} and req_comment is not null order by start_time desc")
    YshYjReq getAncillaryInformation(@Param("patNo") String patNo,
                                     @Param("times") Integer times);

    @Update("update ysh_yj_req set patient_uid = #{uid} where req_no = #{reqNo}")
    void setCheckPatientUid(String uid, Integer reqNo);

    @Select("select jc_id from yj_jc_patient where ba_no = #{patNo}")
    List<String> getJcIdByPatNoList(String patNo);

    @Select("select apply_date,\n" +
            "       apply_doctor_name = (select rtrim(name) from a_employee_mi where code = apply_doctor),\n" +
            "       orderName         = (select rtrim(name) from jc_zd_item where zy_order_code = order_code),\n" +
            "       text_zd,\n" +
            "       text_jc  " +
            "from yj_jc_record a,\n" +
            "     yj_jc_record_report b\n" +
            "where a.jc_id = #{jcId}" +
            "  and a.report_no = b.report_no\n" +
            "  and b.title_code = '01' " +
            " order by apply_date desc")
    List<JianChaJieGuo> selectJieGuo(String jcId);


    @Select("select note , collection_info as collectionInfo from ${tableName} where zy_order_code= #{orderCode}")
    JSONObject getExamineIllustrate(String orderCode, String tableName);

    @Select("select gender_restriction,\n" +
            "       max_age_restriction,\n" +
            "       min_age_restriction,\n" +
            "       zy_order_code as code,rtrim(class) as order_type," +
            " rtrim(name) as name," +
            " cast(rtrim(isnull(nullif(del_flag,\n" +
            "                                ''),\n" +
            "                         0)) as int) as del_flag," +
            " cast(rtrim(isnull(nullif(zy_flag,\n" +
            "                                ''),\n" +
            "                         0)) as int) as zy_flag  " +
            " ${col}  " +
            " from ${tableName} \n" +
            " where ${ew.sqlSegment};")
    List<JyJcCheckItemDto> selectJyJcCheckItemDtoByOrderCode(@Param("ew") QueryWrapper<?> queryWrapper,
                                                             @Param("tableName") String tableName,
                                                             @Param("col") String col);

    @Select("select cast(rtrim(isnull(nullif(c.del_flag,\n" +
            "                                ''),\n" +
            "                         0)) as int)    item_del_flag,\n" +
            "       cast(rtrim(isnull(nullif(a.del_flag,\n" +
            "                                ''),\n" +
            "                         0)) as int) as order_del_flag,\n" +
            "       a.order_name,\n" +
            "       c.name,rtrim(a.order_code) as code " +
            "from yz_order_item a\n" +
            "         left join yz_order_occurence b on (a.order_code = b.order_code)\n" +
            "         left join zd_charge_item c on (c.code = b.occ_code)\n" +
            "where ${ew.sqlSegment};")
    List<JyJcCheckItemDto.ItemInfo> selectItemDetailsByOrderCode(@Param("ew") QueryWrapper<?> queryWrapper);


    @Select("select rtrim(code) code, rtrim(name) name , rtrim(parent_code) as parent_code\n" +
            "from ysh_zd_part_code\n" +
            "where isnull(del_flag, 0) = 0\n")
    List<GetDropdownBox> selectBuWeiAll();


    @Select("select rtrim(parent_code) as parent_code\n" +
            "from ysh_zd_part_code\n" +
            "where isnull(del_flag, 0) = 0\n" +
            "  and parent_code is not null\n" +
            "group by parent_code")
    List<String> selectBuWeiParentCode();
}
