using System;

using HISClinic.DataModel;
using HISClinic.DataServices;

namespace HISClinic.BLL
{
	/// <summary>
	/// Patient 的摘要说明。
	/// </summary>
	public class Patient
	{
		public Patient()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		/// <summary>
		/// 注册病人信息
		/// </summary>
		/// <param name="patientRow"></param>
		/// <returns></returns>
		public bool AddPatientInfo(Patients.t_PatientRow patientRow)
		{
			if(!IsCardNumberExisits(patientRow.CardNumber))
			{
				return (new PatientMapper()).Insert(patientRow);
			}
			
			throw(new ApplicationException("卡号已经存在！"));
		}

		/// <summary>
		/// 修改病人信息
		/// </summary>
		/// <param name="patientRow"></param>
		/// <returns></returns>
		public bool EditPatientInfo(Patients.t_PatientRow patientRow)
		{
			return (new PatientMapper()).Update(patientRow);
		}

		/// <summary>
		/// 根据医疗卡号查找病人
		/// </summary>
		/// <param name="cardNumber"></param>
		/// <returns></returns>
		public PatientsEx FindPatientByCardNumber(string cardNumber)
		{
			return (new PatientMapper()).FindPatientByCardNumber(cardNumber);
		}

		/// <summary>
		/// 判断卡号是否已经存在
		/// </summary>
		/// <param name="cardNumber">卡号</param>
		/// <returns></returns>
		private bool IsCardNumberExisits(string cardNumber)
		{
			PatientsEx patientsEx=(new PatientMapper()).FindPatientByCardNumber(cardNumber);

			if(patientsEx.t_Patient.Count>0)
			{
				return true;
			}
			return false;
		}
	}
}
