784 lines
35 KiB
PHP
784 lines
35 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\UserCaCert;
|
||
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();
|
||
if (empty($report_regulatorys)) {
|
||
$this->line("结束:无可执行订单");
|
||
return;
|
||
}
|
||
|
||
foreach ($report_regulatorys as $report_regulatory){
|
||
$this->line("开始:" . $report_regulatory['report_regulatory_id']);
|
||
|
||
try {
|
||
// 获取问诊订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $report_regulatory['order_inquiry_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
// 问诊订单数据错误
|
||
$this->line("问诊订单数据错误");
|
||
continue;
|
||
}
|
||
|
||
$order_inquiry = $order_inquiry->toArray();
|
||
|
||
// 检测问诊订单
|
||
$res = $this->checkInquiryOrder($order_inquiry);
|
||
if (!$res) {
|
||
continue;
|
||
}
|
||
}catch (\Throwable $e){
|
||
$this->line($e->getMessage());
|
||
continue;
|
||
}
|
||
|
||
// 上报网络咨询
|
||
try {
|
||
if ($report_regulatory['report_consult_status'] != 1 && $report_regulatory['report_consult_int'] < 5){
|
||
$this->line("上报网络咨询");
|
||
|
||
// 获取上报数据-网络咨询
|
||
$consult_data = $this->getConsultData($order_inquiry);
|
||
|
||
// 上报网络咨询
|
||
$regulatoryPlatform = new regulatoryPlatform();
|
||
$result = $regulatoryPlatform->uploadConsult([$consult_data]);
|
||
|
||
$this->line("上报网络咨询成功" . json_encode($result,JSON_UNESCAPED_UNICODE));
|
||
|
||
// 修改上报状态-网络咨询
|
||
$res = $this->modifyReportConsultStatus($report_regulatory, 1);
|
||
if (!$res) {
|
||
// 记录失败
|
||
$this->line("上报成功,存储记录失败");
|
||
}
|
||
}
|
||
}catch (\Throwable $e){
|
||
$this->line("上报网络咨询失败" . $e->getMessage());
|
||
|
||
// 上报失败
|
||
$res = $this->modifyReportConsultStatus($report_regulatory, 2, $e->getMessage());
|
||
if (!$res) {
|
||
// 记录失败
|
||
$this->line("上报网络咨询失败,存储记录失败");
|
||
}
|
||
}
|
||
|
||
|
||
// 上报复诊
|
||
try {
|
||
if ($report_regulatory['is_further_consult'] == 1){
|
||
if ($report_regulatory['report_further_consult_status'] != 1 && $report_regulatory['report_further_consult_int'] < 5) {
|
||
$this->line("上报复诊");
|
||
|
||
// 获取处方数据
|
||
$params = array();
|
||
$params['order_prescription_id'] = $report_regulatory['order_prescription_id'];
|
||
$order_prescription = OrderPrescription::getOne($params);
|
||
if (empty($order_prescription)){
|
||
$this->line("需上报复诊,但无处方数据");
|
||
}else{
|
||
// 获取上报数据-复诊
|
||
$further_consult_data = $this->getFurtherConsultData($order_inquiry,$order_prescription);
|
||
|
||
// 上报复诊
|
||
$regulatoryPlatform = new regulatoryPlatform();
|
||
$result = $regulatoryPlatform->uploadFurtherConsult([$further_consult_data]);
|
||
$this->line("上报复诊成功" . json_encode($result,JSON_UNESCAPED_UNICODE));
|
||
|
||
// 修改上报状态-复诊
|
||
$res = $this->modifyReportFurtherConsultStatus($report_regulatory, 1);
|
||
if (!$res) {
|
||
// 记录失败
|
||
$this->line("上报成功,存储记录失败");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}catch (\Throwable $e){
|
||
$this->line("上报复诊失败" . $e->getMessage());
|
||
|
||
// 上报失败
|
||
$res = $this->modifyReportFurtherConsultStatus($report_regulatory, 2, $e->getMessage());
|
||
if (!$res) {
|
||
// 记录失败
|
||
$this->line("上报复诊失败,存储记录失败");
|
||
}
|
||
}
|
||
|
||
// 上报处方
|
||
try {
|
||
$this->line("上报处方");
|
||
|
||
// 获取处方数据
|
||
$params = array();
|
||
$params['order_prescription_id'] = $report_regulatory['order_prescription_id'];
|
||
$order_prescription = OrderPrescription::getOne($params);
|
||
if (empty($order_prescription)){
|
||
$this->line("需上报复诊,但无处方数据");
|
||
}else{
|
||
// 获取上报数据-处方
|
||
$report_prescription_data = $this->getReportPrescriptionData($order_inquiry, $order_prescription);
|
||
|
||
// 上报处方
|
||
$regulatoryPlatform = new regulatoryPlatform();
|
||
$result = $regulatoryPlatform->uploadRecipe([$report_prescription_data]);
|
||
|
||
$this->line("上报处方成功" . json_encode($result,JSON_UNESCAPED_UNICODE));
|
||
|
||
// 上报成功
|
||
$res = $this->modifyReportRegulatoryPrescription($report_regulatory, 1);
|
||
if (!$res) {
|
||
// 记录失败
|
||
$this->line("上报处方失败,存储记录失败");
|
||
}
|
||
}
|
||
}catch (\Throwable $e){
|
||
$this->line("上报处方失败" . $e->getMessage());
|
||
|
||
// 上报失败
|
||
$res = $this->modifyReportRegulatoryPrescription($report_regulatory, 2, $e->getMessage());
|
||
if (!$res) {
|
||
// 记录失败
|
||
$this->line("上报复诊失败,存储记录失败");
|
||
return ;
|
||
}
|
||
}
|
||
|
||
$this->line("结束:" . $report_regulatory['report_regulatory_id']);
|
||
}
|
||
|
||
$this->line("全部结束");
|
||
}
|
||
|
||
/**
|
||
* 获取符合条件的订单
|
||
* @return array
|
||
*/
|
||
private function getNotReportRegulatory(): array
|
||
{
|
||
$report_regulatory = ReportRegulatory::getNotReportList();
|
||
if (empty($report_regulatory)){
|
||
return [];
|
||
}else{
|
||
return $report_regulatory->toArray();
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 修改上报状态-网络咨询
|
||
* @param array|object $report_regulatory
|
||
* @param int $report_consult_status 上报网络咨询状态(0:未上报 1:已上报 2:上报失败)
|
||
* @param string $report_consult_fail_reason 网络咨询上报失败原因
|
||
* @return bool
|
||
*/
|
||
private function modifyReportConsultStatus(array|object $report_regulatory, int $report_consult_status,string $report_consult_fail_reason = ""): bool
|
||
{
|
||
try {
|
||
// 修改
|
||
$params = array();
|
||
$params['report_regulatory_id'] = $report_regulatory['report_regulatory_id'];
|
||
|
||
$data = array();
|
||
$data['report_consult_status'] = $report_consult_status;
|
||
$data['report_consult_int'] = $report_regulatory['report_consult_int'] + 1;
|
||
$data['report_consult_time'] = date('Y-m-d H:i:s', time());
|
||
$data['report_consult_fail_reason'] = $report_consult_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_further_consult_status 上报网络复诊状态(0:未上报 1:已上报 2:上报失败)
|
||
* @param string $report_further_consult_fail_reason 网络复诊上报失败原因
|
||
* @return bool
|
||
*/
|
||
private function modifyReportFurtherConsultStatus(array|object $report_regulatory, int $report_further_consult_status,string $report_further_consult_fail_reason = ""): bool
|
||
{
|
||
try {
|
||
// 修改
|
||
$params = array();
|
||
$params['report_regulatory_id'] = $report_regulatory['report_regulatory_id'];
|
||
|
||
$data = array();
|
||
$data['report_further_consult_status'] = $report_further_consult_status;
|
||
$data['report_further_consult_int'] = $report_regulatory['report_further_consult_int'] + 1;
|
||
$data['report_further_consult_time'] = date('Y-m-d H:i:s', time());
|
||
$data['report_further_consult_fail_reason'] = $report_further_consult_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 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;
|
||
}
|
||
|
||
// 获取医生ca数据
|
||
$params = array();
|
||
$params['user_id'] = $user_doctor['user_id'];
|
||
$params['type'] = 2;
|
||
$params['is_latest'] = 1;
|
||
$doctor_user_ca_cert = UserCaCert::getOne($params);
|
||
if (empty($doctor_user_ca_cert)){
|
||
$this->line("错误:无医生ca数据");
|
||
return false;
|
||
}
|
||
|
||
// 获取药师ca数据
|
||
$params = array();
|
||
$params['user_id'] = $user_pharmacist['user_id'];
|
||
$params['type'] = 2;
|
||
$params['is_latest'] = 1;
|
||
$pharmacist_user_ca_cert = UserCaCert::getOne($params);
|
||
if (empty($pharmacist_user_ca_cert)){
|
||
$this->line("错误:无药师ca数据");
|
||
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['docCaSign'] = $doctor_user_ca_cert['cert_base64']; // 医师ca签名值
|
||
$data['pharmacistCaSign'] = $pharmacist_user_ca_cert['cert_base64']; // 药师ca签名值
|
||
$data['recipeNo'] = $order_prescription['order_prescription_id']; // 医院处方编号
|
||
$data['cityId'] = "510100"; // 城市ID(参考地区字段)
|
||
|
||
return $data;
|
||
}
|
||
|
||
/**
|
||
* 获取处方商品数据
|
||
* @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;
|
||
}
|
||
|
||
/**
|
||
* 获取上报数据-网络咨询
|
||
* @param array|object $order_inquiry
|
||
* @return array
|
||
*/
|
||
private function getConsultData(array|object $order_inquiry): array
|
||
{
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
if (empty($user_doctor)) {
|
||
$this->line("错误:医生数据错误");
|
||
return [];
|
||
}
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$user_doctor_info = UserDoctorInfo::getOne($params);
|
||
if (empty($user_doctor_info)) {
|
||
$this->line("错误:医生详情数据错误");
|
||
return [];
|
||
}
|
||
|
||
// 获取医生自定义科室数据
|
||
$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 [];
|
||
}
|
||
|
||
// 获取问诊患者数据
|
||
$params = array();
|
||
$params['family_id'] = $order_inquiry['family_id'];
|
||
$patient_family = PatientFamily::getOne($params);
|
||
if (empty($patient_family)) {
|
||
$this->line("错误:问诊患者数据错误");
|
||
return [];
|
||
}
|
||
|
||
// 获取患者问诊病例
|
||
$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 [];
|
||
}
|
||
|
||
// 网络咨询(网络门诊)服务
|
||
$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'] = date('Y-m-d H:i:s',strtotime($order_inquiry['created_at'])); // 咨询申请时间
|
||
$data['consultStartTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['reception_time'])); // 咨询开始时间
|
||
$data['consultEndTime'] = date('Y-m-d H:i:s',strtotime($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代表未留痕
|
||
|
||
return $data;
|
||
}
|
||
|
||
/**
|
||
* 获取上报数据-复诊
|
||
* @param array|object $order_inquiry
|
||
* @param array|object $order_prescription
|
||
* @return array
|
||
*/
|
||
private function getFurtherConsultData(array|object $order_inquiry,array|object $order_prescription): array
|
||
{
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
if (empty($user_doctor)) {
|
||
$this->line("医生数据错误");
|
||
return [];
|
||
}
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$user_doctor_info = UserDoctorInfo::getOne($params);
|
||
if (empty($user_doctor_info)) {
|
||
$this->line("医生详情数据错误");
|
||
return [];
|
||
}
|
||
|
||
// 获取医生自定义科室数据
|
||
$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 [];
|
||
}
|
||
|
||
// 获取问诊患者数据
|
||
$params = array();
|
||
$params['family_id'] = $order_inquiry['family_id'];
|
||
$patient_family = PatientFamily::getOne($params);
|
||
if (empty($patient_family)) {
|
||
$this->line("问诊患者数据错误");
|
||
return [];
|
||
}
|
||
|
||
// 获取患者问诊病例
|
||
$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 [];
|
||
}
|
||
|
||
// 获取患者复诊疾病诊断数据
|
||
$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 [];
|
||
}
|
||
|
||
$icd_name_data = array_column($order_prescription_icd->toArray(), 'icd_name');
|
||
if (count($icd_name_data) > 1) {
|
||
$icd_name = implode('|', $icd_name_data);
|
||
} else {
|
||
$icd_name = $icd_name_data[0];
|
||
}
|
||
|
||
if (empty($icd_name)){
|
||
$this->line("无疾病名称数据");
|
||
return [];
|
||
}
|
||
|
||
$icd_code_data = array_column($order_prescription_icd->toArray(), 'icd_code');
|
||
if (count($icd_code_data) > 1) {
|
||
$icd_code = implode('|', $icd_code_data);
|
||
} else {
|
||
$icd_code = $icd_code_data[0];
|
||
}
|
||
|
||
if (empty($icd_code)){
|
||
$this->line("无icd编码数据");
|
||
return [];
|
||
}
|
||
|
||
// 网络复诊服务
|
||
$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'] = $order_inquiry_case['disease_class_name']; // 首诊诊断 复诊患者在首诊医院的诊断,如有多条,使用“|”进行分隔;当传图片时,需要传图片的base64字符串
|
||
$data['consultTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry_case['diagnosis_date'])); // 首诊时间(使用确诊时间)
|
||
$data['consultOrg'] = "成都金牛欣欣相照互联网医院"; // 首诊机构
|
||
$data['furtherConsultApplyTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['created_at'])); // 复诊申请时间
|
||
$data['furtherConsulStartTime'] = date('Y-m-d H:i:s',strtotime($order_inquiry['reception_time'])); // 复诊开始时间
|
||
$data['furtherConsulEndTime'] = date('Y-m-d H:i:s',strtotime($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;
|
||
}
|
||
}
|