Hrpatient.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. namespace app\admin\controller\hospital;
  3. use app\admin\servies\HrpatientServies;
  4. use app\common\controller\Backend;
  5. /**
  6. * 互认患者
  7. */
  8. class Hrpatient extends Backend
  9. {
  10. /**
  11. * Hrpatient模型对象
  12. * @var object
  13. * @phpstan-var \app\admin\model\hospital\Hrpatient
  14. */
  15. protected object $model;
  16. protected string|array $defaultSortField = 'create_time,desc';
  17. protected array|string $preExcludeFields = ['create_time'];
  18. protected string|array $quickSearchField = ['ID'];
  19. protected array $noNeedPermission = ['getHrpatientList'];
  20. 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'];
  21. public function initialize(): void
  22. {
  23. parent::initialize();
  24. $this->model = new \app\zskk\model\HospitalHrpatient();
  25. }
  26. /**
  27. * 若需重写查看、编辑、删除等方法,请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
  28. */
  29. /**
  30. * 查看
  31. * @throws Throwable
  32. */
  33. public function index(): void
  34. {
  35. if ($this->request->param('select')) {
  36. $this->select();
  37. }
  38. // $hospital_type = $this->request->get("hospital_type", false);
  39. list($where, $alias, $limit, $order) = $this->queryBuilder();
  40. // if($today) {
  41. // $this->setWhereTodayTimestamp($where, 'create_time');
  42. // }
  43. $where = $this->model->encryptWhere($where);
  44. $table = $this->model->getTable();
  45. [$where, $anotherWhere, $search]= $this->handleWhere($where, $table);
  46. $res = $this->model
  47. ->field($this->indexField)
  48. ->withJoin($this->withJoinTable, $this->withJoinType)
  49. ->alias($alias)
  50. ->where($where)
  51. ->where($anotherWhere)
  52. ->order($order)
  53. ->paginate($limit);
  54. $items = $res->items();
  55. $items = $this->handleItems($items, $search);
  56. $this->success('', [
  57. 'list' => $items,
  58. 'total' => $res->total(),
  59. 'remark' => get_route_remark(),
  60. ]);
  61. }
  62. private function handleItems(&$items, $search): array {
  63. if($search['status'] === false && $search['LAB_ITEMNAME'] === false && $search['EXAM_ITEMNAME'] === false) {
  64. return $items;
  65. }
  66. foreach($items as $item) {
  67. $item['LAB_ITEMNAME'] = $this->handleItemArrayString($item['LAB_ITEMNAME'], $search['status'], $search['LAB_ITEMNAME']);
  68. $item['EXAM_ITEMNAME'] = $this->handleItemArrayString($item['EXAM_ITEMNAME'], $search['status'], $search['EXAM_ITEMNAME']);
  69. }
  70. return $items;
  71. }
  72. private function handleItemArrayString($val, $status, $_search): string {
  73. // halt($val, $status, $_search);
  74. if(!$val) {
  75. return str_replace('(是)', '', $val);
  76. }
  77. $status_str = '';
  78. $search_str = '';
  79. if($status === '1') {
  80. $status_str = '(是)';
  81. }
  82. if($status === '2') {
  83. $status_str = '(否)';
  84. }
  85. if($status !== false) {
  86. $search_str = str_replace('%', '', $_search);
  87. }
  88. $_array = explode(',', $val);
  89. $array = array_filter($_array, function($value) use ($status_str, $search_str) {
  90. return strpos($value, $status_str) !== false && strpos($value, $search_str) !== false;
  91. });
  92. return str_replace('(是)', '', implode(',', $array));
  93. }
  94. private function handleWhere(&$where, $table): array
  95. {
  96. $search = [
  97. 'status' => false,
  98. 'LAB_ITEMNAME' => false,
  99. 'EXAM_ITEMNAME' => false,
  100. ];
  101. $statusKey = false;
  102. $anotherWhere = false;
  103. foreach ($where as $key => $value) {
  104. // 不限制互认
  105. if ($value[0] == $table.'status') {
  106. $search['status'] = $value[2];
  107. $statusKey = $key;
  108. }
  109. if($value[0] == $table.'LAB_ITEMNAME')
  110. {
  111. $search['LAB_ITEMNAME'] = $value[2];
  112. }
  113. if($value[0] == $table.'EXAM_ITEMNAME')
  114. {
  115. $search['EXAM_ITEMNAME'] = $value[2];
  116. }
  117. }
  118. if($statusKey !== false) {
  119. unset($where[$statusKey]);
  120. }
  121. if($search['status'] === '0' || $search['status'] === false) {
  122. return [$where, $anotherWhere, $search];
  123. }
  124. $B = $search['status'] === '2' ? 'B': '';
  125. if ($search['LAB_ITEMNAME'] || $search['EXAM_ITEMNAME']) {
  126. foreach ($where as $k=>$v)
  127. {
  128. if($v[0] == $table.'EXAM_ITEMNAME')
  129. {
  130. $where[$k][0] = $table.$B.'HR_EXAM_ITEMNAME';
  131. }
  132. if($v[0] == $table.'LAB_ITEMNAME')
  133. {
  134. $where[$k][0] = $table.$B.'HR_LAB_ITEMNAME';
  135. }
  136. }
  137. } else {
  138. $anotherWhere = $table.$B."HR_LAB_ITEMNAME is not null or ".$table.$B."HR_EXAM_ITEMNAME is not null";
  139. }
  140. return [$where, $anotherWhere, $search];
  141. }
  142. public function getMyHrpatientDetails(HrpatientServies $servies) {
  143. $params = $this->request->post();
  144. $HR_CODE = $params['HR_CODE'] ?? '';
  145. $PATIENT_CODE = $params['PATIENT_CODE'] ?? false;
  146. $data = $servies->getMyHrpatientDetails(['HR_CODE'=>$HR_CODE, 'PATIENT_CODE' => $PATIENT_CODE]);
  147. $this->success('',$data);
  148. }
  149. public function getOtherHrpatientDetail(HrpatientServies $servies) {
  150. $params = $this->request->post();
  151. $HR_CODE = $params['HR_CODE'] ?? '';
  152. $data = $servies->getOtherHrpatientDetail(['HR_CODE'=>$HR_CODE]);
  153. $this->success('',$data);
  154. }
  155. public function getHrpatientList(HrpatientServies $servies) {
  156. $params = $this->request->post();
  157. $ID = $params['ID'] ?? '';
  158. $data = $servies->getHrpatientList(['ID'=>$ID]);
  159. $this->success('',$data);
  160. }
  161. // private function handleWhere(&$where, $table): array
  162. // {
  163. // $obj = [
  164. // 'status' => false,
  165. // 'LAB_ITEMNAME' => false,
  166. // 'EXAM_ITEMNAME' => false,
  167. // ];
  168. // $status = 0;
  169. // $jcjy = 0;
  170. // foreach ($where as $key => $value) {
  171. // // 不限制互认
  172. // if ($value[0] == $table.'status') {
  173. // $status = $value[2];
  174. // unset($where[$key]);
  175. // }
  176. // if($value[0] == $table.'LAB_ITEMNAME')
  177. // {
  178. // $jcjy = 1;
  179. // }
  180. // if($value[0] == $table.'EXAM_ITEMNAME')
  181. // {
  182. // $jcjy = 1;
  183. // }
  184. // }
  185. // $anotherWhere = '';
  186. // switch ($status)
  187. // {
  188. // case 1:
  189. // // 互认
  190. // if($jcjy == 1)
  191. // {
  192. // // 存在检查检验的搜索
  193. // foreach ($where as $k=>$v)
  194. // {
  195. // if($v['0'] == $table.'EXAM_ITEMNAME')
  196. // {
  197. // $where[$k][0] = $table.'HR_EXAM_ITEMNAME';
  198. // }
  199. // if($v['0'] == $table.'LAB_ITEMNAME')
  200. // {
  201. // $where[$k][0] = $table.'HR_LAB_ITEMNAME';
  202. // }
  203. // }
  204. // }else{
  205. // $anotherWhere = $table."HR_LAB_ITEMNAME is not null or ".$table."HR_EXAM_ITEMNAME is not null";
  206. // }
  207. // break;
  208. // case 2:
  209. // //不互认
  210. // if($jcjy == 1)
  211. // {
  212. // // 存在检查检验的搜索
  213. // foreach ($where as $k=>$v)
  214. // {
  215. // if($v['0'] == $table.'EXAM_ITEMNAME')
  216. // {
  217. // $where[$k][0] = $table.'BHR_EXAM_ITEMNAME';
  218. // }
  219. // if($v['0'] == $table.'LAB_ITEMNAME')
  220. // {
  221. // $where[$k][0] = $table.'BHR_LAB_ITEMNAME';
  222. // }
  223. // }
  224. // }else{
  225. // $anotherWhere = $table."BHR_LAB_ITEMNAME is not null or ".$table."BHR_EXAM_ITEMNAME is not null";
  226. // }
  227. // break;
  228. // }
  229. // $where['anotherWhere'] = $anotherWhere;
  230. // return $where;
  231. // }
  232. }