authInitialize(); $this->his_client = app('HisHttpService'); } /** * 获取挂号记录列表 * @param string $patient_id * @param string $start_date * @param string $end_date * @return array * @throws GeneralException */ public function getRecordLists(string $patient_id, string $start_date, string $end_date): array { $response = $this->his_client->getPaidLists($patient_id, $start_date, $end_date); if (!isset($response['RESULTCODE']) || $response['RESULTCODE'] !== '0') { throw new GeneralException($response['ERRORMSG'] ?? '暂无相关挂号记录!', Response::HTTP_SERVICE_UNAVAILABLE); } // 缓存2小时 Cache::set('Outpatient.Record.'. $this->open_id.'.'. $patient_id, json_encode($response, JSON_UNESCAPED_UNICODE), 2 * 60 * 60); return $response; } /** * 获取挂号记录列表 * @param string $patient_id * @param string $serial_no * @return array * @throws GeneralException */ public function getRecordDetails(string $patient_id, string $serial_no): array { $this->getCacheRecordInfo($patient_id, $serial_no); $response = $this->his_client->getPaidDetails($serial_no); if (!isset($response['RESULTCODE']) || $response['RESULTCODE'] !== '0') { throw new GeneralException($response['ERRORMSG'] ?? '暂无相关缴费详情!', Response::HTTP_SERVICE_UNAVAILABLE); } return $response; } /** * 获取缓存里的记录详情 * @param string $patient_id * @param string $serial_no * @return mixed * @throws GeneralException */ protected function getCacheRecordInfo(string $patient_id, string $serial_no): mixed { $cache_key = 'Outpatient.Record.'. $this->open_id.'.'. $patient_id; $record_info = Cache::get($cache_key); if (empty($record_info)) { throw new GeneralException($response['ERRORMSG'] ?? '查询不到缴费记录,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); } $record_info = json_decode($record_info, true); // 获取具体的缴费详情 $record_info = xmlArrayToListByKey($record_info, 'RECORD'); foreach ($record_info['RECORD'] as $v) { if ($v['RCPTID'] === $serial_no) { $info = $v; break; } } if (empty($info)) { throw new GeneralException('查询不到缴费记录,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE); } return $info; } }