You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.2 KiB
104 lines
3.2 KiB
<?php
|
|
declare(strict_types = 1);
|
|
|
|
namespace App\Http\Logics\Outpatient;
|
|
|
|
use App\Exceptions\GeneralException;
|
|
use App\Services\HisHttp\Client;
|
|
use App\Utils\Traits\Logger;
|
|
use App\Utils\Traits\MiniProgramAuth;
|
|
use Illuminate\Auth\AuthenticationException;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class PendingLogic
|
|
{
|
|
use Logger;
|
|
use MiniProgramAuth;
|
|
|
|
private Client $his_client;
|
|
|
|
/**
|
|
* RecordLogic Construct
|
|
* @throws AuthenticationException
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->authInitialize();
|
|
$this->his_client = app('HisHttpService');
|
|
}
|
|
|
|
/**
|
|
* 获取挂号记录列表
|
|
* @param string $patient_id
|
|
* @return array
|
|
* @throws GeneralException
|
|
*/
|
|
public function getLists(string $patient_id,): array
|
|
{
|
|
$response = $this->his_client->getPendingLists($patient_id);
|
|
|
|
if (!isset($response['RESULTCODE']) || $response['RESULTCODE'] !== '0') {
|
|
throw new GeneralException($response['ERRORMSG'] ?? '暂无相关缴费记录!', Response::HTTP_SERVICE_UNAVAILABLE);
|
|
}
|
|
|
|
// 缓存2小时
|
|
Cache::set('Outpatient.Pending.'. $this->open_id.'.'. $patient_id, json_encode($response, JSON_UNESCAPED_UNICODE), 2 * 60 * 60);
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* 获取缴费记录详情
|
|
* @param string $patient_id
|
|
* @param string $serial_no
|
|
* @param string $prescription_ids
|
|
* @param string $reg_id
|
|
* @return array
|
|
* @throws GeneralException
|
|
*/
|
|
public function getDetails(string $patient_id, string $serial_no, string $prescription_ids, string $reg_id): array
|
|
{
|
|
$this->getCachePendingLists($patient_id, $serial_no);
|
|
|
|
$response = $this->his_client->getPendingDetails($prescription_ids, $serial_no, $reg_id);
|
|
|
|
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 getCachePendingLists(string $patient_id, string $serial_no): mixed
|
|
{
|
|
$cache_key = 'Outpatient.Pending.'. $this->open_id.'.'. $patient_id;
|
|
|
|
$pending_lists = Cache::get($cache_key);
|
|
if (empty($pending_lists)) {
|
|
throw new GeneralException($response['ERRORMSG'] ?? '查询不到缴费记录,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE);
|
|
}
|
|
$pending_lists = json_decode($pending_lists, true);
|
|
|
|
// 获取具体的缴费详情
|
|
$pending_lists = xmlArrayToListByKey($pending_lists, 'ITEM');
|
|
foreach ($pending_lists['ITEM'] as $v) {
|
|
if ($v['JZXH'] === $serial_no) {
|
|
$info = $v;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (empty($info)) {
|
|
throw new GeneralException('查询不到待缴费处方,请重新再试!', Response::HTTP_SERVICE_UNAVAILABLE);
|
|
}
|
|
|
|
return $info;
|
|
}
|
|
}
|
|
|