public Task <SavePatientResponse> SavePatientDetails(PatientDetailsList objPatientDetailsList)
 {
     return(restService.SavePatientDetails(objPatientDetailsList));
 }
Example #2
0
        private async void btnSave_Clicked(object sender, EventArgs e)
        {
            try
            {
                string Message = "All Fields are Required";
                //await Navigation.PushAsync(new AddTest());
                //return;
                var Valid = true;
                #region Validation
                foreach (HealthCheckUpDeafult hc in lstHealthCheckupInitial)
                {
                    if (hc.Name == "")
                    {
                        Valid = false;
                        break;
                    }
                    if (hc.Relation == null)
                    {
                        Valid = false;
                        break;
                    }
                    hc.RelationID = objCommonDropDowns.GetRalations().Find(x => x.Name == hc.Relation).ID.ToString();
                    if (hc.EmployeeCode == "" && hc.Relation == "Self")
                    {
                        Valid = false;
                        break;
                    }
                    if (hc.ID == 0 && hc.Relation == "Self")
                    {
                        if (hc.SeniorityLevel == null)
                        {
                            Valid = false;
                            break;
                        }
                        else if (hc.SeniorityLevelID == null)
                        {
                            hc.SeniorityLevelID = objCommonDropDowns.GetSenorityLevels().Find(x => x.Name == hc.SeniorityLevel).ID.ToString();
                        }
                    }
                    else
                    {
                        if (hc.SeniorityLevelID == null && hc.SeniorityLevel != null)
                        {
                            hc.SeniorityLevelID = objCommonDropDowns.GetSenorityLevels().Find(x => x.Name == hc.SeniorityLevel).ID.ToString();
                        }
                    }

                    if (hc.Phone == "")
                    {
                        Valid = false;
                        break;
                    }
                    else if (!Regex.IsMatch(hc.Phone, @"^[0-9]{10}$"))
                    {
                        Message = "Not Valid Mobile No.";
                        // DependencyService.Get<IMessage>().LongAlert("Not Valid Mobile No.");
                        Valid = false;
                    }
                    if (hc.DateOfBirth == "")
                    {
                        Valid = false;
                        break;
                    }
                    if (hc.MaritalStatus == null)
                    {
                        Valid = false;
                        break;
                    }
                    else if (hc.MaritalStatusID == null)
                    {
                        hc.MaritalStatusID = objCommonDropDowns.MaritalStatus().Find(x => x.Name == hc.MaritalStatus).ID;
                    }
                    if (hc.Gender == null)
                    {
                        Valid = false;
                        break;
                    }
                    else
                    {
                        hc.GenderID = objCommonDropDowns.Gender().Find(x => x.Name == hc.Gender).ID;
                    }

                    if (hc.Name.Length < 2)
                    {
                        Valid   = false;
                        Message = "Name should be of atleast 2 characters";
                    }
                }
                #endregion Validation
                string   errorstring = "";
                AHCError err         = new AHCError();
                MessagingCenter.Subscribe <App, string>((App)Xamarin.Forms.Application.Current, "AHCHealthCheckup", (app, message) =>
                {
                    try
                    {
                        err = JsonConvert.DeserializeObject <AHCError>(message);
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                    //var options = obj["fields"][0]["options"].ToList();
                });

                if (Valid)
                {
                    PatientDetailsList    objPatientDetailsList = new PatientDetailsList();
                    List <PatientDetails> lstPatientDetails     = new List <Models.PatientDetails>();
                    PatientDetails        objPatientDetails;

                    foreach (HealthCheckUpDeafult hc in lstHealthCheckupInitial)
                    {
                        objPatientDetails                       = new PatientDetails();
                        objPatientDetails.relation              = hc.RelationID.ToString();
                        objPatientDetails.employee_code         = hc.EmployeeCode;
                        objPatientDetails.name                  = hc.Name;
                        objPatientDetails.phone                 = hc.Phone;
                        CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
                        try
                        {
                            objPatientDetails.date_of_birth = Convert.ToDateTime(hc.DateOfBirth).ToString("yyyy-MM-dd"); //hc.DateOfBirth;
                        }
                        catch (Exception)
                        {
                            string Date = hc.DateOfBirth.ToString().Replace("00:00:00", "").Replace(" ", "");
                            objPatientDetails.date_of_birth = Date;
                        }
                        objPatientDetails.marital_status  = hc.MaritalStatusID.ToString();
                        objPatientDetails.gender          = hc.GenderID.ToString();
                        objPatientDetails.seniority_level = hc.SeniorityLevelID;
                        lstPatientDetails.Add(objPatientDetails);
                    }
                    objPatientDetailsList.patients = lstPatientDetails;
                    overlay.IsVisible = true;
                    SavePatientResponse objSavePatientResponse = await App.TodoManager.SavePatientDetails(objPatientDetailsList);

                    if (objSavePatientResponse.status == "success")
                    {
                        #region  Remove error messages
                        int index = 0;
                        foreach (HealthCheckUpDeafult hc in lstHealthCheckupInitial)
                        {
                            lstHealthCheckupInitial[index].ErrormessageVisiblity = false;
                            lstHealthCheckupInitial[index].ErrorMessage          = "";
                            //  lstHealthCheckUpDeafult.Add(objHealthCheckUpDeafult);
                            index++;
                        }

                        lvHealthCheckups.ItemsSource = null;
                        lvHealthCheckups.ItemsSource = lstHealthCheckupInitial;
                        #endregion
                        await Navigation.PushAsync(new AddTest(objSavePatientResponse.data.id, objSavePatientResponse.data.patients[0].id));

                        //await DisplayAlert("Success", "Patient Added Successfully", "Ok");
                    }
                    else
                    {
                        int     index        = 0;
                        int     errorindex   = 0;
                        string  Errormessage = "";
                        dynamic item         = null;
                        ObservableCollection <HealthCheckUpDeafult> lstHealthCheckUpDeafult = new ObservableCollection <HealthCheckUpDeafult>();
                        HealthCheckUpDeafult objHealthCheckUpDeafult = new HealthCheckUpDeafult();
                        foreach (HealthCheckUpDeafult hc in lstHealthCheckupInitial)
                        {
                            objHealthCheckUpDeafult = hc;
                            if (errorindex < index | index == 0)
                            {
                                item       = err.data.ElementAt(index);
                                errorindex = Convert.ToInt32(item.Key.ToString().Substring(item.Key.IndexOf('.') + 1, 1));
                            }
                            if (errorindex == index)
                            {
                                Errormessage             = "";
                                hc.ErrormessageVisiblity = true;
                                Errormessage            += "\n Error: \n" + string.Join("\n", item.Value) + "\n";
                                objHealthCheckUpDeafult.ErrormessageVisiblity = true;
                                objHealthCheckUpDeafult.ErrorMessage          = Errormessage;
                                //lstHealthCheckUpDeafult[index]=
                                //lstHealthCheckupInitial[index].ErrormessageVisiblity  = true;
                                //  lstHealthCheckupInitial[index].ErrorMessage = Errormessage;
                            }
                            else
                            {
                                objHealthCheckUpDeafult.ErrormessageVisiblity = false;
                                objHealthCheckUpDeafult.ErrorMessage          = "";
                            }
                            lstHealthCheckUpDeafult.Add(objHealthCheckUpDeafult);
                            index++;
                        }
                        lstHealthCheckupInitial      = lstHealthCheckUpDeafult;
                        lvHealthCheckups.ItemsSource = lstHealthCheckUpDeafult;
                        DependencyService.Get <IMessage>().LongAlert(objSavePatientResponse.message);
                    }
                }
                else

                {
                    DependencyService.Get <IMessage>().LongAlert(Message);
                }
            }
            catch (InvalidOperationException ex)
            {
            }
            catch (Exception ex)
            {
                DependencyService.Get <IMessage>().LongAlert();
            }
            finally
            {
                overlay.IsVisible = false;
            }
        }