香洲二院小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mini_xzey/app/Http/Requests/Patient/BindPatientRequest.php

93 lines
2.7 KiB

<?php
namespace App\Http\Requests\Patient;
use App\Dictionary\Patient\IdentifyCardType;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class BindPatientRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array|string>
*/
/**
* 规则
* @return array
*/
public function rules(): array
{
return [
'name' => 'required',
'card_type' => 'required',
'card_no' => ['required', function ($attribute, $value, $fail) {
$card_type = getIDCardType($value);
switch ($card_type) {
// 未知证件,身份证,港澳台社保卡号
case 0:
case 1:
if (!IdentifyCardType::RESIDENT_ID_CARD->validateNumber($value)) {
$fail('证件号码格式错误');
}
break;
case 2:
if (!IdentifyCardType::SOCIAL_SECURITY_CARD->validateNumber($value)) {
$fail('证件号码格式错误');
}
break;
// 2017/2023 版永居证
case 3:
case 4:
if (!IdentifyCardType::FOREIGNER_PERMANENT_RESIDENCE_PERMIT->validateNumber($value)) {
$fail('证件号码格式错误');
}
break;
}
}],
'patient_id' => 'required|max:20'
];
}
/**
* 错误提示语句
* @return array
*/
public function messages(): array
{
return [
'name.required' => '必须填写名称',
'name.max' => '名称限制最大长度为50',
'card_type.required' => '必须选择证件类型',
'card_type.enum' => '证件类型选择错误',
'card_no.required' => '必须填写证件号码',
'patient_id.required' => '必须填写就诊卡号',
'patient_id.max' => '就诊卡号长度最大为20'
];
}
/**
* 字段名称
* @return array
*/
public function attributes(): array
{
return [
'name' => '名称',
'identity_type' => '证件类型',
'identity_no' => '证件号码',
'patient_id' => '就诊卡号',
];
}
}