Patient.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\zskk\controller;
  4. use app\common\controller\ZskkApiController;
  5. use app\common\library\Gm;
  6. use app\common\library\Handle;
  7. use app\zskk\model\Mapping;
  8. use think\Config;
  9. use think\db\exception\DataNotFoundException;
  10. use think\db\exception\DbException;
  11. use think\db\exception\ModelNotFoundException;
  12. use think\facade\Cache;
  13. use think\facade\Db;
  14. use think\Exception;
  15. use think\facade\Log;
  16. use Throwable;
  17. use app\zskk\servies\PatientServies;
  18. class Patient extends ZskkApiController
  19. {
  20. /**
  21. * 后台初始化请求
  22. * @return void
  23. * @throws Throwable
  24. */
  25. public function addPatient(PatientServies $servies): void
  26. {
  27. set_time_limit(0);
  28. Db::startTrans();
  29. $params = $this->request->post();
  30. try{
  31. // var_dump($params['DATA']);die;
  32. $data = $servies->makeMappingData($params['DATA'],'DATA');
  33. $patientData = $data['PATIENT'];
  34. $medical = $data['MEDICAL_INFORMATION'];
  35. $application = $data['EXAM_APPLICATIONS'];
  36. $orders = $data['MEDICAL_ORDERS'];
  37. $exam = $data['EXAM_REPORTS'];
  38. $inspect = $data['INSPECT_REPORTS'];
  39. $diagnoses = $data['DIAGNOSES'];
  40. $mpiData = $servies->getMpi($patientData['ID_CARDNUM']);
  41. $mpiKey = $mpiData['MPI_KEY'] ?? '';
  42. $mpi = $mpiData['MPI'] ?? '';
  43. if(empty($mpiKey))
  44. {
  45. $mpiKey = Handle::makeMpiKey($patientData['ID_CARDNUM']);
  46. $mpi = Handle::makeMpi();
  47. $servies->saveMpi($mpi,$patientData['ID_CARDNUM'],$mpiKey);
  48. }
  49. // $patientCode = Handle::makePatientCode($medical['ORGCODE'],$medical['SERIESNUM']);
  50. $patientCode = Handle::makePatientCode($mpiKey, $medical['ORGCODE'],$medical['SERIESNUM']);
  51. $servies->savePatient($patientData,$mpi,$mpiKey,$patientCode); //患者表patient
  52. $servies->saveMedical($medical,$mpiKey,$patientCode); //medicalinformation表
  53. $servies->saveDiagnose($diagnoses,$patientCode); //diagnoses表
  54. $servies->saveApplication($application,$mpiKey,$patientCode); //examapplication表
  55. $servies->saveOrders($orders,$mpiKey,$patientCode); // 检验医嘱表 返回检验申请单标识
  56. // $servies->saveExamReport($exam,$mpiKey,$patientCode,$application['EXAM_ITEMNAME_CODE']); //检查报告表
  57. $servies->saveExamReport($exam,$mpiKey,$patientCode); //检查报告表
  58. $servies->saveInspectReport($inspect,$mpiKey,$patientCode); // 检验报告表
  59. // 管理后台-医院医院数据-患者信息表
  60. $servies->saveHospitalPatient($mpiKey, $mpi, $patientCode, $patientData, $medical, $diagnoses, $orders, $application);
  61. $servies->updateMiddleStatus($params['middleId'],['status'=>3]);
  62. Db::commit();
  63. }catch (\Exception $e)
  64. {
  65. // 9
  66. $servies->updateMiddleStatus($params['middleId'],['status'=>9]);
  67. Db::rollback();
  68. $this->error($e->getMessage());
  69. }
  70. $this->success('', 'success');
  71. }
  72. /**
  73. * @throws ModelNotFoundException
  74. * @throws DataNotFoundException
  75. * @throws DbException
  76. */
  77. public function getPatientInfo(PatientServies $servies): void
  78. {
  79. $params = $this->request->post();
  80. $patientCode = $params['PATIENT_CODE'];
  81. $data = $servies->getPatient(['PATIENT_CODE'=>$patientCode]);
  82. $this->success('',$data);
  83. }
  84. public function getIdCard()
  85. {
  86. $params = $this->request->get();
  87. $id = $params['id_card'] ?? '';
  88. $id = 'xCldB8dASEqkHUWN2cSByZRbzQCIL7xgFYnHrL8ET0Y=';
  89. $mpiIdCard = Gm::decrypt(\think\facade\Config::get('gm.key'),$id);
  90. echo $mpiIdCard;
  91. $id = 'qrnDuZJDJm+dW/sYPSWahg==';
  92. $mpiIdCard = Gm::decrypt(\think\facade\Config::get('gm.key'),$id);
  93. echo $mpiIdCard;
  94. }
  95. /**
  96. * 上传检查数据
  97. */
  98. public function postExamInfo(PatientServies $servies): void
  99. {
  100. // try {
  101. $params = $this->request->post();
  102. $params = $this->getDecryptData($params['data']);
  103. if(empty($params))
  104. {
  105. $this->error('密文解析失败');
  106. }
  107. $params = $servies->makeMappingData($params,'0','postExamInfo');
  108. // Log::record('检查信息参数'.json_encode($params));
  109. $data = $servies->postExamInfo($params);
  110. // }catch (\Exception $e)
  111. // {
  112. // $this->error($e->getMessage());
  113. // }
  114. $this->success('success','');
  115. }
  116. /**
  117. * 上传检查数据
  118. */
  119. public function postExamReport(PatientServies $servies): void
  120. {
  121. // try {
  122. $params = $this->request->post();
  123. $params = $this->getDecryptData($params['data']);
  124. if(empty($params))
  125. {
  126. $this->error('密文解析失败');
  127. }
  128. $params = $servies->makeMappingData($params,'0','postExamReport');
  129. // Log::record('检查报告参数'.json_encode($params));
  130. $data = $servies->postExamReport($params);
  131. // }catch (\Exception $e)
  132. // {
  133. // $this->error($e->getMessage());
  134. // }
  135. $this->success('success',$data);
  136. }
  137. public function sendTestSms(PatientServies $servies): void
  138. {
  139. $params = $this->request->get();
  140. $data = $servies->sendYqSms($params['phone'],$params['idcard'],$params['institution']);
  141. $this->success('success',$data);
  142. }
  143. /**
  144. * 上传检验数据
  145. */
  146. public function postLabReport(PatientServies $servies): void
  147. {
  148. // try {
  149. $params = $this->request->post();
  150. $params = $this->getDecryptData($params['data']);
  151. if(empty($params))
  152. {
  153. $this->error('密文解析失败');
  154. }
  155. $params = $servies->makeMappingData($params,'0','postLabReport');
  156. // Log::record('检验报告参数'.json_encode($params));
  157. $data = $servies->postLabReport($params);
  158. // $data = $this->makeEncryptData($data);
  159. // }catch (\Exception $e)
  160. // {
  161. // $this->error($e->getMessage());
  162. // }
  163. $this->success('success',$data);
  164. }
  165. public function syncExams(PatientServies $servies)
  166. {
  167. $params = $this->request->post();
  168. if(empty($params))
  169. {
  170. $this->error('接口异常');
  171. }
  172. $data = $servies->syncExam($params);
  173. $this->success('success',$data);
  174. }
  175. }