error('对不起,您还未进行登录,请先登录', '/manage/login/index'); } } /** * 追加名称
* 如:已知医生id,添加医生名字
* 使用表必须以id作为查询主键 * @param type $row * @param type $key * @param type $tablename * @param type $namefield * @return type */ public function appendName($row, $key, $tablename, $namefield) { if (empty($row)) { return $row; } if (empty($key)) { return $row; } $id = $row[$key]; if (!empty($id)) { $rs = Db::table($tablename)->where("id", $id)->field($namefield)->find(); if (!empty($rs)) { $row[$key . "_name"] = $rs[$namefield]; } } return $row; } /** * 展示机构树 */ public function insCombobox() { $rs = Db::table("institution")->field("id,name 'text',parent_institution")->select(); $level = 1; $topIns = array(); $topIns["id"] = ""; // $topIns["name"] = "请选择医疗机构"; $topIns["text"] = "请选择医疗机构"; $insTreeData = self::itsInstitutionCombChild("", $rs, $level); $topIns["children"] = $insTreeData; $viewArr=array(); array_push($viewArr, $topIns); echo json_encode($viewArr); } /** * 遍历显示机构树 * @param type $pid * @return type */ public function itsInstitutionCombChild($parent_id, $rs, $level) { $level = $level + 1; if ($level > 6) { return null; } // echo $level . "-" . $pid . "
"; $childrenArr = array(); if (count($rs) > 0) { foreach ($rs as $key => $val) { if (isset($val["id"])) { $id = $val["id"]; $pidTmp = $val["parent_institution"]; if ($pidTmp == $parent_id || (!empty($parent_id) && strpos("#" . $pidTmp, $parent_id) > 0)) { // 子类 $thisChilds = self::itsInstitutionCombChild($val["id"], $rs, $level); if (!empty($thisChilds)) { $val["children"] = $thisChilds; } // $val["parent_institution"]=null; $keys = array_keys($childrenArr); $val = self::array_remove($val, "parent_institution" ); array_push($childrenArr, $val); //array_splice($rs, $key); } else { } } } } return $childrenArr; } /** * 显示科室 */ public function insDept(){ $request = Request::instance(); $params=$request->param(); $wheres=array(); $selAll=array(); $selAll["id"]=""; $selAll["text"]="查询全部"; if(isset($params['insid'])){ $wheres["institution_id"]=$params['insid']; $orders = array(); $orders["order_num"] = "1"; $rs = Db::table("department")->where($wheres)->field("id,department_name 'text'")->order($orders)->select(); if(!empty($rs)){ array_unshift($rs,$selAll); echo json_encode($rs); }else{ $list=array(); array_push($list, $selAll); echo json_encode($list); } }else{ $list=array(); array_push($list, $selAll); echo json_encode($list); } } /** * 显示科室 */ public function examclass(){ $request = Request::instance(); $params=$request->param(); $wheres=array(); $selAll=array(); $selAll["id"]=""; $selAll["text"]="查询全部"; if(isset($params['insid'])){ $wheres["institution_id"]=$params['insid']; $orders = array(); $orders["name"] = "1"; $rs = Db::table("exam_class")->where($wheres)->field("id,name 'text'")->order($orders)->select(); if(!empty($rs)){ array_unshift($rs,$selAll); echo json_encode($rs); }else{ $list=array(); array_push($list, $selAll); echo json_encode($list); } }else{ $list=array(); array_push($list, $selAll); echo json_encode($list); } } function array_remove($arr, $key) { if (!array_key_exists($key, $arr)) { return $arr; } $keys = array_keys($arr); $index = array_search($key, $keys); if ($index !== FALSE) { array_splice($arr, $index, 1); } return $arr; } }