Patient.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 Throwable;
  16. use app\zskk\servies\PatientServies;
  17. class Patient extends ZskkApiController
  18. {
  19. /**
  20. * 后台初始化请求
  21. * @return void
  22. * @throws Throwable
  23. */
  24. public function addPatient(PatientServies $servies): void
  25. {
  26. set_time_limit(0);
  27. Db::startTrans();
  28. $params = $this->request->post();
  29. try{
  30. // var_dump($params['DATA']);die;
  31. $data = $servies->makeMappingData($params['DATA'],'DATA');
  32. $patientData = $data['PATIENT'];
  33. $medical = $data['MEDICAL_INFORMATION'];
  34. $application = $data['EXAM_APPLICATIONS'];
  35. $orders = $data['MEDICAL_ORDERS'];
  36. $exam = $data['EXAM_REPORTS'];
  37. $inspect = $data['INSPECT_REPORTS'];
  38. $diagnoses = $data['DIAGNOSES'];
  39. $mpiData = $servies->getMpi($patientData['ID_CARDNUM']);
  40. $mpiKey = $mpiData['MPI_KEY'] ?? '';
  41. $mpi = $mpiData['MPI'] ?? '';
  42. if(empty($mpiKey))
  43. {
  44. $mpiKey = Handle::makeMpiKey($patientData['ID_CARDNUM']);
  45. $mpi = Handle::makeMpi();
  46. $servies->saveMpi($mpi,$patientData['ID_CARDNUM'],$mpiKey);
  47. }
  48. // $patientCode = Handle::makePatientCode($medical['ORGCODE'],$medical['SERIESNUM']);
  49. $patientCode = Handle::makePatientCode($mpiKey, $medical['ORGCODE'],$medical['SERIESNUM']);
  50. $servies->savePatient($patientData,$mpi,$mpiKey,$patientCode); //患者表patient
  51. $servies->saveMedical($medical,$mpiKey,$patientCode); //medicalinformation表
  52. $servies->saveDiagnose($diagnoses,$patientCode); //diagnoses表
  53. $servies->saveApplication($application,$mpiKey,$patientCode); //examapplication表
  54. $servies->saveOrders($orders,$mpiKey,$patientCode); // 检验医嘱表 返回检验申请单标识
  55. // $servies->saveExamReport($exam,$mpiKey,$patientCode,$application['EXAM_ITEMNAME_CODE']); //检查报告表
  56. $servies->saveExamReport($exam,$mpiKey,$patientCode); //检查报告表
  57. $servies->saveInspectReport($inspect,$mpiKey,$patientCode); // 检验报告表
  58. // 管理后台-医院医院数据-患者信息表
  59. $servies->saveHospitalPatient($mpiKey, $mpi, $patientCode, $patientData, $medical, $diagnoses, $orders, $application);
  60. $servies->updateMiddleStatus($params['middleId'],['status'=>3]);
  61. Db::commit();
  62. }catch (\Exception $e)
  63. {
  64. // 9
  65. $servies->updateMiddleStatus($params['middleId'],['status'=>9]);
  66. Db::rollback();
  67. $this->error($e->getMessage());
  68. }
  69. $this->success('', 'success');
  70. }
  71. /**
  72. * @throws ModelNotFoundException
  73. * @throws DataNotFoundException
  74. * @throws DbException
  75. */
  76. public function getPatientInfo(PatientServies $servies): void
  77. {
  78. $params = $this->request->post();
  79. $patientCode = $params['PATIENT_CODE'];
  80. $data = $servies->getPatient(['PATIENT_CODE'=>$patientCode]);
  81. $this->success('',$data);
  82. }
  83. /**
  84. * 上传检查数据
  85. */
  86. public function postExamInfo(PatientServies $servies): void
  87. {
  88. try {
  89. $params = $this->request->post();
  90. $params = $this->getDecryptData($params['data']);
  91. $params = $servies->makeMappingData($params,'0','postExamInfo');
  92. $data = $servies->postExamInfo($params);
  93. $data = $this->makeEncryptData($data);
  94. $this->success($data,'');
  95. }catch (\Exception $e)
  96. {
  97. $this->error($e->getMessage());
  98. }
  99. }
  100. /**
  101. * 上传检查数据
  102. */
  103. public function postExamReport(PatientServies $servies): void
  104. {
  105. try {
  106. $params = $this->request->post();
  107. $params = $this->getDecryptData($params['data']);
  108. $params = $servies->makeMappingData($params,'0','postExamReport');
  109. $data = $servies->postExamReport($params);
  110. $data = $this->makeEncryptData($data);
  111. $this->success($data,'');
  112. }catch (\Exception $e)
  113. {
  114. $this->error($e->getMessage());
  115. }
  116. }
  117. /**
  118. * 上传检验数据
  119. */
  120. public function postLisReport(PatientServies $servies): void
  121. {
  122. try {
  123. $params = $this->request->post();
  124. $params = $this->getDecryptData($params['data']);
  125. $params = $servies->makeMappingData($params,'0','postLabReport');
  126. $data = $servies->postLabReport($params);
  127. $data = $this->makeEncryptData($data);
  128. $this->success($data,'');
  129. }catch (\Exception $e)
  130. {
  131. $this->error($e->getMessage());
  132. }
  133. }
  134. }