|
|
|
<?php
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace App\Http\Logics\Outpatient;
|
|
|
|
|
|
|
|
use App\Exceptions\GeneralException;
|
|
|
|
use App\Models\Patient;
|
|
|
|
use App\Services\HisHttp\Client;
|
|
|
|
use App\Utils\Traits\BuildCacheKeyName;
|
|
|
|
use App\Utils\Traits\Logger;
|
|
|
|
use App\Utils\Traits\MiniProgramAuth;
|
|
|
|
use Illuminate\Auth\AuthenticationException;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
class PendingLogic
|
|
|
|
{
|
|
|
|
use Logger;
|
|
|
|
use MiniProgramAuth;
|
|
|
|
use BuildCacheKeyName;
|
|
|
|
|
|
|
|
private Client $his_client;
|
|
|
|
|
|
|
|
private Patient $patient_model;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RecordLogic Construct
|
|
|
|
* @throws AuthenticationException
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->authInitialize();
|
|
|
|
$this->his_client = app('HisHttpService');
|
|
|
|
$this->patient_model = new Patient();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取待缴费记录列表
|
|
|
|
* @param string $patient_number
|
|
|
|
* @return array
|
|
|
|
* @throws GeneralException
|
|
|
|
*/
|
|
|
|
public function getLists(string $patient_number): array
|
|
|
|
{
|
|
|
|
$patient_info = $this->getPatientInfo($this->open_id, $patient_number);
|
|
|
|
$patient_id = $patient_info->patient_id;
|
|
|
|
|
|
|
|
$response = $this->his_client->getPendingLists($patient_id);
|
|
|
|
|
|
|
|
if (!isset($response['success']) || !$response['success']) {
|
|
|
|
// 如果未查询到信息,则返回空数组数据
|
|
|
|
if ($response['msg'] === '查询就诊记录失败:查询结果没记录') {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new GeneralException($response['msg'] ?? '暂无相关缴费记录!', Response::HTTP_SERVICE_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 缓存2小时
|
|
|
|
Redis::setnx($this->getOutpatientPendingListsKey($this->open_id, $patient_id), 7200, json_encode($response, JSON_UNESCAPED_UNICODE));
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取待缴费记录详情
|
|
|
|
* @param string $patient_number
|
|
|
|
* @param string $serial_no
|
|
|
|
* @param string $prescription_ids
|
|
|
|
* @param string $reg_id
|
|
|
|
* @return array
|
|
|
|
* @throws GeneralException
|
|
|
|
*/
|
|
|
|
public function getDetails(string $patient_number, string $serial_no, string $prescription_ids, string $reg_id): array
|
|
|
|
{
|
|
|
|
$patient_info = $this->getPatientInfo($this->open_id, $patient_number);
|
|
|
|
$patient_id = $patient_info->patient_id;
|
|
|
|
|
|
|
|
$this->getCachePendingLists($patient_id, $serial_no);
|
|
|
|
|
|
|
|
$response = $this->his_client->getPendingDetails($prescription_ids, $serial_no, $reg_id);
|
|
|
|
|
|
|
|
if (!isset($response['success']) || !$response['success']) {
|
|
|
|
throw new GeneralException($response['msg'] ?? '暂无相关缴费详情!', Response::HTTP_SERVICE_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 缓存2小时
|
|
|
|
Redis::setnx($this->getOutpatientPendingDetailsKey($this->open_id, $patient_id, $serial_no), 7200, json_encode($response, JSON_UNESCAPED_UNICODE));
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取缓存里的记录详情
|
|
|
|
* @param string $patient_id
|
|
|
|
* @param string $serial_no
|
|
|
|
* @return mixed
|
|
|
|
* @throws GeneralException
|
|
|
|
*/
|
|
|
|
protected function getCachePendingLists(string $patient_id, string $serial_no): mixed
|
|
|
|
{
|
|
|
|
// 缓存键值
|
|
|
|
$cache_key = $this->getOutpatientPendingListsKey($this->open_id, $patient_id);
|
|
|
|
|
|
|
|
// 获取缓存
|
|
|
|
if (Redis::exists($cache_key)) {
|
|
|
|
$response = Redis::get($cache_key);
|
|
|
|
$response = json_decode($response, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果缓存数据有问题
|
|
|
|
if (empty($response)) {
|
|
|
|
$response = $this->his_client->getPendingLists($patient_id);
|
|
|
|
|
|
|
|
if (!isset($response['success']) || !$response['success']) {
|
|
|
|
throw new GeneralException($response['msg'] ?? '查询不到缴费记录,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取具体的缴费详情
|
|
|
|
foreach ($response['response'] as $v) {
|
|
|
|
if ($v['visitNumber'] === $serial_no) {
|
|
|
|
$info[] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($info)) {
|
|
|
|
throw new GeneralException('查询不到待缴费处方,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|