コード例 #1
0
 public function get_hba1c()
 {
     $uuid = Session::get('uuid');
     $hospital_no = HospitalNo::find($uuid);
     $avg = array();
     $avg['name'] = User::find($hospital_no->patient_user_id)->name;
     if ($hospital_no != null) {
         $ranges = [date('Y-m-d')];
         $profile_id = $hospital_no->patient_profile_id;
         $tmp_data = Caselist::where('pp_id', '=', $profile_id)->whereNotNull('cl_blood_hba1c')->orderBy('created_at', 'desc')->take(4)->get();
         $avg['data'] = $tmp_data;
         //temp work around for last data
         /*for($i = 1; $i <= 4; $i++){
               array_push($ranges,date('Y-m-d', strtotime("-3 month", strtotime($ranges[$i - 1]))));
               $avg[$ranges[$i]]["avg"] =  Caselist::where('pp_id', '=' ,$profile_id) -> where('created_at','<', $ranges[$i - 1]) -> where('created_at','>', $ranges[$i]) ->avg('cl_blood_hba1c');
               $avg[$ranges[$i]]["last_date"] =  Caselist::where('pp_id', '=' ,$profile_id) -> where('created_at','<', $ranges[$i - 1]) -> where('created_at','>', $ranges[$i]) -> max('created_at');
               $avg[$ranges[$i]]["first_date"] =  Caselist::where('pp_id', '=' ,$profile_id) -> where('created_at','<', $ranges[$i - 1]) -> where('created_at','>', $ranges[$i]) -> min('created_at');
               $avg[$ranges[$i]]["count"] =  Caselist::where('pp_id', '=' ,$profile_id) -> where('created_at','<', $ranges[$i - 1]) -> where('created_at','>', $ranges[$i]) -> count('cl_blood_hba1c');
           }*/
     }
     return $avg;
 }
コード例 #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $casecare = Caselist::find($id);
     $casecare->delete();
     $msg = '方案资料成功删除。';
     EventController::SaveEvent('caselist', 'destroy(删除)');
     return redirect()->back()->with('message', $msg);
 }
コード例 #3
0
 private function get_case_stat($start, $end, $user_id = null)
 {
     $query = Caselist::select(DB::raw('users.name as name, cl_blood_hba1c as a1c, cl_ldl as ldl, cl_base_sbp, cl_base_ebp, cl_case_date, caselist.cl_doctor as doc'))->where('cl_case_date', '>=', $start)->where('cl_case_date', '<', $end)->leftJoin('users', 'caselist.cl_doctor', '=', 'users.id');
     if ($user_id != null) {
         $query = $query->where('caselist.cl_doctor', '=', $user_id);
     }
     $records = $query->orderBy('users.id')->get();
     $data = array();
     $counter = 0;
     $doc_pk_mapping = array();
     foreach ($records as $record) {
         //a1c
         $level = null;
         $type = 'a1c';
         if ($record[$type] < $this->bounds[$type]['low'] && $record[$type] != 0) {
             $level = 'low';
         } else {
             if ($record[$type] > $this->bounds[$type]['high'] && $record[$type] != 0) {
                 $level = 'high';
             }
         }
         if ($level != null) {
             if (isset($data[$type][$level][$record['doc']])) {
                 $data[$type][$level][$record['doc']]++;
             } else {
                 $data[$type][$level][$record['doc']] = 1;
             }
         }
         if ($record[$type] != 0) {
             if (isset($data[$type]['total'][$record['doc']])) {
                 $data[$type]['total'][$record['doc']]++;
             } else {
                 $data[$type]['total'][$record['doc']] = 1;
             }
         }
         //ldl
         $level = null;
         $type = 'ldl';
         if ($record[$type] < $this->bounds[$type]['low'] && $record[$type] != 0) {
             $level = 'low';
         } else {
             if ($record[$type] > $this->bounds[$type]['high'] && $record[$type] != 0) {
                 $level = 'high';
             }
         }
         if ($level != null) {
             if (isset($data[$type][$level][$record['doc']])) {
                 $data[$type][$level][$record['doc']]++;
             } else {
                 $data[$type][$level][$record['doc']] = 1;
             }
         }
         if ($record[$type] != 0) {
             if (isset($data[$type]['total'][$record['doc']])) {
                 $data[$type]['total'][$record['doc']]++;
             } else {
                 $data[$type]['total'][$record['doc']] = 1;
             }
         }
         //bp
         $level = null;
         $type = 'bp';
         if ($record['cl_base_sbp'] < $this->bounds['bp']['s']['low'] && $record['cl_base_ebp'] < $this->bounds['bp']['e']['low'] && $record['cl_base_sbp'] != 0 && $record['cl_base_ebp'] != 0) {
             $level = 'low';
         } else {
             if ($record['cl_base_sbp'] < $this->bounds['bp']['s']['high'] && $record['cl_base_ebp'] < $this->bounds['bp']['e']['high'] && $record['cl_base_sbp'] != 0 && $record['cl_base_ebp'] != 0) {
                 $level = 'high';
             }
         }
         if ($level != null) {
             if (isset($data[$type][$level][$record['doc']])) {
                 $data[$type][$level][$record['doc']]++;
             } else {
                 $data[$type][$level][$record['doc']] = 1;
             }
         }
         if ($record['cl_base_sbp'] != 0 && $record['cl_base_ebp'] != 0) {
             if (isset($data[$type]['total'][$record['doc']])) {
                 $data[$type]['total'][$record['doc']]++;
             } else {
                 $data[$type]['total'][$record['doc']] = 1;
             }
         }
         $doc_pk_mapping[$record['doc']] = $record['name'];
         $counter++;
     }
     //sort
     foreach ($this->types as $type) {
         foreach ($this->levels as $level) {
             if (isset($data[$type][$level])) {
                 $doc_array = $data[$type][$level];
                 arsort($doc_array);
                 $data[$type][$level] = $doc_array;
             }
         }
     }
     //get total count for person
     if ($user_id != null) {
         $count = Caselist::select(DB::raw('count(*) as count'))->where('cl_case_date', '>=', $start)->where('cl_case_date', '<', $end)->first();
         $total_count = $count['count'];
     } else {
         //just for initial
         $total_count = null;
     }
     //transform to output
     $export_data = array();
     foreach ($this->types as $type) {
         $one_data = array($this->tags_title[$type], '', '', '');
         array_push($export_data, $one_data);
         if ($user_id == null) {
             $sum_count = 0;
             if (isset($data[$type]['total'])) {
                 $sum_count += array_sum($data[$type]['total']);
             }
             $one_data = array('总笔数', $sum_count, '', '百分比');
             array_push($export_data, $one_data);
         } else {
             $sum_count = $total_count;
         }
         if (isset($data[$type]['total'])) {
             reset($data[$type]['total']);
             $first_key = key($data[$type]['total']);
             foreach ($data[$type]['total'] as $doc => $count) {
                 if ($doc === $first_key) {
                     $one_data = array("", $doc_pk_mapping[$doc], $count, round(100 * $count / $sum_count) . '%');
                 } else {
                     $one_data = array("", $doc_pk_mapping[$doc], $count, round(100 * $count / $sum_count) . '%');
                 }
                 $one_data["doctor_detail"] = $doc;
                 array_push($export_data, $one_data);
             }
         } else {
             $one_data = array("", 0, '', '');
             array_push($export_data, $one_data);
         }
         foreach ($this->levels as $level) {
             if (isset($data[$type][$level])) {
                 reset($data[$type][$level]);
                 $first_key = key($data[$type][$level]);
                 foreach ($data[$type][$level] as $doc => $count) {
                     if ($doc === $first_key) {
                         $one_data = array($this->tags[$type][$level], $doc_pk_mapping[$doc], $count, round(100 * $count / $data[$type]['total'][$doc]) . '%');
                     } else {
                         $one_data = array("", $doc_pk_mapping[$doc], $count, round(100 * $count / $data[$type]['total'][$doc]) . '%');
                     }
                     $one_data["doctor_detail"] = $doc;
                     array_push($export_data, $one_data);
                 }
             } else {
                 $one_data = array($this->tags[$type][$level], 0, '', '');
                 array_push($export_data, $one_data);
             }
         }
     }
     $export_data['count'] = $total_count;
     $export_data['name'] = "全院";
     if ($user_id != null && isset($doc_pk_mapping[$user_id])) {
         $export_data['name'] = $doc_pk_mapping[$user_id];
     }
     return $export_data;
 }