123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <?php
- namespace app\admin\controller\hospital;
- use app\admin\servies\HrpatientServies;
- use app\common\controller\Backend;
- /**
- * 互认患者
- */
- class Hrpatient extends Backend
- {
- /**
- * Hrpatient模型对象
- * @var object
- * @phpstan-var \app\admin\model\hospital\Hrpatient
- */
- protected object $model;
- protected string|array $defaultSortField = 'create_time,desc';
- protected array|string $preExcludeFields = ['create_time'];
- protected string|array $quickSearchField = ['ID'];
- protected array $noNeedPermission = ['getHrpatientList'];
- protected string|array $indexField = ['ID', 'MPI', 'ENCOUNTER_DATE', 'NAME', 'GENDER', 'AGE', 'ID_CARDNUM', 'DIAGNOSENAME', 'CHIEFCOMPLAINT', 'LAB_ITEMNAME', 'EXAM_ITEMNAME', 'create_time', 'ORGNAME', 'HRORGNAME', 'HR_CODE'];
- public function initialize(): void
- {
- parent::initialize();
- $this->model = new \app\zskk\model\HospitalHrpatient();
- }
- /**
- * 若需重写查看、编辑、删除等方法,请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
- */
- /**
- * 查看
- * @throws Throwable
- */
- public function index(): void
- {
- if ($this->request->param('select')) {
- $this->select();
- }
- // $hospital_type = $this->request->get("hospital_type", false);
- list($where, $alias, $limit, $order) = $this->queryBuilder();
- // if($today) {
- // $this->setWhereTodayTimestamp($where, 'create_time');
- // }
- $where = $this->model->encryptWhere($where);
- $table = $this->model->getTable();
- [$where, $anotherWhere, $search]= $this->handleWhere($where, $table);
- $res = $this->model
- ->field($this->indexField)
- ->withJoin($this->withJoinTable, $this->withJoinType)
- ->alias($alias)
- ->where($where)
- ->where($anotherWhere)
- ->order($order)
- ->paginate($limit);
- $items = $res->items();
- $items = $this->handleItems($items, $search);
-
- $this->success('', [
- 'list' => $items,
- 'total' => $res->total(),
- 'remark' => get_route_remark(),
- ]);
- }
- private function handleItems(&$items, $search): array {
- if($search['status'] === false && $search['LAB_ITEMNAME'] === false && $search['EXAM_ITEMNAME'] === false) {
- return $items;
- }
- foreach($items as $item) {
- $item['LAB_ITEMNAME'] = $this->handleItemArrayString($item['LAB_ITEMNAME'], $search['status'], $search['LAB_ITEMNAME']);
- $item['EXAM_ITEMNAME'] = $this->handleItemArrayString($item['EXAM_ITEMNAME'], $search['status'], $search['EXAM_ITEMNAME']);
- }
- return $items;
- }
- private function handleItemArrayString($val, $status, $_search): string {
- // halt($val, $status, $_search);
- if(!$val) {
- return str_replace('(是)', '', $val);
- }
- $status_str = '';
- $search_str = '';
- if($status === '1') {
- $status_str = '(是)';
- }
- if($status === '2') {
- $status_str = '(否)';
- }
- if($status !== false) {
- $search_str = str_replace('%', '', $_search);
- }
- $_array = explode(',', $val);
- $array = array_filter($_array, function($value) use ($status_str, $search_str) {
- return strpos($value, $status_str) !== false && strpos($value, $search_str) !== false;
- });
- return str_replace('(是)', '', implode(',', $array));
- }
- private function handleWhere(&$where, $table): array
- {
- $search = [
- 'status' => false,
- 'LAB_ITEMNAME' => false,
- 'EXAM_ITEMNAME' => false,
- ];
- $statusKey = false;
- $anotherWhere = false;
- foreach ($where as $key => $value) {
- // 不限制互认
- if ($value[0] == $table.'status') {
- $search['status'] = $value[2];
- $statusKey = $key;
- }
- if($value[0] == $table.'LAB_ITEMNAME')
- {
- $search['LAB_ITEMNAME'] = $value[2];
- }
- if($value[0] == $table.'EXAM_ITEMNAME')
- {
- $search['EXAM_ITEMNAME'] = $value[2];
- }
- }
- if($statusKey !== false) {
- unset($where[$statusKey]);
- }
- if($search['status'] === '0' || $search['status'] === false) {
- return [$where, $anotherWhere, $search];
- }
- $B = $search['status'] === '2' ? 'B': '';
- if ($search['LAB_ITEMNAME'] || $search['EXAM_ITEMNAME']) {
- foreach ($where as $k=>$v)
- {
- if($v[0] == $table.'EXAM_ITEMNAME')
- {
- $where[$k][0] = $table.$B.'HR_EXAM_ITEMNAME';
- }
- if($v[0] == $table.'LAB_ITEMNAME')
- {
- $where[$k][0] = $table.$B.'HR_LAB_ITEMNAME';
- }
- }
- } else {
- $anotherWhere = $table.$B."HR_LAB_ITEMNAME is not null or ".$table.$B."HR_EXAM_ITEMNAME is not null";
- }
-
- return [$where, $anotherWhere, $search];
- }
- public function getMyHrpatientDetails(HrpatientServies $servies) {
- $params = $this->request->post();
- $HR_CODE = $params['HR_CODE'] ?? '';
- $PATIENT_CODE = $params['PATIENT_CODE'] ?? false;
- $data = $servies->getMyHrpatientDetails(['HR_CODE'=>$HR_CODE, 'PATIENT_CODE' => $PATIENT_CODE]);
- $this->success('',$data);
- }
- public function getOtherHrpatientDetail(HrpatientServies $servies) {
- $params = $this->request->post();
- $HR_CODE = $params['HR_CODE'] ?? '';
- $data = $servies->getOtherHrpatientDetail(['HR_CODE'=>$HR_CODE]);
- $this->success('',$data);
- }
- public function getHrpatientList(HrpatientServies $servies) {
- $params = $this->request->post();
- $ID = $params['ID'] ?? '';
- $data = $servies->getHrpatientList(['ID'=>$ID]);
- $this->success('',$data);
- }
- // private function handleWhere(&$where, $table): array
- // {
- // $obj = [
- // 'status' => false,
- // 'LAB_ITEMNAME' => false,
- // 'EXAM_ITEMNAME' => false,
- // ];
- // $status = 0;
- // $jcjy = 0;
- // foreach ($where as $key => $value) {
- // // 不限制互认
- // if ($value[0] == $table.'status') {
- // $status = $value[2];
- // unset($where[$key]);
- // }
- // if($value[0] == $table.'LAB_ITEMNAME')
- // {
- // $jcjy = 1;
- // }
- // if($value[0] == $table.'EXAM_ITEMNAME')
- // {
- // $jcjy = 1;
- // }
- // }
- // $anotherWhere = '';
- // switch ($status)
- // {
- // case 1:
- // // 互认
- // if($jcjy == 1)
- // {
- // // 存在检查检验的搜索
- // foreach ($where as $k=>$v)
- // {
- // if($v['0'] == $table.'EXAM_ITEMNAME')
- // {
- // $where[$k][0] = $table.'HR_EXAM_ITEMNAME';
- // }
- // if($v['0'] == $table.'LAB_ITEMNAME')
- // {
- // $where[$k][0] = $table.'HR_LAB_ITEMNAME';
- // }
- // }
- // }else{
- // $anotherWhere = $table."HR_LAB_ITEMNAME is not null or ".$table."HR_EXAM_ITEMNAME is not null";
- // }
- // break;
- // case 2:
- // //不互认
- // if($jcjy == 1)
- // {
- // // 存在检查检验的搜索
- // foreach ($where as $k=>$v)
- // {
- // if($v['0'] == $table.'EXAM_ITEMNAME')
- // {
- // $where[$k][0] = $table.'BHR_EXAM_ITEMNAME';
- // }
- // if($v['0'] == $table.'LAB_ITEMNAME')
- // {
- // $where[$k][0] = $table.'BHR_LAB_ITEMNAME';
- // }
- // }
- // }else{
- // $anotherWhere = $table."BHR_LAB_ITEMNAME is not null or ".$table."BHR_EXAM_ITEMNAME is not null";
- // }
- // break;
- // }
- // $where['anotherWhere'] = $anotherWhere;
- // return $where;
- // }
- }
|