Guidance.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\controller;
  3. use app\model\LySymptom;
  4. use app\model\LySymptomLog;
  5. use app\model\RDepartment;
  6. use think\facade\Db;
  7. use think\facade\Request;
  8. class Guidance extends CommonController
  9. {
  10. /**
  11. * 获取年龄性别配置
  12. * @return \think\response\Json
  13. */
  14. public function getConfig()
  15. {
  16. $data = self::initConfig();
  17. return json($data);
  18. }
  19. public static function initConfig(){
  20. return [
  21. 'gender'=>['男','女'],
  22. 'age_range' =>[
  23. 0=>'0~28天',
  24. 1=>'29天~6岁',
  25. 2=>'7岁~14岁',
  26. 3=>'15岁~35岁',
  27. 4=>'36岁~60岁',
  28. 5=>'大于60岁',
  29. ]
  30. ];
  31. }
  32. /**
  33. * 获取症状
  34. * @return \think\response\Json
  35. */
  36. public function getSymptom(){
  37. $text = Request::post('text');
  38. $age = Request::post('age');
  39. $search = ['症状','异常','的','所有','经常','偶尔','症','不正常','感觉'];
  40. $replace = ['','','','','','','','','',''];
  41. $text = str_replace($search,$replace,$text);
  42. if (empty($text)){
  43. $data['type'] = 0;
  44. $data['symptom'] = [];
  45. }else{
  46. if ($age <= 1){
  47. $data['type'] = 0;
  48. $data['symptom'] = [];
  49. }else{
  50. $data['type'] = 1;
  51. $gender = Request::post('gender',0) + 1;
  52. $leng = mb_strlen($text);
  53. if ($leng >= 2){
  54. $arr = [];
  55. for ($i = 0; $i < $leng; $i+=2){
  56. $a = mb_substr($text,$i,2);
  57. if (mb_strlen($a) > 1){
  58. $arr[] = $a;
  59. }
  60. }
  61. $arr[] = $text;
  62. $text = implode('|',$arr);
  63. }
  64. $symptom = LySymptom::where('gender','<=',$gender)
  65. ->where('name|relevant','regexp',$text)
  66. ->column('name');
  67. $data['symptom'] = [];
  68. foreach ($symptom as $item){
  69. if (strpos($item,'儿') !== false){
  70. continue;
  71. }
  72. if ($gender == 1 && strpos($item,'妇') !== false){
  73. continue;
  74. }
  75. $data['symptom'][] = $item;
  76. }
  77. }
  78. }
  79. return json($data);
  80. }
  81. /**
  82. * 获取导诊科室
  83. * @return \think\response\Json
  84. */
  85. public function getGuidance(){
  86. $name = Request::post('name','');
  87. $text = Request::post('text');
  88. $gender = Request::post('gender');
  89. $age = Request::post('age');
  90. if ($age <= 1){
  91. $data['department'] = ['儿科'];
  92. }else{
  93. $result = LySymptom::where('name', 'like', "%$name%")->value('department');
  94. $result = array_unique(explode(' ', $result));
  95. $Department = ['内科', '外科', '儿科','妇产科'];
  96. if ($age != 5){
  97. $Department[] = '老年科';
  98. }
  99. $data['department'] = array_values(array_diff($result, $Department));
  100. }
  101. $config = self::initConfig();
  102. $department = RDepartment::whereIn('department_type',$data['department'])->field('department,parameter')->select()->toArray();
  103. $creat = [
  104. 'text' => $text,
  105. 'name' => $name,
  106. 'age' => $config['age_range'][$age],
  107. 'gender' => $config['gender'][$gender],
  108. 'department' => implode(' ',$data['department'])
  109. ];
  110. $data['department'] = $department;
  111. $data['insert_id'] = Db::name('ly_symptom_log')->insertGetId($creat);
  112. return json($data);
  113. }
  114. /**
  115. * 评价
  116. * @return \think\response\Json
  117. */
  118. public function evaluate(){
  119. $id = Request::post('insert_id');
  120. $evaluate = Request::post('evaluate');
  121. if (LySymptomLog::update(['evaluate'=>$evaluate],['id'=>$id])){
  122. return json(['result'=>true]);
  123. }else{
  124. return json(['result'=>false]);
  125. }
  126. }
  127. }