更新
This commit is contained in:
@@ -1437,6 +1437,75 @@ class DiagnosisLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 新建就诊卡(供小程序调用)
|
||||
* patient_id 可选:有则复用(同患者多张卡),无则自动生成(新患者首张卡)
|
||||
* @param array $params
|
||||
* @return array|bool 成功返回 ['id'=>诊单ID, 'patient_id'=>患者ID],失败返回false
|
||||
*/
|
||||
public static function addCard(array $params)
|
||||
{
|
||||
try {
|
||||
$userId = $params['user_id'] ?? 0;
|
||||
unset($params['user_id']); // 诊单表无此字段,仅用于创建 view_record
|
||||
|
||||
$patientId = $params['patient_id'] ?? 0;
|
||||
if (!$patientId) {
|
||||
$params['patient_id'] = self::generatePatientId();
|
||||
}
|
||||
$params['status'] = 1;
|
||||
|
||||
// 处理既往史数组
|
||||
if (isset($params['past_history']) && is_array($params['past_history'])) {
|
||||
$params['past_history'] = implode(',', $params['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 (isset($params[$field]) && is_array($params[$field])) {
|
||||
$params[$field] = implode(',', $params[$field]);
|
||||
}
|
||||
}
|
||||
if (isset($params['tongue_images']) && is_array($params['tongue_images'])) {
|
||||
$params['tongue_images'] = json_encode($params['tongue_images'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
if (isset($params['report_files']) && is_array($params['report_files'])) {
|
||||
$params['report_files'] = json_encode($params['report_files'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
if (isset($params['diagnosis_date'])) {
|
||||
$params['diagnosis_date'] = is_numeric($params['diagnosis_date']) ? $params['diagnosis_date'] : strtotime($params['diagnosis_date']);
|
||||
}
|
||||
|
||||
$model = Diagnosis::create($params);
|
||||
self::createPatientTrtcAccount($model->patient_id);
|
||||
|
||||
// 关联 diagnosis_view_records,便于用户通过 User::with('diagnosis') 获取就诊卡
|
||||
if ($userId) {
|
||||
$now = time();
|
||||
\app\common\model\DiagnosisViewRecord::create([
|
||||
'user_id' => $userId,
|
||||
'diagnosis_id' => $model->id,
|
||||
'patient_id' => $model->patient_id,
|
||||
'share_user_id' => 0,
|
||||
'view_count' => 1,
|
||||
'first_view_time' => $now,
|
||||
'last_view_time' => $now,
|
||||
'is_confirmed' => 0,
|
||||
'create_time' => $now,
|
||||
'update_time' => $now
|
||||
]);
|
||||
}
|
||||
|
||||
return ['id' => $model->id, 'patient_id' => $model->patient_id];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新就诊卡(供小程序调用)
|
||||
* @param array $params
|
||||
|
||||
Reference in New Issue
Block a user