Patient.php 6.9 KB

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