This commit is contained in:
wucongxing 2023-03-30 13:36:10 +08:00
parent 1d09e024b8
commit 0586745e7b
6 changed files with 244 additions and 84 deletions

View File

@ -217,5 +217,22 @@ function productCancelReasonToString(int|string $cancel_reason): string
} else { } else {
$result = "未知"; $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; return $result;
} }

View File

@ -44,10 +44,10 @@ class PatientFamilyController extends AbstractController
$request->scene('addFamily')->validateResolved(); $request->scene('addFamily')->validateResolved();
// 检测入参身份证号 // 检测入参身份证号
$res = $this->checkRequestIdCard(); // $res = $this->checkRequestIdCard();
if (!empty($res)) { // if (!empty($res)) {
return $this->response->json(fail(HttpEnumCode::HTTP_ERROR, $res)); // return $this->response->json(fail(HttpEnumCode::HTTP_ERROR, $res));
} // }
$patientFamilyService = new PatientFamilyService(); $patientFamilyService = new PatientFamilyService();
$data = $patientFamilyService->addFamily(); $data = $patientFamilyService->addFamily();

View File

@ -11,6 +11,7 @@ use App\Model\OrderInquiry;
use App\Model\UserDoctor; use App\Model\UserDoctor;
use App\Services\ImService; use App\Services\ImService;
use App\Services\MessagePush; use App\Services\MessagePush;
use App\Services\OrderPrescriptionService;
use App\Services\UserDoctorService; use App\Services\UserDoctorService;
use App\Utils\Log; use App\Utils\Log;
use Extend\Alibaba\Oss; use Extend\Alibaba\Oss;
@ -499,4 +500,8 @@ class TestController extends AbstractController
} }
public function test_11(){
$OrderPrescriptionService = new OrderPrescriptionService();
$result = $OrderPrescriptionService->doctorOpenPrescription("499871705345941504");
}
} }

View File

@ -5,12 +5,18 @@ namespace App\Services;
use App\Constants\HttpEnumCode; use App\Constants\HttpEnumCode;
use App\Exception\BusinessException; use App\Exception\BusinessException;
use App\Model\DoctorPharmacistCert; use App\Model\DoctorPharmacistCert;
use App\Model\HospitalDepartmentCustom;
use App\Model\OrderInquiryCase;
use App\Model\OrderPrescription; use App\Model\OrderPrescription;
use App\Model\OrderPrescriptionIcd; use App\Model\OrderPrescriptionIcd;
use App\Model\OrderPrescriptionProduct; use App\Model\OrderPrescriptionProduct;
use App\Model\OrderProductItem; use App\Model\OrderProductItem;
use App\Model\UserDoctor;
use Extend\Alibaba\Oss;
use Extend\Ca\Ca; use Extend\Ca\Ca;
use Hyperf\Contract\LengthAwarePaginatorInterface; use Hyperf\Contract\LengthAwarePaginatorInterface;
use Intervention\Image\ImageManager;
use TCPDF;
class OrderPrescriptionService extends BaseService class OrderPrescriptionService extends BaseService
{ {
@ -99,85 +105,215 @@ class OrderPrescriptionService extends BaseService
return OrderPrescription::getCount($params); 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 { try {
// // 获取处方数据 // 获取处方数据
// $params = array(); $params = array();
// $params['order_prescription_id'] = $order_prescription_id; $params['order_prescription_id'] = $order_prescription_id;
// $order_prescription = OrderPrescription::getOne($params); $order_prescription = OrderPrescription::getOne($params);
// if (empty($order_prescription)){ if (empty($order_prescription)){
// throw new BusinessException("处方数据错误"); throw new BusinessException("处方数据错误");
// } }
//
// // 获取处方关联疾病数据 if (empty($order_prescription['doctor_created_time'])){
// $params = array(); throw new BusinessException("医生开方日期错误");
// $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_icd = OrderPrescriptionIcd::getOne($params);
// // 获取处方关联商品数据 if (empty($order_prescription_icd)){
// $params = array(); throw new BusinessException("处方疾病数据错误");
// $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_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(); $ca = new Ca();
// 获取云证书签名 // 获取云证书签名
$data = array(); $data = array();
$data['created_at'] = $order_prescription; $data['created_at'] = $order_prescription['doctor_created_time'];
$data['department_custom_name'] = "外科"; $data['department_custom_name'] = $hospital_department_custom['department_name'] ?: "";
$data['user_name'] = "测试用户1"; $data['user_name'] = $order_prescription['patient_name'];
$data['sex'] = ""; $data['sex'] = sexToStringSex($order_prescription['patient_sex']);
$data['age'] = 19; $data['age'] = $order_prescription['patient_age'];
$data['allergy_history'] = ""; $data['allergy_history'] = $order_inquiry_case['allergy_history'] ?: "";
$data['icd_name'] = "感冒"; $data['icd_name'] = $icd_name;
$data['doctor_advice'] = "多吃药"; $data['doctor_advice'] = $order_prescription['doctor_advice'] ?: "";
$data['product'] = [
[ // 商品数据
"product_name" => "感冒药150ml*10", $data['product'] = array();
"single_unit" => "一次一包", foreach ($order_prescription_product as $item){
"frequency_use" => "1天3次", $product = array();
"single_use" => "口服", $product['product_name'] = $item['product_name'] . "(" . $item['product_spec'] . ")"; // 商品名称+商品规格
"prescription_product_num" => "X1盒", $product['single_unit'] = $item['single_unit'] ?: ""; // 单次剂量1次1包
], $product['frequency_use'] = $item['frequency_use'] ?: ""; // 使用频率(例1天3次)
[ $product['single_use'] = $item['single_use'] ?: ""; // 单次用法(例:口服)
"product_name" => "感冒药250ml*10", $product['prescription_product_num'] = $item['prescription_product_num'] . $item['packaging_unit']; // 商品数量 + 基本包装单位(例:盒/瓶)
"single_unit" => "一次一包", $data['product'][] = $product;
"frequency_use" => "1天3次", }
"single_use" => "口服",
"prescription_product_num" => "X1盒", $cert_sign_result = $ca->getCertSign("491925054435950592", "491925054435950592", $data);
],
[ // 验证云证书签名-验证无需处理,只要不返回错误即可
"product_name" => "感冒药350ml*10", $ca->verifyPkcs7($cert_sign_result['signP7'],$data);
"single_unit" => "一次一包",
"frequency_use" => "1天3次", // 生成处方pdf图片
"single_use" => "口服", $oss = new Oss();
"prescription_product_num" => "X1盒",
], $filename = "basic/file/prescription.pdf";
[ $sign_image = $oss->getObjectToRAM($filename);
"product_name" => "感冒药450ml*10", $manager = new ImageManager();
"single_unit" => "一次一包",
"frequency_use" => "1天3次", $image = $manager->make($sign_image);
"single_use" => "口服",
"prescription_product_num" => "X1盒", $fontPath = './runtime/ZiYuYongSongTi-2.ttf';
],
[ // 处方号
"product_name" => "感冒药550ml*10", $image->text($order_prescription['prescription_code'], 1480, 540, function ($font) use($fontPath) {
"single_unit" => "一次一包", $font->file($fontPath);
"frequency_use" => "1天3次", $font->size(60);
"single_use" => "口服", $font->align('left');
"prescription_product_num" => "X1盒", });
],
]; // 日期
$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) { } catch (\Exception $e) {

View File

@ -140,15 +140,15 @@ class PatientFamilyService extends BaseService
} }
// 实人认证-生产环境开启 // 实人认证-生产环境开启
$IdCard = new IdCard(); // $IdCard = new IdCard();
//
$params =array(); // $params =array();
$params['name'] = $request_params['card_name']; // $params['name'] = $request_params['card_name'];
$params['cardNo'] = $request_params['id_number']; // $params['cardNo'] = $request_params['id_number'];
$res = $IdCard->checkIdCard($params); // $res = $IdCard->checkIdCard($params);
if (!empty($res)){ // if (!empty($res)){
return fail(HttpEnumCode::HTTP_ERROR,$res); // return fail(HttpEnumCode::HTTP_ERROR,$res);
} // }
Db::beginTransaction(); Db::beginTransaction();

View File

@ -1024,6 +1024,7 @@ class UserDoctorService extends BaseService
$data['pharmacist_fail_reason'] = ""; // 药师审核驳回原因 $data['pharmacist_fail_reason'] = ""; // 药师审核驳回原因
$data['platform_audit_status'] = 0; // 处方平台审核状态0:审核中 1:审核成功 2:审核驳回) $data['platform_audit_status'] = 0; // 处方平台审核状态0:审核中 1:审核成功 2:审核驳回)
$data['platform_fail_reason'] = ""; // 处方平台驳回原因 $data['platform_fail_reason'] = ""; // 处方平台驳回原因
$data['doctor_created_time'] = date('Y-m-d H:i:s',time());
if ($order_prescription['doctor_advice'] != $doctor_advice) { if ($order_prescription['doctor_advice'] != $doctor_advice) {
$data['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['patient_id'] = $order_inquiry['patient_id'];
$data['family_id'] = $order_inquiry['family_id']; $data['family_id'] = $order_inquiry['family_id'];
$data['prescription_status'] = 1; $data['prescription_status'] = 1;
$data['doctor_created_time'] = date('Y-m-d H:i:s',time());
$data['prescription_code'] = $generator->generate(); // 处方编号 $data['prescription_code'] = $generator->generate(); // 处方编号
$data['doctor_name'] = $user_doctor['user_name']; // 医生名称 $data['doctor_name'] = $user_doctor['user_name']; // 医生名称
$data['patient_name'] = $order_inquiry['patient_name']; $data['patient_name'] = $order_inquiry['patient_name'];