<?php
/**
 *
 * @author：llbjj
 * @DateTime：2022/5/6 10:57
 * @Description：
 *
 */

namespace Application\Service\DB\Worklist;

use Application\Service\Extension\Helper\StringHelper;
use Interop\Container\ContainerInterface;
use Laminas\Db\Sql\Predicate\Expression;
use Laminas\Db\Sql\Predicate\Operator;

class Patientworklist extends \Application\Service\DB\AbstractDb
{
    public function __construct($dbAdapter, ContainerInterface $container)
    {
        $this->tableName = 'yikeen_worklist_patientworklist';
        parent::__construct($dbAdapter, $container);
    }

    /**
     * Notes: 获取指定条件下受试者检查点下有设置值的信息
     * User: lltyy
     * DateTime: 2022/10/18 18:01
     *
     * @param $where
     * @param int $work_type
     * @param int $return_type 【返回类型 0 ID值数组 1 数据】
     */
    public function getSetInfo($where,$work_type=1,$return_type=0){
        $set_info = [
            'confirm_no'=>[],
            'confirm_yes'=>[]
        ];
        $cond = [
            'where'=>$where,
            'columns'=>['category_id','info_id','workset_id','confirmation_result','worklistset_user_ids','confirmation_remark','itemsig_worklist_id']
        ];
        $datas = $this->fetchAll($cond);
        if(!empty($datas)){
            foreach($datas as $data){
                $data_category = $data['category_id'];
                $data_info = $data['info_id'];
                $info_key = $data_category.'_'.$data_info;
                if($work_type == 2){
                    $info_key .= '_'.$data['workset_id'];
                }
                if(!empty($data['worklistset_user_ids']) || !empty($data['confirmation_remark']) || !empty($data['confirmation_result'])){
                    if($return_type == 1){
                        if($data['confirmation_result'] != 1){
                            $set_info['confirm_no'][$info_key][] = $data['itemsig_worklist_id'];
                        }else{
                            $set_info['confirm_yes'][$info_key][] = $data['itemsig_worklist_id'];
                        }
                    }else{
                        if($data['confirmation_result'] != 1){
                            $set_info['confirm_no'][] = $info_key;
                        }else{
                            $set_info['confirm_yes'][] = $info_key;
                        }
                    }
                }
            }
        }
        return $set_info;
    }

    /**
     * Notes:获取指定条件下的数据，category_info 为键值，信息为值
     * User: lltyy
     * DateTime: 2022/10/19 15:58
     *
     * @param $where
     */
    public function fetchDataByCategoryAndInfo($where,$key=0){
        $data = [];
        //获取项目工作清单信息
        $columns = ['id','category_id','info_id','workset_id'];
        if($key == 1){
            $columns = ['id','category_id','info_id','workset_id','patient_id','patientchecktime_id','work_type','itemsig_worklist_id','confirmation_result'];
        }
        $where_cond = [
            'where'=>$where,
            'columns'=>$columns,
            'order'=>['id']
        ];
        $work_datas = $this->fetchAll($where_cond);
        if(!empty($work_datas)){
            foreach($work_datas as $work_data){
                if($key == 1){
                    $patient_checktime_key = $work_data['patient_id'].'_'.$work_data['patientchecktime_id'];
                    $category_info_key = $work_data['category_id'].'_'.$work_data['info_id'];
                    $work_type = $work_data['work_type'];
                    $work_key = $work_data['workset_id'];
                    if(in_array($work_type,[1,2])){
                        $work_key = $work_data['itemsig_worklist_id'];
                    }
                    $data[$patient_checktime_key][$work_type][$category_info_key][$work_key] = [
                        'id'=>$work_data['id'],
                        'confirmation_result'=>$work_data['confirmation_result']
                    ];
                }else{
                    $work_key = $work_data['category_id'].'_'.$work_data['info_id'].'_'.$work_data['workset_id'];
                    $data[$work_key] = $work_data;
                }
            }
        }
        return $data;
    }

    /**
     * Notes:同步设置信息【目前只适用work_type=1的数据】
     * User: lltyy
     * DateTime: 2022/10/19 15:47
     *
     * @param $arr
     */
    public function updateSameSet($arr){
        $item_id = $arr['item_id'] ? $arr['item_id'] : 0;
        $itemsig_id = $arr['itemsig_id'] ? $arr['itemsig_id'] : 0;
        $patient_id = $arr['patient_id'] ? $arr['patient_id'] : 0;
        $researchstage_id = $arr['researchstage_id'] ? $arr['researchstage_id'] : 0;
        $checktime_id = $arr['checktime_id'] ? $arr['checktime_id'] : 0;
        $patientchecktime_id = $arr['patientchecktime_id'] ? $arr['patientchecktime_id'] : 0;
        $work_type = $arr['work_type'] ? $arr['work_type'] : 0;
        //获取已有数据信息
        $worklistDatas = $this->fetchDataByCategoryAndInfo([
            'is_del' => 0,
            'patientchecktime_id' => $patientchecktime_id,
            'work_type' => $work_type,
        ]);
        $sigworklistDatas = $this->LocalService()->worklistSigworklist->getDataByWork([
            'is_del' => 0,
            'itemsig_id' => $itemsig_id,
            'work_type' => $work_type,
        ],1);

        foreach ($arr['update_same'] as $sameCategoryInfo=>$sameData){
            $sameCategoryInfo_arr = explode('_',$sameCategoryInfo);
            $same_workset_id = empty($sameCategoryInfo_arr[2]) ? 0 : $sameCategoryInfo_arr[2];
            $update_same = [
                'item_id' => $item_id,
                'itemsig_id' => $itemsig_id,
                'patient_id' => $patient_id,
                'researchstage_id' => $researchstage_id,
                'checktime_id' => $checktime_id,
                'patientchecktime_id' => $patientchecktime_id,
                'work_type' => $work_type,
                'category_id' => empty($sameCategoryInfo_arr[0]) ? 0 : $sameCategoryInfo_arr[0],
                'info_id' => empty($sameCategoryInfo_arr[1]) ? 0 : $sameCategoryInfo_arr[1],
                'workset_id' => $same_workset_id,
                'itemsig_worklistset_id' => 0,
                'itemsig_worklist_id' => 0,
                'worklistset_user_ids' => empty($sameData['worklistset_user_ids']) ? '' : $sameData['worklistset_user_ids'],
                'confirmation_result' => empty($sameData['confirmation_result']) ? NULL : $sameData['confirmation_result'],
                'confirmation_remark' => empty($sameData['confirmation_remark']) ? '' : $sameData['confirmation_remark']
            ];
            $worklist_key = $update_same['category_id'].'_'.$update_same['info_id'];
            if(isset($sigworklistDatas[$worklist_key]) && isset($sigworklistDatas[$worklist_key][$same_workset_id])){
                $update_same['itemsig_worklistset_id'] = empty($sigworklistDatas[$worklist_key][$same_workset_id]['worklistset_id']) ? 0 : $sigworklistDatas[$worklist_key][$same_workset_id]['worklistset_id'];
                $update_same['itemsig_worklist_id'] = empty($sigworklistDatas[$worklist_key][$same_workset_id]['id']) ? 0 : $sigworklistDatas[$worklist_key][$same_workset_id]['id'];
            }
            if(isset($worklistDatas[$sameCategoryInfo])){
                $update_same['id'] = $worklistDatas[$sameCategoryInfo]['id'];
            }
            $this->save($update_same);
        }


        return 200;
    }

    /**
     * Notes: 获取受试者设置信息
     * User: lltyy
     * DateTime: 2022/10/27 10:40
     *
     * @param $arr
     */
    public function confirmPatientData($arr){
        $item_id = $arr['item_id'] ? $arr['item_id'] : 0;
        $itemsig_id = $arr['itemsig_id'] ? $arr['itemsig_id'] : 0;

        //获取中心下设置的信息
        $itemsig_set_where = [
            'is_del' => 0,
            'work_type' => [1, 2],
            'itemsig_id' => $itemsig_id,
            [
                'or' => [
                    new Operator('workset_value', Operator::OP_NE, ''),
                    new Operator('worklistset_ids', Operator::OP_NE, ''),
                    new Operator('workset_remark', Operator::OP_NE, ''),
                ]
            ]
        ];
        $itemsig_set_infos = $this->LocalService()->worklistSigworklist->getSetInfo($itemsig_set_where,[1,2]);
        $itemsig_setflows = isset($itemsig_set_infos[1]) && !empty($itemsig_set_infos[1]) ? $itemsig_set_infos[1] : [];//流程图设置
        $itemsig_setcustomnames = isset($itemsig_set_infos[2]) && !empty($itemsig_set_infos[2]) ? $itemsig_set_infos[2] : [];//药物器械设置

        //获取该中心下的受试者设置信息
        $patient_set_where = [
            'is_del' => 0,
            'work_type' => [1, 2],
            'itemsig_id' => $itemsig_id,
            [
                'or' => [
                    new Operator('worklistset_user_ids', Operator::OP_NE, ''),
                    new Operator('confirmation_result', Operator::OP_NE, ''),
                    new Operator('confirmation_remark', Operator::OP_NE, ''),
                ]
            ]
        ];
        $patient_set_infos = $this->fetchDataByCategoryAndInfo($patient_set_where,1);

        //获取受试者检查点下的表单信息
        $arr = [
            'confirm_no'=>[],
            'confirm_yes'=>[],
            'no_write'=>[]
        ];
        $patient_checktime_select_arr = [
            'item_id'=>$item_id,
            'itemsig_id'=>$itemsig_id,
            'form_code_arr'=>["RDG","WP","GC","CHECKCATE"],
            'patientform_array_key'=>1
        ];
        $patient_checktime_where = [
            'is_del' => 0,
            'itemsig_id' => $itemsig_id,
        ];
        $patient_checktime_columns = ['id','patient_id','checktime_id','form_info'];
        $patient_checktime_datas = $this->LocalService()->itemPatientchecktime->getPatientChecktimeDatas($patient_checktime_select_arr,$patient_checktime_where,$patient_checktime_columns);
        if(!empty($patient_checktime_datas)){
            foreach($patient_checktime_datas as $patient_checktime_data){
                $patient_checktime_id = $patient_checktime_data['id'];
                $patient_id = $patient_checktime_data['patient_id'];
                $patient_checktime_key = $patient_id.'_'.$patient_checktime_id;

                //判断表单流程设置信息
                $patient_checktime_forms = isset($patient_checktime_data['form_all_info']) && !empty($patient_checktime_data['form_all_info']) ? $patient_checktime_data['form_all_info'] : [];
                if(!empty($patient_checktime_forms)){
                    //获取该受试者检查点设置的表单流程信息
                    $patient_checktime_setflow = isset($patient_set_infos[$patient_checktime_key]) && isset($patient_set_infos[$patient_checktime_key][1]) ? $patient_set_infos[$patient_checktime_key][1] : [];
                    foreach($patient_checktime_forms as $patient_checktime_form_id){
                        $patient_checktime_form_key = $patient_checktime_form_id.'_'.$patient_checktime_form_id;
                        $patient_checktime_form_sets = isset($patient_checktime_setflow[$patient_checktime_form_key]) && !empty($patient_checktime_setflow[$patient_checktime_form_key]) ? $patient_checktime_setflow[$patient_checktime_form_key] : [];
                        //判断该受试者检查点是否有设置该表单流程信息
                        if(!empty($patient_checktime_form_sets)){
                            $itemsig_form_set_arr = isset($itemsig_setflows[$patient_checktime_form_key]) && !empty($itemsig_setflows[$patient_checktime_form_key]) ? $itemsig_setflows[$patient_checktime_form_key] : [];
                            foreach($patient_checktime_form_sets as $patientChecktimeFormSetId=>$patient_checktime_form_set){
                                if($patient_checktime_form_set['confirmation_result'] == 1){
                                    $arr['confirm_yes'][$patient_id] = $patient_id;
                                }else{
                                    $arr['confirm_no'][$patient_id] = $patient_id;
                                }
                                if(isset($itemsig_form_set_arr[$patientChecktimeFormSetId])){
                                    unset($itemsig_form_set_arr[$patientChecktimeFormSetId]);
                                }
                            }
                            if(!empty($itemsig_form_set_arr)){
                                $arr['confirm_no'][$patient_id] = $patient_id;
                            }
                        }else{
                            //判断该表单流程中心是否有设置
                            if(isset($itemsig_setflows[$patient_checktime_form_key]) && !empty($itemsig_setflows[$patient_checktime_form_key])){
                                $arr['no_write'][$patient_id] = $patient_id;
                            }
                        }
                    }
                }

                //判断药物器械设置信息
                if(!empty($itemsig_setcustomnames)){
                    //获取该受试者检查点设置的药物器械信息
                    $patient_checktime_setcustomname = isset($patient_set_infos[$patient_checktime_key]) && isset($patient_set_infos[$patient_checktime_key][2]) ? $patient_set_infos[$patient_checktime_key][2] : [];
                    foreach($itemsig_setcustomnames as $itemsig_setcustomname_key=>$itemsig_setcustomname_arr){
                        $patient_checktime_customname_set = isset($patient_checktime_setcustomname[$itemsig_setcustomname_key]) ? $patient_checktime_setcustomname[$itemsig_setcustomname_key] : [];
                        if(!empty($patient_checktime_customname_set)){
                            foreach($itemsig_setcustomname_arr as $itemsig_setcustomnameid){
                                if(isset($patient_checktime_customname_set[$itemsig_setcustomnameid])){
                                    if($patient_checktime_customname_set[$itemsig_setcustomnameid]['confirmation_result'] == 1){
                                        $arr['confirm_yes'][$patient_id] = $patient_id;
                                    }else{
                                        $arr['confirm_no'][$patient_id] = $patient_id;
                                    }
                                }else{
                                    $arr['confirm_no'][$patient_id] = $patient_id;
                                }
                            }
                        }else{
                            $arr['no_write'][$patient_id] = $patient_id;
                        }
                    }
                }
            }
        }

        //如果未填写受试者在未确认中，则从未填写信息中移除
        if(!empty($arr['no_write'])){
            foreach($arr['no_write'] as $noWritePatient){
                if(in_array($noWritePatient,$arr['confirm_no'])){
                    unset($arr['no_write'][$noWritePatient]);
                }else{
                    if(in_array($noWritePatient,$arr['confirm_yes'])){
                        $arr['confirm_no'][$noWritePatient] = $noWritePatient;
                        unset($arr['no_write'][$noWritePatient]);
                        unset($arr['confirm_yes'][$noWritePatient]);
                    }
                }
            }
        }

        //如果已确认受试者在未确认中，则从已确认信息中移除
        if(!empty($arr['confirm_yes'])){
            foreach($arr['confirm_yes'] as $confirmYesPatient){
                if(in_array($confirmYesPatient,$arr['confirm_no'])){
                    unset($arr['confirm_yes'][$confirmYesPatient]);
                }
            }
        }
        return $arr;

    }


    /**
     * Notes: 更新受试者工作清单人员信息
     * User: lltyy
     * DateTime: 2022/11/21 14:49
     *
     * @param $arr
     * @return int
     */
    public function updateWorkUser($arr){
        $parent_item = $arr['parent_item'] ? $arr['parent_item'] : 0;//主项目ID
        $item_id = $arr['item_id'] ? $arr['item_id'] : 0;//副项目ID
        $itemsig_id = $arr['itemsig_id'] ? $arr['itemsig_id'] : 0;//项目中心ID
        $user_id = $arr['user_id'] ? $arr['user_id'] : 0;//工作流程人员ID
        $where = 'is_del = 0 and find_in_set("'.$user_id.'",worklistset_user_ids)';
        if(!empty($parent_item)){
            $item_arr = $this->LocalService()->itemInfo->fetchCol('id',[
                'is_del' => 0,
                'fid' => $parent_item,
            ]);
            if(!empty($item_arr)){
                $where['item_id'] = StringHelper::toArray($item_arr);
            }else{
                $where = [
                    'id' => 0,
                ];
            }
        }
        if(!empty($item_id)){
            $where['item_id'] = $item_id;
        }
        if(!empty($itemsig_id)){
            $where['itemsig_id'] = $itemsig_id;
        }
        $cond = [
            'where'=>$where,
            'columns'=>['id','worklistset_user_ids']
        ];
        $datas = $this->fetchAll($cond);
        if(!empty($datas)){
            foreach($datas as $data){
                $data_user_arr = explode(',',$data['worklistset_user_ids']);
                $delete_key = array_search($user_id,$data_user_arr);
                unset($data_user_arr[$delete_key]);
                $data_users = !empty($data_user_arr) ? implode(',',$data_user_arr) : "";
                $this->update(['worklistset_user_ids'=>$data_users],['id'=>$data['id']]);
            }
        }
        return 200;
    }

    /**
     * Notes:获取指定信息数据
     * User: lltyy
     * DateTime: 2022/11/22 11:02
     *
     * @param $data
     * @return array
     */
    public function fetchPatientWorkData($data){
        $item_id = isset($data['item_id']) ? $data['item_id'] : 0;//副项目ID
        $itemsig_id = isset($data['itemsig_id']) ? $data['itemsig_id'] : 0;//项目中心ID
        $patient_id = isset($data['patient_id']) ? $data['patient_id'] : 0;//项目中心患者ID
        $patientchecktime_id = isset($data['patientchecktime_id']) ? $data['patientchecktime_id'] : 0;//项目受试者检查点ID
        $work_type = isset($data['work_type']) ? $data['work_type'] : 0;//项目受试者检查点工作类型【1 流程图 2 药物器械】
        $checktime_id = isset($data['checktime_id']) ? $data['checktime_id'] : 0;//项目检查点ID
        $researchstage_id = isset($data['researchstage_id']) ? $data['researchstage_id'] : 0;//项目研究阶段ID
        $info_arr = [];
        //获取检查项信息
        if($work_type == 1){
            //获取该项目该检查点下的表单信息
            $checktime_form_arr = [];
            if(!empty($checktime_id)){
                $checktime_form_arr = $this->LocalService()->itemCheckcontent->fetchCol('form_id', [
                    'is_del' => 0,
                    new Operator('form_id', Operator::OP_GT, 0),
                    'check_id' => $checktime_id,
                ]);
            }else{
                $checktime_form_arr = $this->LocalService()->itemPatientcheckcontent->fetchCol('form_id', [
                    'is_del' => 0,
                    new Operator('form_id', Operator::OP_GT, 0),
                    'patientchecktime_id' => $patientchecktime_id,
                ]);
            }

            //获取该受试者检查点下的表单信息
            $patient_writeform_arr = [
                'now_checktime'=>[],
                'other_checktime'=>[]
            ];
            $patient_overform_arr = [
                'now_checktime'=>[],
                'other_checktime'=>[]
            ];
            $patientform_cond = [
                'where' => [
                    'is_del' => 0,
                    'patient_id' => $patient_id,
                    new Operator('form_id', Operator::OP_GT, 0),
                    new Operator('patientchecktime_id', Operator::OP_GT, 0),
                ],
                'columns'=>['form_id','is_complete','patientchecktime_id']
            ];
            $patientform_datas = $this->LocalService()->patientForm->fetchAll($patientform_cond);
            if(!empty($patientform_datas)){
                foreach($patientform_datas as $patientform_data){
                    $patientform_patientchecktime_id = $patientform_data['patientchecktime_id'];
                    $patientform_data_formid = $patientform_data['form_id'];
                    if($patientform_patientchecktime_id == $patientchecktime_id){
                        $patient_writeform_arr['now_checktime'][] = $patientform_data_formid;
                        if($patientform_data['is_complete'] == 1){
                            $patient_overform_arr['now_checktime'][] = $patientform_data_formid;
                        }
                    }else{
                        $patient_writeform_arr['other_checktime'][] = $patientform_data_formid;
                        if($patientform_data['is_complete'] == 1){
                            $patient_overform_arr['other_checktime'][] = $patientform_data_formid;
                        }
                    }

                }
                $checktime_form_arr = !empty($patient_writeform_arr['now_checktime']) ? array_merge($checktime_form_arr,$patient_writeform_arr['now_checktime']) : $checktime_form_arr;
            }
            unset($patientform_datas);

            $checktime_form_arr = array_unique($checktime_form_arr);
            if(!empty($checktime_form_arr)){
                $itemform_cond = [
                    'where'=> [
                        'is_del' => 0,
                        'id' => StringHelper::toArray($checktime_form_arr)
                    ],
                    'columns'=>['id','name','group_id'],
                    'order'=>['order']
                ];
                $info_arr = $this->LocalService()->itemForm->fetchAll($itemform_cond);
                if(!empty($info_arr)){
                    //获取贯穿全程的ID
                    $formGroupWpId = $this->LocalService()->dictionaryFormGroup->getOneFieldVal('id','is_del = 0 and code = "WP"');
                    foreach($info_arr as &$checkCatgory){
                        $form_groupid = $checkCatgory['group_id'];
                        unset($checkCatgory['group_id']);
                        $checkCatgory['info_id'] = $checkCatgory['id'];
                        $checkCatgory['info_id'] = $checkCatgory['id'];
                        $checkCatgory['dic_workset_id'] = 0;
                        $checkCatgory['category_id'] = $checkCatgory['id'];
                        $checkCatgory['info_key'] = $checkCatgory['id'].'_'.$checkCatgory['id'];
                        $is_write = $is_finish = 0;
                        if($form_groupid == $formGroupWpId){
                            $is_write = in_array($checkCatgory['id'],$patient_writeform_arr['now_checktime']) || in_array($checkCatgory['id'],$patient_writeform_arr['other_checktime']) ? 1 : 0;
                            $is_finish = in_array($checkCatgory['id'],$patient_overform_arr['now_checktime']) || in_array($checkCatgory['id'],$patient_overform_arr['other_checktime']) ? 1 : 0;
                        }else{
                            $is_write = in_array($checkCatgory['id'],$patient_writeform_arr['now_checktime']) ? 1 : 0;
                            $is_finish = in_array($checkCatgory['id'],$patient_overform_arr['now_checktime']) ? 1 : 0;
                        }
                        //表单填写情况
                        $checkCatgory['is_write'] = $is_write;
                        $checkCatgory['is_write_text'] = $is_write == 1 ? '已填写' : '未填写';

                        //表单完成情况
                        $checkCatgory['is_finish'] = $is_finish;
                        $checkCatgory['is_finish_text'] = $is_finish == 1 ? '已完成' : '未完成';
                    }
                }
            }
            $data_info_key = count($info_arr);
            unset($checktime_form_arr);
            unset($patient_writeform_arr);
            unset($patient_overform_arr);

            //获取该项目下设置的自定义检查项信息
            $itemother_child_cond = [
                'where'=> [
                    'is_del' => 0,
                    'work_type' => 1,
                    'item_id' => $item_id,
                ],
                'columns'=>['id','name'=>'medical_name'],
                'order'=>['medical_order']
            ];
            $itemother_childs = $this->LocalService()->worklistItemcustomname->fetchAll($itemother_child_cond);
            if(!empty($itemother_childs)){
                foreach($itemother_childs as &$itemother_child){
                    $itemother_child['name'] = '项目自定义 - ' . $itemother_child['name'];
                    $itemother_child['info_id'] = $itemother_child['id'];
                    $itemother_child['dic_workset_id'] = 0;
                    $itemother_child['category_id'] = -2;
                    $itemother_child['info_key'] = '-2_'.$itemother_child['id'];
                    //表单填写情况
                    $itemother_child['is_write'] = '-';
                    $itemother_child['is_write_text'] = '--';

                    //表单完成情况
                    $itemother_child['is_finish'] = '-';
                    $itemother_child['is_finish_text'] = '--';

                    $info_arr[$data_info_key] = $itemother_child;
                    $data_info_key++;
                }
            }
            unset($itemother_childs);

            //获取该项目中心下设置的自定义检查项信息
            $other_child_cond = [
                'where'=> [
                    'is_del' => 0,
                    'work_type' => 1,
                    'item_id' => $item_id,
                    'itemsig_id' => $itemsig_id,
                ],
                'columns'=>['id','name'=>'medical_name'],
                'order'=>['medical_order']
            ];
            $other_childs = $this->LocalService()->worklistSigcustomname->fetchAll($other_child_cond);
            if(!empty($other_childs)){
                foreach($other_childs as &$other_child){
                    $other_child['name'] = '中心自定义 - '.$other_child;
                    $other_child['info_id'] = $other_child['id'];
                    $other_child['dic_workset_id'] = 0;
                    $other_child['category_id'] = '-1_'.$other_child['id'];
                    //表单填写情况
                    $other_child['is_write'] = '-';
                    $other_child['is_write_text'] = '--';

                    //表单完成情况
                    $other_child['is_finish'] = '-';
                    $other_child['is_finish_text'] = '--';

                    $info_arr[$data_info_key] = $other_child;
                    $data_info_key++;
                }
            }
            unset($other_childs);
        }

        //获取药物器械信息
        if($work_type == 2){
            //获取表单信息
            $dicWorksetData = [];
            $dicworkset_cond = [
                'where'=> [
                    'is_del' => 0,
                    'work_type' => $work_type,
                    new Expression("find_in_set(2, user_type)"),
                ],
                'columns'=>['id','name'=>'work_name'],
            ];
            $dicWorksetData = $this->LocalService()->dictionaryWorkset->fetchAll($dicworkset_cond);

            //查询项目药物器械信息
            $itemwork_cond = [
                'where'=> [
                    'is_del' => 0,
                    'item_id' => $item_id,
                    'work_type' => 2,
                ],
                'columns'=>['id','name'=>'medical_name'],
                'order'=>['medical_order']
            ];
            $item_customnames = $this->LocalService()->worklistItemcustomname->fetchAll($itemwork_cond);
            $data_info_key = 0;
            if(!empty($item_customnames)){
                foreach($item_customnames as $item_customname){
                    $itemwork_children_datas = empty($dicWorksetData) ? [] : $dicWorksetData;
                    if(!empty($itemwork_children_datas)){
                        foreach($itemwork_children_datas as &$itemwork_children_data){
                            $itemwork_children_data['name'] = $item_customname['name'].' - '.$itemwork_children_data['name'];
                            $itemwork_children_data['info_id'] = $item_customname['id'];
                            $itemwork_children_data['category_id'] = -2;
                            $itemwork_children_data['dic_workset_id'] = $itemwork_children_data['id'];
                            $itemwork_children_data['info_category'] = $item_customname['id'].'_-2';
                            $itemwork_children_data['info_key'] = '-2_'.$item_customname['id'].'_'.$itemwork_children_data['id'];

                            $info_arr[$data_info_key] = $itemwork_children_data;
                            $data_info_key++;
                        }
                    }
                }
            }
            unset($item_customnames);

            //查询中心药物器械信息
            $itemsigwork_cond = [
                'where'=> [
                    'is_del' => 0,
                    'work_type' => 2,
                    'itemsig_id' => $itemsig_id,
                ],
                'columns'=>['id','name'=>'medical_name'],
                'order'=>['medical_order']
            ];
            $itemsig_customnames = $this->LocalService()->worklistSigcustomname->fetchAll($itemsigwork_cond);
            if(!empty($itemsig_customnames)){
                foreach($itemsig_customnames as $itemsig_customname){
                    $itemsig_children_datas = empty($dicWorksetData) ? [] : $dicWorksetData;
                    if(!empty($itemsig_children_datas)){
                        foreach($itemsig_children_datas as &$itemsig_children_data){
                            $itemsig_children_data['name'] = $itemsig_customname['name'] . ' - ' . $itemsig_children_data['name'];
                            $itemsig_children_data['info_id'] = $itemsig_customname['id'];
                            $itemsig_children_data['category_id'] = 0;
                            $itemsig_children_data['info_category'] = $itemsig_customname['id'] . '_0';
                            $itemsig_children_data['info_key'] = '0_'.$itemsig_customname['id'].'_'.$itemsig_children_data['id'];

                            $info_arr[$data_info_key] = $itemsig_children_data;
                            $data_info_key++;
                        }
                    }
                }
            }
            unset($itemsig_customnames);
            unset($dicWorksetData);
        }

        return $info_arr;
    }

}