hospital-applets-api/app/Services/OrderPrescriptionService.php

186 lines
7.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Model\DoctorPharmacistCert;
use App\Model\OrderPrescription;
use App\Model\OrderPrescriptionIcd;
use App\Model\OrderPrescriptionProduct;
use App\Model\OrderProductItem;
use Extend\Ca\Ca;
use Hyperf\Contract\LengthAwarePaginatorInterface;
class OrderPrescriptionService extends BaseService
{
/**
* 获取医生是否存在被驳回处方
* @param string $doctor_id 医生id
* @return bool
*/
public function getDoctorExistsAuditFail(string $doctor_id): bool
{
$params = array();
$params['doctor_id'] = $doctor_id;
$params['pharmacist_audit_status'] = 2;// 处方审核状态0:审核中 1:审核成功 2:审核驳回)
$params['platform_audit_status'] = 1;// 处方平台审核状态0:审核中 1:审核成功 2:审核驳回)
$params['is_delete'] = 0;// 是否删除0:否 1:是)
return OrderPrescription::getExists($params);
}
/**
* 获取药师待审核处方-分页
* @param string $pharmacist_id 药师id
* @param int $pharmacist_audit_status 药师审核状态0:审核中 1:审核成功 2:审核驳回)
* @param int $platform_audit_status
* @param string|int $page
* @param string|int $per_page
* @return array
*/
public function getPharmacistWaitAuditPage(string $pharmacist_id, int $pharmacist_audit_status, int $platform_audit_status, string|int $page = 1, string|int $per_page = 10): array
{
$params = array();
$params['pharmacist_id'] = $pharmacist_id;
$params['pharmacist_audit_status'] = $pharmacist_audit_status; // 药师审核状态0:审核中 1:审核成功 2:审核驳回)
$params['platform_audit_status'] = $platform_audit_status; // 处方平台审核状态0:审核中 1:审核成功 2:审核驳回)
return OrderPrescription::getPage($params, ['*'], $page, $per_page);
}
/**
* 获取处方中开方药品
* @param string|int $order_prescription_id
* @return array
*/
public function getproductList(string|int $order_prescription_id): array
{
$params = array();
$params['order_prescription_id'] = $order_prescription_id;
$order_prescription_products = OrderPrescriptionProduct::getLimit($params);
if (empty($order_prescription_products)) {
return [];
}
$result = [];
foreach ($order_prescription_products as $order_prescription_product) {
$data = array();
$data['product_id'] = $order_prescription_product['product_id'];
$data['prescription_product_num'] = $order_prescription_product['prescription_product_num'];
$data['product_name'] = $order_prescription_product['product_name'] ?? "";
$data['product_spec'] = $order_prescription_product['product_spec'] ?? "";
$data['single_unit'] = $order_prescription_product['single_unit'] ?? "";
$data['single_use'] = $order_prescription_product['single_use'] ?? "";
$data['packaging_unit'] = $order_prescription_product['packaging_unit'] ?? "";
$data['frequency_use'] = $order_prescription_product['frequency_use'] ?? "";
$data['available_days'] = $order_prescription_product['available_days'] ?? 0;
$result[] = $data;
}
unset($order_product_items);
return $result;
}
/**
* 获取患者某一状态下的处方数量
* @param string $patient_id 患者id
* @param int $prescription_status 处方状态1:待审核 2:待使用 3:已失效 4:已使用)
* @return int
*/
public function getPatientPrescriptionWithStatus(string $patient_id, int $prescription_status): int
{
$params = array();
$params['patient_id'] = $patient_id;
$params['prescription_status'] = $prescription_status;
$params['pharmacist_audit_status'] = 1;
return OrderPrescription::getCount($params);
}
// 开具处方时获取云证书签名
public function getCaCertSign(array $order_prescription, array $order_prescription_icd, array $order_prescription_product)
{
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("处方药品数据错误");
// }
$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" => "感冒药150ml*10",
"single_unit" => "一次一包",
"frequency_use" => "1天3次",
"single_use" => "口服",
"prescription_product_num" => "X1盒",
],
[
"product_name" => "感冒药250ml*10",
"single_unit" => "一次一包",
"frequency_use" => "1天3次",
"single_use" => "口服",
"prescription_product_num" => "X1盒",
],
[
"product_name" => "感冒药350ml*10",
"single_unit" => "一次一包",
"frequency_use" => "1天3次",
"single_use" => "口服",
"prescription_product_num" => "X1盒",
],
[
"product_name" => "感冒药450ml*10",
"single_unit" => "一次一包",
"frequency_use" => "1天3次",
"single_use" => "口服",
"prescription_product_num" => "X1盒",
],
[
"product_name" => "感冒药550ml*10",
"single_unit" => "一次一包",
"frequency_use" => "1天3次",
"single_use" => "口服",
"prescription_product_num" => "X1盒",
],
];
$result = $ca->getCertSign("491925054435950592", "491925054435950592", $data);
} catch (\Exception $e) {
}
}
}