public List <PatientLookup> GetPatientSearchPayload(string isEnrolled) { List <PatientLookup> patientLookups = new List <PatientLookup>(); patientLookups = new List <PatientLookup>(); List <PersonExtLookup> personExt = new List <PersonExtLookup>(); ///todo: add to context/repo /// //personExt = unitOfWork.Pers if (!string.IsNullOrWhiteSpace(isEnrolled) && isEnrolled == "notEnrolledClients") { Expression <Func <PersonExtLookup, bool> > expressionPersonExt = c => c.PatientStatus.ToLower().Contains("not enrolled"); PersonExtRepository repo = new PersonExtRepository(); { personExt = repo.Filter(expressionPersonExt).Take(PredicateBuilder.MaxRecord).ToList(); } repo = null; foreach (PersonExtLookup p in personExt) { patientLookups.Add(new PatientLookup() { Id = p.Id, PersonId = p.PersonId, ptn_pk = p.ptn_pk, EnrollmentNumber = p.EnrollmentNumber, PatientIndex = p.PatientIndex, FirstName = p.FirstName, MiddleName = p.MiddleName, LastName = p.LastName, Sex = p.Sex, Active = p.Active, RegistrationDate = p.RegistrationDate, EnrollmentDate = p.EnrollmentDate, TransferIn = p.TransferIn, DateOfBirth = p.DateOfBirth, DobPrecision = p.DobPrecision, NationalId = p.NationalId, FacilityId = p.FacilityId, PatientType = p.PatientType, PatientStatus = p.PatientStatus, MobileNumber = p.MobileNumber, TBStatus = p.TBStatus, NutritionStatus = p.NutritionStatus, categorization = p.categorization }); } } else { using (UnitOfWork unitOfWork = new UnitOfWork(new LookupContext())) { Expression <Func <PatientLookup, bool> > expresionFinal = c => c.Id > 0; //Expression<Func<PatientLookup, bool>> expressionPatientStatus = // c => c.PatientStatus.ToLower().Contains("not enrolled"); //expresionFinal = PredicateBuilder.And(expresionFinal, expressionPatientStatus); Expression <Func <PatientLookup, bool> > expressionPatientStatusEnrolled = c => c.PatientStatus.ToLower().Contains("active") || c.PatientStatus.ToLower().Contains("death") || c.PatientStatus.ToLower().Contains("LostToFollowUp") || c.PatientStatus.ToLower().Contains("transfer out") || c.PatientStatus.ToLower().Contains("confirmed hiv negative") || c.PatientStatus.ToLower().Contains("hiv negative"); expresionFinal = PredicateBuilder.And(expresionFinal, expressionPatientStatusEnrolled); patientLookups = unitOfWork.PatientLookupRepository.Filter(expresionFinal).Take(PredicateBuilder.MaxRecord).ToList(); } } //if (!string.IsNullOrWhiteSpace(isEnrolled)) //{ // switch (isEnrolled) // { // case "notEnrolledClients": // Expression<Func<PatientLookup, bool>> expressionPatientStatus = // c => c.PatientStatus.ToLower().Contains("not enrolled"); // expresionFinal = PredicateBuilder.And(expresionFinal, expressionPatientStatus); // //Expression<Func<PatientLookup, bool>> expressionPatientMax = // break; // default: // Expression<Func<PatientLookup, bool>> expressionPatientStatusEnrolled = // c => c.PatientStatus.ToLower().Contains("active") || c.PatientStatus.ToLower().Contains("death") || c.PatientStatus.ToLower().Contains("losttofollowup") || c.PatientStatus.ToLower().Contains("transfer out") || c.PatientStatus.ToLower().Contains("hiv negative"); // expresionFinal = PredicateBuilder.And(expresionFinal, expressionPatientStatusEnrolled); // break; // } //} // patientLookups = unitOfWork.PatientLookupRepository.Filter(expresionFinal).Take(PredicateBuilder.MaxRecord).ToList(); return(patientLookups); //var patientSearchDetails = unitOfWork.PatientLookupRepository.FindBy(x=> x.PatientStatus =="not enrolled").ToList(); //return patientSearchDetails; }
public List <PatientLookup> GetPatientSearchPayload(string patientId, string isEnrolled, string firstName, string middleName, string lastName) { List <PersonExtLookup> personExt = new List <PersonExtLookup>(); List <PatientLookup> patientLookups = new List <PatientLookup>(); if (!string.IsNullOrWhiteSpace(isEnrolled) && isEnrolled == "notEnrolledClients") { Expression <Func <PersonExtLookup, bool> > expressionPersonExt = c => c.PatientStatus.ToLower().Contains("not enrolled"); if (!string.IsNullOrWhiteSpace(firstName)) { Expression <Func <PersonExtLookup, bool> > expFN = c => c.FirstName.ToLower().Contains(firstName.ToLower()); expressionPersonExt = PredicateBuilder.And(expressionPersonExt, expFN); } if (!string.IsNullOrWhiteSpace(middleName)) { Expression <Func <PersonExtLookup, bool> > expMName = c => c.MiddleName.ToLower().Contains(middleName.ToLower()); expressionPersonExt = PredicateBuilder.And(expressionPersonExt, expMName); } if (!string.IsNullOrWhiteSpace(lastName)) { Expression <Func <PersonExtLookup, bool> > expLName = c => c.LastName.ToLower().Contains(lastName.ToLower()); expressionPersonExt = PredicateBuilder.And(expressionPersonExt, expLName); } PersonExtRepository repo = new PersonExtRepository(); { personExt = repo.Filter(expressionPersonExt).Take(PredicateBuilder.MaxRecord).ToList(); } repo = null; foreach (PersonExtLookup p in personExt) { patientLookups.Add(new PatientLookup() { Id = p.Id, PersonId = p.PersonId, ptn_pk = p.ptn_pk, EnrollmentNumber = p.EnrollmentNumber, PatientIndex = p.PatientIndex, FirstName = p.FirstName, MiddleName = p.MiddleName, LastName = p.LastName, Sex = p.Sex, Active = p.Active, RegistrationDate = p.RegistrationDate, EnrollmentDate = p.EnrollmentDate, TransferIn = p.TransferIn, DateOfBirth = p.DateOfBirth, DobPrecision = p.DobPrecision, NationalId = p.NationalId, FacilityId = p.FacilityId, PatientType = p.PatientType, PatientStatus = p.PatientStatus, MobileNumber = p.MobileNumber, TBStatus = p.TBStatus, NutritionStatus = p.NutritionStatus, categorization = p.categorization }); } return(patientLookups); } else { using (UnitOfWork unitOfWork = new UnitOfWork(new LookupContext())) { patientLookups = new List <PatientLookup>(); Expression <Func <PatientLookup, bool> > expresionFinal = c => c.Id > 0; if (!string.IsNullOrEmpty(patientId.Trim())) { Expression <Func <PatientLookup, bool> > expressionPatientId = c => c.EnrollmentNumber.ToString().Contains(patientId.Trim().ToString()) || c.PatientClinicId.ToString().Contains(patientId.Trim().ToString()); expresionFinal = PredicateBuilder.And(expresionFinal, expressionPatientId); } if (!string.IsNullOrWhiteSpace(firstName.Trim())) { Expression <Func <PatientLookup, bool> > expressionFirstName = c => c.FirstName.ToLower().Contains(firstName.ToLower()); expresionFinal = PredicateBuilder.And(expresionFinal, expressionFirstName); } if (!string.IsNullOrWhiteSpace(middleName.Trim())) { Expression <Func <PatientLookup, bool> > expressionMiddleName = c => c.MiddleName.ToLower().Contains(middleName.ToLower()); expresionFinal = PredicateBuilder.And(expresionFinal, expressionMiddleName); } if (!string.IsNullOrWhiteSpace(lastName.Trim())) { Expression <Func <PatientLookup, bool> > expressionLastName = c => c.LastName.ToLower().Contains(lastName.ToLower()); expresionFinal = PredicateBuilder.And(expresionFinal, expressionLastName); } if (!string.IsNullOrWhiteSpace(isEnrolled)) { switch (isEnrolled) { case "notEnrolledClients": Expression <Func <PatientLookup, bool> > expressionPatientStatus = c => c.PatientStatus.ToLower().Contains("not enrolled"); expresionFinal = PredicateBuilder.And(expresionFinal, expressionPatientStatus); break; default: Expression <Func <PatientLookup, bool> > expressionPatientStatusEnrolled = c => c.PatientStatus.ToLower().Contains("not enrolled") == false; expresionFinal = PredicateBuilder.And(expresionFinal, expressionPatientStatusEnrolled); break; } } patientLookups = unitOfWork.PatientLookupRepository.Filter(expresionFinal).ToList(); return(patientLookups); } } }