101 lines
2.9 KiB
C#
101 lines
2.9 KiB
C#
|
|
using System;
|
|||
|
|
using System.Data.Common;
|
|||
|
|
|
|||
|
|
public class PatientInfoSettingsViewModel
|
|||
|
|
{
|
|||
|
|
public event Action<bool, string> OnPatientInfoSaved;
|
|||
|
|
|
|||
|
|
private IPatientInfoService _patientService;
|
|||
|
|
|
|||
|
|
public PatientInfoSettingsViewModel()
|
|||
|
|
{
|
|||
|
|
_patientService = ServiceLocator.Get<IPatientInfoService>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public PatientInfo GetCurrentPatientInfo()
|
|||
|
|
{
|
|||
|
|
return _patientService?.GetCurrentPatient();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void SavePatientInfo(PatientInfo info)
|
|||
|
|
{
|
|||
|
|
if (_patientService == null)
|
|||
|
|
{
|
|||
|
|
OnPatientInfoSaved?.Invoke(false, "病人信息服务不可用");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 验证字段
|
|||
|
|
if (string.IsNullOrWhiteSpace(info.Name))
|
|||
|
|
{
|
|||
|
|
OnPatientInfoSaved?.Invoke(false, "病人姓名不能为空");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (string.IsNullOrWhiteSpace(info.HospitalId))
|
|||
|
|
{
|
|||
|
|
OnPatientInfoSaved?.Invoke(false, "住院号不能为空");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 性别验证
|
|||
|
|
if (string.IsNullOrWhiteSpace(info.Gender))
|
|||
|
|
{
|
|||
|
|
OnPatientInfoSaved?.Invoke(false, "性别不能为空");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (info.Gender != "男" && info.Gender != "女")
|
|||
|
|
{
|
|||
|
|
OnPatientInfoSaved?.Invoke(false, "性别格式错误,只能为'男'或'女'");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 年龄验证
|
|||
|
|
if (info.Age < 0 || info.Age > 90)
|
|||
|
|
{
|
|||
|
|
OnPatientInfoSaved?.Invoke(false, "年龄格式错误,要在0-90之间");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 身份证号验证
|
|||
|
|
// if (string.IsNullOrWhiteSpace(info.IdNumber))
|
|||
|
|
// {
|
|||
|
|
// OnPatientInfoSaved?.Invoke(false, "身份证号码不能为空");
|
|||
|
|
// return;
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// if (info.IdNumber.Length != 18)
|
|||
|
|
// {
|
|||
|
|
// OnPatientInfoSaved?.Invoke(false, "身份证号码必须为18位");
|
|||
|
|
// return;
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// 验证身份证号格式(简单版本)
|
|||
|
|
// if (!System.Text.RegularExpressions.Regex.IsMatch(info.IdNumber, @"^\d{17}[\dXx]$"))
|
|||
|
|
// {
|
|||
|
|
// OnPatientInfoSaved?.Invoke(false, "身份证号码格式不正确");
|
|||
|
|
// return;
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// 身高验证(单位:厘米)
|
|||
|
|
if (info.Height <= 0 || info.Height > 250)
|
|||
|
|
{
|
|||
|
|
OnPatientInfoSaved?.Invoke(false, "身高格式错误,要在0-250厘米之间");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 体重验证(单位:千克)
|
|||
|
|
if (info.Weight <= 0 || info.Weight > 300)
|
|||
|
|
{
|
|||
|
|
OnPatientInfoSaved?.Invoke(false, "体重格式错误,要在0-300千克之间");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool success = _patientService.SavePatientInfo(info);
|
|||
|
|
string message = success ? "病人信息保存成功" : "病人信息保存失败";
|
|||
|
|
|
|||
|
|
OnPatientInfoSaved?.Invoke(success, message);
|
|||
|
|
}
|
|||
|
|
}
|