862 lines
37 KiB
PHP
862 lines
37 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Command;
|
||
|
||
use App\Exception\BusinessException;
|
||
use App\Model\HospitalDepartmentCustom;
|
||
use App\Model\OrderInquiry;
|
||
use App\Model\OrderInquiryCase;
|
||
use App\Model\OrderPrescription;
|
||
use App\Model\OrderPrescriptionIcd;
|
||
use App\Model\OrderPrescriptionProduct;
|
||
use App\Model\PatientFamily;
|
||
use App\Model\Product;
|
||
use App\Model\ReportRegulatory;
|
||
use App\Model\UserDoctor;
|
||
use App\Model\UserDoctorInfo;
|
||
use App\Model\UserPharmacist;
|
||
use App\Model\UserPharmacistInfo;
|
||
use Extend\RegulatoryPlatform\regulatoryPlatform;
|
||
use Hyperf\Command\Command as HyperfCommand;
|
||
use Hyperf\Command\Annotation\Command;
|
||
use Hyperf\DbConnection\Db;
|
||
use Hyperf\Redis\Redis;
|
||
use Mockery\Exception;
|
||
use Psr\Container\ContainerExceptionInterface;
|
||
use Psr\Container\ContainerInterface;
|
||
use Psr\Container\NotFoundExceptionInterface;
|
||
|
||
#[Command]
|
||
class ReportRegulatoryCommand extends HyperfCommand
|
||
{
|
||
public function __construct(protected ContainerInterface $container)
|
||
{
|
||
parent::__construct('ReportRegulatory:command');
|
||
}
|
||
|
||
public function configure()
|
||
{
|
||
parent::configure();
|
||
$this->setDescription('上报监管平台');
|
||
}
|
||
|
||
public function handle()
|
||
{
|
||
$this->line("开始");
|
||
|
||
// 获取未上传监管平台订单
|
||
$report_regulatorys = $this->getNotReportRegulatory(0,100);
|
||
if (empty($report_regulatorys)) {
|
||
$this->line("结束:无可执行订单");
|
||
return;
|
||
}
|
||
|
||
foreach ($report_regulatorys as $report_regulatory){
|
||
// 获取处方数据
|
||
$params = array();
|
||
$params['order_prescription_id'] = $report_regulatory['order_prescription_id'];
|
||
$order_prescription = OrderPrescription::getOne($params);
|
||
if (empty($order_prescription)){
|
||
// 无处方数据,不处理
|
||
continue;
|
||
}
|
||
|
||
// 获取问诊订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
// 无处方数据,不处理
|
||
continue;
|
||
}
|
||
|
||
$res = $this->checkInquiryOrder($order_inquiry);
|
||
if (!$res) {
|
||
// 问诊订单数据不符合条件,不执行
|
||
continue;
|
||
}
|
||
|
||
|
||
$this->line("开始:" . $report_regulatory['report_regulatory_id']);
|
||
|
||
// 上报问诊
|
||
if ($report_regulatory['report_inquiry_status'] != 1){
|
||
$this->line("信息:上报问诊");
|
||
|
||
try {
|
||
$this->line("信息:检测执行次数");
|
||
|
||
$key = $report_regulatory['report_regulatory_id'] . 'report_inquiry';
|
||
$res = $this->checkHandleNumber($key);
|
||
|
||
if (!$res){
|
||
$this->line("错误:超出最大执行次数或检测错误");
|
||
$res = $this->modifyReportRegulatoryInquiry($report_regulatory, 2, 1, "超出最大执行次数或检测错误");
|
||
if (!$res) {
|
||
$this->line("错误:系统错误");
|
||
continue;
|
||
}
|
||
}
|
||
|
||
$this->line("信息:检测执行次数通过");
|
||
} catch (\Exception $e) {
|
||
$this->line("错误:" . $e->getMessage());
|
||
continue;
|
||
}
|
||
|
||
try {
|
||
// 检测患者是否首次问诊
|
||
$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($report_regulatory, 1, $is_first ? 1 : 2);
|
||
if (!$res) {
|
||
// 记录失败
|
||
$this->line("错误:上报成功,存储记录失败");
|
||
}
|
||
} else {
|
||
// 上报失败
|
||
$res = $this->modifyReportRegulatoryInquiry($report_regulatory, 2, $is_first ? 1 : 2, $res);
|
||
if (!$res) {
|
||
// 记录失败
|
||
$this->line("错误:上报失败,存储记录失败");
|
||
}
|
||
}
|
||
} catch (\Exception $e) {
|
||
$this->line("错误:" . $e->getMessage());
|
||
// 上报失败
|
||
$res = $this->modifyReportRegulatoryInquiry($report_regulatory, 2, $is_first ? 1 : 2, $e->getMessage());
|
||
if (!$res) {
|
||
// 记录失败
|
||
$this->line("错误:上报失败,存储记录失败");
|
||
}
|
||
continue;
|
||
}
|
||
}
|
||
|
||
// 上报处方
|
||
if ($report_regulatory['report_prescription_status'] != 1){
|
||
$this->line("信息:上报处方");
|
||
|
||
try {
|
||
$this->line("信息:检测执行次数");
|
||
|
||
$key = $report_regulatory['report_regulatory_id'] . 'report_prescription';
|
||
$res = $this->checkHandleNumber($key);
|
||
if (!$res){
|
||
// 修改为上报失败
|
||
$this->line("错误:超出最大执行次数或检测错误");
|
||
$res = $this->modifyReportRegulatoryPrescription($report_regulatory, 2, "超出最大执行次数或检测错误");
|
||
if (!$res) {
|
||
// 记录失败
|
||
$this->line("错误:记录失败");
|
||
}
|
||
}
|
||
|
||
$this->line("信息:检测执行次数通过");
|
||
} catch (\Exception $e) {
|
||
$this->line("错误:" . $e->getMessage());
|
||
continue;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
for ($i = 0; $i < $report_regulatory_count; $i++) {
|
||
|
||
|
||
$this->line("信息:检测执行次数通过");
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
$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 array
|
||
*/
|
||
private function getNotReportRegulatory(): array
|
||
{
|
||
$params = array();
|
||
$params[] = ['report_inquiry_int','<',5];
|
||
$params[] = ['report_prescription_int','<',5];
|
||
|
||
$report_regulatory = ReportRegulatory::getNotReportList($params,['*']);
|
||
if (empty($report_regulatory)){
|
||
return [];
|
||
}else{
|
||
return $report_regulatory->toArray();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 检测执行次数
|
||
* @param string $key
|
||
* @return bool
|
||
* @throws ContainerExceptionInterface
|
||
* @throws NotFoundExceptionInterface
|
||
*/
|
||
protected function checkHandleNumber(string $key): bool
|
||
{
|
||
try {
|
||
$redis = $this->container->get(Redis::class);
|
||
|
||
$redis_key = "ReportRegulatoryInquiry" . $key;
|
||
$redis_value = $redis->get($redis_key);
|
||
if (empty($redis_value)) {
|
||
$redis->set($redis_key, 1, 60 * 60 * 24 * 10);
|
||
return true;
|
||
}
|
||
|
||
// 执行次数过多
|
||
if ($redis_value > 1) {
|
||
// 加入短信队列,通知管理员
|
||
|
||
return false;
|
||
}
|
||
|
||
$redis->incr($redis_key);
|
||
} catch (\Exception $e) {
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* 修改上报问诊数据
|
||
* @param array|object $report_regulatory
|
||
* @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 $report_regulatory, int $report_inquiry_status, int $report_inquiry_type, string $report_inquiry_fail_reason = ""): bool
|
||
{
|
||
try {
|
||
// 修改
|
||
$params = array();
|
||
$params['report_regulatory_id'] = $report_regulatory['report_regulatory_id'];
|
||
|
||
$data = array();
|
||
$data['report_inquiry_status'] = $report_inquiry_status;
|
||
$data['report_inquiry_int'] = $report_regulatory['report_inquiry_int'] + 1;
|
||
$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 $report_regulatory
|
||
* @param int $report_prescription_status 处方上报状态(0:未上报 1:已上报 2:上报失败)
|
||
* @param string $report_prescription_fail_reason 处方上报失败原因
|
||
* @return bool
|
||
*/
|
||
private function modifyReportRegulatoryPrescription(array|object $report_regulatory, int $report_prescription_status, string $report_prescription_fail_reason = ""): bool
|
||
{
|
||
try {
|
||
// 修改
|
||
$params = array();
|
||
$params['report_regulatory_id'] = $report_regulatory['report_regulatory_id'];
|
||
|
||
$data = array();
|
||
$data['report_prescription_status'] = $report_prescription_status;
|
||
$data['report_prescription_int'] = $report_regulatory['report_prescription_int'] + 1;
|
||
$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 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 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;
|
||
}
|
||
}
|