DictService.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. namespace app\api\servies\dict;
  3. use app\api\response\ZskkErrorResponse;
  4. use app\api\servies\ZskkDefaultService;
  5. use app\api\dao\dict\DictDao;
  6. use app\api\servies\common\CommonService;
  7. use app\api\utils\UUIDUtils;
  8. use think\Db;
  9. use think\facade\Log;
  10. use think\Exception;
  11. /**
  12. * 后台控制器基类
  13. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  14. */
  15. class DictService extends ZskkDefaultService {
  16. protected $logName = "DictService";
  17. private $dict = null;
  18. // protected function zskkInit(TestDao $testDao) {
  19. // $this->testDao;
  20. // }
  21. public function __construct(DictDao $dictDao) {
  22. parent::__construct();
  23. $this->dict = $dictDao;
  24. }
  25. public function getDevice($token)
  26. {
  27. try{
  28. $user = $this->dict->getUser($token);
  29. $device_ids = $user['device_ids'] ?? [];
  30. if(!empty($device_ids)){
  31. $device_ids = explode(',', $device_ids);
  32. }else{
  33. // return '';
  34. }
  35. // 获取设备名称
  36. $devices = $this->dict->getDevice($device_ids);
  37. if(empty($devices)){
  38. $devices = $this->dict->getDevice(0);
  39. }
  40. $data = [];
  41. foreach ($devices as $k=>$v){
  42. $subClass = $this->dict->getClass($v['exam_class_id']);
  43. $data[$k]['device'] = $v;
  44. $data[$k]['class'] = $subClass;
  45. }
  46. // 返回
  47. return $data;
  48. } catch (Exception $exception){
  49. $this->throwError($exception->getMessage(),0001);
  50. }
  51. }
  52. public function getDepartment($token)
  53. {
  54. $user = $this->dict->getUser($token);
  55. $data = $this->dict->getDepartment($user['institution_id']);
  56. return $data;
  57. }
  58. public function getDoctors($token)
  59. {
  60. $user = $this->dict->getUser($token);
  61. $data = $this->dict->getDoctors($user['institution_id']);
  62. return $data;
  63. }
  64. public function getExamSubclass()
  65. {
  66. try{
  67. $data = $this->dict->getExamSub();
  68. // 返回
  69. return $data;
  70. } catch (Exception $exception){
  71. $this->throwError($exception->getMessage(),0001);
  72. }
  73. }
  74. public function getExamProject()
  75. {
  76. try{
  77. $data = $this->dict->getProject();
  78. // 返回
  79. return $data;
  80. } catch (Exception $exception){
  81. $this->throwError($exception->getMessage(),0001);
  82. }
  83. }
  84. public function getExamClass()
  85. {
  86. try{
  87. $data = $this->dict->getExamClass();
  88. // 返回
  89. return $data;
  90. } catch (Exception $exception){
  91. $this->throwError($exception->getMessage(),0001);
  92. }
  93. }
  94. public function getIllness()
  95. {
  96. try{
  97. $data = $this->dict->getIllness();
  98. // 返回
  99. return $data;
  100. } catch (Exception $exception){
  101. $this->throwError($exception->getMessage(),0001);
  102. }
  103. }
  104. public function getFamilyIll()
  105. {
  106. try{
  107. $data = $this->dict->getFamilyIll();
  108. // 返回
  109. return $data;
  110. } catch (Exception $exception){
  111. $this->throwError($exception->getMessage(),0001);
  112. }
  113. }
  114. public function icdClass()
  115. {
  116. try {
  117. $data = $this->dict->getIcd();
  118. foreach ($data as &$v){
  119. $v['children'] = $this->dict->getDictChild($v['id']);
  120. }
  121. return $data;
  122. }catch ( Exception $exception){
  123. $this->throwError($exception->getMessage(),0001);
  124. }
  125. }
  126. public function icdList($params)
  127. {
  128. try {
  129. // 1. 拼装搜索条件
  130. $class_id = $params['class_id'] ?? false;
  131. $class_where = false;
  132. if($class_id){
  133. $class_where = ['pid' => $class_id];
  134. }
  135. $name_where = false;
  136. $name = $params['name'] ?? false;
  137. if($name){
  138. $name_where = "`name` LIKE '%$name%' OR `pinyin` LIKE '%$name%' OR `initial` LIKE '%$name%'";
  139. }
  140. $last_id = $params['last_id'] ?? false;
  141. // 2. 查询
  142. return $this->dict->getIcdList($class_where, $name_where, $last_id);
  143. }catch ( Exception $exception){
  144. $this->throwError($exception->getMessage(),0001);
  145. }
  146. }
  147. public function saveQuality($params,$token)
  148. {
  149. $user = $this->dict->getUser($token);
  150. $id = $params['id'] ?? '';
  151. $qcinfo = $this->dict->getQualityById($id);
  152. $report_doctor = $this->dict->getReportDoctor($params['report_id']);
  153. $data = [
  154. 'institution_id'=>$user['institution_id'],
  155. 'report_id'=>$params['report_id'],
  156. 'pic_quality'=>$params['pic_quality'] ?? '',
  157. 'report_quality'=>$params['report_quality'] ?? '',
  158. 'comment_user_id'=>$user['id'],
  159. 'comment_user_name'=>$user['realname'],
  160. 'report_doctor'=>$report_doctor,
  161. ];
  162. $p = implode(',',$params['pic_evaluate'] ?? []);
  163. // if(isset($params['pic_evaluate']) && !empty($params['pic_evaluate'])){
  164. // $p = implode(',',$params['pic_evaluate']);
  165. // }
  166. $r = implode(',',$params['report_evaluate'] ?? []);
  167. // if(isset($params['report_evaluate']) && !empty($params['report_evaluate'])){
  168. // $r = implode(',',$params['report_evaluate']);
  169. // }
  170. $data['pic_evaluate'] = $p;
  171. $data['report_evaluate'] = $r;
  172. if($id){
  173. $qc = $this->dict->updateQuality($id,$data);
  174. if($qcinfo['pic_evaluate']!=$p){
  175. //删除影像评价因子
  176. $this->dict->delPic($id,1);
  177. $this->savePic($params['pic_evaluate'],$id,1);
  178. }
  179. if($qcinfo['report_evaluate']!=$r){
  180. //删除报告评价因子
  181. $this->dict->delPic($id,2);
  182. $this->savePic($params['report_evaluate'],$id,2);
  183. }
  184. }else{
  185. $data['id'] = UUIDUtils::uuid();
  186. $qc = $this->dict->saveQuality($data);
  187. $this->savePic($params['pic_evaluate'],$data['id'],1);
  188. $this->savePic($params['report_evaluate'],$data['id'],2);
  189. }
  190. return $qc;
  191. }
  192. public function savePic($evaluate,$id,$type)
  193. {
  194. foreach ($evaluate as $v){
  195. $report_evaluate = [
  196. 'control_id'=>$id,
  197. 'factor_id'=>$v,
  198. 'type'=>$type,
  199. ];
  200. $this->dict->savePic($report_evaluate);
  201. }
  202. }
  203. public function getQuality($id,$token)
  204. {
  205. $user = $this->dict->getUser($token);
  206. $info = $this->dict->getQuality($id,$user);
  207. $info = json_decode(json_encode($info,true),true);
  208. if(empty($info)){
  209. $info = ['report_id'=>$id];
  210. return $info;
  211. }
  212. foreach ($info as $k=>$v){
  213. if($k == 'pic_evaluate'){
  214. if(empty($v)){
  215. $info[$k] = [];
  216. }else{
  217. $p = explode(',',$v);
  218. $pe = [];
  219. foreach ($p as $value){
  220. $pe[] = (int)$value;
  221. }
  222. $info[$k] = $pe;
  223. }
  224. }
  225. if($k == 'report_evaluate'){
  226. if(empty($v)){
  227. $info[$k] = [];
  228. }else{
  229. $r = explode(',',$v);
  230. $re = [];
  231. foreach ($r as $value){
  232. $re[] = (int)$value;
  233. }
  234. $info[$k] = $re;
  235. }
  236. }
  237. }
  238. return $info;
  239. }
  240. public function qualityFactorPic()
  241. {
  242. $info = $this->dict->getqualityFactorPic();
  243. return $info;
  244. }
  245. public function qualityFactorReport()
  246. {
  247. $info = $this->dict->getqualityFactorReport();
  248. return $info;
  249. }
  250. public function getApplicationDepartment($token)
  251. {
  252. $doctor = $this->getCache($token);
  253. $institution = $doctor['institution_id'];
  254. $info = $this->dict->getApplicationDepartment($institution);
  255. $data = [];
  256. if($institution == '73000003')
  257. {
  258. $data[] = ['application_department'=>'AI-胸片'];
  259. foreach ($info as $k=>$v)
  260. {
  261. $data[] = $v;
  262. }
  263. return $data;
  264. }else{
  265. return $info;
  266. }
  267. }
  268. public function getNewPart($token)
  269. {
  270. // $doctor = $this->getCache($token);
  271. // $institution = $doctor['institution_id'];
  272. $info = $this->dict->getNewPart();
  273. return $info;
  274. }
  275. }