722 lines
28 KiB
PHP
722 lines
28 KiB
PHP
<?php
|
||
|
||
namespace App\Services;
|
||
|
||
use App\Constants\HttpEnumCode;
|
||
use App\Model\BasicJob;
|
||
use App\Model\BasicNation;
|
||
use App\Model\DetectionProject;
|
||
use App\Model\InquiryCaseProduct;
|
||
use App\Model\Order;
|
||
use App\Model\OrderDetection;
|
||
use App\Model\OrderInquiry;
|
||
use App\Model\OrderInquiryCase;
|
||
use App\Model\OrderPrescription;
|
||
use App\Model\OrderPrescriptionIcd;
|
||
use App\Model\OrderPrescriptionProduct;
|
||
use App\Model\OrderServicePackage;
|
||
use App\Model\OrderServicePackageCase;
|
||
use App\Model\PatientFamily;
|
||
use App\Model\PatientFamilyHealth;
|
||
use App\Model\PatientFamilyPersonal;
|
||
use App\Model\User;
|
||
use App\Model\UserDoctor;
|
||
use App\Utils\Log;
|
||
use Hyperf\DbConnection\Db;
|
||
use Hyperf\Redis\Redis;
|
||
|
||
/**
|
||
* 患者家庭成员病例
|
||
*/
|
||
class PatientCaseService extends BaseService
|
||
{
|
||
/**
|
||
* 获取问诊订单病例详情-基础
|
||
* @return array
|
||
*/
|
||
public function getPatientFamilyInquiryCaseSimple(): array
|
||
{
|
||
$order_inquiry_id = $this->request->input('order_inquiry_id');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
return fail();
|
||
}
|
||
|
||
// 获取病例信息
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$params['status'] = 1;
|
||
$order_inquiry_case = OrderInquiryCase::getOne($params);
|
||
if (empty($order_inquiry_case)) {
|
||
return fail();
|
||
}
|
||
|
||
$result = array();
|
||
$result['patient_name'] = $order_inquiry['patient_name'];
|
||
$result['patient_sex'] = $order_inquiry['patient_sex'];
|
||
$result['patient_age'] = $order_inquiry['patient_age'];
|
||
$result['disease_desc'] = $order_inquiry_case['disease_desc'];
|
||
$result['reception_time'] = $order_inquiry['reception_time']; // 接诊时间
|
||
|
||
return success($result);
|
||
}
|
||
|
||
/**
|
||
* 获取问诊订单病例详情
|
||
* @return array
|
||
*/
|
||
public function getPatientFamilyInquiryCase(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
$order_inquiry_id = $this->request->input('order_inquiry_id');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
return fail();
|
||
}
|
||
|
||
// 获取病例信息
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$params['status'] = 1;
|
||
$order_inquiry_case = OrderInquiryCase::getOne($params);
|
||
if (empty($order_inquiry_case)) {
|
||
return fail();
|
||
}
|
||
|
||
$order_inquiry_case = $order_inquiry_case->toArray();
|
||
|
||
// // 获取患者家庭成员信息表-基本信息
|
||
// $params = array();
|
||
// $params['family_id'] = $order_inquiry_case['family_id'];
|
||
// $patient_family = PatientFamily::getOne($params);
|
||
// if (!empty($patient_family)){
|
||
// $order_inquiry_case['height'] = $order_inquiry_case['height'] ?: $patient_family['height'] ?: NULL;
|
||
// $order_inquiry_case['weight'] = $order_inquiry_case['weight'] ?: $patient_family['weight'] ?: NULL;
|
||
// $order_inquiry_case['job_id'] = $order_inquiry_case['job_id'] ?: $patient_family['job_id'] ?: NULL;
|
||
// $order_inquiry_case['job_name'] = $order_inquiry_case['job_name'] ?: $patient_family['job_name'] ?: NULL;
|
||
// $order_inquiry_case['nation_id'] = $order_inquiry_case['nation_id'] ?: $patient_family['nation_id'] ?: NULL;
|
||
// $order_inquiry_case['nation_name'] = $order_inquiry_case['nation_name'] ?: $patient_family['nation_name'] ?: NULL;
|
||
// $order_inquiry_case['marital_status'] = $order_inquiry_case['marital_status'] ?: $patient_family['marital_status'] ?: NULL;
|
||
// }
|
||
//
|
||
// // 获取患者家庭成员信息表-健康情况
|
||
// $params = array();
|
||
// $params['family_id'] = $order_inquiry_case['family_id'];
|
||
// $patient_family_health = PatientFamilyHealth::getOne($params);
|
||
// if (!empty($patient_family_health)) {
|
||
// $order_inquiry_case['diagnosis_hospital'] = $order_inquiry_case['diagnosis_hospital'] ?: $patient_family_health['diagnosis_hospital'] ?: "";
|
||
// $order_inquiry_case['is_take_medicine'] = $order_inquiry_case['is_take_medicine'] ?: $patient_family_health['is_take_medicine'] ?: null;
|
||
// $order_inquiry_case['drugs_name'] = $order_inquiry_case['drugs_name'] ?: $patient_family_health['drugs_name'] ?: "";
|
||
// }
|
||
//
|
||
// // 获取患者家庭成员信息表-个人情况
|
||
// $params = array();
|
||
// $params['family_id'] = $order_inquiry_case['family_id'];
|
||
// $patient_family_personal = PatientFamilyPersonal::getOne($params);
|
||
// if (!empty($patient_family_personal)) {
|
||
// $order_inquiry_case['drink_wine_status'] = $order_inquiry_case['drink_wine_status'] ?: $patient_family_personal['drink_wine_status'] ?: null;
|
||
// $order_inquiry_case['smoke_status'] = $order_inquiry_case['smoke_status'] ?: $patient_family_personal['smoke_status'] ?: null;
|
||
// $order_inquiry_case['chemical_compound_status'] = $order_inquiry_case['chemical_compound_status'] ?: $patient_family_personal['chemical_compound_status'] ?: null;
|
||
// $order_inquiry_case['chemical_compound_describe'] = $order_inquiry_case['chemical_compound_describe'] ?: $patient_family_personal['chemical_compound_describe'] ?: "";
|
||
// $order_inquiry_case['is_operation'] = $order_inquiry_case['is_operation'] ?: $patient_family_personal['is_operation'] ?: null;
|
||
// $order_inquiry_case['operation'] = $order_inquiry_case['operation'] ?: $patient_family_personal['operation'] ?: "";
|
||
// }
|
||
|
||
// 获取用药意向
|
||
$product = [];
|
||
$fields = [
|
||
'inquiry_case_id',
|
||
'product_id',
|
||
'case_product_num',
|
||
];
|
||
$params = array();
|
||
$params['inquiry_case_id'] = $order_inquiry_case['inquiry_case_id'];
|
||
$inquiry_case_product = InquiryCaseProduct::getWithProductList($params, $fields);
|
||
if (!empty($inquiry_case_product)) {
|
||
foreach ($inquiry_case_product as &$item) {
|
||
if (!empty($item['Product'])) {
|
||
$product[] = $item['Product']['product_name'] . ' ' . $item['Product']['product_spec'] . '(' . $item['case_product_num'] . $item['Product']['packaging_unit'] . ')';
|
||
}
|
||
}
|
||
}
|
||
|
||
$order_inquiry_case['product'] = $product;
|
||
unset($inquiry_case_product);
|
||
|
||
// 复诊凭证
|
||
if (!empty($order_inquiry_case['diagnose_images'])) {
|
||
$diagnose_images = explode(',', $order_inquiry_case['diagnose_images']);
|
||
foreach ($diagnose_images as &$item) {
|
||
$item = addAliyunOssWebsite($item);
|
||
}
|
||
|
||
$order_inquiry_case['diagnose_images'] = $diagnose_images;
|
||
}
|
||
|
||
// 检测项目
|
||
$order_inquiry_case['detection_project'] = null;
|
||
if ($order_inquiry['inquiry_type'] == 5) {
|
||
// 获取检测订单
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$order_detection = OrderDetection::getOne($params);
|
||
if (!empty($order_detection)) {
|
||
// 获取检测项目
|
||
$params = array();
|
||
$params['detection_project_id'] = $order_detection['detection_project_id'];
|
||
$detection_project = DetectionProject::getOne($params);
|
||
if (!empty($detection_project)) {
|
||
$order_inquiry_case['detection_project']['detection_project_name'] = $detection_project['detection_project_name']; // 检测项目名称
|
||
$order_inquiry_case['detection_project']['detection_time'] = $order_detection['detection_time']; // 检测时间
|
||
$order_inquiry_case['detection_project']['detection_link'] = addAliyunOssWebsite($order_detection['detection_result_pdf']); // 检测结果链接
|
||
}
|
||
}
|
||
}
|
||
|
||
// 获取处方数据
|
||
$order_inquiry_case['order_prescription'] = null;
|
||
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$order_prescription = OrderPrescription::getOne($params);
|
||
if (!empty($order_prescription)){
|
||
$order_inquiry_case['order_prescription']['doctor_created_time'] = $order_prescription['doctor_created_time']; // 医生开具处方时间
|
||
$order_inquiry_case['order_prescription']['doctor_advice'] = $order_prescription['doctor_advice'];// 医嘱
|
||
|
||
// 获取处方疾病数据
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||
$order_prescription_icds = OrderPrescriptionIcd::getList($params);
|
||
if (empty($order_prescription_icds)){
|
||
return fail();
|
||
}
|
||
|
||
$icd_name = array_column($order_prescription_icds->toArray(),"icd_name");
|
||
$order_inquiry_case['order_prescription']['icd_name'] = implode(";",$icd_name);
|
||
|
||
// 获取处方药品名称
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||
$order_prescription_products = OrderPrescriptionProduct::getList($params);
|
||
if (empty($order_prescription_products)){
|
||
return fail();
|
||
}
|
||
|
||
$order_inquiry_case['order_prescription']["product"] = $order_prescription_products->toArray();
|
||
}
|
||
|
||
return success($order_inquiry_case);
|
||
}
|
||
|
||
/**
|
||
* 获取问诊订单病例缺少字段
|
||
* @return array
|
||
*/
|
||
public function getPatientFamilyInquiryCaseUnfilledFields(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
$order_inquiry_id = $this->request->input('order_inquiry_id');
|
||
|
||
if ($user_info['user_type'] != 2){
|
||
return fail(HttpEnumCode::HTTP_ERROR,"非法请求");
|
||
}
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
return fail();
|
||
}
|
||
|
||
// 获取病例信息
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$params['status'] = 1;
|
||
$order_inquiry_case = OrderInquiryCase::getOne($params);
|
||
if (empty($order_inquiry_case)) {
|
||
return fail();
|
||
}
|
||
|
||
$order_inquiry_case = $order_inquiry_case->toArray();
|
||
|
||
// 初始字段定义
|
||
$fields = [
|
||
"relation", // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 )
|
||
"name", // 患者名称
|
||
"sex", // 患者性别(0:未知 1:男 2:女)
|
||
"age", // 患者年龄
|
||
"height", // 身高(cm)
|
||
"weight", // 体重(kg)
|
||
"marital_status", // 婚姻状况(0:未婚 1:已婚 2:离异)
|
||
"nation_id", // 民族名称
|
||
"job_id", // 职业名称
|
||
"is_allergy_history", // 是否存在过敏史(0:否 1:是)
|
||
"is_family_history", // 是否存在家族病史(0:否 1:是)
|
||
"is_pregnant", // 是否备孕、妊娠、哺乳期(0:否 1:是)
|
||
"is_operation", // 是否存在手术(0:否 1:是)
|
||
"drink_wine_status", // 饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒)
|
||
"smoke_status", // 吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟)
|
||
"chemical_compound_status", // 化合物状态(1:从不 2:偶尔 3:经常 4:每天)
|
||
"diagnosis_hospital", // 确诊医院
|
||
"is_take_medicine", // 正在服药(0:否 1:是)
|
||
];
|
||
|
||
try {
|
||
/**
|
||
* 获取缓存
|
||
* 缓存格式
|
||
* {
|
||
"height":{
|
||
"value":1,
|
||
"is_filled":1
|
||
},
|
||
"weight":{
|
||
"value":1,
|
||
"is_filled":1
|
||
}
|
||
* }
|
||
*/
|
||
$redis = $this->container->get(Redis::class);
|
||
$redis_key = "patient_family_inquiry_case_unfilled_fields_" . $order_inquiry_id;
|
||
$redis_value = $redis->get($redis_key);
|
||
|
||
// 缓存
|
||
if (!empty($redis_value)){
|
||
$redis_value = json_decode($redis_value,true);
|
||
}
|
||
|
||
}catch (\Throwable $e){
|
||
return fail();
|
||
}
|
||
|
||
// 处理字段
|
||
$result = null;
|
||
foreach ($fields as $field){
|
||
if (array_key_exists($field,$order_inquiry_case)){
|
||
if ($order_inquiry_case[$field] !== null){
|
||
continue;
|
||
}
|
||
}
|
||
|
||
// 缓存
|
||
if (!empty($redis_value)){
|
||
if (array_key_exists($field,$redis_value)){
|
||
continue;
|
||
}
|
||
}
|
||
|
||
$result[] = $field;
|
||
}
|
||
|
||
return success($result);
|
||
}
|
||
|
||
/**
|
||
* 医生发送缺少字段至患者
|
||
* @return array
|
||
*/
|
||
public function sendCaseUnfilledFieldsToPatient(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
if ($user_info['user_type'] != 2){
|
||
return fail(HttpEnumCode::HTTP_ERROR,"非法请求");
|
||
}
|
||
|
||
$request_params = $this->request->all();
|
||
|
||
$order_inquiry_id = $request_params['order_inquiry_id'];
|
||
|
||
if (empty($request_params['fields'])){
|
||
return fail(HttpEnumCode::CLIENT_HTTP_ERROR,"请选择需要发送的信息");
|
||
}
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR,"订单数据错误");
|
||
}
|
||
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$doctor = UserDoctor::getOne($params);
|
||
if (empty($doctor)){
|
||
return fail();
|
||
}
|
||
|
||
// 初始字段定义
|
||
$fields = [
|
||
"relation", // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 )
|
||
"name", // 患者名称
|
||
"sex", // 患者性别(0:未知 1:男 2:女)
|
||
"age", // 患者年龄
|
||
"height", // 身高(cm)
|
||
"weight", // 体重(kg)
|
||
"marital_status", // 婚姻状况(0:未婚 1:已婚 2:离异)
|
||
"nation_id", // 民族名称
|
||
"job_id", // 职业名称
|
||
"disease_class_name", // 疾病名称-系统
|
||
"diagnosis_date", // 确诊日期
|
||
"disease_desc", // 病情描述(主诉)
|
||
"is_allergy_history", // 是否存在过敏史(0:否 1:是)
|
||
"allergy_history", // 过敏史描述
|
||
"is_family_history", // 是否存在家族病史(0:否 1:是)
|
||
"family_history", // 家族病史描述
|
||
"is_pregnant", // 是否备孕、妊娠、哺乳期(0:否 1:是)
|
||
"pregnant", // 备孕、妊娠、哺乳期描述
|
||
"is_taboo", // 是否服用过禁忌药物,且无相关禁忌(0:否 1:是)问诊购药时存在
|
||
"is_take_medicine", // 正在服药(0:否 1:是)
|
||
"drugs_name", // 正在服药名称
|
||
"diagnosis_hospital", // 确诊医院
|
||
"is_operation", // 是否存在手术(0:否 1:是)
|
||
"operation", // 手术描述
|
||
"drink_wine_status", // 饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒)
|
||
"smoke_status", // 吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟)
|
||
"chemical_compound_status", // 化合物状态(1:从不 2:偶尔 3:经常 4:每天)
|
||
"chemical_compound_describe", // 化合物描述
|
||
];
|
||
|
||
try {
|
||
$redis = $this->container->get(Redis::class);
|
||
$redis_key = "patient_family_inquiry_case_unfilled_fields_" . $order_inquiry_id;
|
||
|
||
// 获取缓存
|
||
$redis_value = $redis->get($redis_key);
|
||
if (!empty($redis_value)){
|
||
$redis_value = json_decode($redis_value,true);
|
||
}
|
||
|
||
// 患者病例字段
|
||
$case_fields = [];
|
||
foreach ($request_params['fields'] as $key){
|
||
if (!in_array($key,$fields)){
|
||
return fail(HttpEnumCode::HTTP_ERROR,"数据选择错误");
|
||
}
|
||
|
||
$case_fields[] = $key;
|
||
|
||
// 处理缓存
|
||
if (!empty($redis_value)){
|
||
if (array_key_exists($key,$redis_value)){
|
||
continue;
|
||
}
|
||
}
|
||
|
||
$redis_value[$key] = [
|
||
"value" => "",
|
||
"is_filled" => 0
|
||
];
|
||
}
|
||
|
||
if (empty($case_fields)){
|
||
return fail();
|
||
}
|
||
|
||
$case_fields = json_encode($case_fields,JSON_UNESCAPED_UNICODE);
|
||
|
||
// 发送im消息
|
||
$imService = new ImService();
|
||
$imService->CaseUnfilledFieldsToPatient($order_inquiry,$doctor['user_id'],$order_inquiry['user_id'],$case_fields);
|
||
|
||
// 添加缓存-逗号分割字符串
|
||
if (!empty($redis_value)){
|
||
$redis_value = json_encode($redis_value,JSON_UNESCAPED_UNICODE);
|
||
$res = $redis->set($redis_key,$redis_value,31 * 24 * 60 * 60);
|
||
if (!$res){
|
||
return fail();
|
||
}
|
||
}
|
||
}catch (\Throwable $e){
|
||
return fail();
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 患者填写缺少字段至医生
|
||
* @return array
|
||
*/
|
||
public function sendCaseUnfilledFieldsToDoctor(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
if ($user_info['user_type'] != 1){
|
||
return fail(HttpEnumCode::HTTP_ERROR,"非法请求");
|
||
}
|
||
|
||
$request_params = $this->request->all();
|
||
|
||
$order_inquiry_id = $request_params['order_inquiry_id'];
|
||
|
||
if (empty($request_params['fields'])){
|
||
return fail(HttpEnumCode::CLIENT_HTTP_ERROR,"请填写后发送");
|
||
}
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR,"订单数据错误");
|
||
}
|
||
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$doctor = UserDoctor::getOne($params);
|
||
if (empty($doctor)){
|
||
return fail();
|
||
}
|
||
|
||
// 获取病例信息
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$order_inquiry_case = OrderInquiryCase::getOne($params);
|
||
if (empty($order_inquiry_case)) {
|
||
return fail();
|
||
}
|
||
|
||
$order_inquiry_case = $order_inquiry_case->toArray();
|
||
|
||
// 初始字段定义
|
||
$fields = [
|
||
"relation", // 与患者关系(1:本人 2:父母 3:爱人 4:子女 5:亲戚 6:其他 )
|
||
"name", // 患者名称
|
||
"sex", // 患者性别(0:未知 1:男 2:女)
|
||
"age", // 患者年龄
|
||
"height", // 身高(cm)
|
||
"weight", // 体重(kg)
|
||
"marital_status", // 婚姻状况(0:未婚 1:已婚 2:离异)
|
||
"nation_id", // 民族名称
|
||
"job_id", // 职业名称
|
||
"disease_class_name", // 疾病名称-系统
|
||
"diagnosis_date", // 确诊日期
|
||
"disease_desc", // 病情描述(主诉)
|
||
"is_allergy_history", // 是否存在过敏史(0:否 1:是)
|
||
"allergy_history", // 过敏史描述
|
||
"is_family_history", // 是否存在家族病史(0:否 1:是)
|
||
"family_history", // 家族病史描述
|
||
"is_pregnant", // 是否备孕、妊娠、哺乳期(0:否 1:是)
|
||
"pregnant", // 备孕、妊娠、哺乳期描述
|
||
"is_taboo", // 是否服用过禁忌药物,且无相关禁忌(0:否 1:是)问诊购药时存在
|
||
"is_take_medicine", // 正在服药(0:否 1:是)
|
||
"drugs_name", // 正在服药名称
|
||
"diagnosis_hospital", // 确诊医院
|
||
"is_operation", // 是否存在手术(0:否 1:是)
|
||
"operation", // 手术描述
|
||
"drink_wine_status", // 饮酒状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒酒)
|
||
"smoke_status", // 吸烟状态(1:从不 2:偶尔 3:经常 4:每天 5:已戒烟)
|
||
"chemical_compound_status", // 化合物状态(1:从不 2:偶尔 3:经常 4:每天)
|
||
"chemical_compound_describe", // 化合物描述
|
||
];
|
||
|
||
Db::beginTransaction();
|
||
|
||
try {
|
||
$redis = $this->container->get(Redis::class);
|
||
$redis_key = "patient_family_inquiry_case_unfilled_fields_" . $order_inquiry_id;
|
||
$redis_value = $redis->get($redis_key);
|
||
if (!empty($redis_value)){
|
||
$redis_value = json_decode($redis_value,true);
|
||
}
|
||
|
||
// 患者病例字段
|
||
$case_fields = [];
|
||
|
||
// 修改字段
|
||
$order_inquiry_case_data = [];
|
||
|
||
foreach ($request_params['fields'] as $key => $value){
|
||
if (!in_array($key,$fields)){
|
||
if ($key != "order_inquiry_id"){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR,"存在非法数据");
|
||
}
|
||
}
|
||
|
||
// 跳过关联字段传空,如是否是否过敏史、过敏史描述
|
||
if ($value === ""){
|
||
continue;
|
||
}
|
||
|
||
// 判断是否存在于缓存中
|
||
if (!empty($redis_value)){
|
||
if (array_key_exists($key,$redis_value)){
|
||
if ($redis_value[$key]['is_filled'] == 1){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR,"请勿重复提交");
|
||
}
|
||
|
||
$redis_value[$key]['value'] = $value;
|
||
$redis_value[$key]['is_filled'] = 1;
|
||
}
|
||
}
|
||
|
||
// 判断修改数据
|
||
if (array_key_exists($key,$order_inquiry_case)){
|
||
if ($order_inquiry_case[$key] == null){
|
||
$order_inquiry_case_data[$key] = $value;
|
||
}
|
||
|
||
// 处理职业
|
||
if ($key == "job_id"){
|
||
if ($order_inquiry_case["job_name"] == null){
|
||
// 获取职业数据
|
||
$params = array();
|
||
$params['job_id'] = $value;
|
||
$basic_job = BasicJob::getOne($params);
|
||
if (!empty($basic_job)){
|
||
$order_inquiry_case_data["job_name"] = $basic_job['job_name'];
|
||
}
|
||
}
|
||
}
|
||
|
||
// 处理民族
|
||
if ($key == "nation_id"){
|
||
if ($order_inquiry_case["nation_name"] == null){
|
||
// 获取职业数据
|
||
$params = array();
|
||
$params['nation_id'] = $value;
|
||
$basic_nation = BasicNation::getOne($params);
|
||
if (!empty($basic_nation)){
|
||
$order_inquiry_case_data["nation_name"] = $basic_nation['nation_name'];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
$case_fields[$key] = $value;
|
||
}
|
||
|
||
// 存储至问诊病例中
|
||
if (!empty($order_inquiry_case_data)){
|
||
$params = array();
|
||
$params['inquiry_case_id'] = $order_inquiry_case['inquiry_case_id'];
|
||
$res = OrderInquiryCase::edit($params,$order_inquiry_case_data);
|
||
if (!$res){
|
||
Db::rollBack();
|
||
return fail();
|
||
}
|
||
}
|
||
|
||
// 发送im消息
|
||
$case_fields = json_encode($case_fields,JSON_UNESCAPED_UNICODE);
|
||
|
||
$imService = new ImService();
|
||
$imService->CaseUnfilledFieldsToDoctor($order_inquiry,$doctor['user_id'],$user_info['user_id'],$case_fields);
|
||
|
||
// 处理缓存
|
||
if (!empty($redis_value)){
|
||
$redis_value = json_encode($redis_value,JSON_UNESCAPED_UNICODE);
|
||
$res = $redis->set($redis_key,$redis_value,31 * 24 * 60 * 60);
|
||
if (!$res){
|
||
return fail();
|
||
}
|
||
}
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
return fail();
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 获取服务包订单病例详情-基础
|
||
* @return array
|
||
*/
|
||
public function getPatientFamilyServiceCaseSimple(): array
|
||
{
|
||
$order_no = $this->request->route('order_no');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_no'] = $order_no;
|
||
$order = Order::getOne($params);
|
||
if (empty($order)) {
|
||
return fail();
|
||
}
|
||
|
||
$params = array();
|
||
$params['order_service_no'] = $order_no;
|
||
$order_service_package = OrderServicePackage::getOne($params);
|
||
if (empty($order_service_package)) {
|
||
return fail();
|
||
}
|
||
|
||
$params = array();
|
||
$params['order_id'] = $order['order_id'];
|
||
$order_service_package_case = OrderServicePackageCase::getOne($params);
|
||
if (empty($order_service_package_case)) {
|
||
return fail();
|
||
}
|
||
|
||
$result = array();
|
||
$result['patient_name'] = $order_service_package['patient_name'];
|
||
$result['patient_sex'] = $order_service_package['patient_sex'];
|
||
$result['patient_age'] = $order_service_package['patient_age'];
|
||
$result['disease_desc'] = $order_service_package_case['disease_desc'];
|
||
$result['created_at'] = $order_service_package['created_at']; // 创建时间
|
||
|
||
return success($result);
|
||
}
|
||
|
||
/**
|
||
* 获取服务包订单病例详情
|
||
* @return array
|
||
*/
|
||
public function getPatientFamilyServiceCase(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
$order_no = $this->request->route('order_no');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_no'] = $order_no;
|
||
$order = Order::getOne($params);
|
||
if (empty($order)) {
|
||
return fail();
|
||
}
|
||
|
||
$params = array();
|
||
$params['order_service_no'] = $order_no;
|
||
$order_service_package = OrderServicePackage::getOne($params);
|
||
if (empty($order_service_package)) {
|
||
return fail();
|
||
}
|
||
|
||
$params = array();
|
||
$params['order_id'] = $order['order_id'];
|
||
$order_service_package_case = OrderServicePackageCase::getOne($params);
|
||
if (empty($order_service_package_case)) {
|
||
return fail();
|
||
}
|
||
|
||
$order_service_package_case = $order_service_package_case->toArray();
|
||
|
||
// 复诊凭证
|
||
if (!empty($order_service_package_case['diagnose_images'])) {
|
||
$diagnose_images = explode(',', $order_service_package_case['diagnose_images']);
|
||
foreach ($diagnose_images as &$item) {
|
||
$item = addAliyunOssWebsite($item);
|
||
}
|
||
|
||
$order_service_package_case['diagnose_images'] = $diagnose_images;
|
||
}
|
||
|
||
return success($order_service_package_case);
|
||
}
|
||
} |