diff --git a/app/Command/ReportPreProductOrderCommand.php b/app/Command/ReportPreProductOrderCommand.php index 879504e..0efc510 100644 --- a/app/Command/ReportPreProductOrderCommand.php +++ b/app/Command/ReportPreProductOrderCommand.php @@ -58,6 +58,9 @@ class ReportPreProductOrderCommand extends HyperfCommand Db::beginTransaction(); try { + // 检测是否已上报监管平台 未上报监管平台不进行处理 + + // 检测执行次数 $res = $this->checkHandleNumber($item['order_product_id']); if (!$res) { diff --git a/app/Command/ReportRegulatoryCommand.php b/app/Command/ReportRegulatoryCommand.php new file mode 100644 index 0000000..68e5e30 --- /dev/null +++ b/app/Command/ReportRegulatoryCommand.php @@ -0,0 +1,948 @@ +setDescription('上报监管平台'); + } + + public function handle() + { + $this->line("开始"); + + // 获取需执行总数 + $order_prescription_count = $this->getOrderPrescriptionCount(); + if ($order_prescription_count <= 0) { + $this->line("结束:无可执行订单"); + return; + } + + $order_prescription_count = 1; + for ($i = 0; $i < $order_prescription_count; $i++) { + // 获取待上报订单 + $order_prescription = $this->getOrderPrescription(); + if (empty($order_prescription)) { + $this->line("结束:本轮无可执行订单"); + continue; + } + + $this->line("开始:" . $order_prescription['order_prescription_id']); + +// try { +// $this->line("信息:检测执行次数"); +// $res = $this->checkHandleNumber($order_prescription['order_prescription_id']); +// } catch (\Exception $e) { +// $this->line("错误:" . $e->getMessage()); +// continue; +// } + + $res = true; + if (!$res) { + $this->line("错误:超出最大执行次数或检测错误"); + + Db::beginTransaction(); + + try { + // 修改为上报失败 + $this->line("错误:记录上报失败"); + $res = $this->modifyReportRegulatoryInquiry($order_prescription, 2, 1, "超出最大执行次数或检测错误"); + if (!$res) { + Db::rollBack(); + $this->line("错误:系统错误"); + continue; + } + + // 修改为上报失败 + $this->line("错误:记录上报失败"); + $res = $this->modifyReportRegulatoryPrescription($order_prescription, 2, "超出最大执行次数或检测错误"); + if (!$res) { + // 记录失败 + $this->line("错误:记录失败"); + } + + Db::commit(); + + continue; + } catch (\Exception $e) { + Db::rollBack(); + $this->line("错误:" . $e->getMessage()); + continue; + } + } + + $this->line("信息:检测执行次数通过"); + + // 获取问诊订单数据 + $order_inquiry = $this->getOrderInquiry($order_prescription['order_inquiry_id']); + if (empty($order_inquiry)) { + // 无问诊数据,跳过 + $this->line("错误:问诊订单数据为空"); + continue; + } + + $res = $this->checkInquiryOrder($order_inquiry); + if (!$res) { + // 问诊订单数据不符合条件,不执行 + continue; + } + + $this->line("信息:上报监管平台-问诊"); + + try { + // 检测问诊是否已经上报监管平台 + $res = $this->checkIsReportRegulatoryInquiry($order_prescription['order_inquiry_id']); + if (!$res) { + // 检测患者是否首次问诊 + $is_first = $this->checkPatientFirstInquiry($order_prescription['patient_id'], $order_prescription['order_prescription_id']); + + // 获取上报监管数据-问诊 + $report_inquiry_data = $this->getReportInquiryData($order_inquiry, $order_prescription, $is_first); + + // 上报监管平台-问诊 + $res = $this->reportRegulatoryInquiry($report_inquiry_data, $is_first); + if (empty($res)) { + // 上报成功 + $res = $this->modifyReportRegulatoryInquiry($order_prescription, 1, $is_first ? 1 : 2); + if (!$res) { + // 记录失败 + $this->line("错误:记录失败"); + } + } else { + // 上报失败 + $res = $this->modifyReportRegulatoryInquiry($order_prescription, 2, $is_first ? 1 : 2, $res); + if (!$res) { + // 记录失败 + $this->line("错误:记录失败"); + } + } + } + } catch (\Exception $e) { + $this->line("错误:" . $e->getMessage()); + // 上报失败 + $res = $this->modifyReportRegulatoryInquiry($order_prescription, 2, $is_first ? 1 : 2, $e->getMessage()); + if (!$res) { + // 记录失败 + $this->line("错误:记录失败"); + } + continue; + } + + $this->line("信息:上报监管平台-处方"); + + try { + // 检测处方是否已经上报监管平台 + $res = $this->checkIsReportRegulatoryPrescription($order_prescription['order_inquiry_id']); + if (!$res) { + // 获取上报监管数据-处方 + $report_prescription_data = $this->getReportPrescriptionData($order_inquiry, $order_prescription); + + // 上报监管平台-处方 + $res = $this->reportRegulatoryPrescription($report_prescription_data); + if (empty($res)) { + // 上报成功 + $res = $this->modifyReportRegulatoryPrescription($order_prescription, 1); + if (!$res) { + // 记录失败 + $this->line("错误:记录失败"); + } + } else { + // 上报失败 + $res = $this->modifyReportRegulatoryPrescription($order_prescription, 2, $e->getMessage()); + if (!$res) { + // 记录失败 + $this->line("错误:记录失败"); + } + } + } + } catch (\Exception $e) { + $this->line("错误:" . $e->getMessage()); + + // 上报失败 + $res = $this->modifyReportRegulatoryPrescription($order_prescription, 2, $res); + if (!$res) { + // 记录失败 + $this->line("错误:记录失败"); + } + } + + $this->line("结束:" . $order_prescription['order_prescription_id']); + } + + $this->line("全部结束"); + } + + /** + * 获取符合条件的处方订单个数 + * @return int + */ + private function getOrderPrescriptionCount(): int + { + $params = array(); + $params['pharmacist_audit_status'] = 1; + + $prescription_status_params = [2, 3, 4]; + return OrderPrescription::getStatusCount($params, $prescription_status_params); + } + + /** + * 获取符合条件的处方订单 + * @param int $offset 起始位置 + * @param int $limit 个数 + * @return array + */ + private function getOrderPrescription(): array + { +// $params = array(); +// $params['pharmacist_audit_status'] = 1; +// +// $prescription_status_params = [2,3,4]; +// $order_prescription = OrderPrescription::getStatusLimit($params,$prescription_status_params,["*"],$offset,$limit); +// if (empty($order_prescription)){ +// return []; +// } + + $params = array(); + $params['order_inquiry_id'] = "514128068311498753"; + + $prescription_status_params = [1, 2, 3, 4]; + $order_prescription = OrderPrescription::getStatusOne($params, $prescription_status_params, ["*"]); + if (empty($order_prescription)) { + return []; + } + + return $order_prescription->toArray(); + } + + /** + * 检测执行次数 + * @param string $order_prescription_id + * @return bool + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + protected function checkHandleNumber(string $order_prescription_id): bool + { + try { + $redis = $this->container->get(Redis::class); + + $redis_key = "ReportRegulatoryInquiry" . $order_prescription_id; + $redis_value = $redis->get($redis_key); + if (empty($redis_value)) { + $redis->set($redis_key, 1, 60 * 60 * 24 * 5); + return true; + } + + // 执行次数过多 + if ($redis_value > 1) { + // 加入短信队列,通知管理员 + + return false; + } + + $redis->incr($redis_key); + } catch (\Exception $e) { + return false; + } + + return true; + } + + /** + * 新增/修改 问诊数据 + * @param array|object $order_prescription + * @param int $report_inquiry_status 问诊上报状态(0:未上报 1:已上报 2:上报失败) + * @param int $report_inquiry_type 问诊上报类型(1:网络初诊 2:网络复诊) + * @param string $report_inquiry_fail_reason 问诊上报失败原因 + * @return bool + */ + private function modifyReportRegulatoryInquiry(array|object $order_prescription, int $report_inquiry_status, int $report_inquiry_type, string $report_inquiry_fail_reason = ""): bool + { + try { + // 检测数据是否存在 + $params = array(); + $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; + $report_regulatory = ReportRegulatory::getOne($params); + if (empty($report_regulatory)) { + // 新增 + $data = array(); + $data['order_inquiry_id'] = $order_prescription['order_inquiry_id']; + $data['order_prescription_id'] = $order_prescription['order_prescription_id']; + $data['report_inquiry_status'] = $report_inquiry_status; + $data['report_inquiry_type'] = $report_inquiry_type; + $data['report_inquiry_time'] = date('Y-m-d H:i:s', time()); + $data['report_inquiry_fail_reason'] = $report_inquiry_fail_reason; + $report_regulatory = ReportRegulatory::addReportRegulatory($data); + if (empty($report_regulatory)) { + return false; + } + } else { + // 修改 + $params = array(); + $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; + + $data = array(); + $data['report_inquiry_status'] = $report_inquiry_status; + $data['report_inquiry_type'] = $report_inquiry_type; + $data['report_inquiry_time'] = date('Y-m-d H:i:s', time()); + $data['report_inquiry_fail_reason'] = $report_inquiry_fail_reason; + ReportRegulatory::edit($params, $data); + } + } catch (\Exception $e) { + $this->line("失败:" . $e->getMessage()); + return false; + } + + return true; + } + + /** + * 新增/修改 处方数据 + * @param array|object $order_prescription + * @param int $report_prescription_status 处方上报状态(0:未上报 1:已上报 2:上报失败) + * @param string $report_prescription_fail_reason 处方上报失败原因 + * @return bool + */ + private function modifyReportRegulatoryPrescription(array|object $order_prescription, int $report_prescription_status, string $report_prescription_fail_reason = ""): bool + { + try { + // 检测数据是否存在 + $params = array(); + $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; + $report_regulatory = ReportRegulatory::getOne($params); + if (empty($report_regulatory)) { + // 新增 + $data = array(); + $data['order_inquiry_id'] = $order_prescription['order_inquiry_id']; + $data['order_prescription_id'] = $order_prescription['order_prescription_id']; + $data['report_prescription_status'] = $report_prescription_status; + $data['report_prescription_time'] = date('Y-m-d H:i:s', time()); + $data['report_prescription_fail_reason'] = $report_prescription_fail_reason; + $report_regulatory = ReportRegulatory::addReportRegulatory($data); + if (empty($report_regulatory)) { + return false; + } + } else { + // 修改 + $params = array(); + $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; + + $data = array(); + $data['report_prescription_status'] = $report_prescription_status; + $data['report_prescription_time'] = date('Y-m-d H:i:s', time()); + $data['report_prescription_fail_reason'] = $report_prescription_fail_reason; + ReportRegulatory::edit($params, $data); + } + } catch (\Exception $e) { + $this->line("失败:" . $e->getMessage()); + return false; + } + + return true; + } + + /** + * 获取问诊订单数据 + * @param string $order_inquiry_id + * @return array + */ + private function getOrderInquiry(string $order_inquiry_id): array + { + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)) { + return []; + } + + return $order_inquiry->toArray(); + } + + /** + * 检测问诊订单数据 + * @param array|object $order_inquiry 问诊订单数据 + * @return bool true:可执行 false:不可执行 + */ + private function checkInquiryOrder(array|object $order_inquiry): bool + { + // 检测问诊订单状态 + $inquiry_status = [5, 6, 7];// 5:已完成 6:已结束 7:已取消 + if (!in_array($order_inquiry['inquiry_status'], $inquiry_status)) { + // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) + $this->line("信息:订单状态未完成-不执行"); + return false; + } + + // 已取消状态,查看是否完成后取消的 + if ($order_inquiry['inquiry_status'] == 7 && $order_inquiry['cancel_reason'] != 4 && empty($order_inquiry['complete_time'])) { + $this->line("信息:订单为取消的未完成订单,不执行"); + return false; + } + + return true; + } + + /** + * 检测患者是否首次问诊-是否开具过处方 + * @param string $patient_id + * @param string $order_prescription_id + * @return bool true:首次 false:复诊 + */ + private function checkPatientFirstInquiry(string $patient_id, string $order_prescription_id): bool + { + $params = array(); + $params['patient_id'] = $patient_id; + $params['pharmacist_audit_status'] = 1; + + $prescription_status_params = [2, 3, 4]; + $order_prescriptions = OrderPrescription::getStatusList($params, $prescription_status_params); + if (empty($order_prescriptions)) { + return true; + } + + foreach ($order_prescriptions as $item) { + if ($item['order_prescription_id'] == $order_prescription_id) { + continue; + } + + // 开具过处方 + return false; + } + + return true; + } + + /** + * 检测问诊是否已经上报监管平台 + * @param string $order_inquiry_id + * @return bool true:已上报 false:未上报 + */ + private function checkIsReportRegulatoryInquiry(string $order_inquiry_id): bool + { + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $report_regulatory = ReportRegulatory::getOne($params); + if (empty($report_regulatory)) { + return false; + } + + if ($report_regulatory['report_inquiry_status'] == 1) { + return true; + } + + return false; + } + + /** + * 检测处方是否已经上报监管平台 + * @param string $order_inquiry_id + * @return bool true:已上报 false:未上报 + */ + private function checkIsReportRegulatoryPrescription(string $order_inquiry_id): bool + { + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_id; + $report_regulatory = ReportRegulatory::getOne($params); + if (empty($report_regulatory)) { + return false; + } + + if ($report_regulatory['report_prescription_status'] == 1) { + return true; + } + + return false; + } + + /** + * 获取上报监管数据-问诊 + * @param array|object $order_inquiry + * @param array|object $order_prescription + * @param bool $is_first 是否首次问诊 true:是 1:否 + * @return bool|array + */ + private function getReportInquiryData(array|object $order_inquiry, array|object $order_prescription, bool $is_first = true): bool|array + { + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $order_inquiry['doctor_id']; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)) { + $this->line("错误:医生数据错误"); + return false; + } + + $params = array(); + $params['doctor_id'] = $order_inquiry['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; + } + + if ($is_first) { + $this->line("信息:患者首次问诊"); + // 初诊 + // 网络咨询(网络门诊)服务 + $data = array(); + $data['thirdUniqueid'] = $order_inquiry['order_inquiry_id']; // 唯一标识 + $data['orgName'] = "成都金牛欣欣相照互联网医院"; // 机构名称 + $data['orgCode'] = "MA6CGUDA251010619D2112"; // 机构编码 + $data['channelName'] = "成都金牛欣欣相照互联网医院";//平台名称 + $data['section'] = $hospital_department_custom['department_name'];//科室名称 + $data['sectionCode'] = $hospital_department_custom['department_code'];//科室编码 + $data['docName'] = $user_doctor['user_name'];// 姓名(医师、护师、技师) + $data['certificateNum'] = $user_doctor_info['qualification_cert_num']; // 执业资格证号 + $data['patientName'] = $order_inquiry['patient_name']; // 患者姓名 + $data['patientAge'] = (int)$order_inquiry['patient_age']; // 患者年龄 + $data['patientSex'] = $order_inquiry['patient_sex'] == 0 ?: 1; // 患者性别 + $data['patientIdcardType'] = 1; // 证件类型 + $data['patientIdcardNum'] = $patient_family['id_number']; // 患者证件号码 + $data['serviceType'] = 1; // 服务类型 1网络咨询 2网络门诊 + $data['consultNo'] = $order_inquiry['inquiry_no']; // 网络咨询或网络门诊编号 订单编号 + $data['consultType'] = 1; // 咨询类别 1、图文咨询 2语音咨询3、视频咨询 + $data['consultApplyTime'] = $order_inquiry['created_at']; // 咨询申请时间 + $data['consultStartTime'] = $order_inquiry['reception_time']; // 咨询开始时间 + $data['consultEndTime'] = $order_inquiry['complete_time']; // 咨询结束时间 + $data['feeType'] = 1; // 费别 1自费 2医保 + $data['price'] = $order_inquiry['payment_amount_total']; // 咨询价格 元 + $data['isReply'] = 1; //咨询是否回复 0未回复 1已回复 + $data['patientEvaluate'] = 1; //患者满意度 1-5 1代表非常满意 5代表非常不满意 + $data['complainInfo'] = "无"; //投诉举报信息 + $data['disposeResult'] = "无"; //处理结果信息 + $data['isRiskWarn'] = 1; //是否进行诊前风险提示 0否 1是 + $data['isPatientSign'] = 1; //是否确认患者为签约对象 0否 1是 + $data['uploadTime'] = date('Y-m-d H:i:s', time()); //上传时间 + $data['medicalHistory'] = $order_inquiry_case['disease_desc']; //患者病史描述 + $data['docAdvice'] = $order_prescription['doctor_advice'] ?? "无"; // 医生建议描述 医嘱 + $data['cityId'] = "510100"; // 城市ID(参考地区字段) + $data['isMark'] = 1;//是否留痕 1:代表留痕;0代表未留痕 + } else { + $this->line("信息:患者复诊"); + // 获取患者首次问诊病例数据 + $params = array(); + $params['patient_id'] = $order_inquiry['patient_id']; + $params['pharmacist_audit_status'] = 1; + + $prescription_status_params = [2, 3, 4]; + $first_order_prescription = OrderPrescription::getStatusOne($params, $prescription_status_params); + if (empty($first_order_prescription)) { + // 复诊,但是未找到复诊处方单 + $this->line("错误:无初诊处方单"); + return false; + } + + // 获取患者初诊疾病诊断数据 + $params = array(); + $params['order_prescription_id'] = $first_order_prescription['order_prescription_id']; + $first_order_prescription_icd = OrderPrescriptionIcd::getList($params); + if (empty($first_order_prescription_icd)) { + // 复诊,但是未找到关联疾病 + $this->line("错误:无初诊疾病诊断数据"); + return false; + } + + $first_icd_name_data = array_column($first_order_prescription_icd->toArray(), 'icd_name'); + if (!empty($first_icd_name_data)) { + if (count($first_icd_name_data) > 1) { + $first_icd_name = implode('|', $first_icd_name_data); + } else { + $first_icd_name = $first_icd_name_data[0]; + } + } + + // 获取患者复诊疾病诊断数据 + $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_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]; + } + } + + // icd编码 + $icd_code_data = array_column($order_prescription_icd->toArray(), 'icd_code'); + if (!empty($icd_code_data)) { + if (count($icd_code_data) > 1) { + $icd_code = implode('|', $icd_code_data); + } else { + $icd_code = $icd_code_data[0]; + } + } + + // 网络复诊服务 + $data = array(); + $data['thirdUniqueid'] = $order_inquiry['order_inquiry_id']; // 唯一标识 + $data['orgName'] = "成都金牛欣欣相照互联网医院"; // 机构名称 + $data['orgCode'] = "MA6CGUDA251010619D2112"; // 机构编码 + $data['channelName'] = "成都金牛欣欣相照互联网医院";//平台名称 + $data['section'] = $hospital_department_custom['department_name'];//科室名称 + $data['sectionCode'] = $hospital_department_custom['department_code'];//科室编码 + $data['docName'] = $user_doctor['user_name'];// 复诊医师姓名 + $data['certificateNum'] = $user_doctor_info['qualification_cert_num']; // 执业资格证号 + $data['patientName'] = $order_inquiry['patient_name']; // 患者姓名 + $data['patientAge'] = (int)$order_inquiry['patient_age']; // 患者年龄 + $data['patientSex'] = $order_inquiry['patient_sex'] == 0 ?: 1; // 患者性别 + $data['patientIdcardType'] = 1; // 证件类型 + $data['patientIdcardNum'] = $patient_family['id_number']; // 患者证件号码 + $data['furtherConsultNo'] = $order_inquiry['order_inquiry_id']; // 网络复诊编号 + $data['furtherConsulType'] = "1"; // 复诊类别 1、图文诊疗 2、语音诊疗 3、视频诊疗 + $data['medicalHistory'] = $order_inquiry_case['disease_desc']; //患者病史描述 + $data['consultDiagnosisType'] = 1; // 首诊诊断类型 + $data['consultDiagnosis'] = $first_icd_name; // 首诊诊断 复诊患者在首诊医院的诊断,如有多条,使用“|”进行分隔;当传图片时,需要传图片的base64字符串 + $data['consultTime'] = $first_order_prescription['doctor_created_time']; // 首诊时间 + $data['consultOrg'] = "成都金牛欣欣相照互联网医院"; // 首诊机构 + $data['furtherConsultApplyTime'] = $order_inquiry['created_at']; // 复诊申请时间 + $data['furtherConsulStartTime'] = $order_inquiry['reception_time']; // 复诊开始时间 + $data['furtherConsulEndTime'] = $order_inquiry['complete_time']; // 复诊结束时间 + $data['furtherConsulIsReply'] = 1; // 复诊是否回复 0未回复 1已回复 + $data['feeType'] = 1; // 费别 1自费 2医保 + $data['furtherConsultDiagnosis'] = $icd_name; // 复诊诊断 复诊患者在实体医院的诊断名称,如有多条,使用“|”进行分隔 + $data['furtherConsultDiagnosisNo'] = $icd_code; // 复诊icd诊断编码 + $data['furtherConsultPrice'] = $order_inquiry['payment_amount_total']; // 复诊价格 + $data['patientEvaluate'] = 1; // 患者满意度 1-5 1代表非常满意 5代表非常不满意 + $data['complainInfo'] = "无"; // 投诉举报信息 + $data['disposeResult'] = "无"; // 处理结果信息 + $data['isRiskWarn'] = 1; // 是否进行诊前风险提示 0否 1是 + $data['isPatientSign'] = 1; // 是否确认患者为签约对象 0否 1是 + $data['isPrescription'] = 1; // 是否开具处方 0否 1是 + $data['uploadTime'] = date('Y-m-d H:i:s', time()); // 上传时间 + $data['cityId'] = "510100"; // 城市ID(参考地区字段) + $data['isMark'] = 1;//是否留痕 1:代表留痕;0代表未留痕 + } + return $data; + } + + /** + * 上报监管平台-问诊 + * @param array $report_inquiry_data 上报数据 + * @param bool $is_first + * @return string + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + private function reportRegulatoryInquiry(array $report_inquiry_data, bool $is_first = true): string + { + try { + $regulatoryPlatform = new regulatoryPlatform(); + if ($is_first) { + $result = $regulatoryPlatform->uploadConsult([$report_inquiry_data]); + } else { + $result = $regulatoryPlatform->uploadFurtherConsult([$report_inquiry_data]); + } + + return ""; + } catch (\Exception $e) { + $this->line("错误:" . $e->getMessage()); + return $e->getMessage(); + } + } + + /** + * 获取上报监管数据-处方 + * @param array|object $order_inquiry + * @param array|object $order_prescription + * @return bool|array + */ + private function getReportPrescriptionData(array|object $order_inquiry, array|object $order_prescription): bool|array + { + // 获取医生数据 + $params = array(); + $params['doctor_id'] = $order_inquiry['doctor_id']; + $user_doctor = UserDoctor::getOne($params); + if (empty($user_doctor)) { + $this->line("错误:医生数据错误"); + return false; + } + + $params = array(); + $params['doctor_id'] = $order_inquiry['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_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; + } + + $data = array(); + $data['thirdUniqueid'] = $order_inquiry['order_inquiry_id']; // 唯一标识 + $data['orgName'] = "成都金牛欣欣相照互联网医院"; // 机构名称 + $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'] = "成都金牛欣欣相照互联网医院"; // 药师执业机构 + $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; // 费别 1自费 2医保 + $data['medicalHistory'] = $order_inquiry_case['disease_desc']; //患者病史描述 + $data['recipeTime'] = $order_prescription['doctor_created_time']; // 处方日期 + $data['recipeType'] = 2; // 处方类型 1中药 2西药 3成药(三医) + $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['recipeNo'] = $order_prescription['order_prescription_id']; // 医院处方编号 + $data['cityId'] = "510100"; // 城市ID(参考地区字段) + + return $data; + } + + /** + * 上报监管平台-处方 + * @param array $report_prescription_data + * @return string + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + private function reportRegulatoryPrescription(array $report_prescription_data): string + { + try { + $regulatoryPlatform = new regulatoryPlatform(); + $result = $regulatoryPlatform->uploadRecipe([$report_prescription_data]); + + return ""; + } catch (\Exception $e) { + $this->line("错误:" . $e->getMessage()); + return $e->getMessage(); + } + } + + /** + * 获取处方商品数据 + * @param string $order_prescription_id + * @return array + */ + private function getPreProductData(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 []; + } + + // 药品总价格 + $amount_total = 0; + + foreach ($order_prescription_product as $key => $item) { + // 获取商品数据 + $params = array(); + $params['product_id'] = $item['product_id']; + $product = Product::getWithAmountOne($params); + if (empty($product)) { + $this->line("错误:无药品数据"); + return []; + } + + if ($key == 0) { + $drug_name = $item['product_name']; // 药品名称商品名 + $drug_code = $product['product_pharmacy_code']; // 药品编码 + $drug_common_name = $product['common_name']; // 药品通用名 + $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']; // 用药天数 + $quantity = (double)$item['prescription_product_num']; // 数量 + $drug_package = $item['packaging_unit']; // 药品包装 + } else { + $drug_name = $drug_name . "|" . $item['product_name']; // 药品名称商品名 + $drug_code = $drug_code . "|" . $product['product_pharmacy_code']; // 药品编码 + $drug_common_name = $drug_common_name . "|" . $product['common_name']; // 药品通用名 + $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']; // 用药天数 + $quantity = $quantity . "|" . (double)$item['prescription_product_num']; // 数量 + $drug_package = $drug_package . "|" . $item['packaging_unit']; // 药品包装 + } + + $amount_total += $item['product_price'] * $item['prescription_product_num']; + } + + $result = array(); + $result['drug_name'] = $drug_name; + $result['drug_code'] = $drug_code; + $result['drug_common_name'] = $drug_common_name; + $result['specification'] = $specification; + $result['frequency'] = $frequency; + $result['usage'] = $usage; + $result['dose_unit'] = $dose_unit; + $result['dose_each_time'] = $dose_each_time; + $result['medication_days'] = $medication_days; + $result['quantity'] = $quantity; + $result['drug_package'] = $drug_package; + $result['amount_total'] = $amount_total; + + return $result; + } +} diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php index e85086c..dc2e637 100644 --- a/app/Controller/TestController.php +++ b/app/Controller/TestController.php @@ -67,10 +67,10 @@ class TestController extends AbstractController // $this->test_5(); // $this->test_1(); // $this->test_11(); -// $this->test_12(); + $this->test_12(); // $this->test_13(); // $this->test_14(); - $this->test_15(); +// $this->test_15(); } @@ -93,7 +93,7 @@ class TestController extends AbstractController $params['order_prescription_id'] = $order_prescription_id; $order_prescription_product = OrderPrescriptionProduct::getList($params); if (empty($order_prescription_product)) { - throw new BusinessException("处方药品数据错误"); + throw new BusinessException("处方药品数据错误1"); } // 获取问诊订单数据 @@ -101,7 +101,7 @@ class TestController extends AbstractController $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; $order_inquiry = OrderInquiry::getOne($params); if (empty($order_inquiry)) { - throw new BusinessException("处方药品数据错误"); + throw new BusinessException("处方药品数据错误2"); } // 获取商品订单数据 @@ -109,7 +109,7 @@ class TestController extends AbstractController $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; $order_product = OrderProduct::getOne($params); if (empty($order_product)) { - throw new BusinessException("处方药品数据错误"); + throw new BusinessException("处方药品数据错误3"); } // 获取商品订单数据 @@ -117,7 +117,7 @@ class TestController extends AbstractController $params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; $order_product_item = OrderProductItem::getList($params); if (empty($order_product_item)) { - throw new BusinessException("处方药品数据错误"); + throw new BusinessException("处方药品数据错误4"); } $OrderPrescriptionService = new OrderPrescriptionService(); @@ -327,22 +327,6 @@ class TestController extends AbstractController } public function test_15(){ - // 短信 - $data = array(); - $data['template_code'] = "SMS_271540920"; - $data['scene_desc'] = "处方审核通过"; - $data['phone'] = "18221234167"; - - $template_param = array(); - $template_param['name'] = "吴医生"; - $data['template_param'] = $template_param; - - $message = new SendSmsMessageProducer($data); - $producer = ApplicationContext::getContainer()->get(Producer::class); - $result = $producer->produce($message); - if (!$result) { - Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE)); - } } } \ No newline at end of file diff --git a/app/Model/OrderInquiry.php b/app/Model/OrderInquiry.php index 71b6b35..92c1701 100644 --- a/app/Model/OrderInquiry.php +++ b/app/Model/OrderInquiry.php @@ -248,7 +248,7 @@ class OrderInquiry extends Model } /** - * 获取某种状态的所有订单 + * 获取某种状态、不包含某医生的所有订单 * @param array $params * @param array $inquiry_status_params * @param array $not_in_params @@ -282,6 +282,20 @@ class OrderInquiry extends Model ->first($fields); } + /** + * 获取某种状态的订单 + * @param array $params + * @param array $inquiry_status_params + * @param array $fields + * @return object|null + */ + public static function getInquiryStatusList(array $params, array $inquiry_status_params, array $fields = ["*"]): object|null + { + return self::where($params) + ->whereIn('inquiry_status', $inquiry_status_params) + ->get($fields); + } + /** * 修改 * @param array $params @@ -375,4 +389,22 @@ class OrderInquiry extends Model return $data; } + + /** + * 获取某种状态的订单-限制条数 + * @param array $params + * @param array $inquiry_status_params + * @param array $fields + * @param int $offset 起始 + * @param int $limit 个数 + * @return Collection|array + */ + public static function getInquiryStatusLimit(array $params, array $inquiry_status_params, array $fields = ["*"],int $offset = 0,int $limit = 10): Collection|array + { + return self::where($params) + ->whereIn('inquiry_status', $inquiry_status_params) + ->offset($offset) + ->limit($limit) + ->get($fields); + } } diff --git a/app/Model/OrderPrescription.php b/app/Model/OrderPrescription.php index 6266b52..b9d692f 100644 --- a/app/Model/OrderPrescription.php +++ b/app/Model/OrderPrescription.php @@ -244,4 +244,61 @@ class OrderPrescription extends Model ]) ->where($params)->first($fields); } + + /** + * 获取某种状态的处方订单总数 + * @param array $params + * @param array $prescription_status_params + * @return int + */ + public static function getStatusCount(array $params, array $prescription_status_params): int + { + return self::where($params)->whereIn("prescription_status", $prescription_status_params)->count(); + } + + /** + * 获取某种状态的处方订单-限制条数 + * @param array $params + * @param array $prescription_status_params + * @param array $fields + * @param int $offset 起始 + * @param int $limit 个数 + * @return Collection|array + */ + public static function getStatusLimit(array $params, array $prescription_status_params, array $fields = ["*"],int $offset = 0,int $limit = 10): Collection|array + { + return self::where($params) + ->whereIn('prescription_status', $prescription_status_params) + ->offset($offset) + ->limit($limit) + ->get($fields); + } + + /** + * 获取某种状态的处方订单 + * @param array $params + * @param array $prescription_status_params + * @param array $fields + * @return object|null + */ + public static function getStatusList(array $params, array $prescription_status_params, array $fields = ["*"]): object|null + { + return self::where($params) + ->whereIn('prescription_status', $prescription_status_params) + ->get($fields); + } + + /** + * 获取某种状态的处方订单-单条 + * @param array $params + * @param array $prescription_status_params + * @param array $fields + * @return object|null + */ + public static function getStatusOne(array $params, array $prescription_status_params, array $fields = ["*"]): object|null + { + return self::where($params) + ->whereIn('prescription_status', $prescription_status_params) + ->first($fields); + } } diff --git a/app/Model/ReportRegulatory.php b/app/Model/ReportRegulatory.php new file mode 100644 index 0000000..ac8a3db --- /dev/null +++ b/app/Model/ReportRegulatory.php @@ -0,0 +1,86 @@ +first($fields); + } + + /** + * 获取数据-多 + * @param array $params + * @param array $fields + * @return Collection|array + */ + public static function getList(array $params = [], array $fields = ['*']): Collection|array + { + return self::where($params)->get($fields); + } + + /** + * 新增 + * @param array $data + * @return ReportRegulatory|\Hyperf\Database\Model\Model + */ + public static function addReportRegulatory(array $data): ReportRegulatory|\Hyperf\Database\Model\Model + { + return self::create($data); + } + + /** + * 修改 + * @param array $params + * @param array $data + * @return int + */ + public static function edit(array $params = [], array $data = []): int + { + return self::where($params)->update($data); + } +} diff --git a/app/Services/MessagePush.php b/app/Services/MessagePush.php index bd5ccee..0bf739f 100644 --- a/app/Services/MessagePush.php +++ b/app/Services/MessagePush.php @@ -2090,7 +2090,7 @@ class MessagePush extends BaseService $data['inquiry_type'] = $this->order_inquiry['inquiry_type']; // 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药) $data['from_name'] = "肝胆小秘书"; $data['notice_brief_title'] = inquiryTypeToString($this->order_inquiry['inquiry_type']); - $data['notice_title'] = inquiryTypeToString($this->order_inquiry['inquiry_type']); + $data['notice_title'] = "患者已取消问诊咨询,您可选择其他患者的问诊咨询进行接诊。"; $data['notice_content'] = "患者已取消问诊咨询,您可选择其他患者的问诊咨询进行接诊。"; $data['link_type'] = 3; // 问诊消息列表页 diff --git a/app/Services/OrderProductService.php b/app/Services/OrderProductService.php index 60bfecc..0c63f39 100644 --- a/app/Services/OrderProductService.php +++ b/app/Services/OrderProductService.php @@ -311,4 +311,5 @@ class OrderProductService extends BaseService $params['order_product_id'] = $order_product['order_product_id']; OrderProduct::edit($params,$data); } + } \ No newline at end of file diff --git a/extend/RegulatoryPlatform/regulatoryPlatform.php b/extend/RegulatoryPlatform/regulatoryPlatform.php index 43fcb4a..9897ed2 100644 --- a/extend/RegulatoryPlatform/regulatoryPlatform.php +++ b/extend/RegulatoryPlatform/regulatoryPlatform.php @@ -105,11 +105,13 @@ class regulatoryPlatform $access_token = $this->getAccessToken(); } - $arg['accessToken'] = $access_token; - $arg['clientId'] = $this->client_id; + foreach ($arg as &$item){ + $item['accessToken'] = $access_token; + $item['clientId'] = $this->client_id; + } $option = [ - "json" => [$arg] + "json" => $arg ]; $response = $this->httpRequest($this->api_url . '/wjw/upload/uploadConsult', $option); @@ -144,8 +146,10 @@ class regulatoryPlatform $access_token = $this->getAccessToken(); } - $arg['accessToken'] = $access_token; - $arg['clientId'] = $this->client_id; + foreach ($arg as &$item){ + $item['accessToken'] = $access_token; + $item['clientId'] = $this->client_id; + } $option = [ "json" => $arg @@ -166,6 +170,47 @@ class regulatoryPlatform } } + /** + * 上报 电子处方服务 + * @param array $arg + * @return array + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function uploadRecipe(array $arg): array + { + try { + $this->redis = $this->container->get(Redis::class); + + $access_token = $this->redis->get("regulatory_platform_access_token"); + if (empty($access_token)) { + $access_token = $this->getAccessToken(); + } + + foreach ($arg as &$item){ + $item['accessToken'] = $access_token; + $item['clientId'] = $this->client_id; + } + + $option = [ + "json" => $arg + ]; + + $response = $this->httpRequest($this->api_url . '/wjw/upload/uploadRecipe', $option); + if (isset($response['status'])) { + if ($response['status'] != 0) { + if (!empty($response['message'])) { + throw new BusinessException($response['message']); + } + } + } + + return $response; + } catch (GuzzleException $e) { + throw new BusinessException($e->getMessage()); + } + } + /** * 请求封装 @@ -192,7 +237,7 @@ class regulatoryPlatform } $body = json_decode($response->getBody(), true); - dump($body); + Log::getInstance()->info(json_encode($body,JSON_UNESCAPED_UNICODE)); if (empty($body)) { // 返回值为空 throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));