Exemplo n.º 1
0
        public ActionResult SearchPatients(string action, string controller, string mandatoryFields, string FirstName, string LastName, DateTime?DateOfBirth, string Email, string PhoneNumber, string ExternalId)
        {
            PatientModel searchModel = new PatientModel()
            {
                Firstname = FirstName, LastName = LastName, DateOfBirth = DateOfBirth, Email = Email, mobileNumber = PhoneNumber, ExternalId = ExternalId
            };

            TempData["SearchModel"] = searchModel;

            bool error = false;

            if (!string.IsNullOrWhiteSpace(mandatoryFields))
            {
                string        errorMessage = string.Empty;
                List <string> mandatory    = mandatoryFields.ToLower().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                foreach (string field in mandatory)
                {
                    switch (field)
                    {
                    case "email":
                        if (string.IsNullOrWhiteSpace(Email))
                        {
                            errorMessage += "Email is mandatory\n";
                            error         = true;
                        }

                        break;

                    case "firstname":
                        if (string.IsNullOrWhiteSpace(FirstName))
                        {
                            errorMessage += "First name is mandatory\n";
                            error         = true;
                        }

                        break;

                    case "lastname":
                        if (string.IsNullOrWhiteSpace(LastName))
                        {
                            errorMessage += "Last name is mandatory\n";
                            error         = true;
                        }

                        break;

                    case "dateofbirth":
                        if (!DateOfBirth.HasValue)
                        {
                            errorMessage += "Date of birth is mandatory\n";
                            error         = true;
                        }

                        break;

                    case "mobile":
                        if (string.IsNullOrWhiteSpace(PhoneNumber))
                        {
                            errorMessage += "PhoneNumber is mandatory\n";
                            error         = true;
                        }

                        break;
                    }
                }

                if (error)
                {
                    TempData["ErrorMessage"] = errorMessage;
                }
            }

            if (!error)
            {
                PatientClient          client = new PatientClient();
                OperationResultAsLists result = client.FindPatient(FirstName, LastName, DateOfBirth, Email, PhoneNumber, ExternalId);

                if (!result.Succeeded)
                {
                    TempData["ErrorMessage"] = result.ErrorMessages;
                }
                else
                {
                    List <PatientModel> data = new List <PatientModel>();
                    foreach (var u in result.Patients)
                    {
                        data.Add(new PatientModel()
                        {
                            Id = u.Id, Firstname = u.FirstName, LastName = u.LastName, Email = u.Email, DateOfBirth = u.DateOfBirth, mobileNumber = u.PhoneNumber, ExternalId = u.ExternalId
                        });
                    }

                    TempData["Patients"] = data;
                }
            }

            return(RedirectToAction(action, controller));
        }