监管平台更新接口 V2
Build Docker / build (push) Has been cancelled

This commit is contained in:
haomingming
2026-05-12 14:49:47 +08:00
parent f9ba59aa55
commit 012984f636
15 changed files with 1773 additions and 204 deletions
+312 -13
View File
@@ -9,12 +9,12 @@ use App\Model\HospitalDepartmentCustom;
use App\Model\OrderInquiry;
use App\Model\OrderInquiryCase;
use App\Model\OrderPrescription;
use App\Model\OrderPrescriptionFile;
use App\Model\OrderPrescriptionIcd;
use App\Model\OrderPrescriptionProduct;
use App\Model\PatientFamily;
use App\Model\Product;
use App\Model\ReportRegulatory;
use App\Model\UserCaCert;
use App\Model\UserDoctor;
use App\Model\UserDoctorInfo;
use App\Model\UserPharmacist;
@@ -188,7 +188,7 @@ class ReportRegulatoryCommand extends HyperfCommand
}else{
$this->line("C-2、检测处方(抄方)数据");
// 获取上报数据-处方 (抄方类型)
$report_prescription_data = $this->getReportTransferPrescriptionData($order_inquiry, $order_prescription);
$report_prescription_data = $this->getReportTransferPrescriptionDataV2($order_inquiry, $order_prescription);
}
$this->line("C-3、上报处方");
@@ -198,6 +198,17 @@ class ReportRegulatoryCommand extends HyperfCommand
$this->line("C-4、上报处方成功" . json_encode($result,JSON_UNESCAPED_UNICODE));
$report_prescription_detail_data = $this->getReportPrescriptionDetailData(
$order_prescription,
$report_prescription_data
);
if (empty($report_prescription_detail_data)) {
throw new BusinessException("处方明细数据错误");
}
$result = $regulatoryPlatform->uploadRecipeDetail($report_prescription_detail_data);
$this->line("C-4-1、上报处方明细成功" . json_encode($result,JSON_UNESCAPED_UNICODE));
// 上报成功
$res = $this->modifyReportRegulatoryPrescription($report_regulatory, 1);
if (!$res) {
@@ -474,7 +485,7 @@ class ReportRegulatoryCommand extends HyperfCommand
$params['user_id'] = $user_doctor['user_id'];
$params['type'] = 2;
$params['is_latest'] = 1;
$doctor_user_ca_cert = UserCaCert::getOne($params);
$doctor_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'doctor');
if (empty($doctor_user_ca_cert)){
$this->line("错误:无医生ca数据");
return false;
@@ -485,7 +496,7 @@ class ReportRegulatoryCommand extends HyperfCommand
$params['user_id'] = $user_pharmacist['user_id'];
$params['type'] = 2;
$params['is_latest'] = 1;
$pharmacist_user_ca_cert = UserCaCert::getOne($params);
$pharmacist_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'pharmacist');
if (empty($pharmacist_user_ca_cert)){
$this->line("错误:无药师ca数据");
return false;
@@ -533,6 +544,13 @@ class ReportRegulatoryCommand extends HyperfCommand
$data['recipeNo'] = $order_prescription['order_prescription_id']; // 医院处方编号
$data['cityId'] = "510100"; // 城市ID(参考地区字段)
$pharmacist_ca_data = $this->getStoredPrescriptionCaData($order_prescription['order_prescription_id'], 'pharmacist');
$data['caSupplier'] = $pharmacist_ca_data['caSupplier'] ?? "";
$data['caSignType'] = $pharmacist_ca_data['caSignType'] ?? "";
$data['caSignTime'] = $pharmacist_ca_data['caSignTime'] ?? "";
$data['caSignOriginaltext'] = $pharmacist_ca_data['caSignOriginaltext'] ?? "";
$data['caSignText'] = $pharmacist_ca_data['caSignText'] ?? "";
return $data;
}
@@ -544,6 +562,7 @@ class ReportRegulatoryCommand extends HyperfCommand
*/
private function getReportTransferPrescriptionData(array|object $order_inquiry, array|object $order_prescription): bool|array
{
return $this->getReportTransferPrescriptionDataV2($order_inquiry, $order_prescription);
// 获取医生数据
$params = array();
$params['doctor_id'] = $order_prescription['doctor_id'];
@@ -638,7 +657,7 @@ class ReportRegulatoryCommand extends HyperfCommand
$params['user_id'] = $user_doctor['user_id'];
$params['type'] = 2;
$params['is_latest'] = 1;
$doctor_user_ca_cert = UserCaCert::getOne($params);
$doctor_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'doctor');
if (empty($doctor_user_ca_cert)){
$this->line("错误:无医生ca数据");
return false;
@@ -649,7 +668,7 @@ class ReportRegulatoryCommand extends HyperfCommand
$params['user_id'] = $user_pharmacist['user_id'];
$params['type'] = 2;
$params['is_latest'] = 1;
$pharmacist_user_ca_cert = UserCaCert::getOne($params);
$pharmacist_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'pharmacist');
if (empty($pharmacist_user_ca_cert)){
$this->line("错误:无药师ca数据");
return false;
@@ -697,6 +716,160 @@ class ReportRegulatoryCommand extends HyperfCommand
$data['recipeNo'] = $order_prescription['order_prescription_id']; // 医院处方编号
$data['cityId'] = "510100"; // 城市ID(参考地区字段)
$pharmacist_ca_data = $this->getStoredPrescriptionCaData($order_prescription['order_prescription_id'], 'pharmacist');
$data['caSupplier'] = $pharmacist_ca_data['caSupplier'] ?? "";
$data['caSignType'] = $pharmacist_ca_data['caSignType'] ?? "";
$data['caSignTime'] = $pharmacist_ca_data['caSignTime'] ?? "";
$data['caSignOriginaltext'] = $pharmacist_ca_data['caSignOriginaltext'] ?? "";
$data['caSignText'] = $pharmacist_ca_data['caSignText'] ?? "";
return $data;
}
private function getReportTransferPrescriptionDataV2(array|object $order_inquiry, array|object $order_prescription): bool|array
{
$params = array();
$params['doctor_id'] = $order_prescription['doctor_id'];
$user_doctor = UserDoctor::getOne($params);
if (empty($user_doctor)) {
$this->line("閿欒锛氬尰鐢熸暟鎹敊璇?");
return false;
}
$params = array();
$params['doctor_id'] = $order_prescription['doctor_id'];
$user_doctor_info = UserDoctorInfo::getOne($params);
if (empty($user_doctor_info)) {
$this->line("閿欒锛氬尰鐢熻鎯呮暟鎹敊璇?");
return false;
}
$params = array();
$params['department_custom_id'] = $user_doctor['department_custom_id'];
$hospital_department_custom = HospitalDepartmentCustom::getOne($params);
if (empty($hospital_department_custom)) {
$this->line("閿欒锛氬尰鐢熻嚜瀹氫箟鏁版嵁閿欒");
return false;
}
$params = array();
$params['family_id'] = $order_inquiry['family_id'];
$patient_family = PatientFamily::getOne($params);
if (empty($patient_family)) {
$this->line("閿欒锛氶棶璇婃偅鑰呮暟鎹敊璇?");
return false;
}
$params = array();
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
$params['status'] = 1;
$order_inquiry_case = OrderInquiryCase::getOne($params);
if (empty($order_inquiry_case)) {
$this->line("閿欒锛氭偅鑰呴棶璇婄梾渚嬮敊璇?");
return false;
}
$params = array();
$params['pharmacist_id'] = $order_prescription['pharmacist_id'];
$user_pharmacist = UserPharmacist::getOne($params);
if (empty($user_pharmacist)) {
$this->line("閿欒锛氳嵂甯堟暟鎹敊璇?");
return false;
}
$params = array();
$params['pharmacist_id'] = $order_prescription['pharmacist_id'];
$user_pharmacist_info = UserPharmacistInfo::getOne($params);
if (empty($user_pharmacist_info)) {
$this->line("閿欒锛氳嵂甯堣鎯呮暟鎹敊璇?");
return false;
}
$params = array();
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
$order_prescription_icd = OrderPrescriptionIcd::getList($params);
if (empty($order_prescription_icd)) {
$this->line("閿欒锛氭棤澶嶈瘖鐤剧梾璇婃柇鏁版嵁");
return false;
}
$icd_name = "";
$icd_name_data = array_column($order_prescription_icd->toArray(), 'icd_name');
if (!empty($icd_name_data)) {
if (count($icd_name_data) > 1) {
$icd_name = implode('|', $icd_name_data);
} else {
$icd_name = $icd_name_data[0];
}
}
$order_prescription_product = $this->getPreProductData($order_prescription['order_prescription_id']);
if (empty($order_prescription_product)) {
$this->line("閿欒锛氭棤澶勬柟鍟嗗搧鏁版嵁");
return false;
}
$doctor_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'doctor');
if (empty($doctor_user_ca_cert)) {
$this->line("閿欒锛氭棤鍖荤敓ca鏁版嵁");
return false;
}
$pharmacist_user_ca_cert = $this->buildLegacyCaCertPayload($order_prescription['order_prescription_id'], 'pharmacist');
if (empty($pharmacist_user_ca_cert)) {
$this->line("閿欒锛氭棤鑽笀ca鏁版嵁");
return false;
}
$data = array();
$data['thirdUniqueid'] = $order_inquiry['order_inquiry_id'];
$data['orgName'] = "鎴愰兘閲戠墰娆f鐩哥収浜掕仈缃戝尰闄?";
$data['orgCode'] = "MA6CGUDA251010619D2112";
$data['section'] = $hospital_department_custom['department_name'];
$data['sectionCode'] = $hospital_department_custom['department_code'];
$data['docName'] = $user_doctor['user_name'];
$data['docCertificateNum'] = $user_doctor_info['qualification_cert_num'];
$data['pharmacistName'] = $user_pharmacist_info['card_name'];
$data['pharmacistOrg'] = "鎴愰兘閲戠墰娆f鐩哥収浜掕仈缃戝尰闄?";
$data['pharmacistCertificateNum'] = $user_pharmacist_info['qualification_cert_num'];
$data['furtherConsultNo'] = $order_inquiry['order_inquiry_id'];
$data['furtherConsultDiagnosis'] = $icd_name;
$data['patientName'] = $order_inquiry['patient_name'];
$data['patientSex'] = $order_inquiry['patient_sex'] == 0 ?: 1;
$data['patientAge'] = (int) $order_inquiry['patient_age'];
$data['patientIdcardType'] = 1;
$data['patientIdcardNum'] = $patient_family['id_number'];
$data['feeType'] = 1;
$data['medicalHistory'] = $order_inquiry_case['disease_desc'];
$data['recipeTime'] = $order_prescription['doctor_created_time'];
$data['recipeType'] = 2;
$data['reviewTime'] = $order_prescription['pharmacist_verify_time'];
$data['recipeUnitPrice'] = $order_prescription_product['amount_total'];
$data['drugName'] = $order_prescription_product['drug_name'];
$data['drugCode'] = $order_prescription_product['drug_code'];
$data['drugCommonName'] = $order_prescription_product['drug_common_name'];
$data['specification'] = $order_prescription_product['specification'];
$data['frequency'] = $order_prescription_product['frequency'];
$data['usage'] = $order_prescription_product['usage'];
$data['doseUnit'] = $order_prescription_product['dose_unit'];
$data['doseEachTime'] = $order_prescription_product['dose_each_time'];
$data['medicationDays'] = $order_prescription_product['medication_days'];
$data['quantity'] = $order_prescription_product['quantity'];
$data['drugPackage'] = $order_prescription_product['drug_package'];
$data['recipeAllPrice'] = $order_prescription_product['amount_total'];
$data['uploadTime'] = date("Y-m-d H:i:s", time());
$data['docCaSign'] = $doctor_user_ca_cert['cert_base64'];
$data['pharmacistCaSign'] = $pharmacist_user_ca_cert['cert_base64'];
$data['recipeNo'] = $order_prescription['order_prescription_id'];
$data['cityId'] = "510100";
$pharmacist_ca_data = $this->getStoredPrescriptionCaData($order_prescription['order_prescription_id'], 'pharmacist');
$data['caSupplier'] = $pharmacist_ca_data['caSupplier'] ?? "";
$data['caSignType'] = $pharmacist_ca_data['caSignType'] ?? "";
$data['caSignTime'] = $pharmacist_ca_data['caSignTime'] ?? "";
$data['caSignOriginaltext'] = $pharmacist_ca_data['caSignOriginaltext'] ?? "";
$data['caSignText'] = $pharmacist_ca_data['caSignText'] ?? "";
return $data;
}
@@ -736,9 +909,9 @@ class ReportRegulatoryCommand extends HyperfCommand
$specification = $item['product_spec']; // 规格
$frequency = $item['frequency_use']; // 使用频度
$usage = $item['single_use']; // 用法
$dose_unit = $product['single_unit']; // 剂量单位
$dose_each_time = $product['single_unit']; // 每次剂量
$medication_days = (double)$product['available_days']; // 用药天数
$dose_unit = $item['single_unit']; // 剂量单位
$dose_each_time = $item['single_unit']; // 每次剂量
$medication_days = (double)$item['available_days']; // 用药天数
$quantity = (double)$item['prescription_product_num']; // 数量
$drug_package = $item['packaging_unit']; // 药品包装
} else {
@@ -748,14 +921,22 @@ class ReportRegulatoryCommand extends HyperfCommand
$specification = $specification . "|" . $item['product_spec']; // 规格
$frequency = $frequency . "|" . $item['frequency_use']; // 使用频度
$usage = $usage . "|" . $item['single_use']; // 用法
$dose_unit = $dose_unit . "|" . $product['single_unit']; // 剂量单位
$dose_each_time = $dose_each_time . "|" . $product['single_unit']; // 每次剂量
$medication_days = $medication_days . "|" . (double)$product['available_days']; // 用药天数
$dose_unit = $dose_unit . "|" . $item['single_unit']; // 剂量单位
$dose_each_time = $dose_each_time . "|" . $item['single_unit']; // 每次剂量
$medication_days = $medication_days . "|" . (double)$item['available_days']; // 用药天数
$quantity = $quantity . "|" . (double)$item['prescription_product_num']; // 数量
$drug_package = $drug_package . "|" . $item['packaging_unit']; // 药品包装
}
$amount_total += $item['product_price'] * $item['prescription_product_num'];
$amount_total = bcadd(
(string) $amount_total,
bcmul(
(string) ($item['product_price'] ?? $product['product_price'] ?? 0),
(string) $item['prescription_product_num'],
2
),
2
);
}
$result = array();
@@ -775,11 +956,121 @@ class ReportRegulatoryCommand extends HyperfCommand
return $result;
}
private function getPreProductDetailData(string $order_prescription_id): array
{
$params = array();
$params['order_prescription_id'] = $order_prescription_id;
$order_prescription_product = OrderPrescriptionProduct::getList($params);
if (empty($order_prescription_product)) {
$this->line("错误:无处方药品数据");
return [];
}
$result = [];
foreach ($order_prescription_product as $item) {
$params = array();
$params['product_id'] = $item['product_id'];
$product = Product::getWithAmountOne($params);
if (empty($product)) {
$this->line("错误:无药品数据");
return [];
}
$amount_total = bcmul(
(string) ($item['product_price'] ?? $product['product_price'] ?? 0),
(string) $item['prescription_product_num'],
2
);
$result[] = [
'drug_name' => (string) ($item['product_name'] ?? ''),
'drug_code' => (string) ($product['product_pharmacy_code'] ?? ''),
'drug_common_name' => (string) ($product['common_name'] ?? ''),
'specification' => (string) ($item['product_spec'] ?? ''),
'frequency' => (string) ($item['frequency_use'] ?? ''),
'usage' => (string) ($item['single_use'] ?? ''),
'dose_unit' => (string) ($item['single_unit'] ?? $product['single_unit'] ?? ''),
'dose_each_time' => (string) ($item['single_unit'] ?? $product['single_unit'] ?? ''),
'medication_days' => (string) ($item['available_days'] ?? $product['available_days'] ?? ''),
'quantity' => (string) $item['prescription_product_num'],
'drug_package' => (string) ($item['packaging_unit'] ?? ''),
'product_price' => (string) ($item['product_price'] ?? $product['product_price'] ?? 0),
'amount_total' => $amount_total,
];
}
return $result;
}
private function getReportPrescriptionDetailData(
array|object $order_prescription,
array $report_prescription_data
): array {
$product_details = $this->getPreProductDetailData((string) $order_prescription['order_prescription_id']);
if (empty($product_details)) {
return [];
}
$result = [];
foreach ($product_details as $detail) {
$row = $report_prescription_data;
$row['recipeUnitPrice'] = $detail['product_price'];
$row['drugName'] = $detail['drug_name'];
$row['drugCode'] = $detail['drug_code'];
$row['drugCommonName'] = $detail['drug_common_name'];
$row['specification'] = $detail['specification'];
$row['frequency'] = $detail['frequency'];
$row['usage'] = $detail['usage'];
$row['doseUnit'] = $detail['dose_unit'];
$row['doseEachTime'] = $detail['dose_each_time'];
$row['medicationDays'] = $detail['medication_days'];
$row['quantity'] = $detail['quantity'];
$row['drugPackage'] = $detail['drug_package'];
$row['recipeAllPrice'] = $detail['amount_total'];
$row['uploadTime'] = date("Y-m-d H:i:s", time());
$result[] = $row;
}
return $result;
}
/**
* 获取上报数据-网络咨询
* @param array|object $order_inquiry
* @return array
*/
private function getStoredPrescriptionCaData(string|int $order_prescription_id, string $role): array
{
$params = array();
$params['order_prescription_id'] = $order_prescription_id;
$order_prescription_file = OrderPrescriptionFile::getOne($params);
if (empty($order_prescription_file)) {
return [];
}
$prefix = $role === 'doctor' ? 'doctor' : 'pharmacist';
return [
'caSupplier' => (string) ($order_prescription_file[$prefix . '_ca_supplier'] ?? ''),
'caSignType' => (string) ($order_prescription_file[$prefix . '_ca_sign_type'] ?? ''),
'caSignTime' => (string) ($order_prescription_file[$prefix . '_ca_sign_time'] ?? ''),
'caSignOriginaltext' => (string) ($order_prescription_file[$prefix . '_ca_sign_originaltext'] ?? ''),
'caSignText' => (string) ($order_prescription_file[$prefix . '_ca_sign_text'] ?? ''),
];
}
private function buildLegacyCaCertPayload(string|int $order_prescription_id, string $role): array
{
$ca_data = $this->getStoredPrescriptionCaData($order_prescription_id, $role);
if (empty($ca_data['caSignText'])) {
return [];
}
return [
'cert_base64' => $ca_data['caSignText'],
];
}
private function getConsultData(array|object $order_inquiry): array
{
// 获取医生数据
@@ -836,6 +1127,7 @@ class ReportRegulatoryCommand extends HyperfCommand
$data['section'] = $hospital_department_custom['department_name'];//科室名称
$data['sectionCode'] = $hospital_department_custom['department_code'];//科室编码
$data['docName'] = $user_doctor['user_name'];// 姓名(医师、护师、技师)
$data['doc_idcard'] = $user_doctor_info['card_num']; // 医生身份证号
$data['certificateNum'] = $user_doctor_info['qualification_cert_num']; // 执业资格证号
$data['patientName'] = $order_inquiry['patient_name']; // 患者姓名
$data['patientAge'] = (int)$order_inquiry['patient_age']; // 患者年龄
@@ -992,6 +1284,13 @@ class ReportRegulatoryCommand extends HyperfCommand
$data['cityId'] = "510100"; // 城市ID(参考地区字段)
$data['isMark'] = 1;//是否留痕 1:代表留痕;0:代表未留痕
$doctor_ca_data = $this->getStoredPrescriptionCaData($order_prescription['order_prescription_id'], 'doctor');
$data['caSupplier'] = $doctor_ca_data['caSupplier'] ?? "";
$data['caSignType'] = $doctor_ca_data['caSignType'] ?? "";
$data['caSignTime'] = $doctor_ca_data['caSignTime'] ?? "";
$data['caSignOriginaltext'] = $doctor_ca_data['caSignOriginaltext'] ?? "";
$data['caSignText'] = $doctor_ca_data['caSignText'] ?? "";
return $data;
}
}