报告完整流程.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /report/save 方法完整操作流程
  2. 1. 控制器层 (ReportController.php:45-56)
  3. public function save(ReportService $service)
  4. {
  5. $params = $this->getParams();
  6. ReportValidate::checkSave($params); // 参数验证
  7. $token = $this->getToken();
  8. $result = $service->updateReport($params['exam_id'], $params, 'save', '2', $token);
  9. return $this->success($result);
  10. }
  11. 参数说明:
  12. - exam_id:检查ID
  13. - params:所有表单参数
  14. - 'save':操作类型(保存)
  15. - '2':报告类型(2=本地报告,1=远程报告)
  16. - token:用户token
  17. 2. 核心业务逻辑 (ReportService.php:214-413)
  18. 2.1 权限验证
  19. // 1. 获取检查信息
  20. $exam = $this->reportDao->getExam($examId);
  21. $phone = $exam['phone'] ?? '';
  22. $studyId = $exam['study_id'];
  23. // 2. 获取用户信息
  24. $user = $this->reportDao->getUser($token);
  25. $user_id = $user['id'];
  26. // 3. 验证报告权限
  27. $result = $this->reportAuthentication($user_id, $type, $exam['institution_id'], $reportType);
  28. if(!$result){
  29. throw '权限未分配,请联系管理员';
  30. }
  31. 2.2 获取或创建报告记录
  32. $rt = ($reportType == 1) ? 2 : 1;
  33. $report = $this->reportDao->getReport($examId, $rt, $ra_id);
  34. $reportId = $report['id'] ?? null;
  35. // 如果报告不存在,创建新报告
  36. if(empty($reportId)){
  37. if($type == 'save'){
  38. $insert_data = [
  39. 'id' => UUIDUtils::uuid(),
  40. 'exam_id' => $examId,
  41. 'createdAt' => date('Y-m-d H:i:s'),
  42. 'report_result' => 1,
  43. 'type' => $rt,
  44. 'remote_application_id' => $ra_id
  45. ];
  46. $insert_res = $this->reportDao->insertReport($insert_data);
  47. $reportId = $insert_data['id'];
  48. }
  49. }
  50. 2.3 检查报告锁定状态
  51. // 检查是否被其他医生锁定
  52. if ($user_id !== $report['report_doctor_id'] && !empty($report['report_doctor_id']))
  53. {
  54. throw '该报告已被其他医师书写,请刷新当前有页面进行查看!';
  55. }
  56. 2.4 添加报告锁定记录(特定机构)
  57. // 如果是特定机构(43600001),添加锁定状态
  58. if($user['institution_id'] == '43600001')
  59. {
  60. if($type == 'save' || $type == 'audit')
  61. {
  62. $middle = [
  63. 'institution_id' => $user['institution_id'],
  64. 'status' => 0, // 0=锁定中
  65. 'doctor_id' => $user['id'],
  66. 'doctor_name' => $user['realname'],
  67. 'exam_id' => $examId,
  68. 'is_sync' => 0,
  69. 'report_id' => $reportId
  70. ];
  71. $middleInfo = $this->reportDao->getMiddle(['exam_id'=>$examId]);
  72. if($middleInfo) {
  73. unset($middle['is_sync']);
  74. $middleWhere = ['exam_id'=>$examId];
  75. }
  76. $this->reportDao->saveRmiddle($middle, $middleWhere);
  77. }
  78. }
  79. 2.5 更新检查基本信息
  80. // 处理性别字段
  81. switch ($data['sex']){
  82. case 'M':
  83. case '男':
  84. $sex = 'M';
  85. break;
  86. case 'F':
  87. case '女':
  88. $sex = 'F';
  89. break;
  90. default:
  91. $sex = $data['sex'];
  92. break;
  93. }
  94. // 更新患者基本信息
  95. $update = [
  96. 'name' => $data['name'],
  97. 'sex' => $sex,
  98. 'age' => $data['age'],
  99. 'exam_class' => $data['exam_class'],
  100. 'exam_project' => $data['exam_project'] ?? null,
  101. 'phone' => $data['phone']
  102. ];
  103. if($rt == 1){
  104. $exam_res = $this->reportDao->updateExamMsg($examId, $exam['patient_id'], $update);
  105. }else{
  106. $remote_res = $this->reportDao->updateRemote($ra_id, $update);
  107. }
  108. 2.6 更新报告内容
  109. $report_up = [
  110. 'impression' => $data['impression'] ?? null, // 诊断意见
  111. 'description' => $data['description'] ?? null, // 报告描述
  112. 'report_result' => $data['report_result'] ?? null, // 报告结果
  113. 'hr_status' => $data['hr_status'] ?? 1 // 高危状态
  114. ];
  115. 2.7 调用 updateReportData 方法 (ReportService.php:782-922)
  116. 2.7.1 验证流程状态
  117. // 本地保存
  118. if($report_type == 2){
  119. $write = $this->reportDao->getExam($exam_id);
  120. if($write['write_report'] != 1)
  121. {
  122. // 检查状态:必须是3、7或12才能书写
  123. if($exam_status != 3 && $exam_status != 7 && $exam_status != 12){
  124. throw '流程顺序错误,无法书写报告';
  125. }
  126. }
  127. }
  128. 2.7.2 更新报告数据
  129. $update = [
  130. 'impression' => $data['impression'],
  131. 'description' => $data['description'],
  132. 'hr_status' => $data['hr_status'],
  133. 'report_result' => $data['report_result'],
  134. 'report_datetime' => date('Y-m-d H:i:s'), // 书写时间
  135. 'report_doctor_id' => $user['id'], // 书写医生ID
  136. 'report_doctor_name' => $user['realname'] // 书写医生姓名
  137. ];
  138. // 更新报告表
  139. $result = $this->reportDao->updateReport($exam_id, 1, $update);
  140. // 更新检查状态为7(已书写)
  141. $this->reportDao->updateExamStatus($exam_id, 7);
  142. 2.7.3 插入报告痕迹记录
  143. $trace = [
  144. 'id' => UUIDUtils::uuid(),
  145. 'impression' => $update['impression'] ?? '',
  146. 'description' => $update['description'] ?? '',
  147. 'report_result' => $update['report_result'] ?? '',
  148. 'report_id' => $rid,
  149. 'createdAt' => date('Y-m-d H:i:s'),
  150. 'doctor_id' => $user['id'],
  151. 'type' => 1 // 1=书写
  152. ];
  153. $result = $this->reportDao->insertReportRecord($trace);
  154. 涉及的数据库表操作
  155. 1. report 表
  156. - INSERT:创建新报告记录(如果不存在)
  157. - UPDATE:更新报告内容(impression、description、report_result、hr_status、report_datetime、report_doctor_id、report_doctor_name)
  158. 2. exam 表
  159. - SELECT:查询检查信息
  160. - UPDATE:更新患者基本信息(name、sex、age、exam_class、exam_project、phone)
  161. - UPDATE:更新检查状态为7(已书写)
  162. 3. rmiddle 表(报告锁定中间表,仅特定机构)
  163. - INSERT/UPDATE:保存报告锁定记录
  164. 4. report_record 表(报告痕迹表)
  165. - INSERT:插入报告操作痕迹记录
  166. 5. patient 表
  167. - UPDATE:更新患者信息(通过 exam_id 关联)
  168. 6. remote_application 表(远程报告,如果是远程类型)
  169. - UPDATE:更新远程申请单信息
  170. 操作总结
  171. /report/save 方法执行以下操作:
  172. 1. ✅ 参数验证
  173. 2. ✅ 权限验证:检查用户是否有报告书写权限
  174. 3. ✅ 获取/创建报告:如果报告不存在则创建新记录
  175. 4. ✅ 锁定检查:防止多个医生同时编辑同一报告
  176. 5. ✅ 添加锁定记录:为特定机构添加报告锁定状态
  177. 6. ✅ 更新患者基本信息:姓名、性别、年龄、检查类型、手机号等
  178. 7. ✅ 更新报告内容:诊断意见、报告描述、报告结果、高危状态
  179. 8. ✅ 更新书写医生信息:记录书写医生ID和姓名
  180. 9. ✅ 更新书写时间:记录报告书写时间
  181. 10. ✅ 更新检查状态:将检查状态更新为7(已书写)
  182. 11. ✅ 插入报告痕迹:保存报告修改历史记录
  183. 关键状态码
  184. - exam_status:
  185. - 3:待书写
  186. - 7:已书写
  187. - 8:已审核
  188. - 9:已确认
  189. - 12:特殊状态(允许书写)
  190. - report 锁定状态:
  191. - 0:锁定中
  192. - 1:已解锁
  193. 这个方法实现了完整的报告保存流程,包括权限控制、并发控制、数据更新和历史记录等功能。