179 lines
6.5 KiB
PHP
Executable File
179 lines
6.5 KiB
PHP
Executable File
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
|
// +----------------------------------------------------------------------
|
|
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
|
// | 开源版本可自由商用,可去除界面版权logo
|
|
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
|
// | github下载:https://github.com/likeshop-github/likeadmin
|
|
// | 访问官网:https://www.likeadmin.cn
|
|
// | likeadmin团队 版权所有 拥有最终解释权
|
|
// +----------------------------------------------------------------------
|
|
// | author: likeadminTeam
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\adminapi\validate\tcm;
|
|
|
|
use app\common\model\tcm\Diagnosis;
|
|
use app\common\validate\BaseValidate;
|
|
|
|
/**
|
|
* 中医辨房病因诊单验证
|
|
* Class DiagnosisValidate
|
|
* @package app\adminapi\validate\tcm
|
|
*/
|
|
class DiagnosisValidate extends BaseValidate
|
|
{
|
|
protected $rule = [
|
|
'id' => 'require|checkDiagnosis',
|
|
'patient_name' => 'require|length:1,50',
|
|
'id_card' => 'length:15,18',
|
|
'phone' => 'require|mobile',
|
|
'gender' => 'require|in:0,1',
|
|
'age' => 'require|number|between:0,150',
|
|
'diagnosis_type' => 'require',
|
|
'status' => 'in:0,1',
|
|
'show_card' => 'in:0,1',
|
|
'create_source' => 'max:32',
|
|
'current_medications' => 'max:2000',
|
|
'tongue_images' => 'array',
|
|
'report_files' => 'array',
|
|
'diabetes_discovery_year' => 'max:50',
|
|
'start_date' => 'date',
|
|
'end_date' => 'date|checkDateRange',
|
|
'diagnosis_id' => 'require|integer|checkDiagnosisId',
|
|
'tracking_content' => 'require|length:1,1000',
|
|
];
|
|
|
|
protected $message = [
|
|
'id.require' => '参数缺失',
|
|
'patient_name.require' => '请输入患者姓名',
|
|
'patient_name.length' => '患者姓名长度须在1-50位字符',
|
|
'id_card.length' => '身份证号长度不正确',
|
|
'phone.require' => '请输入手机号',
|
|
'phone.mobile' => '手机号格式不正确',
|
|
'gender.require' => '请选择性别',
|
|
'gender.in' => '性别参数错误',
|
|
'age.require' => '请输入年龄',
|
|
'age.number' => '年龄必须为数字',
|
|
'age.between' => '年龄范围0-150',
|
|
'diagnosis_type.require' => '请选择诊断类型',
|
|
'status.in' => '状态参数错误',
|
|
'create_source.max' => '渠道来源长度不能超过32个字符',
|
|
'current_medications.max' => '在用药物最多2000个字符',
|
|
'diabetes_discovery_year.max' => '发现糖尿病患病史最多50个字符',
|
|
'start_date.date' => '开始日期格式不正确',
|
|
'end_date.date' => '结束日期格式不正确',
|
|
'diagnosis_id.require' => '诊单ID不能为空',
|
|
'tracking_content.require' => '跟踪备注内容不能为空',
|
|
'tracking_content.length' => '跟踪备注最多1000个字符',
|
|
];
|
|
|
|
public function sceneAdd()
|
|
{
|
|
// 全局规则中含 tracking 相关字段,新增诊单不应校验诊单 ID
|
|
return $this->remove('id', true)
|
|
->remove('diagnosis_id', true)
|
|
->remove('tracking_content', true);
|
|
}
|
|
|
|
public function sceneEdit()
|
|
{
|
|
return $this->only(['id', 'patient_name', 'id_card', 'phone', 'gender', 'age', 'diagnosis_date', 'diagnosis_type', 'syndrome_type', 'marital_status', 'height', 'weight', 'region', 'systolic_pressure', 'diastolic_pressure', 'fasting_blood_sugar', 'diabetes_discovery_year', 'local_hospital_diagnosis', 'local_hospital_name', 'past_history', 'symptoms', 'tongue_coating', 'pulse', 'treatment_principle', 'prescription', 'doctor_advice', 'remark', 'current_medications', 'status', 'show_card', 'create_source']);
|
|
}
|
|
|
|
public function sceneId()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
public function sceneReadonlyDetail()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
public function sceneTrackingWindow()
|
|
{
|
|
return $this->only(['id', 'start_date', 'end_date']);
|
|
}
|
|
|
|
/** 新增跟踪备注:诊单ID + 备注内容 */
|
|
public function sceneAddTrackingNote()
|
|
{
|
|
return $this->only(['diagnosis_id', 'tracking_content']);
|
|
}
|
|
|
|
/** 拉取跟踪备注列表:诊单ID */
|
|
public function sceneTrackingNotes()
|
|
{
|
|
return $this->only(['diagnosis_id']);
|
|
}
|
|
|
|
public function sceneGenerateQrcode()
|
|
{
|
|
return $this->only(['diagnosis_id', 'doctor_id', 'patient_id', 'share_user_id', 'mini_program_path'])
|
|
->append('patient_id', 'require')
|
|
->append('share_user_id', 'require')
|
|
->append('diagnosis_id', 'checkQrcodeIds')
|
|
->append('doctor_id', 'checkQrcodeIds');
|
|
}
|
|
|
|
public function sceneGenerateOrderQrcode()
|
|
{
|
|
return $this->only([]);
|
|
}
|
|
|
|
public function sceneFillIdCard()
|
|
{
|
|
return $this->only(['id', 'id_card'])
|
|
->append('id', 'require')
|
|
->append('id_card', 'require|length:15,18');
|
|
}
|
|
|
|
public function sceneGuahaoLogList()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
protected function checkDiagnosis($value)
|
|
{
|
|
$diagnosis = Diagnosis::findOrEmpty($value);
|
|
if ($diagnosis->isEmpty()) {
|
|
return '诊单不存在';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/** 校验 diagnosis_id 字段(addTrackingNote 等场景使用,避开 id 字段) */
|
|
protected function checkDiagnosisId($value)
|
|
{
|
|
$diagnosis = Diagnosis::findOrEmpty($value);
|
|
if ($diagnosis->isEmpty()) {
|
|
return '诊单不存在';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/** end_date 不能早于 start_date */
|
|
protected function checkDateRange($value, $rule, $data = [])
|
|
{
|
|
$start = $data['start_date'] ?? '';
|
|
if ($start && $value && strtotime($value) < strtotime($start)) {
|
|
return '结束日期不能早于开始日期';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/** 视频场景需 doctor_id,确认诊单需 diagnosis_id */
|
|
protected function checkQrcodeIds($value, $rule, $data = [])
|
|
{
|
|
$page = $data['mini_program_path'] ?? '';
|
|
$hasDoctor = !empty($data['diagnosis_id']);
|
|
$hasDiagnosis = !empty($data['diagnosis_id']);
|
|
if ($page === 'pages/login/login') {
|
|
return $hasDoctor ? true : '视频二维码需传挂号医生ID';
|
|
}
|
|
return $hasDiagnosis ? true : '诊单ID不能为空';
|
|
}
|
|
}
|