新增药师开具处方ca签章

This commit is contained in:
2023-04-03 11:34:53 +08:00
parent d09f9d8d77
commit 29965b14af
10 changed files with 225 additions and 90 deletions
+107 -46
View File
@@ -4,7 +4,7 @@ namespace App\Services;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Model\DoctorPharmacistCert;
use App\Model\UserCaCert;
use App\Model\HospitalDepartmentCustom;
use App\Model\OrderInquiryCase;
use App\Model\OrderPrescription;
@@ -108,8 +108,11 @@ class OrderPrescriptionService extends BaseService
return OrderPrescription::getCount($params);
}
/**
* 开具处方
* 医生-正常开具
* 药师-先开具药师处方,再开具医院签章
* @param string $order_prescription_id
* @param string $user_id
* @return array
@@ -125,31 +128,40 @@ class OrderPrescriptionService extends BaseService
throw new BusinessException("用户数据错误");
}
// 获取用户info数据
$params = array();
$params['user_id'] = $user['user_id'];
$sign_image_path = "";
if ($user['user_type'] == 2){
$user_doctor_info = UserDoctorInfo::getOne($params);
if (!empty($user_doctor_info)){
$sign_image_path = $user_doctor_info['sign_image'];
}
}elseif ($user['user_type'] == 3){
$user_pharmacist_info = UserPharmacistInfo::getOne($params);
if (!empty($user_pharmacist_info)){
$sign_image_path = $user_pharmacist_info['sign_image'];
}
}else{
if ($user['user_type'] != 2 && $user['user_type'] != 3){
throw new BusinessException("用户类型错误");
}
if (empty($sign_image_path)){
throw new BusinessException("无签名图片");
// 获取用户info数据
$params = array();
$params['user_id'] = $user['user_id'];
if ($user['user_type'] == 2){
$user_doctor_info = UserDoctorInfo::getOne($params);
if (empty($user_doctor_info)){
throw new BusinessException("用户数据错误");
}
$user_sign_image_path = $user_doctor_info['sign_image'];
$user_entity_id = "491925054435950592";
} else{
$user_pharmacist_info = UserPharmacistInfo::getOne($params);
if (!empty($user_pharmacist_info)){
throw new BusinessException("用户数据错误");
}
$user_sign_image_path = $user_pharmacist_info['sign_image'];
$user_entity_id = $user['user_id'];
$hospital_sign_image_path = "basic/file/hospital_signature.png";
$hospital_entity_id = "5345345461";
}
if (empty($user_sign_image_path) || empty($user_entity_id)){
throw new BusinessException("无签名图片/用户唯一标识");
}
// 去除第一个/ oss不识别
$sign_image_path = substr($sign_image_path, 1, strlen($sign_image_path) - 1);
$sign_image_path = substr($user_sign_image_path, 1, strlen($user_sign_image_path) - 1);
// 获取处方数据
$params = array();
@@ -163,9 +175,9 @@ class OrderPrescriptionService extends BaseService
throw new BusinessException("医生开方日期错误");
}
// 药师端检测处方图片
// 检测处方图片
if ($user['user_type'] == 3 && empty($order_prescription['prescription_img'])){
throw new BusinessException("医生开方日期错误");
throw new BusinessException("处方图片错误");
}
// 获取处方关联疾病数据
@@ -240,28 +252,30 @@ class OrderPrescriptionService extends BaseService
$product['prescription_product_num'] = $item['prescription_product_num'] . $item['packaging_unit']; // 商品数量 + 基本包装单位(例:盒/瓶)
$data['product'][] = $product;
}
dump("签名获取成功");
if ($user['user_type'] == 3){
$cert_sign_result = $ca->getCertSign($user['user_id'], $user['user_id'], $data);
}else{
$cert_sign_result = $ca->getCertSign("491925054435950592", "491925054435950592", $data);
}
$cert_sign_result = $ca->getCertSign($user_entity_id, $user_entity_id, $data);
// 验证云证书签名-验证无需处理,只要不返回错误即可
$ca->verifyPkcs7($cert_sign_result['signP7'],$data);
dump("签名验证成功");
dump("云证书签名验证成功");
if ($user['user_type'] == 3){
$cert_sign_result = $ca->getCertSign($hospital_entity_id, $hospital_entity_id, $data);
// 验证云证书签名-验证无需处理,只要不返回错误即可
$ca->verifyPkcs7($cert_sign_result['signP7'],$data);
dump("医院云证书签名获取成功");
}
$oss = new Oss();
// 医生
if ($user['user_type'] == 2){
// 下载基础处方pdf图片
// 下载基础处方图片
$prescription_basic_filename = "basic/file/prescription.jpg";
$prescription_image = $oss->getObjectToRAM($prescription_basic_filename);
dump("下载基础处方pdf图片成功");
dump("下载基础处方图片成功");
$manager = new ImageManager();
@@ -398,9 +412,8 @@ class OrderPrescriptionService extends BaseService
$local = "./runtime/" . $order_prescription['order_prescription_id'] . '.' . 'pdf';
$prescription_pdf_local = $oss->getObjectToLocal($prescription_pdf_path,$local);
$oss->getObjectToLocal($prescription_pdf_path,$local);
dump("下载医生开具的处方pdf成功");
}
// 下载签名图片
@@ -444,12 +457,7 @@ class OrderPrescriptionService extends BaseService
$data = array();
$data['sign_param'] = json_encode($sign_param);
$data['pdf_file'] = $pdf_file;
if ($user['user_type'] == 2){
$sign_pdf_result = $ca->addSignPdf("491925054435950592",$data);
}else{
$sign_pdf_result = $ca->addSignPdf($user['user_id'],$data);
}
$sign_pdf_result = $ca->addSignPdf($user_entity_id,$data);
if (empty($sign_pdf_result[0]['fileId'])){
throw new BusinessException("处方签章失败");
}
@@ -458,11 +466,7 @@ class OrderPrescriptionService extends BaseService
// 下载处方签章文件
$file_id = $sign_pdf_result[0]['fileId'];
if ($user['user_type'] == 2){
$prescription_pdf_result = $ca->getSignedFile("491925054435950592",$file_id);
}else{
$prescription_pdf_result = $ca->getSignedFile($user['user_id'],$file_id);
}
$prescription_pdf_result = $ca->getSignedFile($user_entity_id,$file_id);
if (empty($prescription_pdf_result)){
throw new BusinessException("下载处方签章文件失败");
@@ -474,6 +478,63 @@ class OrderPrescriptionService extends BaseService
$filename = "applet/prescription/" . $order_prescription['order_prescription_id'] . '.' . 'pdf';
$prescription_pdf_url = $oss->putObject($filename, $prescription_pdf_result);
if ($user['user_type'] == 3){
// 药师端时,需要进行系统签章
// 把药师签章的pdf存储至本地文件
$file = fopen("./runtime/" . $order_prescription['order_prescription_id'] . '.' . 'pdf', "w");
fwrite($file, $prescription_pdf_result);
fclose($file);
// 下载医院签名图片
$style = "image/resize,w_300,h_300";
$sign_image = $oss->getCusTomObjectToRAM($hospital_sign_image_path,$style);
$sign_image = base64_encode($sign_image);
if (!$sign_image){
throw new BusinessException("医院签名图片下载失败");
}
$sign_param = [
[ // 医院签章
"llx"=>"1550", // 左边底部X坐标
"lly"=>"1350", // 左边底部Y坐标
"urx"=>"2250", // 右边上部x坐标
"ury"=>"650", // 右边上部y坐标
"pageList"=>[1],
"sealImg"=>$sign_image
],
];
// 打开处方pdf文件
unset($pdf_file);
$pdf_file = fopen("./runtime/" . $order_prescription['order_prescription_id'] . ".pdf",'r');
// 处方pdf进行签章
$data = array();
$data['sign_param'] = json_encode($sign_param);
$data['pdf_file'] = $pdf_file;
$hospital_sign_pdf_result = $ca->addSignPdf($hospital_entity_id,$data);
if (empty($hospital_sign_pdf_result[0]['fileId'])){
throw new BusinessException("处方签章失败");
}
dump("处方pdf进行签章成功");
// 下载处方签章文件
unset($prescription_pdf_result);
$file_id = $hospital_sign_pdf_result[0]['fileId'];
$prescription_pdf_result = $ca->getSignedFile($hospital_entity_id,$file_id);
if (empty($prescription_pdf_result)){
throw new BusinessException("下载处方签章文件失败");
}
dump("下载处方签章文件成功");
// 上传oss
$hospital_filename = "applet/prescription/" . $order_prescription['order_prescription_id'] . '.' . 'pdf';
$prescription_pdf_url = $oss->putObject($hospital_filename, $prescription_pdf_result);
}
$result = array();
$result['prescription_img_url'] = $prescription_img_url ?? $order_prescription['prescription_img'];
$result['prescription_pdf_url'] = '/' . $prescription_pdf_url ?: "";