package thyyxxk.webserver.dao.his.medicaladvice.medicamanage;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
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.datamodify.YzActOrder;
import thyyxxk.webserver.entity.inpatient.patient.Patient;
import thyyxxk.webserver.entity.inpatient.patient.YzQueryBase;
import thyyxxk.webserver.entity.medicaladvice.medicamanage.YzOrderParam;
import thyyxxk.webserver.entity.medicaladvice.medicamanage.YzPrintVO;

import java.util.List;

/**
 * @Description:医嘱管理
 * @Author:lihong
 * @Date: 2023/3/13
 */
@Mapper
public interface MedicalManagementDao {
    @Select("SELECT act_order_no=a.act_order_no,\n" +
            "              inpatient_no=a.inpatient_no,\n" +
            "              name        =c.name,\n" +
            "              dept_code   =a.ward_code,\n" +
            "              bed_no      =c.bed_no,\n" +
            "              sex         =c.sex,\n" +
            "              age         =space(10),\n" +
            "              order_name  =rtrim(a.order_name),\n" +
            "              start_time  =case when  isnull(a.parent_no,'')=''  then a.start_time else (select start_time from yz_act_order where a.parent_no=act_order_no) end,\n" +
            "              print_page      =a.print_page,\n" +
            "              doctor_code     =physician,\n" +
            "              nurse_code      =executer1,\n" +
            "              self_buy        =a.self_buy,\n" +
            "              page_no         =isnull(print_page,0),\n" +
            "              page_no_old     =0,\n" +
            "              last_rows       =0,\n" +
            "              modifier        =case when exclu_group_type='1' then null  else a.modifier end,\n" +
            "              executer2       =case when exclu_group_type='1' then null  else a.executer2 end,\n" +
            "              drug_quan       =a.drug_quan,\n" +
            "              dose            =a.dose ,\n" +
            "              dose_unit       =a.dose_unit,\n" +
            "               frequ_code =(select print_name from yz_order_frequency where a.frequ_code =code)," +
            "              supply_code     =a.supply_code,\n" +
            "              spec            =a.drug_specification,\n" +
            "              group_no        =a.group_no,\n" +
            "              parent_no       =a.parent_no,\n" +
            "              instruction     =a.instruction,\n" +
            "              parent_flag     =space(2),\n" +
            "              parent_flag2    =space(2),\n" +
            "              end_time        =case when exclu_group_type='1' then null else a.end_time end,\n" +
            "              ps_status='',\n" +
            "              ps_oper='',\n" +
            "              ps_time='',\n" +
            "              act_order_no_b=a.act_order_no,\n" +
            "              order_time_b= case when isnull(a.parent_no,'')='' then convert(char(16),a.confirm_time,121) else (select convert(char(16),confirm_time,121) from yz_act_order where a.parent_no=act_order_no) end,\n" +
            "              order_name2 =space(32),\n" +
            "              exec_id,\n" +
            "              exec_id2 = case when exclu_group_type='1'  then null  else a.executer2 end,\n" +
            "              cx_flag='0',\n" +
            "              sort_no=0,\n" +
            "              a.confirm_time,\n" +
            " new_order_name_code = isnull(a.instruction,'') +(case when isnull(ps_status,'')='' then '' when ps_status='0'then '皮试:阴性'else '皮试:阳性'end) + ' ' +\n" +
            "                                    (case when a.self_buy = '1' then '自备'when a.self_buy = '2' then '嘱托' else '' end) + ' ' +\n" +
            "                                    (case when isnull(a.supply_code,'') = '' then '' else (select print_name from yz_supply_type where  supply_code = a.supply_code) end ),\n" +
            "              new_order_name = rtrim(a.order_name) + (case when a.group_no <> '00' then (case when isnull(a.drug_specification,'')=''then '' else '(' + isnull(a.drug_specification,'')+')' end) + ' ' +\n" +
            "                                                                                        (case when isnull(a.dose_unit,'') = '' then '' else  rtrim(a.dose) + (select name from yp_zd_unit where code=a.dose_unit) end) + ' ' +\n" +
            "                                                                                        (case when isnull(a.dose_unit,'') = '' then '' else  '共'+ rtrim(a.drug_quan) + (select name from yp_zd_unit where code=a.mini_unit) end) else isnull(a.drug_specification,'') end  )"+
            " FROM      ${tableName} a, yz_order_item b , view_zy_patient_all c\n" +
            " WHERE       a.inpatient_no = #{patNo} and\n" +
            "        a.admiss_times = #{times} AND\n" +
            "    ${pageCondition} and \n" +
            "    (a.frequ_code <> 'ONCE' or isnull(b.frequ_type,'')='1') and\n" +
            "        a.status_flag > '1'   and\n" +
            "        a.inpatient_no = c.inpatient_no  and\n" +
            "        a.admiss_times = c.admiss_times  and\n" +
            "        a.order_code   = b.order_code    and\n" +
            "        a.group_no     ='00'  and\n" +
            "        a.doctor_flag='1'\n" +
            " union all\n" +
            " SELECT act_order_no=a.act_order_no,\n" +
            "              inpatient_no=a.inpatient_no,\n" +
            "              name        =c.name,\n" +
            "              dept_code   =a.ward_code,\n" +
            "              bed_no      =c.bed_no,\n" +
            "              sex         =c.sex,\n" +
            "              age         =space(10),\n" +
            "              order_name  =rtrim(a.order_name),\n" +
            "              start_time  =case when  isnull(a.parent_no,'')=''  then a.start_time else (select start_time from yz_act_order where a.parent_no=act_order_no) end,\n" +
            "              print_page     =a.print_page,\n" +
            "              doctor_code     =physician,\n" +
            "              nurse_code      =executer1,\n" +
            "              self_buy        =a.self_buy,\n" +
            "              page_no         =isnull(print_page,'0'),\n" +
            "              page_no_old     =0,\n" +
            "              last_rows       =0,\n" +
            "              modifier        =a.modifier,\n" +
            "              executer2       =a.executer2,\n" +
            "              drug_quan       =a.drug_quan,\n" +
            "              dose            =a.dose,\n" +
            "              dose_unit       =a.dose_unit,\n" +
            "               frequ_code =(select print_name from yz_order_frequency where a.frequ_code =code), " +
            "              supply_code     =a.supply_code,\n" +
            "              spec            =a.drug_specification,\n" +
            "              group_no        =a.group_no,\n" +
            "              parent_no       =a.parent_no,\n" +
            "              instruction     =a.instruction,\n" +
            "              parent_flag     =space(2),\n" +
            "              parent_flag2     =space(2),\n" +
            "              end_time        =a.end_time,\n" +
            "              ps_status=case when a.ps_status is null then ''\n" +
            "                             when a.ps_status='0'then '皮试:阴性'else '皮试:阳性'end,\n" +
            "              a.ps_oper,\n" +
            "              a.ps_time,\n" +
            "              act_order_no_b=case when parent_no is null then act_order_no else parent_no end ,\n" +
            "              order_time_b= case when isnull(a.parent_no,'')='' then convert(char(16),a.confirm_time,121) else (select convert(char(16),confirm_time,121) from yz_act_order where a.parent_no=act_order_no) end,\n" +
            "              order_name2 =space(32),\n" +
            "              exec_id,\n" +
            "              exec_id2 = a.executer2 ,\n" +
            "              cx_flag='0',\n" +
            "              sort_no=0,\n" +
            "              a.confirm_time,\n" +
            " new_order_name_code = isnull(a.instruction,'') +(case when isnull(ps_status,'')='' then '' when ps_status='0'then '皮试:阴性'else '皮试:阳性'end) + ' ' +\n" +
            "                                    (case when a.self_buy = '1' then '自备'when a.self_buy = '2' then '嘱托' else '' end) + ' ' +\n" +
            "                                    (case when isnull(a.supply_code,'') = '' then '' else (select print_name from yz_supply_type where  supply_code = a.supply_code) end ),\n" +
            "              new_order_name = rtrim(a.order_name) + (case when a.group_no <> '00' then (case when isnull(a.drug_specification,'')=''then '' else '(' + isnull(a.drug_specification,'')+')' end) + ' ' +\n" +
            "                                                                                        (case when isnull(a.dose_unit,'') = '' then '' else  rtrim(a.dose) + (select name from yp_zd_unit where code=a.dose_unit) end) + ' ' +\n" +
            "                                                                                        (case when isnull(a.dose_unit,'') = '' then '' else  '共'+ rtrim(a.drug_quan) + (select name from yp_zd_unit where code=a.mini_unit) end) else isnull(a.drug_specification,'') end  )"+
            " FROM       ${tableName} a, view_zy_patient_all c\n" +
            " WHERE       a.inpatient_no = #{patNo} and\n" +
            "        a.admiss_times = #{times} AND\n" +
            "    ${pageCondition} and"  +
            "    (a.frequ_code <> 'ONCE' ) and\n" +
            "        a.status_flag > '1'   and\n" +
            "        a.inpatient_no = c.inpatient_no  and\n" +
            "        a.admiss_times = c.admiss_times  and\n" +
            "        a.group_no     <> '00'      and\n" +
            "        a.doctor_flag='1'\n" +
            "order by page_no,confirm_time,act_order_no_b,act_order_no")
    List<YzPrintVO> getcqYzPrint(@Param("patNo") String patNo, @Param("times")Integer times,@Param("pageCondition")String pageCondition,@Param("tableName")String tableName);
    @Select("SELECT act_order_no=a.act_order_no,\n" +
            "              inpatient_no=a.inpatient_no,\n" +
            "              name        =c.name,\n" +
            "              dept_code   =a.dept_code,\n" +
            "              bed_no      =c.bed_no,\n" +
            "              sex         =c.sex,\n" +
            "              age         =space(10),\n" +
            "              order_name  =rtrim(a.order_name),\n" +
            "              order_name1  =rtrim(a.order_name),\n" +
            "              start_time  =case when  isnull(a.parent_no,'')=''  then a.start_time else (select start_time from yz_act_order where a.parent_no=act_order_no) end,\n" +
            "              print_page_once=a.print_page_once,\n" +
            "              doctor_code     =physician,\n" +
            "              nurse_code      =executer1,\n" +
            "              self_buy        =a.self_buy,\n" +
            "              page_no         =isnull(print_page_once,0),\n" +
            "              page_no_old     =0,\n" +
            "              last_rows       =0,\n" +
            "              modifier        =a.modifier,\n" +
            "              executer2       =a.executer2,\n" +
            "              drug_quan       =a.drug_quan,\n" +
            "              dose            =a.dose ,\n" +
            "              dose_unit       =a.dose_unit,\n" +
            "              frequ_code =(select print_name from yz_order_frequency where a.frequ_code =code)," +
            "              supply_code     =a.supply_code,\n" +
            "              spec            =a.drug_specification,\n" +
            "              group_no        =a.group_no,\n" +
            "              parent_no       =a.parent_no,\n" +
            "              instruction     =a.instruction,\n" +
            "              parent_flag     =space(2),\n" +
            "              parent_flag2     =space(2),\n" +
            "              end_time        =a.end_time,\n" +
            "              exec_time=a.exec_time,\n" +
            "              exec_id  =a.exec_id,\n" +
            "              ps_status=case when isnull(ps_status,'')='' then ''\n" +
            "                             when ps_status='0'then '皮试:阴性'else '皮试:阳性'end,\n" +
            "              a.ps_oper,\n" +
            "              a.ps_time,\n" +
            "              act_order_no_b=case when isnull(a.parent_no,'')='' then a.act_order_no else a.parent_no end,\n" +
            "              exec_id2 = a.exec_id2 ,\n" +
            "              order_time_b= case when isnull(a.parent_no,'')='' then convert(char(16),a.confirm_time,121) else (select convert(char(16),confirm_time,121) from yz_act_order where a.parent_no=act_order_no) end,a.drug_occ,a.ward_code,\n" +
            "              cx_flag='0',\n" +
            "              sort_no=0,\n" +
            "              mini_unit = a.mini_unit,\n" +
            "              new_order_name_code = isnull(a.instruction,'') +(case when isnull(ps_status,'')='' then '' when ps_status='0'then '皮试:阴性'else '皮试:阳性'end) + ' ' +\n" +
            "                                    (case when a.self_buy = '1' then '自备'when a.self_buy = '2' then '嘱托' else '' end) + ' ' +\n" +
            "                                    (case when isnull(a.supply_code,'') = '' then '' else (select print_name from yz_supply_type where  supply_code = a.supply_code) end ),\n" +
            "              new_order_name = rtrim(a.order_name) + (case when a.group_no <> '00' or a.order_code = '06248' then (case when isnull(a.drug_specification,'')=''then '' else '(' + isnull(a.drug_specification,'')+')' end) + ' ' +\n" +
            "                                                                                                                  (case when isnull(a.dose_unit,'') = '' then '' else  rtrim(a.dose) + (select name from yp_zd_unit where code=a.dose_unit) end) + ' ' +\n" +
            "                                                                                                                  (case when isnull(a.dose_unit,'') = '' then '' else  '共'+ rtrim(a.drug_quan) + (select name from yp_zd_unit where code=a.mini_unit) end) else ' ' end),\n" +
            "              a.confirm_time\n" +
            " FROM       ${tableName} a, yz_order_item b,view_zy_patient_all c\n" +
            " WHERE       a.inpatient_no = #{patNo} and\n" +
            "        a.admiss_times = #{times} AND\n" +
            "    ${pageCondition} and\n" +
            "    (a.frequ_code = 'ONCE' ) and\n" +
            "        a.status_flag > '1'   and\n" +
            "        a.inpatient_no = c.inpatient_no  and\n" +
            "        a.admiss_times = c.admiss_times  and\n" +
            "        a.doctor_flag='1' and\n" +
            "        a.group_no='00' and\n" +
            "        a.order_code =b.order_code       and\n" +
            "        isnull(b.frequ_type,'') <> '1'\n" +
            " union\n" +
            " SELECT act_order_no=a.act_order_no,\n" +
            "              inpatient_no=a.inpatient_no,\n" +
            "              name        =c.name,\n" +
            "              dept_code   =a.dept_code,\n" +
            "              bed_no      =c.bed_no,\n" +
            "              sex         =c.sex,\n" +
            "              age         =space(10),\n" +
            "              order_name  =rtrim(a.order_name),\n" +
            "              order_name1  =rtrim(a.order_name),\n" +
            "              start_time  =case when  isnull(a.parent_no,'')=''  then a.start_time else (select start_time from yz_act_order where a.parent_no=act_order_no) end,\n" +
            "              print_page_once=a.print_page_once,\n" +
            "              doctor_code     =physician,\n" +
            "              nurse_code      =executer1,\n" +
            "              self_buy        =a.self_buy,\n" +
            "              page_no         =isnull(print_page_once,0),\n" +
            "              page_no_old     =0,\n" +
            "              last_rows       =0,\n" +
            "              modifier        =a.modifier,\n" +
            "              executer2       =a.executer2,\n" +
            "              drug_quan       =a.drug_quan,\n" +
            "              dose            =a.dose ,\n" +
            "              dose_unit       =a.dose_unit,\n" +
            "               frequ_code =(select print_name from yz_order_frequency where a.frequ_code =code)," +
            "              supply_code     =a.supply_code,\n" +
            "              spec            =a.drug_specification,\n" +
            "              group_no        =a.group_no,\n" +
            "              parent_no       =a.parent_no,\n" +
            "              instruction     =a.instruction,\n" +
            "              parent_flag     =space(2),\n" +
            "              parent_flag2     =space(2),\n" +
            "              end_time        =a.end_time,\n" +
            "              exec_time=a.exec_time,\n" +
            "              exec_id  =a.exec_id,\n" +
            "              ps_status=case when isnull(ps_status,'')='' then ''\n" +
            "                             when ps_status='0'then '皮试:阴性'else '皮试:阳性'end,\n" +
            "              a.ps_oper,\n" +
            "              a.ps_time,\n" +
            "              act_order_no_b=case when isnull(a.parent_no,'')='' then a.act_order_no else a.parent_no end,\n" +
            "              exec_id2 = a.exec_id2 ,\n" +
            "              order_time_b= case when isnull(a.parent_no,'')='' then convert(char(16),a.confirm_time,121) else (select convert(char(16),confirm_time,121) from yz_act_order where a.parent_no=act_order_no) end,a.drug_occ,a.ward_code,\n" +
            "              cx_flag='0',\n" +
            "              sort_no=0,\n" +
            "              mini_unit = a.mini_unit,\n" +
            "              new_order_name_code = isnull(a.instruction,'') +(case when isnull(ps_status,'')='' then '' when ps_status='0'then '皮试:阴性'else '皮试:阳性'end) + ' ' +\n" +
            "                                    (case when a.self_buy = '1' then '自备'when a.self_buy = '2' then '嘱托' else '' end) + ' ' +\n" +
            "                                    (case when isnull(a.supply_code,'') = '' then '' else (select print_name from yz_supply_type where  supply_code = a.supply_code) end ),\n" +
            "              new_order_name = rtrim(a.order_name) + (case when a.group_no <> '00' then (case when isnull(a.drug_specification,'')=''then '' else '(' + isnull(a.drug_specification,'')+')' end) + ' ' +\n" +
            "                                                                                        (case when isnull(a.dose_unit,'') = '' then '' else  rtrim(a.dose) + (select name from yp_zd_unit where code=a.dose_unit) end) + ' ' +\n" +
            "                                                                                        (case when isnull(a.dose_unit,'') = '' then '' else  '共'+ rtrim(a.drug_quan) + (select name from yp_zd_unit where code=a.mini_unit) end) else isnull(a.drug_specification,'') end  ),\n" +
            "              a.confirm_time\n" +
            " FROM       ${tableName} a, view_zy_patient_all c\n" +
            " WHERE       a.inpatient_no = #{patNo} and\n" +
            "        a.admiss_times = #{times} AND\n" +
            "    ${pageCondition} and\n" +
            "    (a.frequ_code = 'ONCE' ) and\n" +
            "        a.status_flag > '1'   and\n" +
            "        a.inpatient_no = c.inpatient_no  and\n" +
            "        a.admiss_times = c.admiss_times  and\n" +
            "        a.doctor_flag='1' and\n" +
            "        a.group_no <> '00'\n" +
            " union\n" +
            " SELECT act_order_no=a.act_order_no,\n" +
            "              inpatient_no=a.inpatient_no,\n" +
            "              name        =c.name,\n" +
            "              dept_code   =a.dept_code,\n" +
            "              bed_no      =c.bed_no,\n" +
            "              sex         =c.sex,\n" +
            "              age         =space(10),\n" +
            "              order_name  =rtrim(a.order_name),\n" +
            "              order_name1  =rtrim(a.order_name),\n" +
            "              start_time  =case when  isnull(a.parent_no,'')=''  then a.start_time else (select start_time from yz_act_order where a.parent_no=act_order_no) end,\n" +
            "              print_page_once=a.print_page_once,\n" +
            "              doctor_code     =physician,\n" +
            "              nurse_code      =executer1,\n" +
            "              self_buy        =a.self_buy,\n" +
            "              page_no         =isnull(print_page_once,0),\n" +
            "              page_no_old     =0,\n" +
            "              last_rows       =0,\n" +
            "              modifier        =a.modifier,\n" +
            "              executer2       =a.executer2,\n" +
            "              drug_quan       =a.drug_quan,\n" +
            "              dose            =a.dose ,\n" +
            "              dose_unit       =a.dose_unit,\n" +
            "               frequ_code =(select print_name from yz_order_frequency where a.frequ_code =code)," +
            "              supply_code     =a.supply_code,\n" +
            "              spec            =a.drug_specification,\n" +
            "              group_no        =a.group_no,\n" +
            "              parent_no       =a.parent_no,\n" +
            "              instruction     =a.instruction,\n" +
            "              parent_flag     =space(2),\n" +
            "              parent_flag2     =space(2),\n" +
            "              end_time        =a.end_time,\n" +
            "              exec_time=a.exec_time,\n" +
            "              exec_id  =a.exec_id,\n" +
            "              ps_status=case when isnull(ps_status,'')='' then ''\n" +
            "                             when ps_status='0'then '皮试:阴性'else '皮试:阳性'end,\n" +
            "              a.ps_oper,\n" +
            "              a.ps_time,\n" +
            "              act_order_no_b=case when isnull(a.parent_no,'')='' then a.act_order_no else a.parent_no end,\n" +
            "              exec_id2 = a.exec_id2 ,\n" +
            "              order_time_b= case when  isnull(a.parent_no,'')=''  then convert(char(16),a.confirm_time,121) else (select convert(char(16),confirm_time,121) from yz_act_order where a.parent_no=act_order_no) end,a.drug_occ,a.ward_code,\n" +
            "              cx_flag='0',\n" +
            "              sort_no=0,\n" +
            "              mini_unit = a.mini_unit,\n" +
            "              new_order_name_code = isnull(a.instruction,'') +(case when isnull(ps_status,'')='' then '' when ps_status='0'then '皮试:阴性'else '皮试:阳性'end) + ' ' +\n" +
            "                                    (case when a.self_buy = '1' then '自备'when a.self_buy = '2' then '嘱托' else '' end) + ' ' +\n" +
            "                                    (case when isnull(a.supply_code,'') = '' then '' else (select print_name from yz_supply_type where  supply_code = a.supply_code) end ),\n" +
            "              new_order_name = rtrim(a.order_name) + (case when a.group_no <> '00' then (case when isnull(a.drug_specification,'')=''then '' else '(' + isnull(a.drug_specification,'')+')' end) + ' ' +\n" +
            "                                                                                        (case when isnull(a.dose_unit,'') = '' then '' else  rtrim(a.dose) + (select name from yp_zd_unit where code=a.dose_unit) end) + ' ' +\n" +
            "                                                                                        (case when isnull(a.dose_unit,'') = '' then '' else  '共'+ rtrim(a.drug_quan) + (select name from yp_zd_unit where code=a.mini_unit) end) else isnull(a.drug_specification,'') end  ),\n" +
            "              a.confirm_time\n" +
            " FROM       ${tableName} a, view_zy_patient_all c\n" +
            " WHERE       a.inpatient_no = #{patNo} and\n" +
            "        a.admiss_times = #{times} AND\n" +
            "   ${pageCondition}  and\n" +
            "    (a.frequ_code = 'ONCE' ) and\n" +
            "        a.status_flag > '1'   and\n" +
            "        a.inpatient_no = c.inpatient_no  and\n" +
            "        a.admiss_times = c.admiss_times  and\n" +
            "        a.doctor_flag='1' and\n" +
            "        a.group_no = '00' and\n" +
            "    (a.order_name like '%草药%' or a.order_name like '%会诊%')\n" +
            "order by page_no,confirm_time,act_order_no_b")
    List<YzPrintVO> getlsYzPrint(@Param("patNo") String patNo, @Param("times")Integer times,@Param("pageCondition")String pageCondition,@Param("tableName") String tableName);
    @Select("select\n" +
            "                   RTRIM(a.bed_no) bedNo,\n" +
            "                   RTRIM(a.inpatient_no) inpatientNo,\n" +
            "                   a.admiss_times,\n" +
            "                   RTRIM(a.name) as name,\n" +
            "    sex=isnull(a.sex, 9)\n" +
            " from ${tableName}  a with(nolock) ${ew.customSqlSegment}" +
            " ORDER BY cast(a.bed_no AS int)")
    List<Patient> queryPatientInfo(@Param(Constants.WRAPPER)QueryWrapper<?> query,@Param("tableName")String tableName);
    @Select("select top 1 1  from op_record where inpatient_no=#{patNo} and admiss_times=#{times}")
    Integer existOprt(@Param("patNo") String patNo, @Param("times")Integer times);
    @Select(" select max(print_page) print_page,max(print_page_once) print_page_once  from  ${tableName} where inpatient_no=#{patNo} and admiss_times =#{times} ")
    YzPrintVO selectMaxPagaNo(YzOrderParam param);
    @Update(" UPDATE yz_act_order SET ${printPageWhere} = #{pageNo} WHERE act_order_no in  (${orderNoList})")
    void updatePrintPageNo(@Param("orderNoList") String orderNoList,@Param("pageNo")Integer pageNo, @Param("printPageWhere")String printPageWhere);
    @Update(" update  ${tableName}  set  ${printPageWhere}  where inpatient_no =#{param.patNo} and admiss_times =#{param.times}")
    void updatePrintPage(@Param("param") YzOrderParam param, @Param("printPageWhere") String printPageWhere,@Param("tableName") String tableName);
    @Select("<script>" +
            " SELECT act_order_no=a.act_order_no," +
            "       inpatient_no=a.inpatient_no," +
            "       dept_code =a.dept_code," +
            "       order_name =rtrim(a.order_name + isnull(drug_specification, ''))," +
            "       start_time =a.start_time," +
            "       physician =(select name from a_employee_mi where code= physician)," +
            "       executer1 =(select name from a_employee_mi where code = executer1)," +
            "       page_no =isnull(print_order, '0')," +
            "       modifier =  (select name from a_employee_mi where code = a.modifier)," +
            "       executer2 =(select name from a_employee_mi where code = a.executer2)," +
            "       drug_quan =a.drug_quan," +
            "       dose =a.dose," +
            "       dose_unit =(select name from yp_zd_unit where code = a.dose_unit),"+
            "       frequ_code =(select print_name from yz_order_frequency where code = a.frequ_code)," +
            "       supply_code =(select print_name from yz_supply_type where supply_code = a.supply_code)," +
            "       a.drug_specification," +
            "       parent_no =case when parent_no is null then act_order_no else parent_no end," +
            "       instruction =a.instruction," +
            "       end_time =a.end_time," +
            "       order_time_b= convert(char(16), order_time, 121)," +
            "       status_flag=a.status_flag," +
            "         a.group_no," +
            "       exec_id=(select name from a_employee_mi where code = a.exec_id)," +
            "       a.exec_time" +
            " FROM yz_act_order a," +
            "     yz_order_item b" +
            " WHERE a.inpatient_no =  #{patNo}" +
            "  and a.admiss_times = #{times}" +
            "  AND a.dept_code = #{wardCode}" +
            "<if test=\" yzType == '0'.toString \">"+
            "  AND  (a.frequ_code != 'ONCE' or isnull(frequ_type, '0') = '1')" +
            "</if>"+
            "<if test=\" yzType == '1'.toString \">"+
            "  AND (a.frequ_code = 'ONCE' )" +
            "</if>"+
            "<if test=\" queryRange == '0'.toString \">"+
            "  and a.status_flag &gt; '1'" +
            "</if>"+
            "<if test=\" queryRange == '1'.toString \">"+
            "  and a.status_flag = '5'" +
            "</if>"+
            "<if test=\" queryRange == '2'.toString \">"+
            "  and a.status_flag in ('2','3','4')" +
            "</if>"+
            "<if test=\" startTime !=null \">"+
            "  and a.start_time &gt;= #{startTime}" +
            "</if>"+
            "<if test=\" endTime !=null \">"+
            "  and a.start_time &lt;= #{endTime}" +
            "</if>"+
            "  and a.order_code = b.order_code" +
            "  and a.group_no = '00'" +
            "  and a.doctor_flag = '1'" +
            " union all" +
            " SELECT act_order_no=a.act_order_no," +
            "       inpatient_no=a.inpatient_no," +
            "       dept_code =a.dept_code," +
            "       order_name =rtrim(a.order_name + isnull(drug_specification, ''))," +
            "       start_time =a.start_time," +
            "       doctor_code =(select name from a_employee_mi where code= physician)," +
            "       nurse_code =(select name from a_employee_mi where code = executer1)," +
            "       page_no =isnull(print_order, '0')," +
            "       modifier =  (select name from a_employee_mi where code = a.modifier)," +
            "       executer2 =(select name from a_employee_mi where code = a.executer2)," +
            "       drug_quan =a.drug_quan," +
            "       dose =a.dose," +
            "       dose_unit =(select name from yp_zd_unit where code = a.dose_unit),"+
            "       frequ_code =(select print_name from yz_order_frequency where code = a.frequ_code)," +
            "       supply_code =(select print_name from yz_supply_type where supply_code = a.supply_code)," +
            "       a.drug_specification," +
            "       parent_no =case when parent_no is null then act_order_no else parent_no end," +
            "       instruction =a.instruction," +
            "       end_time =a.end_time," +
            "       order_time_b= convert(char(16), order_time, 121)," +
            "       status_flag=a.status_flag," +
            "        a.group_no," +
            "       exec_id=(select name from a_employee_mi where code = a.exec_id)," +
            "       a.exec_time" +
            " FROM yz_act_order a" +
            " WHERE a.inpatient_no = #{patNo}" +
            "  and a.admiss_times = #{times}" +
            "  AND a.dept_code = #{wardCode}" +
            "<if test=\" yzType == '0'.toString \">"+
            "  AND (a.frequ_code != 'ONCE')" +
            "</if>"+
            "<if test=\" yzType == '1'.toString \">"+
            "  AND (a.frequ_code = 'ONCE')" +
            "</if>"+
            "<if test=\" queryRange == '0'.toString \">"+
            "  and a.status_flag &gt; '1'" +
            "</if>"+
            "<if test=\" queryRange == '1'.toString \">"+
            "  and a.status_flag = '5'" +
            "</if>"+
            "<if test=\" queryRange == '2'.toString \">"+
            "  and a.status_flag in ('2','3','4')" +
            "</if>"+
            "<if test=\" startTime !=null \">"+
            "  and a.start_time &gt;= #{startTime}" +
            "</if>"+
            "<if test=\" endTime !=null \">"+
            "  and a.start_time &lt;= #{endTime}" +
            "</if>"+
            "  and a.group_no != '00'" +
            "  and a.doctor_flag = '1'" +
            " order by page_no, order_time_b, parent_no, act_order_no"+
            "</script>")
    List<YzActOrder> listYzCheckData(YzQueryBase yzQueryBase);
}
