GuidanceBz.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\controller;
  3. use app\model\BzSymptom;
  4. use app\model\LySymptomLog;
  5. use think\facade\Db;
  6. use think\facade\Request;
  7. class GuidanceBz extends CommonController
  8. {
  9. /**
  10. * 获取年龄性别配置
  11. * @return \think\response\Json
  12. */
  13. public function getConfig()
  14. {
  15. $data = self::initConfig();
  16. return json($data);
  17. }
  18. public static function initConfig(){
  19. return [
  20. 'gender'=>['男','女'],
  21. 'age_range' =>[
  22. 0=>'0~28天',
  23. 1=>'29天~6岁',
  24. 2=>'7岁~14岁',
  25. 3=>'15岁~35岁',
  26. 4=>'36岁~60岁',
  27. 5=>'大于60岁',
  28. ]
  29. ];
  30. }
  31. /**
  32. * 获取症状列表
  33. * @return \think\response\Json
  34. */
  35. public function getBzmptomList(){
  36. $text = Request::post('relevant'); // 相关词语
  37. $age = Request::post('age'); //年龄段
  38. $location = Request::post('location'); //症状部位
  39. if (empty($relevant)){
  40. $result = BzSymptom::where('location',$location)->column('name');
  41. }else{
  42. $result = BzSymptom::where('location',$location)->column('name');
  43. }
  44. return json($result);
  45. // if (empty($text)){
  46. // $data['type'] = 0;
  47. // $data['symptom'] = [];
  48. // }else{
  49. // if ($age <= 1){
  50. // $data['type'] = 0;
  51. // $data['symptom'] = [];
  52. // }else{
  53. // $data['type'] = 1;
  54. // $gender = Request::post('gender',0) + 1;
  55. // $leng = mb_strlen($text);
  56. // if ($leng >= 2){
  57. // $arr = [];
  58. // for ($i = 0; $i < $leng; $i+=2){
  59. // $a = mb_substr($text,$i,2);
  60. // if (mb_strlen($a) > 1){
  61. // $arr[] = $a;
  62. // }
  63. // }
  64. // $arr[] = $text;
  65. // $text = implode('|',$arr);
  66. // }
  67. // $symptom = LySymptom::where('gender','<=',$gender)
  68. // ->where('name|relevant','regexp',$text)
  69. // ->column('name');
  70. // $data['symptom'] = [];
  71. // foreach ($symptom as $item){
  72. // if (strpos($item,'儿') !== false){
  73. // continue;
  74. // }
  75. // if ($gender == 1 && strpos($item,'妇') !== false){
  76. // continue;
  77. // }
  78. // $data['symptom'][] = $item;
  79. // }
  80. // }
  81. // }
  82. // return json($data);
  83. }
  84. /**
  85. * 获取导诊科室
  86. * @return \think\response\Json
  87. */
  88. public function getGuidanceBz(){
  89. $name = Request::post('name',''); //症状名称
  90. $location = Request::post('location',''); //症状部位
  91. $age = Request::post('age'); // 年龄段
  92. $gender = Request::post('gender'); //性别
  93. $text = Request::post('text'); //
  94. $info = BzSymptom::whereIn('name',$name)->where('location',$location)->select()->toArray();
  95. $department = [];
  96. foreach ($info as $k => $v){
  97. $department[] = $v['department'];
  98. //$a = explode(' ',$v['department']);
  99. //$department = array_merge($department,array_unique($a));
  100. }
  101. if ($age == '0~28天' || $age == '29天~6岁'){
  102. $department = ['儿科 儿科门诊'];
  103. }
  104. // 返回数据
  105. $data['gender'] = $gender;
  106. $data['age'] = $age;
  107. $data['name'] = $name;
  108. $data['location'] = $location;
  109. $data['department'] = implode(',',$department);
  110. $data['created_at'] = date("Y-m-d H:i:s",time());
  111. //写入log
  112. $data['insert_id'] = Db::name('bz_symptom_log')->insertGetId($data);
  113. return json($data);
  114. if ($age <= 1){
  115. $data['department'] = ['儿科'];
  116. }else{
  117. $result = LySymptom::where('name', 'like', "%$name%")->value('department');
  118. $result = array_unique(explode(' ', $result));
  119. $Department = ['内科', '外科', '儿科','妇产科'];
  120. if ($age != 5){
  121. $Department[] = '老年科';
  122. }
  123. $data['department'] = array_values(array_diff($result, $Department));
  124. }
  125. $config = self::initConfig();
  126. $department = RDepartment::whereIn('department_type',$data['department'])->field('department,parameter')->select()->toArray();
  127. $creat = [
  128. 'text' => $text,
  129. 'name' => $name,
  130. 'age' => $config['age_range'][$age],
  131. 'gender' => $config['gender'][$gender],
  132. 'department' => implode(' ',$data['department'])
  133. ];
  134. $data['department'] = $department;
  135. $data['insert_id'] = Db::name('ly_symptom_log')->insertGetId($creat);
  136. return json($data);
  137. }
  138. /**
  139. * 评价
  140. * @return \think\response\Json
  141. */
  142. public function evaluate(){
  143. $id = Request::post('insert_id');
  144. $evaluate = Request::post('evaluate');
  145. if (LySymptomLog::update(['evaluate'=>$evaluate],['id'=>$id])){
  146. return json(['result'=>true]);
  147. }else{
  148. return json(['result'=>false]);
  149. }
  150. }
  151. }