QcService.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace app\api\servies\qc;
  3. use app\api\actions\ZskkCache;
  4. use app\api\dao\exam\ExamDao;
  5. use app\api\dao\xz\XzDao;
  6. use app\api\model\api\ApiModel;
  7. use app\api\request\ZskkDefaultRequest;
  8. use app\api\response\ZskkErrorResponse;
  9. use app\api\servies\wechat\WechatService;
  10. use app\api\servies\xz\XzService;
  11. use app\api\servies\ZskkDefaultService;
  12. use app\api\utils\UUIDUtils;
  13. use app\api\validate\report\ReportValidate;
  14. use app\api\dao\report\ReportDao;
  15. use app\api\model\exam\ExamModel;
  16. use app\api\model\institution\InstitutionModel;
  17. use app\api\model\qc\QcExamModel;
  18. use app\api\model\qc\QcModel;
  19. use app\api\model\report\ReportModel;
  20. use app\api\model\studies\StudiesModel;
  21. use app\api\servies\common\CommonService;
  22. use app\common\library\send_message;
  23. use app\common\library\uploadToCloud;
  24. use DateTime;
  25. use PHPMailer\PHPMailer\PHPMailer;
  26. use think\facade\Config;
  27. use think\facade\Log;
  28. use think\Db;
  29. use think\db\exception;
  30. /**
  31. * 后台控制器基类
  32. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  33. */
  34. class QcService extends ZskkDefaultService {
  35. protected $logName = "QcService";
  36. private $reportModel = null;
  37. private $examModel = null;
  38. private $studyModel = null;
  39. private $institutionModel = null;
  40. private $qcModel = null;
  41. public function __construct(ReportModel $reportModel, ExamModel $examModel, StudiesModel $studyModel, InstitutionModel $institutionModel, QcExamModel $qcModel) {
  42. parent::__construct();
  43. $this->reportModel = $reportModel;
  44. $this->examModel = $examModel;
  45. $this->studyModel = $studyModel;
  46. $this->institutionModel = $institutionModel;
  47. $this->qcModel = $qcModel;
  48. }
  49. public function testAnalysis() {
  50. $limit = 100;
  51. $exams = $this->examModel
  52. ->where('institution_id', '06300006')
  53. ->where('qc_status', 1)
  54. ->where('exam_status', 9)
  55. ->order('createdAt', 'desc')
  56. ->limit($limit)
  57. ->select();
  58. foreach($exams as $exam) {
  59. $this->analysis($exam['id']);
  60. }
  61. if(count($exams) === $limit) {
  62. $this->testAnalysis();
  63. }
  64. }
  65. public function getInstitutionName($institution_id) {
  66. $name = $this->institutionModel->where('id', $institution_id)->value('name');
  67. return $name;
  68. }
  69. public function analysis($exam_id) {
  70. $exam = $this->examModel->where('id', $exam_id)->find();
  71. $report = $this->reportModel->where('exam_id', $exam_id)->find();
  72. $study = $this->studyModel->where('id', $exam['study_id'])->find();
  73. $studyDay = $exam['exam_datetime'];
  74. $studyTime = $study['studytime'];
  75. $studyDate = $this->getStudyDate($studyDay, $studyTime);
  76. // 判断报告医生和审核医生是否同一人;
  77. // 判断检查时间和审核时间是否超过2个小时;
  78. // 判断是否存在身份证号、手机号、检查日期、报告日期、审核日期为空,
  79. $time = $this->diffTime($studyDate, $report['review_datetime']);
  80. $qcExam = [
  81. 'exam_id' => $exam_id,
  82. 'institution_id' => $exam['institution_id'],
  83. 'name' => $exam['name'],
  84. 'card_num' => $exam['card_num'],
  85. 'exam_class' => $exam['exam_class'],
  86. 'phone' => $exam['phone'],
  87. 'studydate' => $studyDate,
  88. 'studyday' => $this->date2day($studyDate),
  89. 'reportdate' => $report['report_datetime'],
  90. 'reportday' => $this->date2day($report['report_datetime']),
  91. 'reviewdate' => $report['review_datetime'],
  92. 'reviewday' => $this->date2day($report['review_datetime']),
  93. 'study_doctor_id' => null,
  94. 'report_doctor_id' => $report['report_doctor_id'],
  95. 'review_doctor_id' => $report['review_doctor_id'],
  96. 'study_doctor_name' => null,
  97. 'report_doctor_name' => $report['report_doctor_name'],
  98. 'review_doctor_name' => $report['review_doctor_name'],
  99. 'report_interval' => $time,
  100. 'institution_name' => $this->getInstitutionName($exam['institution_id']),
  101. ];
  102. $this->saveQcExam($qcExam);
  103. $exam['qc_status'] = 2;
  104. $exam->save();
  105. }
  106. private function saveQcExam($qcExam) {
  107. // $qcModel = $this->qcModel;
  108. $qcModel = new QcExamModel();
  109. $old = $qcModel->where('exam_id', $qcExam['exam_id'])->find();
  110. if($old) {
  111. $old->save($qcExam);
  112. } else {
  113. $qcModel->save($qcExam);
  114. }
  115. }
  116. private function getStudyDate($studyDay, $studyTime) {
  117. if(!$studyDay) {
  118. return null;
  119. }
  120. if(!$studyTime) {
  121. return null;
  122. }
  123. // strtotime()
  124. $studyTime = explode('.', $studyTime)[0];
  125. $formattedDateTime = date('Y-m-d H:i:s', strtotime($studyDay . ' ' . $studyTime));
  126. return $formattedDateTime;
  127. }
  128. public function diffTime($studyDate, $reviewDate) {
  129. return strtotime($reviewDate) - strtotime($studyDate);
  130. }
  131. public function date2day($date) {
  132. $formattedDate = date("Ymd", strtotime($date));
  133. $intDate = (int)$formattedDate;
  134. return $intDate;
  135. }
  136. }