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

namespace Application\Service\DB\Collect;
use Interop\Container\ContainerInterface;
class Patientmedicalblack extends \Application\Service\DB\AbstractDb
{
    public function __construct($dbAdapter, ContainerInterface $container)
    {
        $this->tableName = 'yikeen_collect_patientmedicalblack';
        parent::__construct($dbAdapter, $container);
    }

    /**
     * Notes:获取指定条件下的匹配的数据
     * User: lltyy
     * DateTime: 2023/5/26 8:09
     *
     * @param $where//数据条件
     * @param int $return_type//返回类型【0 医嘱下的匹配上的黑名单名称 1 医嘱黑名单匹配记录ID】
     * @return array
     */
    public function fetchBlackMateByMedical($where,$return_type = 0){
        $datas = [];
        if(empty($return_type)){
            $columns = ['id','medical_id','mate_black'];
        }
        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_black = !empty($matedata['mate_black']) ? json_decode($matedata['mate_black'], true) : [];
                    $datas[$medical_id] = $mate_black;
                }
                if($return_type == 1){
                    $datas[$medical_id] = $matedata['id'];
                }
            }
        }
        unset($cond);
        unset($matedatas);
        return $datas;
    }
}