82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using HospitalContracts.BindingModels;
|
|
using HospitalContracts.ViewModels;
|
|
using HospitalDataModels.Models;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Xml.Linq;
|
|
|
|
namespace HospitalDatabaseImplement.Models
|
|
{
|
|
public class Patient : IPatientModel
|
|
{
|
|
public int Id { get; private set; }
|
|
|
|
public string Surname { get; private set; } = string.Empty;
|
|
[Required]
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
public string? Patronymic { get; private set; } = string.Empty;
|
|
[Required]
|
|
public DateTime BirthDate { get; private set; }
|
|
|
|
public int? TreatmentId { get; private set; }
|
|
public virtual Treatment? Treatment { get; set; }
|
|
|
|
public static Patient? Create(PatientBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Patient()
|
|
{
|
|
Id = model.Id,
|
|
Surname = model.Surname,
|
|
Name = model.Name,
|
|
Patronymic = model.Patronymic,
|
|
BirthDate = model.BirthDate,
|
|
TreatmentId = model.TreatmentId
|
|
};
|
|
}
|
|
|
|
public static Patient? Create(XElement element)
|
|
{
|
|
if (element == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Patient()
|
|
{
|
|
Surname = element.Element("Surname")!.Value,
|
|
Name = element.Element("Name")!.Value,
|
|
Patronymic = element.Element("Patronymic")?.Value,
|
|
BirthDate = DateTime.ParseExact(element.Element("BirthDate")!.Value, "dd.mm.yyyy", null),
|
|
TreatmentId = Convert.ToInt32(element.Element("TreatmentId")?.Value)
|
|
};
|
|
}
|
|
|
|
public void Update(PatientBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Surname = model.Surname;
|
|
Name = model.Name;
|
|
Patronymic = model.Patronymic;
|
|
BirthDate = model.BirthDate;
|
|
TreatmentId = model.TreatmentId;
|
|
}
|
|
public PatientViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Surname = Surname,
|
|
Name = Name,
|
|
Patronymic = Patronymic,
|
|
BirthDate = BirthDate,
|
|
TreatmentId = TreatmentId,
|
|
TreatmentName = Treatment?.Name
|
|
};
|
|
}
|
|
}
|