diff --git a/app/Common/Common.php b/app/Common/Common.php index bc55af6..93aea9f 100644 --- a/app/Common/Common.php +++ b/app/Common/Common.php @@ -235,4 +235,20 @@ function sexToStringSex(string|int $sex): string } return $result; +} + +/** + * 检测并创建目录 + * @param string $dir 文件目录 + * @param int $mode 权限 + * @return bool + */ +function mkdirs(string $dir, int $mode = 0755): bool +{ + if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE; + + if (!mkdirs(dirname($dir), $mode)) return FALSE; + + return @mkdir($dir, $mode); + } \ No newline at end of file diff --git a/app/Controller/PatientOrderController.php b/app/Controller/PatientOrderController.php index 324bad8..67e5afc 100644 --- a/app/Controller/PatientOrderController.php +++ b/app/Controller/PatientOrderController.php @@ -70,6 +70,8 @@ class PatientOrderController extends AbstractController /** * 问诊订单取消支付 * @return ResponseInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function putPatientInquiryOrderCancelPay(): ResponseInterface { diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php index f373a73..dd1496a 100644 --- a/app/Controller/TestController.php +++ b/app/Controller/TestController.php @@ -32,7 +32,6 @@ use App\Services\UserDoctorService; use App\Utils\Log; use Extend\Alibaba\Oss; use Extend\Ca\Ca; -use Extend\Ca\CaOffline; use Extend\Ca\CaOnline; use Extend\Kuaidi100\Kuaidi; use Extend\Prescription\Prescription; @@ -46,22 +45,37 @@ use Imagick; use Intervention\Image\ImageManager; use Spatie\PdfToImage\Pdf; use Swoole\Coroutine; +use Swoole\Coroutine\Channel; use Swoole\Coroutine\WaitGroup; use TCPDF; class TestController extends AbstractController { public function test(){ +// $this->test_8(); +// $this->test_3(); +// $this->test_4(); +// $this->test_6(); +// $this->test_9(); +// $this->test_10(); +// $this->test_11(); + $this->test_5(); +// $this->test_1(); +// $this->test_11(); +// $this->test_12(); +// $this->test_13(); +// $this->test_14(); +// $this->test_15(); } // 获取云证书-首次 public function test_1(){ - $CaOffline = new CaOffline(); + $ca = new Ca(); // // 测试医生 // $data = array(); // $data['user_id'] = "491925054435950592"; // $data['card_num'] = "410323199603261241"; -// $result = $CaOffline->getCloudCert($data); +// $result = $ca->getCloudCert($data); // // $data = array(); // $data['user_id'] = "491925054435950592"; @@ -78,7 +92,7 @@ class TestController extends AbstractController // $data = array(); // $data['user_id'] = "534534546"; // $data['card_num'] = "410323199603261240"; -// $result = $CaOffline->getCloudCert($data); +// $result = $ca->getCloudCert($data); // // $data = array(); // $data['user_id'] = "534534546"; @@ -95,7 +109,7 @@ class TestController extends AbstractController // $data = array(); // $data['user_id'] = "5345345461"; // $data['card_num'] = "91510106MABTJY4K9R"; -// $result = $CaOffline->getCloudCert($data,"Organizational"); +// $result = $ca->getCloudCert($data,"Organizational"); // // $data = array(); // $data['is_system'] = 1; @@ -109,6 +123,430 @@ class TestController extends AbstractController // } } + // 获取用户云证书数据-验证PKCS7签名 + public function test_2(){ + $ca = new Ca(); + + $params = array(); + $params['user_id'] = "491925054435950592"; + $params['type'] = 1; + $doctor_pharmacist_cert = UserCaCert::getOne($params); + if (empty($doctor_pharmacist_cert)){ + return fail(HttpEnumCode::HTTP_ERROR,"用户数据错误"); + } + + // 获取云证书签名 + $data = array(); + $data['created_at'] = "2023-03-01 12:44:10"; + $data['department_custom_name'] = "外科"; + $data['user_name'] = "测试用户1"; + $data['sex'] = "男"; + $data['age'] = 19; + $data['allergy_history'] = "无"; + $data['icd_name'] = "感冒"; + $data['doctor_advice'] = "多吃药"; + $data['product'] = [ + [ + "product_name" => "感冒药1(50ml*10)", + "single_unit" => "一次一包", + "frequency_use" => "1天3次", + "single_use" => "口服", + "prescription_product_num" => "X1盒", + ], + [ + "product_name" => "感冒药2(50ml*10)", + "single_unit" => "一次一包", + "frequency_use" => "1天3次", + "single_use" => "口服", + "prescription_product_num" => "X1盒", + ], + [ + "product_name" => "感冒药3(50ml*10)", + "single_unit" => "一次一包", + "frequency_use" => "1天3次", + "single_use" => "口服", + "prescription_product_num" => "X1盒", + ], + [ + "product_name" => "感冒药4(50ml*10)", + "single_unit" => "一次一包", + "frequency_use" => "1天3次", + "single_use" => "口服", + "prescription_product_num" => "X1盒", + ], + [ + "product_name" => "感冒药5(50ml*10)", + "single_unit" => "一次一包", + "frequency_use" => "1天3次", + "single_use" => "口服", + "prescription_product_num" => "X1盒", + ], + ]; + + $result = $ca->getCertSign("491925054435950592","491925054435950592",$data); + + // 验证PKCS7签名-验证无需处理,只要不返回错误即可 + $ca->verifyPkcs7($result['signP7'],$data); + } + + // 添加签章配置(首次) + public function test_3(){ + $CaOnline = new CaOnline(); + +// // 下载阿里云图片 +// $oss = new Oss(); +// +// $filename = "applet/doctor/cert/f2abdb81-fac0-4264-bc11-aa2b6cf2761c.png"; +// +// $style = "image/resize,m_lfit,w_100,h_350"; +// +// $sign_image = $oss->getCusTomObjectToRAM($filename,$style); +// $sign_image = base64_encode($sign_image); +// if (!$sign_image){ +// return fail(HttpEnumCode::SERVER_ERROR); +// } +// +// $sign_param = [ +// [ +// "llx"=> "500", // 左边底部X坐标 +// "lly"=>"3015", // 左边底部Y坐标 +// "urx"=>"850", // 右边上部x坐标 +// "ury"=>"3115", // 右边上部y坐标 +// "pageList"=>[1], +// "sealImg"=>$sign_image +// ] +// ]; +// $data = array(); +// $data['sign_param'] = json_encode($sign_param); +// $data['seal_img'] = $sign_image; +// +// $result = $ca->addUserSignConfig("491925054435950592","410323199603261241",$data); + + // 下载阿里云图片 + $oss = new Oss(); + + $filename = "applet/doctor/cert/f2abdb81-fac0-4264-bc11-aa2b6cf2761c.png"; + + $style = "image/resize,m_lfit,w_100,h_350"; + + $sign_image = $oss->getCusTomObjectToRAM($filename,$style); + $sign_image = base64_encode($sign_image); + if (!$sign_image){ + return fail(HttpEnumCode::SERVER_ERROR); + } + + $sign_param = [ + [ // 医生端 + "llx" => "120", // 左边底部X坐标 + "lly" => "190", // 左边底部Y坐标 + "urx" => "190", // 右边上部x坐标 + "ury" => "140", // 右边上部y坐标 + "pageList" => [1], + "sealImg" => $sign_image + ], + ]; + $data = array(); + $data['sign_param'] = json_encode($sign_param); + $data['seal_img'] = $sign_image; + + $result = $CaOnline->addUserSignConfig("491925054435950592","130582199202032038",$data); + } + + // 获取用户签章图片 + public function test_4(){ + $ca = new Ca(); + $result = $ca->getFetchUserSeal("491925054435950592"); + $data = urldecode($result[0]['sealImg']); + dump($data); + } + + // 生成处方pdf图片 + public function test_5(){ + // 下载阿里云图片 +// $oss = new Oss(); +// +// $filename = "basic/file/prescription.jpg"; +// $sign_image = $oss->getObjectToRAM($filename); + + $sign_image = fopen("./extend/Ca/prescription.jpg", 'r+'); + + $manager = new ImageManager(); + + $image = $manager->make($sign_image); + + $fontPath = './extend/Ca/msyh.ttf'; + + // 处方号 + $image->text('1234567890', 1480, 540, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 日期 + $image->text('2023-03-21', 354, 675, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 科室 + $image->text('测试科室1', 1385, 675, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 姓名 + $image->text('测试姓名', 354, 795, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 性别 + $image->text('男', 1385, 790, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 年龄 + $image->text('19', 354, 900, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 过敏史 + $image->text('对阿莫西林过敏对阿莫西林过敏', 405, 1030, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 初步诊断 + $image->text('对阿莫西林过敏对阿莫西林过敏', 445, 1145, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 医生建议 + $image->text('没有建议', 445, 1252, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + $data = array(); + $data['product'] = [ + [ + "product_name" => "感冒药1(50ml*10)", + "single_unit" => "一次一包", + "frequency_use" => "1天3次", + "single_use" => "口服", + "prescription_product_num" => "X1盒", + ], + [ + "product_name" => "感冒药2(50ml*10)", + "single_unit" => "一次一包", + "frequency_use" => "1天3次", + "single_use" => "口服", + "prescription_product_num" => "X1盒", + ], + [ + "product_name" => "感冒药3(50ml*10)", + "single_unit" => "一次一包", + "frequency_use" => "1天3次", + "single_use" => "口服", + "prescription_product_num" => "X1盒", + ], + [ + "product_name" => "感冒药4(50ml*10)", + "single_unit" => "一次一包", + "frequency_use" => "1天3次", + "single_use" => "口服", + "prescription_product_num" => "X1盒", + ], + [ + "product_name" => "感冒药5(50ml*10)", + "single_unit" => "一次一包", + "frequency_use" => "1天3次", + "single_use" => "口服", + "prescription_product_num" => "X1盒", + ], + ]; + + // 用药 + foreach ($data['product'] as $key => $item){ + if ($key <= 2){ + $x_axis = 229; + $y_axis = 1600 + $key * 350; + }else{ + $x_axis = 1240; + $y_axis = 1600 + ($key - 3) * 350; + } + + + $image->text($item['product_name'], $x_axis, $y_axis, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(50); + $font->align('left'); + }); + + $image->text("用量:" . $item['single_unit'] . " " . $item['frequency_use'], $x_axis, $y_axis+90, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(50); + $font->align('left'); + }); + + $image->text("用法:" . $item['single_use'], $x_axis, $y_axis+180, function ($font) use($fontPath) { + $font->file($fontPath); + $font->size(50); + $font->align('left'); + }); + } + + // 将处理后的图片重新保存到其他路径 +// $image->save('./runtime/2.jpg'); + + $result = (string) $image->encode('png', 75); + + // 图片生成pdf + $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); + + $pdf->AddPage(); + $pdf->Image('@' . $result, 10, 10, 0, 0, '', '', '', false, 300, '', false, false, 0, false, false, false); + + $path = dirname(__DIR__, 2) . "/file/prescription/"; + $a = mkdirs($path); + if (!$a){ + // 目录创建失败 + } + $pdf->Output(dirname(__DIR__, 2) . "/file/prescription/" . "prescription_img.pdf","F"); + + } + + // pdf进行签章 + public function test_6(){ + $pdf_file = fopen("./runtime/prescription.pdf",'r'); + + $oss = new Oss(); + + $filename = "applet/doctor/cert/f2abdb81-fac0-4264-bc11-aa2b6cf2761c.png"; + + $style = "image/resize,m_lfit,w_100,h_350"; + + $sign_image = $oss->getCusTomObjectToRAM($filename,$style); + $sign_image = base64_encode($sign_image); + if (!$sign_image){ + return fail(HttpEnumCode::SERVER_ERROR); + } + + $sign_param = [ + [ // 医生端 + "llx"=>"120", // 左边底部X坐标 + "lly"=>"190", // 左边底部Y坐标 + "urx"=>"190", // 右边上部x坐标 + "ury"=>"140", // 右边上部y坐标 + "pageList"=>[1], + "sealImg"=>$sign_image + ], +// [ // 药师端 +// "llx"=>"350", // 左边底部X坐标 +// "lly"=>"190", // 左边底部Y坐标 +// "urx"=>"440", // 右边上部x坐标 +// "ury"=>"140", // 右边上部y坐标 +// "pageList"=>[1], +// "sealImg"=>$sign_image +// ] + ]; + $data = array(); + $data['sign_param'] = json_encode($sign_param); + $data['pdf_file'] = $pdf_file; + + $ca = new Ca(); + $result = $ca->addSignPdf("491925054435950592",$data); + + $file_id = $result[0]['fileId']; + + $result = $ca->getSignedFile("491925054435950592",$file_id); + if (empty($result)){ + return fail(); + } + +// $file = fopen("./runtime/test.pdf", "w") or die("Unable to open file!"); +// fwrite($file, $result); +// fclose($file); + + // 上传阿里云oss + + $oss = new Oss(); + + $filename = "applet/doctor/prescription/test.pdf"; + + $result = $oss->putObject($filename, $result); + dump($result); + } + + // 延迟队列测试 + public function test_7(){ + $out_trade_no = $this->request->input('out_trade_no'); + if ($out_trade_no == 1){ + // 增加至取消订单延迟队列 + $data = array(); + $data['order_no'] = 111; + $data['order_type'] = 1; + + $message = new CancelUnpayOrdersDelayDirectProducer($data); + $message->setDelayMs(1000 * 5 * 1); + $producer = $this->container->get(Producer::class); + $res = $producer->produce($message); + if (!$res) { + Db::rollBack(); + return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败"); + } + }else{ + // 增加至取消订单延迟队列 + $data = array(); + $data['order_no'] = 2222; + $data['order_type'] = 1; + + $message = new CancelUnpayOrdersDelayDirectProducer($data); + $message->setDelayMs(1000 * 15 * 1); + $producer = $this->container->get(Producer::class); + $res = $producer->produce($message); + if (!$res) { + Db::rollBack(); + return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败"); + } + } + } + + // 删除签章配置 + public function test_8(){ + $ca = new Ca(); + $result = $ca->deleteUserSignConfig("491925054435950592"); + } + + // 下载签章的pdf文件 + public function test_9(){ + $ca = new Ca(); + $result = $ca->getSignedFile("5345345461","1642769369872105473"); + if (empty($result)){ + return fail(); + } + + // 上传阿里云oss + + $oss = new Oss(); + + $filename = "applet/doctor/prescription/111.pdf"; + + $result = $oss->putObject($filename, $result); + dump($result); + } // 处方上报处方平台 public function test_11(){ @@ -360,4 +798,47 @@ class TestController extends AbstractController // return fail(); // } } + + public function test_15(){ + $wg = new \Hyperf\Utils\WaitGroup(); + $channel = new Channel(); + $wg->add(2); + + co(function () use ($wg,$channel) { + defer(function() use ($wg) { + dump("执行了defer"); + $wg->done(); + }); + + dump("执行了协程1"); + }); + + co(function () use ($wg,$channel) { + defer(function() use ($wg) { + dump("执行了defer"); + $wg->done(); + }); + + dump("执行了协程2"); + }); + + + + + + $wg->wait(); + + $res = $channel->isEmpty(); + if ($res){ + dump("存在异常"); + } + + $res = $channel->close(); + dump($res); + + $a = $wg->count(); + dump($a); + + dump("执行完毕"); + } } \ No newline at end of file diff --git a/app/Model/UserCaCert.php b/app/Model/UserCaCert.php index d9186db..bca471a 100644 --- a/app/Model/UserCaCert.php +++ b/app/Model/UserCaCert.php @@ -18,6 +18,8 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property string $cert_chain_p7 证书链 * @property string $cert_serial_number 证书序列号 * @property string $ca_pin ca认证pin值 + * @property int $is_sign_config 是否已添加签章配置(第一次需申请) + * @property string $sign_config 签章坐标配置 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 */ @@ -33,7 +35,7 @@ class UserCaCert extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['cert_id', 'user_id', 'is_system', 'type', 'cert_base64', 'cert_chain_p7', 'cert_serial_number', 'ca_pin', 'created_at', 'updated_at']; + protected array $fillable = ['cert_id', 'user_id', 'is_system', 'type', 'cert_base64', 'cert_chain_p7', 'cert_serial_number', 'ca_pin', 'is_sign_config', 'sign_config', 'created_at', 'updated_at']; protected string $primaryKey = "cert_id"; diff --git a/app/Services/CaService.php b/app/Services/CaService.php new file mode 100644 index 0000000..39d3f3a --- /dev/null +++ b/app/Services/CaService.php @@ -0,0 +1,511 @@ +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']; + $this->user_entity_id = $user['user_id']; + + $this->hospital_sign_image_path = "basic/file/hospital_signature.png"; + $this->hospital_entity_id = "5345345461"; + } + + if (empty($user_sign_image_path) || empty($user_entity_id)) { + throw new BusinessException("无签名图片/用户唯一标识"); + } + + // 去除用户签名图片第一个/ oss不识别 + $this->sign_image_path = substr($user_sign_image_path, 1, strlen($user_sign_image_path) - 1); + + $order_prescription_id = $order_prescription['order_prescription_id']; + + // 创建协程客户端 + $wg = new WaitGroup(); + + // 创建通道 + $channel = new Channel(); + + $wg->add(4); + + // 获取处方关联疾病名称 + co(function () use ($wg,$channel,&$icd_name,$order_prescription_id) { + defer(function() use ($wg) { + $wg->done(); + }); + + $params = array(); + $params['order_prescription_id'] = $order_prescription_id; + $order_prescription_icd = OrderPrescriptionIcd::getList($params); + if (empty($order_prescription_icd)) { + $channel->push('处方疾病数据错误'); + return; + } + + $icd_name = array_column($order_prescription_icd->toArray(), 'icd_name'); + if (!empty($icd_name)) { + if (count($icd_name) > 1) { + $this->icd_name = implode(';', $icd_name); + } else { + $this->icd_name = $icd_name[0]; + } + } + }); + + // 获取处方关联商品数据 + co(function () use ($wg,$channel,$order_prescription_id) { + defer(function() use ($wg) { + $wg->done(); + }); + + $params = array(); + $params['order_prescription_id'] = $order_prescription_id; + $order_prescription_product = OrderPrescriptionProduct::getList($params); + if (empty($order_prescription_product)) { + $channel->push('处方药品数据错误'); + return; + } + + $this->order_prescription_product = $order_prescription_product->toArray(); + }); + + // 获取医生自定义科室数据 + $doctor_id = $order_prescription['doctor_id']; + co(function () use ($wg,$channel,&$hospital_department_custom,$doctor_id) { + defer(function() use ($wg) { + $wg->done(); + }); + + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $doctor_id; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)) { + $channel->push('医生数据错误'); + return; + } + + // 获取医生自定义科室数据 + $params = array(); + $params['department_custom_id'] = $user_doctor['department_custom_id']; + $hospital_department_custom = HospitalDepartmentCustom::getOne($params); + if (empty($hospital_department_custom)) { + $channel->push('医生自定义数据错误'); + return; + } + + $this->department_name = $hospital_department_custom['department_name'] ?: ""; + }); + + // 获取处方关联病例数据 + $order_inquiry_id = $order_prescription['order_inquiry_id']; + co(function () use ($wg,$channel,&$order_inquiry_case,$order_inquiry_id) { + defer(function() use ($wg) { + $wg->done(); + }); + + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + $channel->push('处方病例数据错误'); + return; + } + + $this->allergy_history = $order_inquiry_case['allergy_history'] ?: "无"; + }); + + // 结束 + $wg->wait(); + + // 判断通道是否存在异常数据 + $res = $channel->isEmpty(); + if ($res){ + // 读取通道数据 + $data = $channel->pop(); + + // 关闭channel通道 + $channel->close(); + + throw new BusinessException($data); + }else{ + // 关闭channel通道 + $channel->close(); + } + + $this->icd_name = $icd_name; + } + + /** + * 获取云证书签名+验证云证书签名 + * @param array|object $order_prescription + * @param int $type 类型 1:用户 2:医院 + */ + public function getVerifyCertSign(array|object $order_prescription,int $type) + { + $CaOnline = new CaOnline(); + + // 获取云证书签名 + $data = array(); + $data['created_at'] = $order_prescription['doctor_created_time']; + $data['department_custom_name'] = $this->department_name; + $data['user_name'] = $order_prescription['patient_name']; + $data['sex'] = sexToStringSex($order_prescription['patient_sex']); + $data['age'] = $order_prescription['patient_age']; + $data['allergy_history'] = $this->allergy_history; + $data['icd_name'] = $this->icd_name; + $data['doctor_advice'] = $order_prescription['doctor_advice'] ?: "无"; + + // 商品数据 + $data['product'] = array(); + foreach ($this->order_prescription_product as $item) { + $product = array(); + $product['product_name'] = $item['product_name'] . "(" . $item['product_spec'] . ")"; // 商品名称+商品规格 + $product['single_unit'] = $item['single_unit'] ?: ""; // 单次剂量(例:1次1包) + $product['frequency_use'] = $item['frequency_use'] ?: ""; // 使用频率(例:1天3次) + $product['single_use'] = $item['single_use'] ?: ""; // 单次用法(例:口服) + $product['prescription_product_num'] = $item['prescription_product_num'] . $item['packaging_unit']; // 商品数量 + 基本包装单位(例:盒/瓶) + $data['product'][] = $product; + } + + if ($type == 1){ + // 用户 + $cert_sign_result = $CaOnline->getCertSign($this->user_entity_id, $this->user_entity_id, $data); + }else{ + // 医院 + $cert_sign_result = $CaOnline->getCertSign($this->hospital_entity_id, $this->hospital_entity_id, $data); + } + + // 验证云证书签名 验证无需处理,只要不返回错误即可 + $CaOnline->verifyPkcs7($cert_sign_result['signP7'], $data); + } + + /** + * 生成处方图片+处方图片生成pdf + * @param array|object $order_prescription + * @return string + */ + public function createPrescriptionImgPdf(array|object $order_prescription): string + { + // 打开基础处方图片 + $prescription_image = fopen("./extend/Ca/prescription.jpg", 'r+'); + + $manager = new ImageManager(); + + $image = $manager->make($prescription_image); + + $fontPath = './extend/Ca/msyh.ttf'; + + // 处方号 + $image->text($order_prescription['prescription_code'], 1480, 540, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 日期 + $image->text(date('Y-m-d', strtotime($order_prescription['doctor_created_time'])), 354, 675, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 科室 + $image->text($this->department_name ?: "", 1385, 675, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 姓名 + $image->text($order_prescription['patient_name'], 354, 795, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 性别 + $image->text(sexToStringSex($order_prescription['patient_sex']), 1385, 790, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 年龄 + $image->text($order_prescription['patient_age'], 354, 900, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 过敏史 + $image->text($this->allergy_history ?: "无", 405, 1030, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 初步诊断 + $image->text($this->icd_name, 445, 1145, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 医生建议 + $image->text($order_prescription['doctor_advice'], 445, 1252, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 商品数据 + foreach ($this->order_prescription_product as $key => $item) { + $x_axis = 229; + $y_axis = 1600 + $key * 250; + $x_axis_num = 1900;// 数量使用 + + // 商品名称 + $image->text($item['product_name'], $x_axis, $y_axis, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(50); + $font->align('left'); + }); + + $image->text("X" . $item['prescription_product_num'] . $item['packaging_unit'], $x_axis_num, $y_axis, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(50); + $font->align('left'); + }); + + // 用量 + $image->text("用量:" . $item['single_unit'] . " " . $item['frequency_use'], $x_axis, $y_axis + 70, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(50); + $font->align('left'); + }); + + // 用法 + $image->text("用法:" . $item['single_use'], $x_axis, $y_axis + 140, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(50); + $font->align('left'); + }); + } + + // 生成图片 + $img_result = (string)$image->encode('png', 75); + + // 上传处方图片至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; + + // 图片生成pdf + $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); + + $pdf->AddPage(); + $pdf->Image('@' . $img_result, 10, 10, 0, 0, '', '', '', false, 300, '', false, false, 0, false, false, false); + + $prescription_pdf_local_filename = $order_prescription['order_prescription_id'] . '.' . 'pdf'; + $prescription_pdf_local_path = dirname(__DIR__, 2) . "/file/prescription/"; + + $res = mkdirs($prescription_pdf_local_path); + if (!$res){ + throw new BusinessException("处方临时目录创建失败"); + } + + // 图片生成的处方pdf存储为本地文件 runtime目录下 + $pdf->Output($prescription_pdf_local_path . $prescription_pdf_local_filename, "F"); + + return $prescription_img_url; + } + + /** + * 下载医生开具的处方pdf + * 存在:当次发版内医生开具后,药师再去开具 + * 不存在:医生开具后,进行发版过,此时需重新下载 + * @param array|object $order_prescription + * @return void + */ + public function downDoctorPrescriptionPdf(array|object $order_prescription): void + { + $local_path = "./runtime/file/prescription/" . $order_prescription['order_prescription_id'] . '.' . 'pdf'; + $res = file_exists($local_path); + if (!$res){ + // 去除第一个/ oss不识别 + $prescription_pdf_path = substr($order_prescription['prescription_pdf'], 1, strlen($order_prescription['prescription_pdf']) - 1); + + $oss = new Oss(); + $oss->getObjectToLocal($prescription_pdf_path, $local_path); + } + } + + /** + * 进行处方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 + { + // 下载签名图片 + if ($type == 1){ + $local_path = "./extend/Ca/hospital_signature.png"; + $res = file_exists($local_path); + if ($res){ + // 读取本地文件 + $sign_image = fopen($local_path,'r'); + } + } + + if (!isset($sign_image)){ + $oss = new Oss(); + + if ($type == 1){ + $style = "image/resize,w_300,h_300"; + $sign_image = $oss->getCusTomObjectToRAM($this->hospital_sign_image_path, $style); + }else{ + $style = "image/resize,m_lfit,w_100,h_350"; + $sign_image = $oss->getCusTomObjectToRAM($this->sign_image_path, $style); + } + } + + $sign_image = base64_encode($sign_image); + if (!$sign_image) { + throw new BusinessException("签名图片下载失败"); + } + + if ($type == 1){ + // 医院 + $llx = "370"; // 左边底部X坐标 控制左右(越小越左) + $lly = "210"; // 左边底部Y坐标 控制上下(越小越下) + $urx = "520"; // 右边上部x坐标 + $ury = "360"; // 右边上部y坐标 + } elseif ($type == 2){ + // 医生端 + $llx = "120"; // 左边底部X坐标 + $lly = "190"; // 左边底部Y坐标 + $urx = "190"; // 右边上部x坐标 + $ury = "140"; // 右边上部y坐标 + }else{ + // 药师端 + $llx = "350"; // 左边底部X坐标 + $lly = "190"; // 左边底部Y坐标 + $urx = "440"; // 右边上部x坐标 + $ury = "140"; // 右边上部y坐标 + } + + $sign_param = [ + [ + "llx" => $llx, // 左边底部X坐标 + "lly" => $lly, // 左边底部Y坐标 + "urx" => $urx, // 右边上部x坐标 + "ury" => $ury, // 右边上部y坐标 + "pageList" => [1], + "sealImg" => $sign_image + ], + ]; + + // 打开处方pdf文件 + $pdf_file = fopen("./runtime/" . $order_prescription['order_prescription_id'] . ".pdf", 'r'); + if (!$pdf_file) { + throw new BusinessException("处方图片打开失败"); + } + + $CaOnline = new CaOnline(); + + // 处方pdf进行签章 + $data = array(); + $data['sign_param'] = json_encode($sign_param); + $data['pdf_file'] = $pdf_file; + $sign_pdf_result = $CaOnline->addSignPdf($this->user_entity_id, $data); + if (empty($sign_pdf_result[0]['fileId'])) { + throw new BusinessException("处方签章失败"); + } + + 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); + } +} \ No newline at end of file diff --git a/app/Services/OrderPrescriptionService.php b/app/Services/OrderPrescriptionService.php index 533057a..fef9a4b 100644 --- a/app/Services/OrderPrescriptionService.php +++ b/app/Services/OrderPrescriptionService.php @@ -29,6 +29,7 @@ use Extend\Prescription\Prescription; use Hyperf\Contract\LengthAwarePaginatorInterface; use Hyperf\Utils\WaitGroup; use Intervention\Image\ImageManager; +use Swoole\Coroutine\Channel; use TCPDF; class OrderPrescriptionService extends BaseService @@ -144,37 +145,6 @@ class OrderPrescriptionService extends BaseService 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($user_sign_image_path, 1, strlen($user_sign_image_path) - 1); - // 获取处方数据 $params = array(); $params['order_prescription_id'] = $order_prescription_id; @@ -192,380 +162,77 @@ class OrderPrescriptionService extends BaseService throw new BusinessException("处方图片错误"); } - // 获取处方关联疾病数据 - $params = array(); - $params['order_prescription_id'] = $order_prescription_id; - $order_prescription_icd = OrderPrescriptionIcd::getList($params); - if (empty($order_prescription_icd)) { - throw new BusinessException("处方疾病数据错误"); - } + $CaService = new CaService($order_prescription,$user); - // 获取处方关联商品数据 - $params = array(); - $params['order_prescription_id'] = $order_prescription_id; - $order_prescription_product = OrderPrescriptionProduct::getList($params); - if (empty($order_prescription_product)) { - throw new BusinessException("处方药品数据错误"); - } + // 获取云证书签名+验证云证书签名 + $CaService->getVerifyCertSign($order_prescription,1); - // 获取医生数据 - $params = array(); - $params['doctor_id'] = $order_prescription['doctor_id']; - $user_doctor = UserDoctor::getOne($params); - if (empty($user_doctor)) { - throw new BusinessException("医生数据错误"); - } - - // 获取医生自定义科室数据 - $params = array(); - $params['department_custom_id'] = $user_doctor['department_custom_id']; - $hospital_department_custom = HospitalDepartmentCustom::getOne($params); - if (empty($hospital_department_custom)) { - throw new BusinessException("医生自定义数据错误"); - } - - // 获取处方关联病例数据 - $params = array(); - $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; - $order_inquiry_case = OrderInquiryCase::getOne($params); - if (empty($order_inquiry_case)) { - throw new BusinessException("处方病例数据错误"); - } - - // 处理疾病数据 - $icd_name = array_column($order_prescription_icd->toArray(), 'icd_name'); - if (!empty($icd_name)) { - if (count($icd_name) > 1) { - $icd_name = implode(';', $icd_name); - } else { - $icd_name = $icd_name[0]; - } - } else { - $icd_name = ""; - } - - $CaOnline = new CaOnline(); - - // 获取云证书签名 - $data = array(); - $data['created_at'] = $order_prescription['doctor_created_time']; - $data['department_custom_name'] = $hospital_department_custom['department_name'] ?: ""; - $data['user_name'] = $order_prescription['patient_name']; - $data['sex'] = sexToStringSex($order_prescription['patient_sex']); - $data['age'] = $order_prescription['patient_age']; - $data['allergy_history'] = $order_inquiry_case['allergy_history'] ?: "无"; - $data['icd_name'] = $icd_name; - $data['doctor_advice'] = $order_prescription['doctor_advice'] ?: "无"; - - // 商品数据 - $data['product'] = array(); - foreach ($order_prescription_product as $item) { - $product = array(); - $product['product_name'] = $item['product_name'] . "(" . $item['product_spec'] . ")"; // 商品名称+商品规格 - $product['single_unit'] = $item['single_unit'] ?: ""; // 单次剂量(例:1次1包) - $product['frequency_use'] = $item['frequency_use'] ?: ""; // 使用频率(例:1天3次) - $product['single_use'] = $item['single_use'] ?: ""; // 单次用法(例:口服) - $product['prescription_product_num'] = $item['prescription_product_num'] . $item['packaging_unit']; // 商品数量 + 基本包装单位(例:盒/瓶) - $data['product'][] = $product; - } - - dump("获取用户云证书签名"); - $cert_sign_result = $CaOnline->getCertSign($user_entity_id, $user_entity_id, $data); - dump("获取用户云证书签名成功"); - - // 验证云证书签名-验证无需处理,只要不返回错误即可 - dump("验证用户云证书签名"); - $CaOnline->verifyPkcs7($cert_sign_result['signP7'], $data); - dump("验证用户云证书签名成功"); - - if ($user['user_type'] == 3) { - dump("获取医院云证书签名"); - unset($cert_sign_result); - $cert_sign_result = $CaOnline->getCertSign($hospital_entity_id, $hospital_entity_id, $data); - dump("获取医院云证书签名成功"); - - // 验证云证书签名-验证无需处理,只要不返回错误即可 - dump("验证医院云证书签名"); - $CaOnline->verifyPkcs7($cert_sign_result['signP7'], $data); - dump("验证医院云证书签名成功"); - } - - $oss = new Oss(); // 医生 if ($user['user_type'] == 2) { - // 下载基础处方图片 - $prescription_basic_filename = "basic/file/prescription.jpg"; - $prescription_image = $oss->getObjectToRAM($prescription_basic_filename); - - dump("下载基础处方图片成功"); - - $manager = new ImageManager(); - - $image = $manager->make($prescription_image); - - $fontPath = './extend/Ca/msyh.ttf'; - - // 处方号 - $image->text($order_prescription['prescription_code'], 1480, 540, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(60); - $font->align('left'); - }); - - // 日期 - $image->text(date('Y-m-d', strtotime($order_prescription['doctor_created_time'])), 354, 675, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(60); - $font->align('left'); - }); - - // 科室 - $image->text($hospital_department_custom['department_name'] ?: "", 1385, 675, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(60); - $font->align('left'); - }); - - // 姓名 - $image->text($order_prescription['patient_name'], 354, 795, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(60); - $font->align('left'); - }); - - // 性别 - $image->text(sexToStringSex($order_prescription['patient_sex']), 1385, 790, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(60); - $font->align('left'); - }); - - // 年龄 - $image->text($order_prescription['patient_age'], 354, 900, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(60); - $font->align('left'); - }); - - // 过敏史 - $image->text($order_inquiry_case['allergy_history'] ?: "无", 405, 1030, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(60); - $font->align('left'); - }); - - // 初步诊断 - $image->text($icd_name, 445, 1145, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(60); - $font->align('left'); - }); - - // 医生建议 - $image->text($order_prescription['doctor_advice'] ?: "无", 445, 1252, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(60); - $font->align('left'); - }); - - // 商品数据 - foreach ($order_prescription_product as $key => $item) { - $x_axis = 229; - $y_axis = 1600 + $key * 250; - $x_axis_num = 1900;// 数量使用 - - // 商品名称 - $image->text($item['product_name'], $x_axis, $y_axis, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(50); - $font->align('left'); - }); - - $image->text("X" . $item['prescription_product_num'] . $item['packaging_unit'], $x_axis_num, $y_axis, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(50); - $font->align('left'); - }); - - // 用量 - $image->text("用量:" . $item['single_unit'] . " " . $item['frequency_use'], $x_axis, $y_axis + 70, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(50); - $font->align('left'); - }); - - // 用法 - $image->text("用法:" . $item['single_use'], $x_axis, $y_axis + 140, function ($font) use ($fontPath) { - $font->file($fontPath); - $font->size(50); - $font->align('left'); - }); - } - - // 生成图片 - $img_result = (string)$image->encode('png', 75); - dump("处方图片生成成功"); - - // 上传处方图片至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; - dump("处方图片上传oss成功"); - - // 图片生成pdf - $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); - - $pdf->AddPage(); - $pdf->Image('@' . $img_result, 10, 10, 0, 0, '', '', '', false, 300, '', false, false, 0, false, false, false); - - $prescription_pdf_local_filename = $order_prescription['order_prescription_id'] . '.' . 'pdf'; - - // 图片生成的处方pdf存储为本地文件 - $pdf->Output(dirname(__DIR__, 2) . "/" . $prescription_pdf_local_filename, "F"); - - dump("处方图片生成pdf成功"); + // 生成处方图片+处方图片生成pdf + $prescription_img_url = $CaService->createPrescriptionImgPdf($order_prescription); } // 药师 if ($user['user_type'] == 3) { + // 获取医院云证书签名+验证云证书签名 + $CaService->getVerifyCertSign($order_prescription,2); + // 下载医生开具的处方pdf - // 去除第一个/ oss不识别 - $prescription_pdf_path = substr($order_prescription['prescription_pdf'], 1, strlen($order_prescription['prescription_pdf']) - 1); - - $local = "./runtime/" . $order_prescription['order_prescription_id'] . '.' . 'pdf'; - - $oss->getObjectToLocal($prescription_pdf_path, $local); - dump("下载医生开具的处方pdf成功"); + $CaService->downDoctorPrescriptionPdf($order_prescription); } - // 下载签名图片 - $style = "image/resize,m_lfit,w_100,h_350"; - $sign_image = $oss->getCusTomObjectToRAM($sign_image_path, $style); - $sign_image = base64_encode($sign_image); - if (!$sign_image) { - throw new BusinessException("签名图片下载失败"); - } + // 进行处方pdf签章 + $file_id = $CaService->addSignPdf($order_prescription,$user['user_type']); - dump("下载签名图片成功"); - - if ($user['user_type'] == 2) { - $sign_param = [ - [ // 医生端 - "llx" => "120", // 左边底部X坐标 - "lly" => "190", // 左边底部Y坐标 - "urx" => "190", // 右边上部x坐标 - "ury" => "140", // 右边上部y坐标 - "pageList" => [1], - "sealImg" => $sign_image - ], - ]; - } else { - $sign_param = [ - [ // 药师端 - "llx" => "350", // 左边底部X坐标 - "lly" => "190", // 左边底部Y坐标 - "urx" => "440", // 右边上部x坐标 - "ury" => "140", // 右边上部y坐标 - "pageList" => [1], - "sealImg" => $sign_image - ] - ]; - } - - // 打开处方pdf文件 - $pdf_file = fopen("./runtime/" . $order_prescription['order_prescription_id'] . ".pdf", 'r'); - if (!$pdf_file) { - throw new BusinessException("处方图片打开失败"); - } - - - // 处方pdf进行签章 - $data = array(); - $data['sign_param'] = json_encode($sign_param); - $data['pdf_file'] = $pdf_file; - $sign_pdf_result = $CaOnline->addSignPdf($user_entity_id, $data); - if (empty($sign_pdf_result[0]['fileId'])) { - throw new BusinessException("处方签章失败"); - } - - dump("处方pdf进行签章成功"); - - // 下载处方签章文件 - $file_id = $sign_pdf_result[0]['fileId']; - $prescription_pdf_result = $CaOnline->getSignedFile($user_entity_id, $file_id); - - if (empty($prescription_pdf_result)) { - throw new BusinessException("下载处方签章文件失败"); - } - - dump("下载处方签章文件成功"); - - // 上传oss - $filename = "applet/prescription/" . $order_prescription['order_prescription_id'] . '.' . 'pdf'; - $prescription_pdf_url = $oss->putObject($filename, $prescription_pdf_result); - dump("处方pdf上传pss成功"); +// // 增加队列处理、自动下载处方签章文件并上传oss +// // 未存在file_id时,药师审核列表无法看到、自动审核不处理 +// +// +// // 下载处方签章文件 +// $prescription_pdf_result = $CaOnline->getSignedFile($user_entity_id, $file_id); +// +// if (empty($prescription_pdf_result)) { +// throw new BusinessException("下载处方签章文件失败"); +// } +// +// dump("下载处方签章文件成功"); +// +// // 上传oss +// $filename = "applet/prescription/" . $order_prescription['order_prescription_id'] . '.' . 'pdf'; +// $prescription_pdf_url = $oss->putObject($filename, $prescription_pdf_result); +// dump("处方pdf上传pss成功"); if ($user['user_type'] == 3) { // 药师端时,需要进行系统签章 // 把药师签章的pdf存储至本地文件 - $file = fopen("./runtime/" . $order_prescription['order_prescription_id'] . '.' . 'pdf', "w"); - fwrite($file, $prescription_pdf_result); - fclose($file); + // 下载药师签章pdf图片 + $CaService->downCaPdf($file_id,$order_prescription['order_prescription_id']); - // 下载医院签名图片 - $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("医院签名图片下载失败"); - } + // 进行处方pdf签章 + $file_id = $CaService->addSignPdf($order_prescription,$user['user_type']); - $sign_param = [ - [ // 医院签章 - "llx" => "370", // 左边底部X坐标 控制左右(越小越左) - "lly" => "210", // 左边底部Y坐标 控制上下(越小越下) - "urx" => "520", // 右边上部x坐标 - "ury" => "360", // 右边上部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 = $CaOnline->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 = $CaOnline->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); - dump("上传医院处方签章文件成功"); + // 加入下载签章队列 +// +// // 下载处方签章文件 +// unset($prescription_pdf_result); +// $file_id = $hospital_sign_pdf_result[0]['fileId']; +// $prescription_pdf_result = $CaOnline->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); +// dump("上传医院处方签章文件成功"); } $result = array(); $result['prescription_img_url'] = $prescription_img_url ?? $order_prescription['prescription_img']; - $result['prescription_pdf_url'] = '/' . $prescription_pdf_url ?: ""; return $result; } catch (\Exception $e) { diff --git a/app/Services/OrderPrescriptionService_1.php b/app/Services/OrderPrescriptionService_1.php new file mode 100644 index 0000000..b3a03e9 --- /dev/null +++ b/app/Services/OrderPrescriptionService_1.php @@ -0,0 +1,911 @@ +add(4); + + // 获取处方关联疾病名称 + $icd_name = ""; + co(function () use ($wg,$channel,&$icd_name,$order_prescription_id) { + defer(function() use ($wg) { + $wg->done(); + }); + + $params = array(); + $params['order_prescription_id'] = $order_prescription_id; + $order_prescription_icd = OrderPrescriptionIcd::getList($params); + if (empty($order_prescription_icd)) { + $channel->push('处方疾病数据错误'); + return; + } + + $icd_name = array_column($order_prescription_icd->toArray(), 'icd_name'); + if (!empty($icd_name)) { + if (count($icd_name) > 1) { + $icd_name = implode(';', $icd_name); + } else { + $icd_name = $icd_name[0]; + } + } + }); + + // 获取处方关联商品数据 + $order_prescription_product = []; + co(function () use ($wg,$channel,&$order_prescription_product,$order_prescription_id) { + defer(function() use ($wg) { + $wg->done(); + }); + + $params = array(); + $params['order_prescription_id'] = $order_prescription_id; + $order_prescription_product = OrderPrescriptionProduct::getList($params); + if (empty($order_prescription_product)) { + $channel->push('处方药品数据错误'); + return; + } + }); + + // 获取医生自定义科室数据 + $hospital_department_custom = []; + $doctor_id = $order_prescription['doctor_id']; + co(function () use ($wg,$channel,&$hospital_department_custom,$doctor_id) { + defer(function() use ($wg) { + $wg->done(); + }); + + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $doctor_id; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)) { + $channel->push('医生数据错误'); + return; + } + + // 获取医生自定义科室数据 + $params = array(); + $params['department_custom_id'] = $user_doctor['department_custom_id']; + $hospital_department_custom = HospitalDepartmentCustom::getOne($params); + if (empty($hospital_department_custom)) { + $channel->push('医生自定义数据错误'); + return; + } + }); + + // 获取处方关联病例数据 + $order_inquiry_case = []; + $order_inquiry_id = $order_prescription['order_inquiry_id']; + co(function () use ($wg,$channel,&$order_inquiry_case,$order_inquiry_id) { + defer(function() use ($wg) { + $wg->done(); + }); + + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $order_inquiry_case = OrderInquiryCase::getOne($params); + if (empty($order_inquiry_case)) { + $channel->push('处方病例数据错误'); + return; + } + }); + + // 结束 + $wg->wait(); + + // 判断通道是否存在异常数据 + $res = $channel->isEmpty(); + if ($res){ + // 读取通道数据 + $data = $channel->pop(); + + // 关闭channel通道 + $channel->close(); + + throw new BusinessException($data); + }else{ + // 关闭channel通道 + $channel->close(); + } + + $CaOnline = new CaOnline(); + + // 获取云证书签名 + $data = array(); + $data['created_at'] = $order_prescription['doctor_created_time']; + $data['department_custom_name'] = $hospital_department_custom['department_name'] ?: ""; + $data['user_name'] = $order_prescription['patient_name']; + $data['sex'] = sexToStringSex($order_prescription['patient_sex']); + $data['age'] = $order_prescription['patient_age']; + $data['allergy_history'] = $order_inquiry_case['allergy_history'] ?: "无"; + $data['icd_name'] = $icd_name; + $data['doctor_advice'] = $order_prescription['doctor_advice'] ?: "无"; + + // 商品数据 + $data['product'] = array(); + foreach ($order_prescription_product as $item) { + $product = array(); + $product['product_name'] = $item['product_name'] . "(" . $item['product_spec'] . ")"; // 商品名称+商品规格 + $product['single_unit'] = $item['single_unit'] ?: ""; // 单次剂量(例:1次1包) + $product['frequency_use'] = $item['frequency_use'] ?: ""; // 使用频率(例:1天3次) + $product['single_use'] = $item['single_use'] ?: ""; // 单次用法(例:口服) + $product['prescription_product_num'] = $item['prescription_product_num'] . $item['packaging_unit']; // 商品数量 + 基本包装单位(例:盒/瓶) + $data['product'][] = $product; + } + + dump("获取用户云证书签名"); + $cert_sign_result = $CaOnline->getCertSign($user_entity_id, $user_entity_id, $data); + dump("获取用户云证书签名成功"); + + // 验证云证书签名-验证无需处理,只要不返回错误即可 + dump("验证用户云证书签名"); + $CaOnline->verifyPkcs7($cert_sign_result['signP7'], $data); + dump("验证用户云证书签名成功"); + + if ($user['user_type'] == 3) { + dump("获取医院云证书签名"); + unset($cert_sign_result); + $cert_sign_result = $CaOnline->getCertSign($hospital_entity_id, $hospital_entity_id, $data); + dump("获取医院云证书签名成功"); + + // 验证云证书签名-验证无需处理,只要不返回错误即可 + dump("验证医院云证书签名"); + $CaOnline->verifyPkcs7($cert_sign_result['signP7'], $data); + dump("验证医院云证书签名成功"); + } + + $oss = new Oss(); + // 医生 + if ($user['user_type'] == 2) { + // 下载基础处方图片 + $prescription_basic_filename = "basic/file/prescription.jpg"; + $prescription_image = $oss->getObjectToRAM($prescription_basic_filename); + + dump("下载基础处方图片成功"); + + $manager = new ImageManager(); + + $image = $manager->make($prescription_image); + + $fontPath = './extend/Ca/msyh.ttf'; + + // 处方号 + $image->text($order_prescription['prescription_code'], 1480, 540, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 日期 + $image->text(date('Y-m-d', strtotime($order_prescription['doctor_created_time'])), 354, 675, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 科室 + $image->text($hospital_department_custom['department_name'] ?: "", 1385, 675, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 姓名 + $image->text($order_prescription['patient_name'], 354, 795, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 性别 + $image->text(sexToStringSex($order_prescription['patient_sex']), 1385, 790, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 年龄 + $image->text($order_prescription['patient_age'], 354, 900, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 过敏史 + $image->text($order_inquiry_case['allergy_history'] ?: "无", 405, 1030, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 初步诊断 + $image->text($icd_name, 445, 1145, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 医生建议 + $image->text($order_prescription['doctor_advice'] ?: "无", 445, 1252, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(60); + $font->align('left'); + }); + + // 商品数据 + foreach ($order_prescription_product as $key => $item) { + $x_axis = 229; + $y_axis = 1600 + $key * 250; + $x_axis_num = 1900;// 数量使用 + + // 商品名称 + $image->text($item['product_name'], $x_axis, $y_axis, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(50); + $font->align('left'); + }); + + $image->text("X" . $item['prescription_product_num'] . $item['packaging_unit'], $x_axis_num, $y_axis, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(50); + $font->align('left'); + }); + + // 用量 + $image->text("用量:" . $item['single_unit'] . " " . $item['frequency_use'], $x_axis, $y_axis + 70, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(50); + $font->align('left'); + }); + + // 用法 + $image->text("用法:" . $item['single_use'], $x_axis, $y_axis + 140, function ($font) use ($fontPath) { + $font->file($fontPath); + $font->size(50); + $font->align('left'); + }); + } + + // 生成图片 + $img_result = (string)$image->encode('png', 75); + dump("处方图片生成成功"); + + // 上传处方图片至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; + dump("处方图片上传oss成功"); + + // 图片生成pdf + $pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false); + + $pdf->AddPage(); + $pdf->Image('@' . $img_result, 10, 10, 0, 0, '', '', '', false, 300, '', false, false, 0, false, false, false); + + $prescription_pdf_local_filename = $order_prescription['order_prescription_id'] . '.' . 'pdf'; + + // 图片生成的处方pdf存储为本地文件 + $pdf->Output(dirname(__DIR__, 2) . "/" . $prescription_pdf_local_filename, "F"); + + dump("处方图片生成pdf成功"); + } + + // 药师 + if ($user['user_type'] == 3) { + // 下载医生开具的处方pdf + // 去除第一个/ oss不识别 + $prescription_pdf_path = substr($order_prescription['prescription_pdf'], 1, strlen($order_prescription['prescription_pdf']) - 1); + + $local = "./runtime/" . $order_prescription['order_prescription_id'] . '.' . 'pdf'; + + $oss->getObjectToLocal($prescription_pdf_path, $local); + dump("下载医生开具的处方pdf成功"); + } + + // 下载签名图片 + $style = "image/resize,m_lfit,w_100,h_350"; + $sign_image = $oss->getCusTomObjectToRAM($sign_image_path, $style); + $sign_image = base64_encode($sign_image); + if (!$sign_image) { + throw new BusinessException("签名图片下载失败"); + } + + dump("下载签名图片成功"); + + if ($user['user_type'] == 2) { + $sign_param = [ + [ // 医生端 + "llx" => "120", // 左边底部X坐标 + "lly" => "190", // 左边底部Y坐标 + "urx" => "190", // 右边上部x坐标 + "ury" => "140", // 右边上部y坐标 + "pageList" => [1], + "sealImg" => $sign_image + ], + ]; + } else { + $sign_param = [ + [ // 药师端 + "llx" => "350", // 左边底部X坐标 + "lly" => "190", // 左边底部Y坐标 + "urx" => "440", // 右边上部x坐标 + "ury" => "140", // 右边上部y坐标 + "pageList" => [1], + "sealImg" => $sign_image + ] + ]; + } + + // 打开处方pdf文件 + $pdf_file = fopen("./runtime/" . $order_prescription['order_prescription_id'] . ".pdf", 'r'); + if (!$pdf_file) { + throw new BusinessException("处方图片打开失败"); + } + + + // 处方pdf进行签章 + $data = array(); + $data['sign_param'] = json_encode($sign_param); + $data['pdf_file'] = $pdf_file; + $sign_pdf_result = $CaOnline->addSignPdf($user_entity_id, $data); + if (empty($sign_pdf_result[0]['fileId'])) { + throw new BusinessException("处方签章失败"); + } + + dump("处方pdf进行签章成功"); + + // 下载处方签章文件 + $file_id = $sign_pdf_result[0]['fileId']; + $prescription_pdf_result = $CaOnline->getSignedFile($user_entity_id, $file_id); + + if (empty($prescription_pdf_result)) { + throw new BusinessException("下载处方签章文件失败"); + } + + dump("下载处方签章文件成功"); + + // 上传oss + $filename = "applet/prescription/" . $order_prescription['order_prescription_id'] . '.' . 'pdf'; + $prescription_pdf_url = $oss->putObject($filename, $prescription_pdf_result); + dump("处方pdf上传pss成功"); + + 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" => "370", // 左边底部X坐标 控制左右(越小越左) + "lly" => "210", // 左边底部Y坐标 控制上下(越小越下) + "urx" => "520", // 右边上部x坐标 + "ury" => "360", // 右边上部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 = $CaOnline->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 = $CaOnline->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); + dump("上传医院处方签章文件成功"); + } + + $result = array(); + $result['prescription_img_url'] = $prescription_img_url ?? $order_prescription['prescription_img']; + $result['prescription_pdf_url'] = '/' . $prescription_pdf_url ?: ""; + return $result; + + } catch (\Exception $e) { + throw new BusinessException($e->getMessage()); + } + } + + /** + * 上报处方平台 + * @param string $order_product_id 商品订单id + * @return bool + */ + public function reportPrescription(string $order_product_id): bool + { + // 获取商品订单数据 + $params = array(); + $params['order_product_id'] = $order_product_id; + $order_product = OrderProduct::getOne($params); + if (empty($order_product)) { + throw new BusinessException("上报处方平台失败:商品订单数据错误"); + } + + // 获取处方数据 + $params = array(); + $params['order_prescription_id'] = $order_product['order_prescription_id']; + $order_prescription = OrderPrescription::getOne($params); + if (empty($order_prescription)) { + throw new BusinessException("上报处方平台失败:处方数据错误"); + } + + // 获取问诊订单数据 + $params = array(); + $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)) { + throw new BusinessException("上报处方平台失败:问诊订单数据错误"); + } + + // 获取商品订单列表数据 + $params = array(); + $params['order_product_id'] = $order_product['order_product_id']; + $order_product_item = OrderProductItem::getList($params); + if (empty($order_product_item)) { + throw new BusinessException("上报处方平台失败:商品订单列表数据错误"); + } + + $wg = new WaitGroup(); + $wg->add(8); + + $user = []; // 就诊患者用户数据 + $patient_family = []; // 家庭成员-基本信息 + $order_prescription_icd = []; // 处方关联疾病数据 + $user_doctor = []; // 医生数据 + $user_doctor_info = []; // 医生详情数据 + $user_pharmacist = []; // 药师数据 + $user_pharmacist_info = []; // 药师详数据 + $order_inquiry_case = []; // 病例数据 + + $user_id = $order_inquiry['user_id']; + $doctor_id = $order_prescription['doctor_id']; + $family_id = $order_inquiry['family_id']; + $pharmacist_id = $order_prescription['pharmacist_id']; + $order_inquiry_id = $order_inquiry['order_inquiry_id']; + + // 获取就诊患者用户数据 + co(function () use ($wg, &$user, $user_id) { + $params = array(); + $params['user_id'] = $user_id; + $user = User::getOne($params)->toArray(); + // 计数器减一 + $wg->done(); + }); + + // 获取家庭成员-基本信息 + co(function () use ($wg, &$patient_family, $family_id) { + $params = array(); + $params['family_id'] = $family_id; + $patient_family = PatientFamily::getOne($params); + + // 计数器减一 + $wg->done(); + }); + + // 获取处方关联疾病数据 + $order_prescription_id = $order_prescription['order_prescription_id']; + co(function () use ($wg, &$order_prescription_icd, $order_prescription_id) { + $params = array(); + $params['order_prescription_id'] = $order_prescription_id; + $order_prescription_icd = OrderPrescriptionIcd::getList($params); + + // 计数器减一 + $wg->done(); + }); + + // 获取医生数据 + co(function () use ($wg, &$user_doctor, $doctor_id) { + $params = array(); + $params['doctor_id'] = $doctor_id; + $user_doctor = UserDoctor::getOne($params); + + // 计数器减一 + $wg->done(); + }); + + // 获取医生详情数据 + co(function () use ($wg, &$user_doctor_info, $doctor_id) { + $params = array(); + $params['doctor_id'] = $doctor_id; + $user_doctor_info = UserDoctorInfo::getOne($params); + + // 计数器减一 + $wg->done(); + }); + + // 获取药师数据 + co(function () use ($wg, &$user_pharmacist, $pharmacist_id) { + $params = array(); + $params['pharmacist_id'] = $pharmacist_id; + $user_pharmacist = UserPharmacist::getOne($params); + + // 计数器减一 + $wg->done(); + }); + + // 获取药师详情数据 + co(function () use ($wg, &$user_pharmacist_info, $pharmacist_id) { + $params = array(); + $params['pharmacist_id'] = $pharmacist_id; + $user_pharmacist_info = UserPharmacistInfo::getOne($params); + + // 计数器减一 + $wg->done(); + }); + + // 获取病例数据 + co(function () use ($wg, &$order_inquiry_case, $order_inquiry_id) { + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $params['status'] = 1; + $order_inquiry_case = OrderInquiryCase::getOne($params); + + // 计数器减一 + $wg->done(); + }); + + $wg->wait(); + + if (empty($user)) { + throw new BusinessException("用户数据错误"); + } + if (empty($patient_family)) { + throw new BusinessException("用户家庭成员错误"); + } + if (empty($order_prescription_icd)) { + throw new BusinessException("处方疾病数据错误"); + } + if (empty($user_doctor)) { + throw new BusinessException("医生数据错误"); + } + if (empty($user_doctor_info)) { + throw new BusinessException("医生详情数据错误"); + } + if (empty($user_pharmacist)) { + throw new BusinessException("药师数据错误"); + } + if (empty($user_pharmacist_info)) { + throw new BusinessException("药师详情数据错误"); + } + if (empty($order_inquiry_case)) { + throw new BusinessException("病例数据错误"); + } + + // 处理疾病数据 + $icd_name = array_column($order_prescription_icd->toArray(), 'icd_name'); + if (!empty($icd_name)) { + if (count($icd_name) > 1) { + $icd_name = implode(';', $icd_name); + } else { + $icd_name = $icd_name[0]; + } + } else { + $icd_name = ""; + } + + // 获取医生科室 + $params = array(); + $params['department_custom_id'] = $user_doctor['department_custom_id']; + $hospital_department_custom = HospitalDepartmentCustom::getOne($params); + if (empty($hospital_department_custom)) { + throw new BusinessException("医生科室数据错误"); + } + + $arg = array(); + $arg['terminalCode'] = "ZD-10003"; + $arg['orderNo'] = $order_product['order_product_no']; // 订单编号 + $arg['transactNo'] = $order_product['escrow_trade_no']; // 流水单号 + $arg['payDate'] = $order_product['pay_time']; // 支付时间 + $arg['money'] = $order_product['payment_amount_total']; // 订单金额 + $arg['freight'] = $order_product['logistics_fee']; // 运费(单位:元) + $arg['takeTypeCode'] = 2; // 取货方式 1 自提 2 快递,目前只支持快递,传固定值 2 + $arg['buyerName'] = $order_product['consignee_name'];// 收货人姓名 + $arg['buyerPhone'] = $order_product['consignee_tel'];// 收货人联系方式 + $arg['buyerAddress'] = $order_product['address'];// 收货人地址 + $arg['provinceCode'] = $order_product['province_id']; // 收货地址(省) 编码 + $arg['provinceName'] = $order_product['province']; // 收货地址(省) 名称 + $arg['cityCode'] = $order_product['city_id']; // 收货地址(市) 编码 + $arg['cityName'] = $order_product['city']; // 收货地址(市) 名称 + $arg['districtCode'] = $order_product['county_id']; // 收货地址(区 县)编码 + $arg['districtName'] = $order_product['county']; // 收货地址(区 县)名称 + + $arg['presList'][0]['prescriptionNo'] = $order_prescription['prescription_code']; // 处方编号 + $arg['presList'][0]['prescriptionSubType'] = 1; // 处方类型 0:无类型 1:普 通处方 2:儿科处 方 + $arg['presList'][0]['patientName'] = $order_prescription['patient_name']; // 就诊人姓名 + $arg['presList'][0]['patientPhone'] = $user['mobile']; // 就诊人联系方式 + $arg['presList'][0]['idCard'] = $patient_family['id_number']; // 身份证号 + $arg['presList'][0]['advice'] = $order_prescription['doctor_advice'] ?: ""; // 医嘱 + $arg['presList'][0]['diagnosisName'] = $icd_name ?: ""; // 诊断 + $arg['presList'][0]['thirdDoctorName'] = $user_doctor['user_name']; // 开方医生姓名 + $arg['presList'][0]['thirdDeptName'] = $hospital_department_custom['department_name'] ?: ""; // 开方科室名称 + $arg['presList'][0]['thirdDoctorNameImg'] = addAliyunOssWebsite($user_doctor_info['sign_image']); // 开方医生签名链接 + $arg['presList'][0]['prescriptionTime'] = $order_prescription['doctor_created_time']; // 开方时间 + $arg['presList'][0]['thirdFirstPharmacist'] = $user_pharmacist['user_name']; // 初审药师姓名 + $arg['presList'][0]['thirdFirstPharmacistImg'] = addAliyunOssWebsite($user_pharmacist_info['sign_image']); // 初审药师签名链接 + $arg['presList'][0]['thirdFirstTime'] = $order_prescription['pharmacist_verify_time']; // 初审时间 + $arg['presList'][0]['thirdLastPharmacist'] = $user_pharmacist['user_name']; // 终审药师姓名 + $arg['presList'][0]['thirdLastPharmacistImg'] = addAliyunOssWebsite($user_pharmacist_info['sign_image']); // 终审药师签名 链接 + $arg['presList'][0]['ThirdLastTime'] = $order_prescription['pharmacist_verify_time']; // 终审时间 + $arg['presList'][0]['thirdSignImg'] = addAliyunOssWebsite("/basic/file/hospital_signature.png"); // 处方签章链接 + $arg['presList'][0]['referenceCharge'] = $order_product['amount_total']; // 处方费用(不包含运费) + $arg['presList'][0]['chiefComplaint'] = $order_inquiry_case['disease_desc'] ?: ""; // 主诉 + $arg['presList'][0]['historyPresent'] = $order_inquiry_case['disease_class_name'] ?: ""; // 现病史 + $arg['presList'][0]['pastHistory'] = $order_inquiry_case['family_history'] ?: "无"; // 既往史 + $arg['presList'][0]['physicalExamination'] = "无"; // 体格检查 + $arg['presList'][0]['supplementaryExamination'] = "无"; // 辅助检查 + $arg['presList'][0]['allergicHistory'] = $order_inquiry_case['allergy_history'] ?: "无"; // 过敏史 + + // 药品数据 + foreach ($order_product_item as $key => $item) { + // 获取商品数据 + $params = array(); + $params['product_id'] = $item['product_id']; + $product = Product::getOne($params); + if (empty($product)) { + throw new BusinessException("药品数据错误"); + } + + $arg['presList'][0]['drugList'][$key]['drugCode'] = $product['product_platform_code']; // 药品编码 + $arg['presList'][0]['drugList'][$key]['approvalNumber'] = $product['license_number']; // 批准文号 + $arg['presList'][0]['drugList'][$key]['drugName'] = $product['product_name']; // 药品名称 + $arg['presList'][0]['drugList'][$key]['specifications'] = $product['product_spec']; // 药品规格 + $arg['presList'][0]['drugList'][$key]['price'] = $product['product_price']; // 药品单价 + $arg['presList'][0]['drugList'][$key]['packingCount'] = $item['amount']; // 药品数量 + $arg['presList'][0]['drugList'][$key]['surplusPackingCount'] = 0; // 处方药品剩余使用数量 + $arg['presList'][0]['drugList'][$key]['packingUnit'] = $product['packaging_unit']; // 药品单位 + $arg['presList'][0]['drugList'][$key]['singleDosage'] = 1; // 单次用量 + $arg['presList'][0]['drugList'][$key]['singleDosageUnit'] = "片"; // 单次用量单位 + $arg['presList'][0]['drugList'][$key]['useName'] = $product['single_use']; // 用法名称 + $arg['presList'][0]['drugList'][$key]['frequencyName'] = $product['frequency_use']; // 频次名称 + $arg['presList'][0]['drugList'][$key]['useDays'] = $product['available_days']; // 使用天数 + + $arg['presList'][0]['orderDrugList'][$key]['drugCode'] = $product['product_platform_code']; // 药品编码 + $arg['presList'][0]['orderDrugList'][$key]['approvalNumber'] = $product['license_number']; // 批准文号 + $arg['presList'][0]['orderDrugList'][$key]['drugName'] = $product['product_name']; // 药品名称 + $arg['presList'][0]['orderDrugList'][$key]['specifications'] = $product['product_spec']; // 药品规格 + $arg['presList'][0]['orderDrugList'][$key]['price'] = $product['product_price']; // 药品单价 + $arg['presList'][0]['orderDrugList'][$key]['drugCount'] = $item['amount']; // 药品数量 + $arg['presList'][0]['orderDrugList'][$key]['packingUnit'] = $product['packaging_unit']; // 药品单位 + } + + $Prescription = new Prescription(); + $result = $Prescription->reportPrescription($arg); + if ($result['resultCode'] != "1000"){ + if(!empty($result['resultDesc'])){ + throw new BusinessException("上报处方平台失败:" .$result['resultDesc']); + } + + throw new BusinessException("上报处方平台失败:操作编码:" . $result['resultCode']); + } + + return true; + } + +} \ No newline at end of file diff --git a/app/Services/UserDoctorService.php b/app/Services/UserDoctorService.php index e2ac03f..72277ff 100644 --- a/app/Services/UserDoctorService.php +++ b/app/Services/UserDoctorService.php @@ -1153,7 +1153,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['prescription_pdf_url'])){ + if (empty($prescription_open_result['prescription_img_url'])){ Db::rollBack(); return fail(HttpEnumCode::SERVER_ERROR, "处方开具失败"); } @@ -1161,7 +1161,6 @@ class UserDoctorService extends BaseService // 修改处方表 $data = array(); $data['prescription_img'] = $prescription_open_result['prescription_img_url']; - $data['prescription_pdf'] = $prescription_open_result['prescription_pdf_url']; $data['doctor_created_time'] = date('Y-m-d H:i:s',time()); $data['prescription_status'] = 1; // 处方状态(1:待审核 3:待使用 4:已失效 5:已使用) $data['pharmacist_audit_status'] = 0; // 药师审核驳回原因 @@ -1371,7 +1370,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['prescription_pdf_url'])){ + if (empty($prescription_open_result['prescription_img_url'])){ Db::rollBack(); return fail(HttpEnumCode::SERVER_ERROR, "处方开具失败"); } @@ -1379,7 +1378,6 @@ class UserDoctorService extends BaseService // 修改处方表 $data = array(); $data['prescription_img'] = $prescription_open_result['prescription_img_url']; - $data['prescription_pdf'] = $prescription_open_result['prescription_pdf_url']; $data['doctor_created_time'] = date('Y-m-d H:i:s',time()); $params = array(); @@ -2146,4 +2144,6 @@ class UserDoctorService extends BaseService return $result; } + + } \ No newline at end of file diff --git a/app/Services/UserPharmacistService.php b/app/Services/UserPharmacistService.php index 1911f57..73088eb 100644 --- a/app/Services/UserPharmacistService.php +++ b/app/Services/UserPharmacistService.php @@ -233,7 +233,7 @@ class UserPharmacistService extends BaseService // 药师ca签章 $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['prescription_pdf_url'])){ + if (empty($prescription_open_result['prescription_img_url'])){ Db::rollBack(); return fail(HttpEnumCode::SERVER_ERROR, "处方审核失败"); } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 8759d5a..4bb0cff 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -18,6 +18,7 @@ use GuzzleHttp\Exception\GuzzleException; use Hyperf\Amqp\Result; use Hyperf\DbConnection\Db; use Hyperf\Redis\Redis; +use Hyperf\Utils\WaitGroup; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; diff --git a/extend/Ca/ZiYuYongSongTi-2.ttf b/extend/Ca/ZiYuYongSongTi-2.ttf deleted file mode 100644 index 643a988..0000000 Binary files a/extend/Ca/ZiYuYongSongTi-2.ttf and /dev/null differ diff --git a/extend/Ca/hospital_signature.png b/extend/Ca/hospital_signature.png new file mode 100644 index 0000000..10f6ef4 Binary files /dev/null and b/extend/Ca/hospital_signature.png differ diff --git a/extend/Ca/prescription.jpg b/extend/Ca/prescription.jpg new file mode 100644 index 0000000..ac4beb4 Binary files /dev/null and b/extend/Ca/prescription.jpg differ