香洲二院小程序
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.
 
 
mini_xzey/app/Http/Logics/Report/InspectLogic.php

164 lines
5.4 KiB

<?php
declare(strict_types = 1);
namespace App\Http\Logics\Report;
use App\Dictionary\Order\PayType;
use App\Dictionary\Order\SourceId;
use App\Dictionary\Order\Status;
use App\Dictionary\Order\Type;
use App\Dictionary\Patient\CardType;
use App\Dictionary\Report\ImageType;
use App\Exceptions\GeneralException;
use App\Models\Order;
use App\Models\Patient;
use App\Models\RegistrationRecord;
use App\Services\HisHttp\Client;
use App\Utils\Statics\BuildCacheKeyName;
use App\Utils\Traits\Logger;
use App\Utils\Traits\MiniProgramAuth;
use App\Utils\Traits\SendSubscribeMessage;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;
use ReflectionException;
use Symfony\Component\HttpFoundation\Response;
use UnifyPayment\Cores\Struct\RefundOrder;
use UnifyPayment\Unify;
class InspectLogic
{
use Logger;
use MiniProgramAuth;
private Client $his_client;
private Patient $patient_model;
private Order $order_model;
/**
* RecordLogic Construct
* @throws AuthenticationException
*/
public function __construct()
{
$this->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'];
}
}