新增自动开具处方。修改ca对接

This commit is contained in:
2023-04-21 13:39:17 +08:00
parent 739286e54a
commit 298283b3fe
13 changed files with 682 additions and 121 deletions
+70 -29
View File
@@ -59,6 +59,13 @@ class CaService extends BaseService
// 信用代码
protected string $org_num;
// 处方pdf本地地址
protected string $prescription_pdf_local_path;
// 处方pdf oss地址
protected string $prescription_pdf_oss_path;
/**
* 初始化类,此处会获取基础数据
* @param array|object $order_prescription 处方表数据
@@ -215,6 +222,12 @@ class CaService extends BaseService
// 关闭channel通道
$channel->close();
}
// 处方pdf本地地址
$this->prescription_pdf_local_path = "./runtime/file/prescription/" . $order_prescription_id . '.pdf';
// 处方pdf oss地址
$this->prescription_pdf_oss_path = "applet/prescription/" . $order_prescription_id. '.pdf';
}
/**
@@ -382,8 +395,8 @@ class CaService extends BaseService
// 上传处方图片至oss
$oss = new Oss();
$prescription_img_oss_filename = "applet/prescription/" . $order_prescription['order_prescription_id'] . '.' . 'jpg';
$prescription_img_url = $oss->putObject($prescription_img_oss_filename, $img_result);
$prescription_img_url = '/' . $prescription_img_url;
$prescription_img_oss_path = $oss->putObject($prescription_img_oss_filename, $img_result);
$prescription_img_oss_path = '/' . $prescription_img_oss_path;
// 图片生成pdf
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
@@ -402,37 +415,78 @@ class CaService extends BaseService
// 图片生成的处方pdf存储为本地文件 runtime目录下
$pdf->Output($prescription_pdf_local_path . $prescription_pdf_local_filename, "F");
return $prescription_img_url;
return $prescription_img_oss_path;
}
/**
* 下载医生开具的处方pdf
* 下载Oss中处方pdf
* 存在:当次发版内医生开具后,药师再去开具
* 不存在:医生开具后,进行发版过,此时需重新下载
* @param string $order_prescription_id
* @param string $doctor_pdf_oss_path
* @return void
*/
public function downDoctorPrescriptionPdf(string $order_prescription_id,string $doctor_pdf_oss_path): void
public function downOssPdfToLocal(): void
{
$local_path = "./runtime/file/prescription/" . $order_prescription_id . '.' . 'pdf';
$res = file_exists($local_path);
$res = file_exists($this->prescription_pdf_local_path);
if (!$res){
// 去除第一个/ oss不识别
$prescription_pdf_path = substr($doctor_pdf_oss_path, 1, strlen($doctor_pdf_oss_path) - 1);
// $prescription_pdf_path = substr($doctor_pdf_oss_path, 1, strlen($doctor_pdf_oss_path) - 1);
$oss = new Oss();
$oss->getObjectToLocal($prescription_pdf_path, $local_path);
$oss->getObjectToLocal($this->prescription_pdf_oss_path, $this->prescription_pdf_local_path);
}
}
/**
* 下载CA中pdf至本地文件
* @param string $file_id
* @param int $type 类型 1:用户 2:医院
* @return void
*/
public function downCaPdfToLocal(string $file_id,int $type): void
{
$CaOnline = new CaOnline();
if ($type == 1){
// 用户
$prescription_pdf_result = $CaOnline->getSignedFile($this->user_entity_id, $file_id);
}else{
// 医院
$prescription_pdf_result = $CaOnline->getSignedFile($this->hospital_entity_id, $file_id);
}
$file = fopen($this->prescription_pdf_local_path, "w");
fwrite($file, $prescription_pdf_result);
fclose($file);
}
/**
* 下载CA中的pdf并上传至oss
* @param string $file_id
* @param int $type 类型 1:用户 2:医院
* @return string oss地址
*/
public function downCaPdfToOss(string $file_id,int $type): string
{
$CaOnline = new CaOnline();
if ($type == 1){
// 用户
$prescription_pdf_result = $CaOnline->getSignedFile($this->user_entity_id, $file_id);
}else{
// 医院
$prescription_pdf_result = $CaOnline->getSignedFile($this->hospital_entity_id, $file_id);
}
// 上传oss
$oss = new Oss();
return $oss->putObject($this->prescription_pdf_oss_path, $prescription_pdf_result);
}
/**
* 进行处方pdf签章
* @param array|object $order_prescription
* @param string $type 类型 1:医院 2:医生 3:药师
* @return string 文件id
*/
public function addSignPdf(array|object $order_prescription,string $type): string
public function addSignPdf(string $type): string
{
// 下载签名图片
if ($type == 1){
@@ -529,9 +583,9 @@ class CaService extends BaseService
}
// 打开处方pdf文件
$pdf_file = fopen("./runtime/file/prescription/" . $order_prescription['order_prescription_id'] . ".pdf", 'r');
$pdf_file = fopen($this->prescription_pdf_local_path, 'r');
if (!$pdf_file) {
throw new BusinessException("处方图片打开失败");
throw new BusinessException("处方pdf打开失败");
}
// 处方pdf进行签章
@@ -543,22 +597,9 @@ class CaService extends BaseService
throw new BusinessException("处方签章失败");
}
fclose($pdf_file);
return $sign_pdf_result[0]['fileId'];
}
/**
* 下载签章pdf图片
* @param string $file_id
* @param string $order_prescription_id
* @return void
*/
public function downCaPdf(string $file_id,string $order_prescription_id): void
{
$CaOnline = new CaOnline();
$prescription_pdf_result = $CaOnline->getSignedFile($this->user_entity_id, $file_id);
$file = fopen("./runtime/file/prescription/" . $order_prescription_id . '.pdf', "w");
fwrite($file, $prescription_pdf_result);
fclose($file);
}
}
+2 -2
View File
@@ -437,10 +437,10 @@ class ImService extends BaseService
* @param string $patient_user_id
* @param string $product_name
* @param string $order_prescription_id
* @param string $message_type 6/7
* @param string|int $message_type 6/7
* @return void
*/
public function prescriptionIssued(array|object $order_inquiry, string $doctor_user_id, string $patient_user_id, string $product_name, string $order_prescription_id, string $message_type): void
public function prescriptionIssued(array|object $order_inquiry, string $doctor_user_id, string $patient_user_id, string $product_name, string $order_prescription_id, string|int $message_type): void
{
try {
// 发送消息
+42
View File
@@ -450,6 +450,48 @@ class MessagePush extends BaseService
return true;
}
/**
* 患者-处方审核未通过
* 站内
* @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function patientPrescriptionVerifyFail(): bool
{
try {
// 获取医生数据
$params = array();
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)){
throw new BusinessException("加入推送队列失败:医生数据为空");
}
// 站内
// 服务消息
$data = array();
$data['user_id'] = $this->user['user_id'];
$data['notice_type'] = 3;
$data['notice_system_type'] = 1;
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "{$user_doctor['user_name']}医生为您开具的电子处方未通过审核,点击查看详情。";
$data['notice_title'] = "{$user_doctor['user_name']}医生为您开具的电子处方未通过审核,点击查看详情。";
$data['notice_content'] = "{$user_doctor['user_name']}医生为您开具的电子处方未通过审核,您可以稍后重新发起问诊申请开具处方。";
$message = new SendStationMessageProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
throw new BusinessException("加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
}
} catch (\Exception $e) {
throw new BusinessException("加入推送队列失败" . $e->getMessage());
}
return true;
}
/**
* 优惠劵发放
* 站内
+50 -16
View File
@@ -30,6 +30,8 @@ use Extend\Prescription\Prescription;
use Hyperf\Contract\LengthAwarePaginatorInterface;
use Hyperf\Utils\WaitGroup;
use Intervention\Image\ImageManager;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Swoole\Coroutine\Channel;
use TCPDF;
@@ -127,11 +129,11 @@ class OrderPrescriptionService extends BaseService
* 开具处方
* 医生-正常开具
* 药师-先开具药师处方,再开具医院签章
* @param string $order_prescription_id
* @param string $user_id
* @param string $order_prescription_id 处方id
* @param string $user_id 用户id
* @return array
*/
public function openPrescription(string $order_prescription_id, string $user_id,string $doctor_pdf_oss_path = ""): array
public function openPrescription(string $order_prescription_id, string $user_id): array
{
try {
// 获取用户数据
@@ -166,38 +168,34 @@ class OrderPrescriptionService extends BaseService
// 医生
if ($user['user_type'] == 2) {
// 生成处方图片+处方图片生成pdf
$prescription_img_url = $CaService->createPrescriptionImgPdf($order_prescription);
$prescription_img_oss_path = $CaService->createPrescriptionImgPdf($order_prescription);
}
// 药师
// 药师-医院签章
if ($user['user_type'] == 3) {
// 检测处方图片
if (empty($doctor_pdf_oss_path)){
throw new BusinessException("处方文件错误");
}
// 获取医院云证书签名+验证云证书签名
$CaService->getVerifyCertSign($order_prescription,2);
// 下载医生开具的处方pdf
$CaService->downDoctorPrescriptionPdf($order_prescription['order_prescription_id'],$doctor_pdf_oss_path);
// 下载医生开具的处方pdf至本地,文件存在时不进行下载
$CaService->downOssPdfToLocal();
}
// 进行处方pdf签章
$file_id = $CaService->addSignPdf($order_prescription,$user['user_type']);
$file_id = $CaService->addSignPdf($user['user_type']);
// 药师-医院签章
if ($user['user_type'] == 3) {
// 药师端时,需要进行系统签章
// 把药师签章的pdf存储至本地文件
// 下载药师签章pdf图片
$CaService->downCaPdf($file_id,$order_prescription['order_prescription_id']);
$CaService->downCaPdfToLocal($file_id,1);
// 进行处方pdf签章
$file_id = $CaService->addSignPdf($order_prescription,$user['user_type']);
$file_id = $CaService->addSignPdf($user['user_type']);
}
$result = array();
$result['prescription_img_url'] = $prescription_img_url ?? "";
$result['prescription_img_oss_path'] = $prescription_img_oss_path ?? "";
$result['file_id'] = $file_id;
return $result;
@@ -481,4 +479,40 @@ class OrderPrescriptionService extends BaseService
return true;
}
/**
* 药师驳回处方
* @param string $order_prescription_id 处方id
* @param string $doctor_user_id 医生user_id
* @param string $patient_user_id 患者user_id
* @param string $order_inquiry_id 问诊订单id
* @param string $pharmacist_fail_reason 驳回原因
* @return void
*/
public function rejectPrescription(string $order_prescription_id, string $doctor_user_id, string $patient_user_id, string $order_inquiry_id,string $pharmacist_fail_reason = ""): void
{
try {
$params = array();
$params['order_prescription_id'] = $order_prescription_id;
$data = array();
$data['pharmacist_audit_status'] = 2;
$data['pharmacist_verify_time'] = date('Y-m-d H:i:s', time());
$data['pharmacist_fail_reason'] = $pharmacist_fail_reason;
OrderPrescription::edit($params, $data);
// 医生-开具的处方审核未通过
$MessagePush = new MessagePush($doctor_user_id, $order_inquiry_id);
$MessagePush->prescriptionVerifyFail($order_prescription_id);
// 患者-处方审核未通过
$MessagePush = new MessagePush($patient_user_id, $order_inquiry_id);
$MessagePush->patientPrescriptionVerifyFail();
} catch (\Exception $e) {
throw new BusinessException($e->getMessage());
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
throw new BusinessException($e->getMessage());
}
}
}
+10 -2
View File
@@ -10,6 +10,7 @@ use App\Model\Hospital;
use App\Model\OrderInquiry;
use App\Model\OrderInquiryCase;
use App\Model\OrderPrescription;
use App\Model\OrderPrescriptionFile;
use App\Model\OrderPrescriptionProduct;
use App\Model\OrderProduct;
use App\Model\OrderProductItem;
@@ -1199,7 +1200,6 @@ class PatientOrderService extends BaseService
$fields = [
'order_prescription_id',
'prescription_status',
'prescription_img',
'pharmacist_id',
'doctor_id',
];
@@ -1214,7 +1214,15 @@ class PatientOrderService extends BaseService
return fail();
}
$order_prescription['prescription_img'] = addAliyunOssWebsite($order_prescription['prescription_img']);
// 获取处方文件数据
$params = array();
$params['order_prescription_id'] = $order_prescription_id;
$order_prescription_file = OrderPrescriptionFile::getOne($params);
if (empty($order_prescription_file)){
return fail();
}
$order_prescription['prescription_img_oss_path'] = addAliyunOssWebsite($order_prescription_file['prescription_img_oss_path']);
// 获取处方中医生签名
$params = array();
+17 -23
View File
@@ -1378,7 +1378,7 @@ class UserDoctorService extends BaseService
// 开具处方
$OrderPrescriptionService = new OrderPrescriptionService();
$prescription_open_result = $OrderPrescriptionService->openPrescription($order_prescription->order_prescription_id,$user_info['user_id']);
if (empty($prescription_open_result['prescription_img_url']) || empty($prescription_open_result['file_id'])){
if (empty($prescription_open_result['prescription_img_oss_path']) || empty($prescription_open_result['file_id'])){
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR, "处方开具失败");
}
@@ -1394,6 +1394,7 @@ class UserDoctorService extends BaseService
// 修改处方表
$data = array();
$data['pharmacist_id'] = "534534546"; // 药师id 现固定为此用户,后续可以考虑开启队列
$data['is_auto_phar_verify'] = $system_config['is_auto_phar_verify_prescription'];// 是否药师自动审核(0:否 1:是)
$data['doctor_created_time'] = date('Y-m-d H:i:s',time());
@@ -1405,13 +1406,14 @@ class UserDoctorService extends BaseService
$data = array();
$data['order_prescription_id'] = $order_prescription->order_prescription_id;
$data['doctor_ca_file_id'] = $prescription_open_result['file_id'];
$data['doctor_img_oss_path'] = $prescription_open_result['prescription_img_url'];
$data['prescription_img_oss_path'] = $prescription_open_result['prescription_img_oss_path'];
$order_prescription_file = OrderPrescriptionFile::addOrderPrescriptionFile($data);
if (empty($order_prescription_file)){
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR, "处方开具失败");
}
// 检测药师自动审核配置开启状态
if ($system_config['is_auto_phar_verify_prescription'] == 1){
// 添加药师自动签章审核队列
$data = array();
@@ -1432,18 +1434,6 @@ class UserDoctorService extends BaseService
$ImService = new ImService();
$ImService->pharmacistVerify($order_inquiry,(string)$order_prescription->order_prescription_id,$product_name,$user_doctor['user_id'],$order_inquiry['user_id']);
// 加入分配药师队列
$data = array();
$data['order_prescription_id'] = $order_prescription['order_prescription_id'];
$message = new AssignPharmacistProducer($data);
$producer = ApplicationContext::getContainer()->get(Producer::class);
$result = $producer->produce($message);
if (!$result) {
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR);
}
Db::commit();
} catch (\Exception $e) {
Db::rollBack();
@@ -1671,14 +1661,7 @@ class UserDoctorService extends BaseService
$params['order_inquiry_id'] = $order_inquiry_id;
OrderInquiry::edit($params,$data);
// 发送IM消息-医生接诊
$imService = new ImService();
$imService->doctorInquiry($order_inquiry,$user_info['user_id'],$order_inquiry['user_id']);
// 发送站内、订阅、短信消息-医生已接诊
$MessagePush = new MessagePush($order_inquiry['user_id'],$order_inquiry['order_inquiry_id']);
$MessagePush->patientAcceptedInquiry();
// 添加自动完成队列
if ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3){
// 专家问诊-公益问诊
$time = 1000 * 60 * 60;
@@ -1690,7 +1673,6 @@ class UserDoctorService extends BaseService
$time = 1000 * 60 * 30;
}
// 添加自动完成队列
$data = array();
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
@@ -1708,6 +1690,18 @@ class UserDoctorService extends BaseService
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
}
try {
// 发送IM消息-医生接诊
$imService = new ImService();
$imService->doctorInquiry($order_inquiry,$user_info['user_id'],$order_inquiry['user_id']);
// 发送站内、订阅、短信消息-医生已接诊
$MessagePush = new MessagePush($order_inquiry['user_id'],$order_inquiry['order_inquiry_id']);
$MessagePush->patientAcceptedInquiry();
}catch(\Exception $e){
return success([],HttpEnumCode::HTTP_SUCCESS,$e->getMessage());
}
return success();
}
+15 -2
View File
@@ -8,6 +8,7 @@ use App\Amqp\Producer\PrescriptionExpiredDelayDirectProducer;
use App\Constants\HttpEnumCode;
use App\Model\OrderInquiry;
use App\Model\OrderPrescription;
use App\Model\OrderPrescriptionFile;
use App\Model\OrderPrescriptionProduct;
use App\Model\User;
use App\Model\UserDoctor;
@@ -100,7 +101,6 @@ class UserPharmacistService extends BaseService
"prescription_status",
"pharmacist_audit_status",
"platform_audit_status",
"prescription_img",
"doctor_id",
];
@@ -112,6 +112,16 @@ class UserPharmacistService extends BaseService
return fail();
}
// 获取处方文件数据
$params = array();
$params['order_prescription_id'] = $order_prescription_id;
$order_prescription_file = OrderPrescriptionFile::getOne($params);
if (empty($order_prescription_file)){
return fail();
}
$order_prescription['prescription_img_oss_path'] = addAliyunOssWebsite($order_prescription_file['prescription_img_oss_path']);
$order_prescription['prescription_img'] = addAliyunOssWebsite($order_prescription['prescription_img']);
// 获取处方中医生签名
@@ -134,6 +144,7 @@ class UserPharmacistService extends BaseService
*/
public function putPrescriptionVerify(): array
{
return fail(HttpEnumCode::SERVER_ERROR,"暂时无法人工审核");
$user_info = $this->request->getAttribute("userInfo") ?? [];
$order_prescription_id = $this->request->route('order_prescription_id');
@@ -164,7 +175,7 @@ class UserPharmacistService extends BaseService
// 验证处方状态
if ($order_prescription['prescription_status'] != 1){
// 处方状态(1:待审核 3:待使用 4:已失效 5:已使用)
// 处方状态(1:待审核 2:待使用 3:已失效 4:已使用)
return fail(HttpEnumCode::HTTP_ERROR,"处方审核失败");
}
@@ -332,4 +343,6 @@ class UserPharmacistService extends BaseService
return success($result);
}
}