1
This commit is contained in:
parent
1d09e024b8
commit
0586745e7b
@ -217,5 +217,22 @@ function productCancelReasonToString(int|string $cancel_reason): string
|
||||
} else {
|
||||
$result = "未知";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换性别至字符串
|
||||
* @param string|int $sex
|
||||
* @return string
|
||||
*/
|
||||
function sexToStringSex(string|int $sex): string
|
||||
{
|
||||
$result = "未知";
|
||||
if ($sex == 1){
|
||||
$result = "男";
|
||||
}elseif ($sex == 2){
|
||||
$result = "女";
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
@ -44,10 +44,10 @@ class PatientFamilyController extends AbstractController
|
||||
$request->scene('addFamily')->validateResolved();
|
||||
|
||||
// 检测入参身份证号
|
||||
$res = $this->checkRequestIdCard();
|
||||
if (!empty($res)) {
|
||||
return $this->response->json(fail(HttpEnumCode::HTTP_ERROR, $res));
|
||||
}
|
||||
// $res = $this->checkRequestIdCard();
|
||||
// if (!empty($res)) {
|
||||
// return $this->response->json(fail(HttpEnumCode::HTTP_ERROR, $res));
|
||||
// }
|
||||
|
||||
$patientFamilyService = new PatientFamilyService();
|
||||
$data = $patientFamilyService->addFamily();
|
||||
|
||||
@ -11,6 +11,7 @@ use App\Model\OrderInquiry;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Services\ImService;
|
||||
use App\Services\MessagePush;
|
||||
use App\Services\OrderPrescriptionService;
|
||||
use App\Services\UserDoctorService;
|
||||
use App\Utils\Log;
|
||||
use Extend\Alibaba\Oss;
|
||||
@ -499,4 +500,8 @@ class TestController extends AbstractController
|
||||
|
||||
}
|
||||
|
||||
public function test_11(){
|
||||
$OrderPrescriptionService = new OrderPrescriptionService();
|
||||
$result = $OrderPrescriptionService->doctorOpenPrescription("499871705345941504");
|
||||
}
|
||||
}
|
||||
@ -5,12 +5,18 @@ namespace App\Services;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\DoctorPharmacistCert;
|
||||
use App\Model\HospitalDepartmentCustom;
|
||||
use App\Model\OrderInquiryCase;
|
||||
use App\Model\OrderPrescription;
|
||||
use App\Model\OrderPrescriptionIcd;
|
||||
use App\Model\OrderPrescriptionProduct;
|
||||
use App\Model\OrderProductItem;
|
||||
use App\Model\UserDoctor;
|
||||
use Extend\Alibaba\Oss;
|
||||
use Extend\Ca\Ca;
|
||||
use Hyperf\Contract\LengthAwarePaginatorInterface;
|
||||
use Intervention\Image\ImageManager;
|
||||
use TCPDF;
|
||||
|
||||
class OrderPrescriptionService extends BaseService
|
||||
{
|
||||
@ -99,85 +105,215 @@ class OrderPrescriptionService extends BaseService
|
||||
return OrderPrescription::getCount($params);
|
||||
}
|
||||
|
||||
// 开具处方时获取云证书签名
|
||||
public function getCaCertSign(array $order_prescription, array $order_prescription_icd, array $order_prescription_product)
|
||||
// 医生开具处方
|
||||
public function doctorOpenPrescription(string $order_prescription_id)
|
||||
{
|
||||
try {
|
||||
// // 获取处方数据
|
||||
// $params = array();
|
||||
// $params['order_prescription_id'] = $order_prescription_id;
|
||||
// $order_prescription = OrderPrescription::getOne($params);
|
||||
// if (empty($order_prescription)){
|
||||
// throw new BusinessException("处方数据错误");
|
||||
// }
|
||||
//
|
||||
// // 获取处方关联疾病数据
|
||||
// $params = array();
|
||||
// $params['order_prescription_id'] = $order_prescription_id;
|
||||
// $order_prescription_icd = OrderPrescriptionIcd::getOne($params);
|
||||
// if (empty($order_prescription_icd)){
|
||||
// throw new BusinessException("处方疾病数据错误");
|
||||
// }
|
||||
//
|
||||
// // 获取处方关联商品数据
|
||||
// $params = array();
|
||||
// $params['order_prescription_id'] = $order_prescription_id;
|
||||
// $order_prescription_product = OrderPrescriptionProduct::getList($params);
|
||||
// if (empty($order_prescription_product)){
|
||||
// throw new BusinessException("处方药品数据错误");
|
||||
// }
|
||||
// 获取处方数据
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription_id;
|
||||
$order_prescription = OrderPrescription::getOne($params);
|
||||
if (empty($order_prescription)){
|
||||
throw new BusinessException("处方数据错误");
|
||||
}
|
||||
|
||||
if (empty($order_prescription['doctor_created_time'])){
|
||||
throw new BusinessException("医生开方日期错误");
|
||||
}
|
||||
|
||||
// 获取处方关联疾病数据
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription_id;
|
||||
$order_prescription_icd = OrderPrescriptionIcd::getOne($params);
|
||||
if (empty($order_prescription_icd)){
|
||||
throw new BusinessException("处方疾病数据错误");
|
||||
}
|
||||
|
||||
// 获取处方关联商品数据
|
||||
$params = array();
|
||||
$params['order_prescription_id'] = $order_prescription_id;
|
||||
$order_prescription_product = OrderPrescriptionProduct::getList($params);
|
||||
if (empty($order_prescription_product)){
|
||||
throw new BusinessException("处方药品数据错误");
|
||||
}
|
||||
|
||||
// 获取医生数据
|
||||
$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)){
|
||||
$icd_name = implode(';',$icd_name);
|
||||
}else{
|
||||
$icd_name = "";
|
||||
}
|
||||
|
||||
$ca = new Ca();
|
||||
|
||||
// 获取云证书签名
|
||||
$data = array();
|
||||
$data['created_at'] = $order_prescription;
|
||||
$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盒",
|
||||
],
|
||||
];
|
||||
$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;
|
||||
}
|
||||
|
||||
$cert_sign_result = $ca->getCertSign("491925054435950592", "491925054435950592", $data);
|
||||
|
||||
// 验证云证书签名-验证无需处理,只要不返回错误即可
|
||||
$ca->verifyPkcs7($cert_sign_result['signP7'],$data);
|
||||
|
||||
// 生成处方pdf图片
|
||||
$oss = new Oss();
|
||||
|
||||
$filename = "basic/file/prescription.pdf";
|
||||
$sign_image = $oss->getObjectToRAM($filename);
|
||||
$manager = new ImageManager();
|
||||
|
||||
$image = $manager->make($sign_image);
|
||||
|
||||
$fontPath = './runtime/ZiYuYongSongTi-2.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){
|
||||
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');
|
||||
});
|
||||
}
|
||||
|
||||
// 生成图片
|
||||
$img_result = (string) $image->encode('png', 75);
|
||||
|
||||
// 图片生成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);
|
||||
$pdf->Output(dirname(__DIR__, 2) . "/prescription_img.pdf","F");
|
||||
|
||||
$result = $ca->getCertSign("491925054435950592", "491925054435950592", $data);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
|
||||
@ -140,15 +140,15 @@ class PatientFamilyService extends BaseService
|
||||
}
|
||||
|
||||
// 实人认证-生产环境开启
|
||||
$IdCard = new IdCard();
|
||||
|
||||
$params =array();
|
||||
$params['name'] = $request_params['card_name'];
|
||||
$params['cardNo'] = $request_params['id_number'];
|
||||
$res = $IdCard->checkIdCard($params);
|
||||
if (!empty($res)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,$res);
|
||||
}
|
||||
// $IdCard = new IdCard();
|
||||
//
|
||||
// $params =array();
|
||||
// $params['name'] = $request_params['card_name'];
|
||||
// $params['cardNo'] = $request_params['id_number'];
|
||||
// $res = $IdCard->checkIdCard($params);
|
||||
// if (!empty($res)){
|
||||
// return fail(HttpEnumCode::HTTP_ERROR,$res);
|
||||
// }
|
||||
|
||||
Db::beginTransaction();
|
||||
|
||||
|
||||
@ -1024,6 +1024,7 @@ class UserDoctorService extends BaseService
|
||||
$data['pharmacist_fail_reason'] = ""; // 药师审核驳回原因
|
||||
$data['platform_audit_status'] = 0; // 处方平台审核状态(0:审核中 1:审核成功 2:审核驳回)
|
||||
$data['platform_fail_reason'] = ""; // 处方平台驳回原因
|
||||
$data['doctor_created_time'] = date('Y-m-d H:i:s',time());
|
||||
if ($order_prescription['doctor_advice'] != $doctor_advice) {
|
||||
$data['doctor_advice'] = $doctor_advice; // 医嘱
|
||||
}
|
||||
@ -1194,6 +1195,7 @@ class UserDoctorService extends BaseService
|
||||
$data['patient_id'] = $order_inquiry['patient_id'];
|
||||
$data['family_id'] = $order_inquiry['family_id'];
|
||||
$data['prescription_status'] = 1;
|
||||
$data['doctor_created_time'] = date('Y-m-d H:i:s',time());
|
||||
$data['prescription_code'] = $generator->generate(); // 处方编号
|
||||
$data['doctor_name'] = $user_doctor['user_name']; // 医生名称
|
||||
$data['patient_name'] = $order_inquiry['patient_name'];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user