123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace app\api\servies\qc;
- use app\api\actions\ZskkCache;
- use app\api\dao\exam\ExamDao;
- use app\api\dao\xz\XzDao;
- use app\api\model\api\ApiModel;
- use app\api\request\ZskkDefaultRequest;
- use app\api\response\ZskkErrorResponse;
- use app\api\servies\wechat\WechatService;
- use app\api\servies\xz\XzService;
- use app\api\servies\ZskkDefaultService;
- use app\api\utils\UUIDUtils;
- use app\api\validate\report\ReportValidate;
- use app\api\dao\report\ReportDao;
- use app\api\model\exam\ExamModel;
- use app\api\model\institution\InstitutionModel;
- use app\api\model\qc\QcExamModel;
- use app\api\model\qc\QcModel;
- use app\api\model\report\ReportModel;
- use app\api\model\studies\StudiesModel;
- use app\api\servies\common\CommonService;
- use app\common\library\send_message;
- use app\common\library\uploadToCloud;
- use DateTime;
- use PHPMailer\PHPMailer\PHPMailer;
- use think\facade\Config;
- use think\facade\Log;
- use think\Db;
- use think\db\exception;
- /**
- * 后台控制器基类
- * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
- */
- class QcService extends ZskkDefaultService {
- protected $logName = "QcService";
- private $reportModel = null;
- private $examModel = null;
- private $studyModel = null;
- private $institutionModel = null;
- private $qcModel = null;
- public function __construct(ReportModel $reportModel, ExamModel $examModel, StudiesModel $studyModel, InstitutionModel $institutionModel, QcExamModel $qcModel) {
- parent::__construct();
- $this->reportModel = $reportModel;
- $this->examModel = $examModel;
- $this->studyModel = $studyModel;
- $this->institutionModel = $institutionModel;
- $this->qcModel = $qcModel;
- }
- public function testAnalysis() {
- $limit = 100;
- $exams = $this->examModel
- ->where('institution_id', '06300006')
- ->where('qc_status', 1)
- ->where('exam_status', 9)
- ->order('createdAt', 'desc')
- ->limit($limit)
- ->select();
- foreach($exams as $exam) {
- $this->analysis($exam['id']);
- }
- if(count($exams) === $limit) {
- $this->testAnalysis();
- }
- }
- public function getInstitutionName($institution_id) {
- $name = $this->institutionModel->where('id', $institution_id)->value('name');
- return $name;
- }
- public function analysis($exam_id) {
- $exam = $this->examModel->where('id', $exam_id)->find();
- $report = $this->reportModel->where('exam_id', $exam_id)->find();
- $study = $this->studyModel->where('id', $exam['study_id'])->find();
- $studyDay = $exam['exam_datetime'];
- $studyTime = $study['studytime'];
- $studyDate = $this->getStudyDate($studyDay, $studyTime);
- // 判断报告医生和审核医生是否同一人;
- // 判断检查时间和审核时间是否超过2个小时;
- // 判断是否存在身份证号、手机号、检查日期、报告日期、审核日期为空,
- $time = $this->diffTime($studyDate, $report['review_datetime']);
- $qcExam = [
- 'exam_id' => $exam_id,
- 'institution_id' => $exam['institution_id'],
- 'name' => $exam['name'],
- 'card_num' => $exam['card_num'],
- 'exam_class' => $exam['exam_class'],
- 'phone' => $exam['phone'],
- 'studydate' => $studyDate,
- 'studyday' => $this->date2day($studyDate),
- 'reportdate' => $report['report_datetime'],
- 'reportday' => $this->date2day($report['report_datetime']),
- 'reviewdate' => $report['review_datetime'],
- 'reviewday' => $this->date2day($report['review_datetime']),
- 'study_doctor_id' => null,
- 'report_doctor_id' => $report['report_doctor_id'],
- 'review_doctor_id' => $report['review_doctor_id'],
- 'study_doctor_name' => null,
- 'report_doctor_name' => $report['report_doctor_name'],
- 'review_doctor_name' => $report['review_doctor_name'],
- 'report_interval' => $time,
- 'institution_name' => $this->getInstitutionName($exam['institution_id']),
- ];
- $this->saveQcExam($qcExam);
- $exam['qc_status'] = 2;
- $exam->save();
- }
- private function saveQcExam($qcExam) {
- // $qcModel = $this->qcModel;
- $qcModel = new QcExamModel();
- $old = $qcModel->where('exam_id', $qcExam['exam_id'])->find();
- if($old) {
- $old->save($qcExam);
- } else {
- $qcModel->save($qcExam);
- }
- }
- private function getStudyDate($studyDay, $studyTime) {
- if(!$studyDay) {
- return null;
- }
- if(!$studyTime) {
- return null;
- }
- // strtotime()
- $studyTime = explode('.', $studyTime)[0];
- $formattedDateTime = date('Y-m-d H:i:s', strtotime($studyDay . ' ' . $studyTime));
- return $formattedDateTime;
- }
- public function diffTime($studyDate, $reviewDate) {
- return strtotime($reviewDate) - strtotime($studyDate);
- }
- public function date2day($date) {
- $formattedDate = date("Ymd", strtotime($date));
- $intDate = (int)$formattedDate;
- return $intDate;
- }
- }
|