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

namespace Application\Service\DB\Ocr;
use Application\Service\Extension\Helper\StringHelper;
use Interop\Container\ContainerInterface;
use Laminas\Db\Sql\Predicate\Operator;
use Laminas\Stdlib\ArrayUtils;
use Application\Common\Com;
class Matewhite extends \Application\Service\DB\AbstractDb
{
    public function __construct($dbAdapter, ContainerInterface $container)
    {
        $this->tableName = 'yikeen_ocr_matewhite';
        parent::__construct($dbAdapter, $container);
    }

    /**
     * Notes: 添加新匹配信息
     * User: llbjj
     * DateTime: 2023/6/9 13:54
     *
     * @param array $params
     */
    public function addNewMateData(array $params) {

        // 删除之前匹配上的指标
        $this->upDelState([
            'medical_id' => $params['medical_id']
        ]);

        $medicalData = $this->LocalService()->ocrMedical->fetchOne([
            'where' => [
                'id' => $params['medical_id'],
                'is_del' => 0
            ],
            'columns' => ['id','annex_id', 'sig_id', 'patient_id', 'medical_name']
        ]);


        //获取黑/白名单数据
        $wordDatas = $this->LocalService()->ocrMedicalword->wordNameData('is_del = 0');
        $white_word_arr = isset($wordDatas['white_word']) && !empty($wordDatas['white_word']) ? $wordDatas['white_word'] : [];

        $addData = [
            'annex_id' => $medicalData['annex_id'],
            'sig_id' => $medicalData['sig_id'],
            'patient_id' => $medicalData['patient_id'],
            'medical_id' => $medicalData['id'],
            'medical_name' => $medicalData['medical_name'],
            'white_word' => json_encode($white_word_arr,true),
            'mate_white' => json_encode($params['mate_white']),
            'is_del' => 0
        ];

        $this->save($addData);
    }


    /**
     * Notes:获取指定的医嘱名称数据 与 黑/白名单关键字匹配，存入匹配信息表
     * User: lltyy
     * DateTime: 2023/5/26 15:00
     *
     * @param $where//条件
     * @param int $limit
     * @param int $offset
     * @param $white_word_arr//白名单
     * @param array $black_word_arr//黑名单
     * @param array $black_white_word_arr//黑名单下白名单
     * @return int
     */
    public function mateWordData($where,$limit=0,$offset=0,&$white_word_arr,&$black_word_arr=[],&$black_white_word_arr=[],&$drug_arr=[],&$takeDatas=[]){
        //获取指定条件下的医嘱数据
        $medicalCond = [
            'where'=>$where,
            'columns'=>['id','annex_id','sig_id','patient_id','medical_name','ocr_start_date','ocr_end_date'],
            'order'=>['id']
        ];
        if(!empty($limit) || !empty($offset)){
            $medicalCond['limit'] = $limit;
            $medicalCond['offset'] = $offset;
        }
        $medicalDatas = $this->LocalService()->ocrMedical->fetchAll($medicalCond);
        $last_medical_id = 0;
        if(!empty($medicalDatas)){
            $delete_arr = $delete_mate_arr = [];
            foreach($medicalDatas as $medicalKey=>$medical_info){
                $last_medical_id = $medical_info['id'];
                $medical_info_name = trim($medical_info['medical_name']);
                if(empty($medical_info_name)){
                    $delete_arr[] = $medical_info['id'];
                    unset($medicalDatas[$medicalKey]);
                }
                $delete_mate_arr[] = $medical_info['id'];
            }
            $medicalDatas = array_values($medicalDatas);

            //删除原匹配数据
            $this->LocalService()->ocrMedical->update(['mate_type'=>0,'is_lock'=>0,'drug_id'=>0,'is_dispensary'=>0,'dosage_num'=>'','dosage_unit'=>0],[
                'is_del' => 0,
                'id' => StringHelper::toArray($delete_mate_arr),
            ]);
            $this->upDelState([
                'is_del' => 0,
                'medical_id' => StringHelper::toArray($delete_mate_arr),
            ],1);
            $this->LocalService()->ocrMateblack->upDelState([
                'is_del' => 0,
                'medical_id' => StringHelper::toArray($delete_mate_arr),
            ],1);
            $this->LocalService()->ocrMatedrug->upDelState([
                'is_del' => 0,
                'medical_id' => StringHelper::toArray($delete_mate_arr),
            ],1);
            unset($delete_mate_arr);

            //删除不符合要求的数据
            if(!empty($delete_arr)){
                $this->LocalService()->ocrMedical->upDelState([
                    'is_del' => 0,
                    'id' => StringHelper::toArray($delete_arr),
                ],1);
            }
            unset($delete_arr);

            if(!empty($medicalDatas)) {
                $delete_str_arr = ["↑","↓","#","！","~","*","☑","★","◆","。",".","(",")","（","）","?",":","：","√","？","^","<",">","|","、","《","》","，",",","{","}","[","]","【","】","+","--","=","～"];
                foreach ($medicalDatas as $medicalDataKey=>&$medicalData) {
                    $medical_id = $medicalData['id'];
                    $medical_name = trim($medicalData['medical_name']);
                    $mate_medical_name = trim($medicalData['ocr_start_date']).trim($medicalData['medical_name']);
                    $mate_medical_name = str_replace($delete_str_arr,'',$mate_medical_name);
                    $medicalData['mate_medical_name'] = $mate_medical_name;

                    $mate_type = 0;

                    //已匹配上白名单的词
                    $white_word = [];
                    if(!empty($white_word_arr)){
                        foreach($white_word_arr as $white_word_str){
                            if(strpos($mate_medical_name,$white_word_str) !== false){
                                $white_word[] = $white_word_str;
                            }
                        }
                    }
                    if (!empty($white_word)) {
                        //保存匹配白名单数据
                        $save_data = [
                            'annex_id' => $medicalData['annex_id'],
                            'sig_id' => $medicalData['sig_id'],
                            'patient_id' => $medicalData['patient_id'],
                            'medical_id' => $medical_id,
                            'medical_name' => $medical_name,
                            'white_word' => json_encode($white_word_arr),
                            'mate_white' => json_encode($white_word)
                        ];
                        $matewhite_id = $this->save($save_data);
                        unset($save_data);

                        //已匹配上黑名单的词
                        $black_word = [];
                        if(!empty($black_word_arr)){
                            foreach($black_word_arr as $black_word_str){
                                if(strpos($mate_medical_name,$black_word_str) !== false){
                                    $black_word[] = $black_word_str;
                                }
                            }
                        }
                        if (!empty($black_word)) {
                            //已匹配上黑名单下的白名单词
                            $black_white_word = [];
                            if(!empty($black_white_word_arr)){
                                foreach($black_white_word_arr as $black_white_word_str){
                                    if(strpos($mate_medical_name,$black_white_word_str) !== false){
                                        $black_white_word[] = $black_white_word_str;
                                    }
                                }
                            }
                            if (empty($black_white_word)) {
                                $mate_type = 2;
                                //保存匹配白名单与黑名单匹配数据
                                $save_black = [
                                    'annex_id' => $medicalData['annex_id'],
                                    'sig_id' => $medicalData['sig_id'],
                                    'patient_id' => $medicalData['patient_id'],
                                    'medical_id' => $medical_id,
                                    'white_id' => $matewhite_id,
                                    'medical_name' => $medical_name,
                                    'black_word' => json_encode($black_word_arr),
                                    'mate_black' => json_encode($black_word)
                                ];
                                $this->LocalService()->ocrMateblack->save($save_black);
                                unset($save_black);
                            } else {
                                $mate_type = 1;
                            }
                            unset($black_white_word);
                        } else {
                            $mate_type = 1;
                        }
                        unset($black_word);
                    }
                    unset($white_word);
                    unset($medical_name_arr);

                    //更新日期
                    $medical_date = trim($medicalData['ocr_start_date']);
                    $medical_date = $this->LocalService()->ocrRawdata->replaceRawdata($medical_date,1);
                    $medical_date = $medical_date != '' ? $medical_date : '';
                    //更新日期
                    $end_date = trim($medicalData['ocr_end_date']);
                    $end_date = $this->LocalService()->ocrRawdata->replaceRawdata($end_date,1);
                    $end_date = $end_date != '' ? $end_date : '';

                    //获取匹配的药物名称
                    $drug_id = 0;
                    $is_dispensary = 0;
                    $dosage_unit = 0;
                    if($mate_type == 1){
                        $drug_id = $this->LocalService()->ocrMatedrug->mateDrugdata($medicalData,$drug_arr,0);

                        //取药状态
                        if(strpos($medical_name,'取药') !== false && strpos($medical_name,'非取药') == false){
                            $is_dispensary = 1;
                        }
                        if(strpos($medical_name,'出院带药') !== false && strpos($medical_name,'非出院带药') == false){
                            $is_dispensary = 1;
                        }

                        //剂量单位
                        if(!empty($takeDatas)){
                            foreach($takeDatas as $takeData){
                                if(empty($dosage_unit) && strpos($medical_name,$takeData['name']) !== false){
                                    $dosage_unit = $takeData['id'];
                                    break;
                                }
                            }
                        }else{
                            $dosage_unit = 0;
                        }

                    }

                    $this->LocalService()->ocrMedical->update(['mate_type' => $mate_type,'medical_date'=>$medical_date,'end_date'=>$end_date,'drug_id'=>$drug_id,'is_dispensary'=>$is_dispensary,'dosage_unit'=>$dosage_unit], [
                        'id' => $medical_id
                    ]);
                    unset($medicalDatas[$medicalDataKey]);
                }
            }
        }
        unset($medicalCond);
        unset($medicalDatas);

        return $last_medical_id;
    }

     /**
     * Notes:获取指定的医嘱名称数据 与 黑/白名单关键字匹配，存入匹配信息表
     * User: lltyy
     * DateTime: 2023/5/26 15:00
     *
     * @param $where//条件
     * @param int $limit
     * @param int $offset
     * @param $white_word_arr//白名单
     * @param array $black_word_arr//黑名单
     * @param array $black_white_word_arr//黑名单下白名单
     * @return int
     */
    public function OLDmateWordData($where,$limit=0,$offset=0,&$white_word_arr,&$black_word_arr=[],&$black_white_word_arr=[],&$drug_arr=[],&$takeDatas=[]){
        //获取指定条件下的医嘱数据
        $medicalCond = [
            'where'=>$where,
            'columns'=>['id','annex_id','sig_id','patient_id','medical_name','ocr_start_date','ocr_end_date'],
            'order'=>['id']
        ];
        if(!empty($limit) || !empty($offset)){
            $medicalCond['limit'] = $limit;
            $medicalCond['offset'] = $offset;
        }
        $medicalDatas = $this->LocalService()->ocrMedical->fetchAll($medicalCond);
        //echo "<pre>";
        //print_R($medicalDatas);exit;
        $last_medical_id = 0;
        if(!empty($medicalDatas)){
            $delete_arr = $delete_mate_arr = [];
            foreach($medicalDatas as $medicalKey=>$medical_info){
                $last_medical_id = $medical_info['id'];
                $medical_info_name = trim($medical_info['medical_name']);
                if(empty($medical_info_name)){
                    $delete_arr[] = $medical_info['id'];
                    unset($medicalDatas[$medicalKey]);
                }
                $delete_mate_arr[] = $medical_info['id'];
            }
            $medicalDatas = array_values($medicalDatas);

            //删除原匹配数据
            $this->LocalService()->ocrMedical->update(['mate_type'=>0,'is_lock'=>0,'drug_id'=>0,'dosage_id'=>0,'is_dispensary'=>0,'dosage_num'=>0,'dosage_unit'=>0,'times_id'=>0],'is_del = 0 and id in ('.implode(',',$delete_mate_arr).')');
            $this->upDelState([
                'is_del' => 0,
                'medical_id' => StringHelper::toArray($delete_mate_arr),
            ],1);
            $this->LocalService()->ocrMateblack->upDelState([
                'is_del' => 0,
                'medical_id' => StringHelper::toArray($delete_mate_arr),
            ],1);
            $this->LocalService()->ocrMatedrug->upDelState([
                'is_del' => 0,
                'medical_id' => StringHelper::toArray($delete_mate_arr),
            ],1);
            unset($delete_mate_arr);

            //删除不符合要求的数据
            if(!empty($delete_arr)){
                $this->LocalService()->ocrMedical->upDelState([
                    'is_del' => 0,
                    'id' => StringHelper::toArray($delete_arr),
                ],1);
            }
            unset($delete_arr);

            if(!empty($medicalDatas)) {
                $delete_str_arr = ["↑","↓","#","！","~","*","☑","★","◆","。",".","(",")","（","）","?",":","：","√","？","^","<",">","|","、","《","》","，",",","{","}","[","]","【","】","+","--","=","～"];
                foreach ($medicalDatas as $medicalDataKey=>&$medicalData) {
                    $medical_id = $medicalData['id'];
                    $medical_name = trim($medicalData['medical_name']);
                    $mate_medical_name = trim($medicalData['ocr_start_date']).trim($medicalData['medical_name']);
                    $mate_medical_name = str_replace($delete_str_arr,'',$mate_medical_name);

                    $mate_type = 0;

                    //切割医嘱内容
                    $medicalName = "{$mate_medical_name}";
                    $medical_name_arr = !empty($medicalName) ? Com::cutIntoSlices($medicalName) : [];
                    $medical_name_arr = !empty($medical_name_arr) ? array_values($medical_name_arr) : [];
                    $medicalData['mate_medical_name'] = $mate_medical_name;
                    $medicalData['mate_medical_name_arr'] = $medical_name_arr;

                    //已匹配上白名单的词
                    $white_word = !empty($white_word_arr) ? array_uintersect($white_word_arr, $medical_name_arr, "strcasecmp") : [];
                    $white_word = isset($white_word) && !empty($white_word) ? array_values($white_word) : [];
                    if (!empty($white_word)) {
                        //保存匹配白名单数据
                        $save_data = [
                            'annex_id' => $medicalData['annex_id'],
                            'sig_id' => $medicalData['sig_id'],
                            'patient_id' => $medicalData['patient_id'],
                            'medical_id' => $medical_id,
                            'medical_name' => $medical_name,
                            'white_word' => json_encode($white_word_arr),
                            'mate_white' => json_encode($white_word)
                        ];
                        $matewhite_id = $this->save($save_data);
                        unset($save_data);

                        //已匹配上黑名单的词
                        $black_word = !empty($black_word_arr) ? array_uintersect($black_word_arr, $medical_name_arr, "strcasecmp") : [];
                        $black_word = isset($black_word) && !empty($black_word) ? array_values($black_word) : [];
                        if (!empty($black_word)) {
                            //已匹配上黑名单下的白名单词
                            $black_white_word = !empty($black_white_word_arr) ? array_uintersect($black_white_word_arr, $medical_name_arr, "strcasecmp") : [];
                            $black_white_word = isset($black_white_word) && !empty($black_white_word) ? array_values($black_white_word) : [];
                            if (empty($black_white_word)) {
                                $mate_type = 2;
                                //保存匹配白名单与黑名单匹配数据
                                $save_black = [
                                    'annex_id' => $medicalData['annex_id'],
                                    'sig_id' => $medicalData['sig_id'],
                                    'patient_id' => $medicalData['patient_id'],
                                    'medical_id' => $medical_id,
                                    'white_id' => $matewhite_id,
                                    'medical_name' => $medical_name,
                                    'black_word' => json_encode($black_word_arr),
                                    'mate_black' => json_encode($black_word)
                                ];
                                $this->LocalService()->ocrMateblack->save($save_black);
                                unset($save_black);
                            } else {
                                $mate_type = 1;
                            }
                            unset($black_white_word);
                        } else {
                            $mate_type = 1;
                        }
                        unset($black_word);
                    }
                    unset($white_word);
                    unset($medical_name_arr);

                    //更新日期
                    $medical_date = trim($medicalData['ocr_start_date']);
                    $medical_date = $this->LocalService()->ocrRawdata->replaceRawdata($medical_date,1);
                    $medical_date = $medical_date != '' ? $medical_date : '';
                    //更新日期
                    $end_date = trim($medicalData['ocr_end_date']);
                    $end_date = $this->LocalService()->ocrRawdata->replaceRawdata($end_date,1);
                    $end_date = $end_date != '' ? $end_date : '';

                    //获取匹配的药物名称
                    $drug_id = 0;
                    $is_dispensary = 0;
                    $dosage_unit = 0;

                    $this->LocalService()->ocrMedical->update(['mate_type' => $mate_type,'medical_date'=>$medical_date,'end_date'=>$end_date,'drug_id'=>$drug_id,'is_dispensary'=>$is_dispensary,'dosage_unit'=>$dosage_unit], [
                        'id' => $medical_id
                    ]);
                    unset($medicalDatas[$medicalDataKey]);
                }
            }
        }
        unset($medicalCond);
        unset($medicalDatas);

        return $last_medical_id;
    }

    /**
     * Notes: 获取指定条件下的匹配的数据
     * User: lltyy
     * DateTime: 2023/4/25 10:16
     *
     * @param $where
     * @return array
     */
    public function fetchMedicalMatedata($where,$return_type = 0){
        $datas = [];
        if(empty($return_type)){
            $columns = ['id','medical_id','mate_white'];
        }
        if($return_type == 1){
            $columns = ['id','medical_id'];
        }
        //获取指定条件下的识别结果数据
        $cond = [
            'where'=>$where,
            'columns'=>$columns,
            'order'=>['id']
        ];
        $matedatas = $this->fetchAll($cond);
        if(!empty($matedatas)){
            foreach($matedatas as &$matedata) {
                $medical_id = $matedata['medical_id'];
                if(empty($return_type)) {
                    $mate_white = !empty($matedata['mate_white']) ? json_decode($matedata['mate_white'], true) : [];
                    $datas[$medical_id] = $mate_white;
                }
                if($return_type == 1){
                    $datas[$medical_id] = $matedata['id'];
                }
            }
        }
        unset($cond);
        unset($matedatas);
        return $datas;
    }


    /**
     * Notes:识别医嘱数据 - 匹配
     * User: lltyy
     * DateTime: 2023/5/12 14:51
     *
     */
    public function scanMedical($where='') {
        //获取黑/白名单数据
        $wordDatas = $this->LocalService()->ocrMedicalword->wordNameData('is_del = 0');
        $white_word_arr = isset($wordDatas['white_word']) && !empty($wordDatas['white_word']) ? $wordDatas['white_word'] : [];
        $black_word_arr = isset($wordDatas['black_word']) && !empty($wordDatas['black_word']) ? $wordDatas['black_word'] : [];
        $black_white_word_arr = isset($wordDatas['black_white_word']) && !empty($wordDatas['black_white_word']) ? $wordDatas['black_white_word'] : [];
        unset($wordDatas);

        //获取药物数据
        $drugDatas = $this->LocalService()->ocrDrug->fetchAll(['where'=>'is_del = 0','columns'=>['id','name','drug_word'],'order'=>['category_type','drug_order']]);
        if(!empty($drugDatas)){
            $delete_str_arr = ["↑","↓","#","！","~","*","☑","★","◆","。",".","(",")","（","）","?",":","：","√","？","^","<",">","|","、","《","》","，",",","{","}","[","]","【","】","+","--","=","～"];
            $delete_name_arr = ['钠注射液','物注射液','颗粒','注射液','注射','胶囊','片'];
            foreach($drugDatas as &$drugData){
                $mate_drug_name = $drugData['name'];
                if(!empty($delete_name_arr)){
                    foreach($delete_name_arr as $delete_name){
                        if(strpos($mate_drug_name,$delete_name) !== false){
                            $delete_index = strpos($mate_drug_name,$delete_name);
                            $mate_drug_name = substr_replace($mate_drug_name,'',$delete_index);
                            unset($delete_index);
                        }
                    }
                }

                $mate_drug_name = mb_substr($mate_drug_name,0,8);
                if(strpos($mate_drug_name,'(') !== false){
                    $delete_index = strpos($mate_drug_name,'(');
                    $mate_drug_name = substr_replace($mate_drug_name,'',$delete_index);
                    unset($delete_index);
                }
                if(strpos($mate_drug_name,'（') !== false){
                    $delete_index = strpos($mate_drug_name,'（');
                    $mate_drug_name = substr_replace($mate_drug_name,'',$delete_index);
                    unset($delete_index);
                }
                $mate_drug_name = str_replace($delete_str_arr,'',$mate_drug_name);
                $mate_drug_word = json_decode($drugData['drug_word'],true);
                $drugData['mate_drug_name'] = $mate_drug_name;
                $drugData['mate_keyword_arr'] = $mate_drug_word;
                unset($drugData['drug_word']);
            }
            unset($delete_str_arr);
            unset($delete_name_arr);
        }

        //获取剂量单位数据
        $takeDatas = $this->LocalService()->ocrTake->fetchAll(['where'=>'is_del = 0 and take_type = 2','columns'=>['id','name'],'order'=>['take_order']]);


        if(empty($where)){
            $where = [
                'is_del' => 0,
                'is_lock' => 0,
            ];
        }

        //匹配黑白名单、药物【5979】
        //新加中心：1981,16204,16278,16518,16763,16973,17292
        //新加中心：6090,6699,8224,8698,11191,11249,14190,15490
        //新加中心：1373,2472,3777,4561,5680,5704,12696
        //新加中心：1373,8698,9058,11141,11653,11686,13272,13695,14045,15112,16763
        //新加中心：1373,3777,10114,11204,11249,15490
        //新加中心：4702,6090,6699,8776
        //新加中心：5704,6090,6699,8776,11191,11249,15490,16351,17480
        //1,276,812,1659,1981,3032,4702,4989,5290,5516,5992,6451,6697,7713,7915,8517,8539,8776,9103,9654,10114,10398,10559,10853,11118,11127,11674,11686,12075,12497,13272,13545,13695,13919,13940,13953,14045,14300,14444,14508,14813,15112,15936,16204,16278,16351,16518,16527,16763,16973,17292,17429,17480
        $sig_id_arr = [];
        if(!empty($sig_id_arr)){
            $where['sig_id'] = StringHelper::toArray($sig_id_arr);
        }
        $annex_id_arr = [];
        //$annex_id_arr = [147480,147505,147557,147562,147622,147669,147695,148078,148124,148136,148415,148450,148495,148516,148799,148820,148843,148846,148900,149053,149299,149321,149649,149652,149998,150027,150052,150115,150117,150120,150165,150178,150188,150191,150207,150209,150215,150218,150229,150265,150268,150284,150305,150352,150367,150372,150377,150387,150401,150406,150424,150466,150469,150475,150482,150488,150569,150628,150658,150672,150691,150694,150801,150810,150819,150941,150957,150962,151002,151009,151012,151018,151034,151039,151046,151053,151060,151071,151091,151165,151171,151174,151177,151199,151236,403102,403112,403138,403166,403187,403225,403230,403239,403271,403280,403293,403298,403394,403428,403439,403503,403551,403586,403655,403705,403739,403752,403768,403852,478853,517579,517581,517583,517585,517587,517589,517591,517593,517595,517612,517614,517634,517636,517644,517646,517648,517650,517652,517658,517671,517673,517675,517699,517721,527644,527646,527652,527654,527656,527660,527666,527668,527670,527676,527678,527680,527682,527686,527692,527731,527735,527737,527739,527743,527745,527747,527749,527751,527753,527776,527778,527780,527784,527788,527790,527794,527798,527800,527822,527830,527832,527838,527842,527844,527848,527850,527880,527884,527892,527896,527898,527916,527926,527938,527940,527942,527944,527948,527950,527962,527964,527968,527974,527986,527990,527994,527996,528000,528004,528010,528012,528014,528016,528020,528022,528028,528030,528041,528045,528047,528050,528052,528056,528069,528073,528075,528077,528081,528083,528087,528093,528097,528099,528101,528124,528126,528130,528152,528154,528156,528158,528160,528166,528168,528170,528172,528180,528182,528190,528192,528194,528196,528208,528212,528214,528232,528236,528252,528256,528272,528284,528286];
        if(!empty($annex_id_arr)){
            $where['annex_id'] = StringHelper::toArray($annex_id_arr);
        }

        //获取删除识别数据的信息记录表
        $delete_name_arr = $this->LocalService()->ocrDeletename->fetchCol('delete_name','is_del = 0 and annex_type = 2 and sig_id = 0');
        $delete_name_arr = array_values($delete_name_arr);
        $this->LocalService()->ocrMedical->deleteDataHaveName($where,$delete_name_arr,0);
        unset($delete_name_arr);

        //获取替换识别数据的信息记录表
        $replace_cond = [
            'where'=>'is_del = 0 and annex_type = 2',
            'columns'=>['info_type','replace_pre','replace_after'],
            'order'=>['id']
        ];
        $replace_arr = $this->LocalService()->ocrReplace->fetchAll($replace_cond);
        $this->LocalService()->ocrMedical->replaceDataHaveInfo($where,$replace_arr,0);
        unset($replace_arr);

        $bool = true;
        $page = 0;
        $limit = 1000;
        $last_medical_id = 0;
        while ($bool) {
            $page++;
            echo "medicalPAGE {$page}：" . PHP_EOL;
            $last_medical_id = $this->mateWordData(ArrayUtils::merge($where, [
                new Operator('id', Operator::OP_GT, $last_medical_id),
            ]),$limit,0,$white_word_arr,$black_word_arr,$black_white_word_arr,$drugDatas,$takeDatas);
            if(!$last_medical_id) $bool = false;
        }
        unset($white_word_arr);
        unset($black_word_arr);
        unset($black_white_word_arr);
        unset($drugDatas);
        unset($takeDatas);
    }

}