authInitialize(); $this->setChannel('refund'); $this->his_client = app('HisHttpService'); $this->patient_model = new Patient(); } /** * 获取报告列表 * @param string $patient_number * @param string $start_date * @param string $end_date * @return mixed * @throws GeneralException */ public function lists(string $patient_number, string $start_date, string $end_date): mixed { $patient_info = $this->getHisPatientInfo($this->open_id, $patient_number); $response = $this->his_client->getInspectReportLists($patient_info['name'], $patient_info['idCardNo'], $start_date, $end_date); if (!isset($response['success']) || !$response['success']) { throw new GeneralException($response['msg'] ?? '找不到该就诊卡!', Response::HTTP_SERVICE_UNAVAILABLE); } Redis::setex(BuildCacheKeyName::getInspectReportListsKey($this->open_id, $patient_info['patient_id']), 3600, json_encode($response['response'], JSON_UNESCAPED_UNICODE)); return $response['response']; } /** * 获取报告详情 * @param string $patient_number * @param string $serial_no * @return array * @throws GeneralException */ public function details(string $patient_number, string $serial_no) { $patient_info = $this->getPatientInfo($this->open_id, $patient_number); // 缓存键名 $report_lists_cache_key = BuildCacheKeyName::getInspectReportListsKey($this->open_id, $patient_info['patient_id']); $report_images_cache_key = BuildCacheKeyName::getInspectReportDetailsImagesKey($this->open_id, $patient_info['patient_id'], $serial_no); if (!Redis::exists($report_lists_cache_key)) { throw new GeneralException('找不到报告详情,请重新再试!', Response::HTTP_BAD_REQUEST); } $lists = Redis::get($report_lists_cache_key); $lists = json_decode($lists, true); $info = []; foreach ($lists['body'] as $v) { if ($serial_no === $v['sourceId']) { $info = $v; break; } } if (empty($info)) { throw new GeneralException('找不到报告详情,请重新再试!', Response::HTTP_BAD_REQUEST); } $images = []; if (!Redis::exists($report_images_cache_key)) { $image_response = $this->his_client->getInspectReportImages(ImageType::IMAGE,$serial_no); if (isset($image_response['success']) && $image_response['success']) { $images = $image_response['response']['fileBase64']; } // 缓存图片base64进去 if (!empty($images)) { Redis::setex($report_images_cache_key, 3600, json_encode($images, JSON_UNESCAPED_UNICODE)); } } else { $images = Redis::get($report_images_cache_key); $images = json_decode($images, true); } $info['pacs'] = $images; return $info; } /** * 获取数据库里的患者信息 * @param string $open_id * @param string $patient_number * @return mixed * @throws GeneralException */ protected function getPatientInfo(string $open_id, string $patient_number): mixed { $info = $this->patient_model->getBindPatientInfoByPatientNumber($open_id, $patient_number); if (empty($info)) { throw new GeneralException('找不到患者信息,请重新再试!', Response::HTTP_BAD_REQUEST); } return $info; } /** * 获取HIS里的患者信息 * @param string $open_id * @param string $patient_number * @return mixed * @throws GeneralException */ protected function getHisPatientInfo(string $open_id, string $patient_number): mixed { $info = $this->getPatientInfo($open_id, $patient_number); $response = $this->his_client->getPatientInfo($info['patient_number'], CardType::OUTPATIENT_NO, $info['name']); if (!isset($response['success']) || !$response['success']) { throw new GeneralException($response['msg'] ?? '找不到该就诊卡!', Response::HTTP_SERVICE_UNAVAILABLE); } return $response['response']; } }