public List <Relative> GetRelativesOfPatient(Patient patient) { SessionFactory SF = new SessionFactory(); SF.Init(); SF.OpenSession(); GenericDaoImpl <Patient, int> patientDao = new GenericDaoImpl <Patient, int>(SF.GetSession()); Patient p = patientDao.Get(patient.ID_Patient); p.relativeList = new List <int>(); RelativeDaoImpl relativeDao = new RelativeDaoImpl(SF.GetSession()); List <Relative> tempList = relativeDao.GetListRelativesOfPatient(patient.ID_Patient).ToList(); if (tempList.Count > 0) { foreach (Relative item in tempList) { p.relativeList.Add(item.ID_Relative); } } SF.CloseSession(); return(tempList); }
public void DeletePatient(List <Patient> listPatients) { SessionFactory SF = new SessionFactory(); SF.Init(); SF.OpenSession(); GenericDaoImpl <Patient, int> patientDao = new GenericDaoImpl <Patient, int>(SF.GetSession()); RelativeDaoImpl relativeDao = new RelativeDaoImpl(SF.GetSession()); OrderOfPatientDaoImpl orderDao = new OrderOfPatientDaoImpl(SF.GetSession()); SpecimentsInOrderDaoImpl specimentDao = new SpecimentsInOrderDaoImpl(SF.GetSession()); TestsInOrderDaoImpl testDao = new TestsInOrderDaoImpl(SF.GetSession()); GenericDaoImpl <Gender, int> genderDao = new GenericDaoImpl <Gender, int>(SF.GetSession()); List <Relative> listRel; List <OrderOfPatient> listOrd; List <SpecimentsInOrder> listSpec; List <TestsInOrder> listTest; Gender male = genderDao.Get(1); Gender female = genderDao.Get(2); foreach (Patient patient in listPatients) { if (patient.Gender.ID_Gender == male.ID_Gender) { patient.Gender = male; } else if (patient.Gender.ID_Gender == female.ID_Gender) { patient.Gender = female; } listRel = relativeDao.GetListRelativesOfPatient(patient.ID_Patient).ToList(); listOrd = orderDao.GetOrdersOfPatient(patient.ID_Patient).ToList(); if (listRel.Count == 0 && listOrd.Count == 0) { patientDao.Delete(patient); } else if (listRel.Count > 0 || listOrd.Count > 0) { if (listRel.Count > 0) { foreach (Relative item in listRel) { item.Status = 0; relativeDao.SaveOrUpdate(item); } } if (listOrd.Count > 0) { foreach (OrderOfPatient item in listOrd) { item.Status = 0; orderDao.SaveOrUpdate(item); listSpec = specimentDao.GetSpecimentsOfOrder(item.ID_Order).ToList(); if (listSpec.Count > 0) { foreach (SpecimentsInOrder itemSpec in listSpec) { itemSpec.Status = 0; specimentDao.SaveOrUpdate(itemSpec); listTest = testDao.GetTestsOfSpeciment(itemSpec.ID_SpecimentOrder).ToList(); if (listTest.Count > 0) { foreach (TestsInOrder itemTest in listTest) { itemTest.Status = 0; testDao.SaveOrUpdate(itemTest); } } } } } } patient.Status = 0; patientDao.SaveOrUpdate(patient); } } SF.CloseSession(); }