更新
This commit is contained in:
@@ -66,7 +66,7 @@ class DiagnosisLogic extends BaseLogic
|
||||
$multiSelectFields = [
|
||||
'diet_condition', 'body_feeling', 'sleep_condition', 'eye_condition',
|
||||
'head_feeling', 'sweat_condition', 'skin_condition', 'urine_condition',
|
||||
'stool_condition', 'kidney_condition'
|
||||
'stool_condition', 'kidney_condition', 'local_hospital_diagnosis'
|
||||
];
|
||||
|
||||
foreach ($multiSelectFields as $field) {
|
||||
@@ -156,7 +156,7 @@ class DiagnosisLogic extends BaseLogic
|
||||
$multiSelectFields = [
|
||||
'diet_condition', 'body_feeling', 'sleep_condition', 'eye_condition',
|
||||
'head_feeling', 'sweat_condition', 'skin_condition', 'urine_condition',
|
||||
'stool_condition', 'kidney_condition'
|
||||
'stool_condition', 'kidney_condition', 'local_hospital_diagnosis'
|
||||
];
|
||||
|
||||
foreach ($multiSelectFields as $field) {
|
||||
@@ -231,7 +231,7 @@ class DiagnosisLogic extends BaseLogic
|
||||
$multiSelectFields = [
|
||||
'diet_condition', 'body_feeling', 'sleep_condition', 'eye_condition',
|
||||
'head_feeling', 'sweat_condition', 'skin_condition', 'urine_condition',
|
||||
'stool_condition', 'kidney_condition'
|
||||
'stool_condition', 'kidney_condition', 'local_hospital_diagnosis'
|
||||
];
|
||||
|
||||
foreach ($multiSelectFields as $field) {
|
||||
@@ -242,18 +242,105 @@ class DiagnosisLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
// 处理舌苔照片(JSON转数组)
|
||||
|
||||
if (!empty($diagnosis['tongue_images'])) {
|
||||
$diagnosis['tongue_images'] = json_decode($diagnosis['tongue_images'], true) ?: [];
|
||||
} else {
|
||||
$diagnosis['tongue_images'] = [];
|
||||
}
|
||||
// 先尝试 JSON 解析(兼容旧数据)
|
||||
$files = json_decode($diagnosis['tongue_images'], true);
|
||||
if (is_array($files)) {
|
||||
$diagnosis['tongue_images'] = $files;
|
||||
} else {
|
||||
// JSON 解析失败则按逗号分割
|
||||
$diagnosis['tongue_images'] = array_filter(explode(',', $diagnosis['tongue_images'])) ?: [];
|
||||
}
|
||||
} else {
|
||||
$diagnosis['tongue_images'] = [];
|
||||
}
|
||||
|
||||
// 处理检查报告(JSON转数组)
|
||||
if (!empty($diagnosis['report_files'])) {
|
||||
$diagnosis['report_files'] = json_decode($diagnosis['report_files'], true) ?: [];
|
||||
if (!empty($diagnosis['report_files'])) {
|
||||
// 先尝试 JSON 解析(兼容旧数据)
|
||||
$files = json_decode($diagnosis['report_files'], true);
|
||||
if (is_array($files)) {
|
||||
$diagnosis['report_files'] = $files;
|
||||
} else {
|
||||
// JSON 解析失败则按逗号分割
|
||||
$diagnosis['report_files'] = array_filter(explode(',', $diagnosis['report_files'])) ?: [];
|
||||
}
|
||||
} else {
|
||||
$diagnosis['report_files'] = [];
|
||||
}
|
||||
// 处理诊断日期格式
|
||||
if (!empty($diagnosis['diagnosis_date'])) {
|
||||
$diagnosis['diagnosis_date'] = date('Y-m-d', $diagnosis['diagnosis_date']);
|
||||
}
|
||||
|
||||
// 如果local_hospital_visit_date为空但diagnosis_date有值,则使用diagnosis_date
|
||||
if (empty($diagnosis['local_hospital_visit_date']) && !empty($diagnosis['diagnosis_date'])) {
|
||||
$diagnosis['local_hospital_visit_date'] = $diagnosis['diagnosis_date'];
|
||||
}
|
||||
|
||||
return $diagnosis;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 诊单详情(患者端)
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public static function diagnosisDetail(array $params): array
|
||||
{
|
||||
$diagnosisId = $params['id'] ?? 0;
|
||||
$userId = $params['user_id'] ?? 0;
|
||||
|
||||
if (!$diagnosisId || !$userId) {
|
||||
self::setError('参数不完整');
|
||||
return [];
|
||||
}
|
||||
|
||||
$diagnosis = Diagnosis::where('id', $diagnosisId)
|
||||
->where('patient_id', $userId)
|
||||
->findOrEmpty()
|
||||
->toArray();
|
||||
|
||||
if (empty($diagnosis)) {
|
||||
self::setError('诊单不存在或无权限访问');
|
||||
return [];
|
||||
}
|
||||
|
||||
// 处理既往史为数组
|
||||
if (!empty($diagnosis['past_history'])) {
|
||||
$diagnosis['past_history'] = explode(',', $diagnosis['past_history']);
|
||||
} else {
|
||||
$diagnosis['report_files'] = [];
|
||||
$diagnosis['past_history'] = [];
|
||||
}
|
||||
|
||||
// 处理现病史多选字段为数组
|
||||
$multiSelectFields = [
|
||||
'diet_condition', 'body_feeling', 'sleep_condition', 'eye_condition',
|
||||
'head_feeling', 'sweat_condition', 'skin_condition', 'urine_condition',
|
||||
'stool_condition', 'kidney_condition', 'local_hospital_diagnosis'
|
||||
];
|
||||
|
||||
foreach ($multiSelectFields as $field) {
|
||||
if (!empty($diagnosis[$field])) {
|
||||
$diagnosis[$field] = explode(',', $diagnosis[$field]);
|
||||
} else {
|
||||
$diagnosis[$field] = [];
|
||||
}
|
||||
}
|
||||
|
||||
// 处理检查报告为数组
|
||||
if (!empty($diagnosis['examination_report'])) {
|
||||
$diagnosis['examination_report'] = explode(',', $diagnosis['examination_report']);
|
||||
} else {
|
||||
$diagnosis['examination_report'] = [];
|
||||
}
|
||||
|
||||
// 处理舌苔照片为数组
|
||||
if (!empty($diagnosis['tongue_photo'])) {
|
||||
$diagnosis['tongue_photo'] = explode(',', $diagnosis['tongue_photo']);
|
||||
} else {
|
||||
$diagnosis['tongue_photo'] = [];
|
||||
}
|
||||
|
||||
// 处理诊断日期格式
|
||||
@@ -261,6 +348,11 @@ class DiagnosisLogic extends BaseLogic
|
||||
$diagnosis['diagnosis_date'] = date('Y-m-d', $diagnosis['diagnosis_date']);
|
||||
}
|
||||
|
||||
// 如果local_hospital_visit_date为空但diagnosis_date有值,则使用diagnosis_date
|
||||
if (empty($diagnosis['local_hospital_visit_date']) && !empty($diagnosis['diagnosis_date'])) {
|
||||
$diagnosis['local_hospital_visit_date'] = $diagnosis['diagnosis_date'];
|
||||
}
|
||||
|
||||
return $diagnosis;
|
||||
}
|
||||
|
||||
@@ -360,7 +452,10 @@ class DiagnosisLogic extends BaseLogic
|
||||
|
||||
// 医生userId
|
||||
$doctorUserId = 'doctor_' . $adminId;
|
||||
|
||||
$query = Diagnosis::where('id', $patientId)
|
||||
->where('delete_time', null)->find();
|
||||
|
||||
|
||||
// 患者userId(必须与小程序端一致)
|
||||
$patientUserId = 'patient_' . $patientId;
|
||||
|
||||
@@ -382,6 +477,7 @@ class DiagnosisLogic extends BaseLogic
|
||||
'sdkAppId' => (int)$config['sdkAppId'], // 确保返回整数
|
||||
'userId' => $doctorUserId, // 医生的userId
|
||||
'userSig' => $userSig,
|
||||
'assistant_id'=>$query->assistant_id?'doctor_'.$query->assistant_id:'',
|
||||
'patientUserId' => $patientUserId, // 患者的userId(用于发起通话)
|
||||
'expireTime' => 86400 // 24小时
|
||||
];
|
||||
@@ -720,14 +816,14 @@ class DiagnosisLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
// 患者userId
|
||||
$patientUserId = 'doctor_' . $patientId;
|
||||
// 医助userId(使用 doctor_ 前缀)
|
||||
$doctorUserId = 'doctor_' . $patientId;
|
||||
|
||||
// 生成患者的 UserSig
|
||||
// 生成医助的 UserSig
|
||||
$userSig = self::generateUserSig(
|
||||
$config['sdkAppId'],
|
||||
$config['secretKey'],
|
||||
$patientUserId
|
||||
$doctorUserId
|
||||
);
|
||||
|
||||
if (!$userSig) {
|
||||
@@ -735,19 +831,19 @@ class DiagnosisLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
// 确保患者账号已导入IM
|
||||
self::ensurePatientImAccount($patientId, $patientUserId);
|
||||
// 确保医助账号已导入IM(使用正确的方法)
|
||||
self::importDoctorAccountToIm($patientId, $doctorUserId);
|
||||
|
||||
\think\facade\Log::info('小程序获取患者签名成功 - doctor_id: ' . $patientId . ', user_id: ' . $patientUserId);
|
||||
\think\facade\Log::info('获取医助签名成功 - admin_id: ' . $patientId . ', user_id: ' . $doctorUserId);
|
||||
|
||||
return [
|
||||
'sdkAppId' => (int)$config['sdkAppId'],
|
||||
'userId' => $patientUserId,
|
||||
'userId' => $doctorUserId,
|
||||
'userSig' => $userSig,
|
||||
'expireTime' => 86400
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
\think\facade\Log::error('获取患者签名失败 - patient_id: ' . $patientId . ', error: ' . $e->getMessage());
|
||||
\think\facade\Log::error('获取医助签名失败 - admin_id: ' . $patientId . ', error: ' . $e->getMessage());
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
@@ -868,8 +964,8 @@ class DiagnosisLogic extends BaseLogic
|
||||
throw new \Exception('小程序配置未设置');
|
||||
}
|
||||
|
||||
// 构建小程序路径和参数
|
||||
$page = 'pages/order/monad/monad';
|
||||
// 构建小程序路径和参数(前端可传 mini_program_path 覆盖默认路径)
|
||||
$page = !empty($params['mini_program_path']) ? $params['mini_program_path'] : 'pages/order/monad/monad';
|
||||
$scene = "id={$diagnosisId}&share_user={$shareUserId}";
|
||||
|
||||
// 调用微信接口生成小程序码
|
||||
@@ -1346,7 +1442,17 @@ class DiagnosisLogic extends BaseLogic
|
||||
$updateData = [
|
||||
'patient_name' => $params['patient_name'] ?? '',
|
||||
'gender' => $params['gender'] ?? 1,
|
||||
'age' => $params['age'] ?? 0,
|
||||
'age' => !empty($params['age']) ? intval($params['age']) : 0,
|
||||
'id_card' => $params['id_card'] ?? '',
|
||||
'height' => !empty($params['height']) ? floatval($params['height']) : null,
|
||||
'weight' => !empty($params['weight']) ? floatval($params['weight']) : null,
|
||||
'systolic_pressure' => !empty($params['systolic_pressure']) ? intval($params['systolic_pressure']) : null,
|
||||
'diastolic_pressure' => !empty($params['diastolic_pressure']) ? intval($params['diastolic_pressure']) : null,
|
||||
'fasting_blood_sugar' => !empty($params['fasting_blood_sugar']) ? floatval($params['fasting_blood_sugar']) : null,
|
||||
'diabetes_discovery_year' => !empty($params['diabetes_discovery_year']) ? intval($params['diabetes_discovery_year']) : null,
|
||||
'local_hospital_diagnosis' => $params['local_hospital_diagnosis'] ?? '',
|
||||
'local_hospital_name' => $params['local_hospital_name'] ?? '',
|
||||
'local_hospital_visit_date' => $params['local_hospital_visit_date'] ?? '',
|
||||
'diagnosis_type' => $params['diagnosis_type'] ?? '',
|
||||
'syndrome_type' => $params['syndrome_type'] ?? '',
|
||||
'diabetes_type' => $params['diabetes_type'] ?? '',
|
||||
@@ -1367,14 +1473,16 @@ class DiagnosisLogic extends BaseLogic
|
||||
'fatty_liver_degree' => $params['fatty_liver_degree'] ?? '',
|
||||
// 既往史字段
|
||||
'past_history' => $params['past_history'] ?? '',
|
||||
'trauma_history' => $params['trauma_history'] ?? 0,
|
||||
'surgery_history' => $params['surgery_history'] ?? 0,
|
||||
'allergy_history' => $params['allergy_history'] ?? 0,
|
||||
'family_history' => $params['family_history'] ?? 0,
|
||||
'pregnancy_history' => $params['pregnancy_history'] ?? 0,
|
||||
'trauma_history' => isset($params['trauma_history']) ? intval($params['trauma_history']) : 0,
|
||||
'surgery_history' => isset($params['surgery_history']) ? intval($params['surgery_history']) : 0,
|
||||
'allergy_history' => isset($params['allergy_history']) ? intval($params['allergy_history']) : 0,
|
||||
'family_history' => isset($params['family_history']) ? intval($params['family_history']) : 0,
|
||||
'pregnancy_history' => isset($params['pregnancy_history']) ? intval($params['pregnancy_history']) : 0,
|
||||
// 临床信息
|
||||
'symptoms' => $params['symptoms'] ?? '',
|
||||
'tongue_coating' => $params['tongue_coating'] ?? '',
|
||||
'tongue_images' => $params['tongue_images'] ?? '',
|
||||
'report_files' => $params['report_files'] ?? '',
|
||||
'pulse' => $params['pulse'] ?? '',
|
||||
'treatment_principle' => $params['treatment_principle'] ?? '',
|
||||
'prescription' => $params['prescription'] ?? '',
|
||||
@@ -1386,8 +1494,12 @@ class DiagnosisLogic extends BaseLogic
|
||||
// 处理诊断日期
|
||||
if (!empty($params['diagnosis_date'])) {
|
||||
$updateData['diagnosis_date'] = strtotime($params['diagnosis_date']);
|
||||
} elseif (!empty($params['local_hospital_visit_date'])) {
|
||||
// 如果没有diagnosis_date但有local_hospital_visit_date,则使用local_hospital_visit_date
|
||||
$updateData['diagnosis_date'] = strtotime($params['local_hospital_visit_date']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 执行更新
|
||||
$diagnosis->save($updateData);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user