Exemplo n.º 1
0
        public static async Task <bool> PostReview(String Review, int Stars, int MedicID, String Title)
        {
            //user/rate?medic_id=&user_id=
            Dictionary <int, String[]> Data = new Dictionary <int, string[]>
            {
                { 0, new String[] { "user_id", Utilities.ID.ToString() } },
                { 1, new String[] { "medic_id", MedicID.ToString() } },
                { 2, new String[] { "review", "{Title [length=" + Title.Length + "]:" + Title + "}{Content [length=" + Review.Length + "]:" + Review + "}" } },
                { 3, new String[] { "rate", Stars.ToString() } },
            };

            try
            {
                String ResultJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), "user/rate");

                var DecodedJson = JObject.Parse(ResultJson);

                return((bool)DecodedJson["status"]);
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Alert", ex.Message, "Ok");

                return(false);
            }
        }
        public static async Task <bool> PostSettings(bool ChangePassword, String Phone = "", String OldPassword = "", String NewPassword = "")
        {
            Dictionary <int, String[]> Data = new Dictionary <int, string[]>
            {
                { 0, new String[] { "user_id", Utilities.ID.ToString() } },
            };

            if (!ChangePassword)
            {
                Data.Add(1, new String[] { "phone", Phone });
            }
            else
            {
                Data.Add(1, new String[] { "change_password", "1" });
                Data.Add(2, new String[] { "old_password", OldPassword });
                Data.Add(3, new String[] { "new_password", NewPassword });
            }

            try
            {
                String ResultJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), "user/profile/settings/" + Utilities.ID);

                var DecodedJson = JObject.Parse(ResultJson);

                return((bool)DecodedJson["status"]);
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Alert", ex.Message, "Ok");

                return(false);
            }
        }
        public static async Task <bool> BookAppointment(int UserID, String DateBooked, TimeSpan TimeBooked, MedicalPractitionerType AppointmentType, int MedPRactID, String Description, String PhoneNo)
        {
            String Time12Hours = "", Meridiem = "";
            int    hours = Convert.ToInt32(TimeBooked.ToString("hh"));

            if (hours > 12)
            {
                Time12Hours += (hours - 12);
                Meridiem    += "PM";
            }
            else if (hours == 0)
            {
                Time12Hours += "12";
                Meridiem    += "AM";
            }
            else if (hours == 12)
            {
                Time12Hours += "12";
                Meridiem    += "PM";
            }
            else
            {
                Time12Hours += hours;
                Meridiem    += "AM";
            }

            Time12Hours += ":" + TimeBooked.ToString("mm");
            Time12Hours += " ";
            Time12Hours += Meridiem;

            Dictionary <int, String[]> Data = new Dictionary <int, string[]>
            {
                { 0, new String[] { "user_id", Utilities.ID.ToString() } },
                { 1, new String[] { "entity_id", MedPRactID.ToString() } },
                { 2, new String[] { "appointment_type", (AppointmentType == MedicalPractitionerType.Doctor) ? "p" : "i" } },
                { 3, new String[] { "time", Time12Hours } },
                { 4, new String[] { "phone_number", PhoneNo } },
                { 5, new String[] { "description", Description } },
                { 6, new String[] { "date", DateBooked } },
            };

            try
            {
                String ResponseJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), "user/appointments/new");

                var DecodedJson = JObject.Parse(ResponseJson);
                if (!(bool)DecodedJson["status"])
                {
                    await App.Current.MainPage.DisplayAlert("Alert", DecodedJson["message"].ToString(), "ok");
                }
                return(Convert.ToBoolean(DecodedJson["status"]));
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Alert", ex.Message, "ok");

                return(false);
            }
        }
        public static async Task <int> AppointmentStatus(int RequestStatus, int AppointmentID, int UserID)
        {
            String ResponseJson = "";

            Dictionary <int, String[]> Data = new Dictionary <int, string[]>
            {
                { 0, new String[] { "id", AppointmentID.ToString() } },
                { 1, new String[] { "status", RequestStatus.ToString() } },
            };

            if (RequestStatus == -1)
            {
                Data.Add(2, new String[] { "remark", "Appointment Rejected." });
            }

            try
            {
                if (RequestStatus == 0)
                {
                    await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), "user/appointments/");

                    return(0);
                }
                else
                {
                    ResponseJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), "user/appointments/");

                    var DecodedJson = JObject.Parse(ResponseJson);

                    //status message
                    if ((bool)DecodedJson["status"] && (int)DecodedJson["appointment_status"] == 1)
                    {
                        bool InitMessage = await ChatController.SendChat(UserID, "{Appointment Accepted, Default Message}");

                        if (InitMessage)
                        {
                            return(1);
                        }
                        return(0);
                    }
                    else if ((bool)DecodedJson["status"] && (int)DecodedJson["appointment_status"] != 1)
                    {
                        return((int)DecodedJson["appointment_status"]);
                    }
                    else
                    {
                        return(-2);
                    }
                }
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Alert", ex.Message, "ok");

                return(-1);
            }
        }
        public static async Task <bool> PostMedicalRecords(String Record, String Title, int UserID, RecordType UserRecordType)
        {
            ///for entity id, if personal currently using a default medic id
            Dictionary <int, String[]> Data = new Dictionary <int, string[]>
            {
                { 0, new String[] { "user_id", (UserRecordType == RecordType.Personal)? Utilities.ID.ToString() : UserID.ToString() } },
                { 1, new String[] { "entity_id", (UserRecordType == RecordType.Personal) ? "1" : Utilities.MedicID.ToString() } },
                { 2, new String[] { "description", "{" + Enum.GetName(typeof(RecordType), UserRecordType) + "}{Title [length=" + Title.Length + "]:" + Title + "}{Content [length=" + Record.Length + "]:" + Record + "}" } },
            };

            try
            {
                String URL = "";
                switch (UserRecordType)
                {
                case RecordType.Personal:
                    URL = "user/medical-records/new";
                    break;

                case RecordType.Drug:
                    URL = "user/prescribtions/new";
                    break;

                case RecordType.Lab:
                    URL = "user/lab-results/new";
                    break;

                case RecordType.Medical:
                    URL = "user/medical-records/new";
                    break;
                }

                String ResultJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), URL);

                var DecodedJson = JObject.Parse(ResultJson);
                return((bool)DecodedJson["status"]);
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Alert", ex.Message, "Ok");

                return(false);
            }
        }
        public static async Task ListMedicalPractioner(StackLayout Stack, MedicalPractitionerType MPType)
        {
            Device.BeginInvokeOnMainThread(delegate { Stack.Children.Clear(); });

            //posting empty values as the PostAsync requires a FormUrlEncodedContent
            Dictionary <int, String[]> Data = new Dictionary <int, string[]>
            {
                { 0, new String[] { "n/a", "n/a" } },
            };

            String ResponseJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), (MPType == MedicalPractitionerType.Doctor)? "user/search/medics" : "user/search/institutions");

            var DecodedJson = JObject.Parse(ResponseJson);

            await Utilities.RunTask(async delegate
            {
                foreach (var Medic in DecodedJson["medics"])
                {
                    String MedicBioData = (MPType == MedicalPractitionerType.Doctor) ? await MedicalPractitionerController.GetBioDetails((int)Medic["medic"]["id"]) : "No Bio Data Provided";
                    MedicBioData        = (String.IsNullOrEmpty(MedicBioData) ? "No Bio Data provided." : MedicBioData);



                    Device.BeginInvokeOnMainThread(() =>
                    {
                        ///only add the child if it is of the same specialty type
                        //if ( Enum.GetName(typeof(MedicalPractitionerType),MPType) ==  ((MPType == MedicalPractitionerType.Doctor) ? Enum.GetName(typeof(MedicalPractitionerType), Medic["medic"]["specialty"]) : Enum.GetName(typeof(MedicalPractitionerType), Medic["specialty"]))) Stack.Children.Add(MedPractListTemplate.ListTemplate02((MPType == MedicalPractitionerType.Doctor) ? (int)Medic["medic"]["id"] : (int)Medic["id"], MPType, Medic["name"].ToString(), (MedicBioData.Length >= 25) ? MedicBioData.Substring(0, 25) : MedicBioData, new Random().Next(1, 6), Utilities.Source("doc_anim.jpg", typeof(AppointmentController)), 4.1, Medic["address"].ToString(), (MPType == MedicalPractitionerType.Doctor) ? Convert.ToDouble(Medic["medic"]["charge"]) : 0, String.Empty));
                        if (MPType == MedicalPractitionerType.Doctor)
                        {
                            Stack.Children.Add(MedPractListTemplate.ListTemplate02((MPType == MedicalPractitionerType.Doctor) ? (int)Medic["medic"]["id"] : (int)Medic["id"], MPType, Medic["name"].ToString(), (MedicBioData.Length >= 25) ? MedicBioData.Substring(0, 25) : MedicBioData, new Random().Next(1, 6), Utilities.Source("doc_anim.jpg", typeof(AppointmentController)), 4.1, Medic["address"].ToString(), (MPType == MedicalPractitionerType.Doctor) ? Convert.ToDouble(Medic["medic"]["charge"]) : 0, String.Empty));
                        }
                        else
                        {
                            if (Enum.GetName(typeof(MedicalPractitionerType), MPType).ToLower() == Medic["category"].ToString().ToLower())
                            {
                                Stack.Children.Add(MedPractListTemplate.ListTemplate02((int)Medic["id"], MPType, Medic["name"].ToString(), (MedicBioData.Length >= 25) ? MedicBioData.Substring(0, 25) : MedicBioData, new Random().Next(1, 6), Utilities.Source("doc_anim.jpg", typeof(AppointmentController)), 4.1, Medic["address"].ToString(), 0, String.Empty));
                            }
                        }
                    });
                }
            });
        }
Exemplo n.º 7
0
        /// <summary>
        /// PostProfileDetails posts the user details
        /// </summary>
        /// <returns>
        /// String message showing status of the post
        /// </returns>
        public static async Task <bool> PostProfileDetails(String AccountNumber, String Charge, String BankName, String AccountName, String WorkingHours)
        {
            Dictionary <int, String[]> Data = new Dictionary <int, string[]>
            {
                { 0, new String[] { "account_number", AccountNumber.ToString() } },
                { 1, new String[] { "hourly_charge", Charge.ToString() } },
                { 2, new String[] { "bank_name", BankName.ToString() } },
                { 3, new String[] { "account_name", AccountName.ToString() } },
                { 4, new String[] { "working_hours", WorkingHours.ToString() } },
            };

            String ResultJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), "user/profile/medic/" + Utilities.MedicID);

            var DecodedJson = JObject.Parse(ResultJson);

            if ((bool)DecodedJson["status"])
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 8
0
        public static async Task <bool> PostBioDetails(String BioDetail)
        {
            Dictionary <int, String[]> Data = new Dictionary <int, string[]>
            {
                { 0, new String[] { "bio", BioDetail } },
            };

            try
            {
                String ResultJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), "user/profile/bio/" + Utilities.MedicID);

                var DecodedJson = JObject.Parse(ResultJson);
                return((bool)DecodedJson["status"]);
            }
            catch
            {
                await App.Current.MainPage.DisplayAlert("Alert", "An Error occurred while fecting your Bio Data", "Ok");

                return(false);
            }
        }
        public static async Task SearchMedicalPractioner(String Name, MedicalPractitionerType MPType, StackLayout Stack)
        {
            Device.BeginInvokeOnMainThread(delegate
            {
                Stack.Children.Clear();
            });

            Dictionary <int, String[]> Data = new Dictionary <int, string[]>
            {
                { 0, new String[] { "name", Name } },
            };

            String ResponseJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), (MPType == MedicalPractitionerType.Doctor)? "user/search/medics" : "user/search/institutions");

            var DecodedJson = JObject.Parse(ResponseJson);

            await Utilities.RunTask(async delegate
            {
                foreach (var Medic in DecodedJson["medics"])
                {
                    String MedicBioData = (MPType == MedicalPractitionerType.Doctor) ? await MedicalPractitionerController.GetBioDetails((int)Medic["medic"]["id"]) : "No Bio Data Provided";
                    MedicBioData        = (String.IsNullOrEmpty(MedicBioData) ? "No Bio Data provided." : MedicBioData);
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Stack.Children.Add(MedPractListTemplate.ListTemplate02((int)Medic["medic"]["id"], MPType, Medic["name"].ToString(), MedicBioData.Substring(0, 25), new Random().Next(1, 6), Utilities.Source("doc_anim.jpg", typeof(AppointmentController)), 4.1, Medic["address"].ToString(), Convert.ToDouble(Medic["medic"]["charge"]), String.Empty));
                    });
                }
            });

            //no result
            Device.BeginInvokeOnMainThread(delegate
            {
                if (Stack.Children.Count == 0)
                {
                    Stack.Children.Add(new Label {
                        Text = "Search returned no result. Please verify supplied name.", Style = App.Current.Resources["_EmptyLabelTemplate"] as Style
                    });
                }
            });
        }
Exemplo n.º 10
0
        public static async Task Withdraw(int Amount)
        {
            //user_id & amount

            Dictionary <int, String[]> Data = new Dictionary <int, string[]>
            {
                { 0, new String[] { "user_id", Utilities.ID.ToString() } },
                { 1, new String[] { "amount", Amount.ToString() } },
            };

            try
            {
                String ResponseJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), "user/withdraw");

                await App.Current.MainPage.DisplayAlert("Alert", ResponseJson, "Ok");
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Alert", ex.Message, "Ok");
            }


            //var DecodedJson = JObject.Parse(ResponseJson);
        }
        public static async Task GetMedicalRecords(RecordType UserRecordType, StackLayout ParentStack)
        {
            Dictionary <String, String> ResultingData = new Dictionary <String, String>();

            Dictionary <int, String[]> Data = new Dictionary <int, string[]>
            {
                { 0, new String[] { "user_id", Utilities.ID.ToString() } },
            };

            String URL = "";

            switch (UserRecordType)
            {
            case RecordType.Personal:
                URL = "user/medical-records/search";
                break;

            case RecordType.Drug:
                URL = "user/prescribtions/search";
                break;

            case RecordType.Lab:
                URL = "user/lab-results/search";
                break;

            case RecordType.Medical:
                URL = "user/medical-records/search";
                break;
            }

            try
            {
                int NoOfChangesMade = 0;

                String ResultJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), URL);


                var DecodedJson = JObject.Parse(ResultJson);

                if ((int)DecodedJson["records"] > 0)
                {
                    foreach (var Child in DecodedJson["results"])
                    {
                        ///StoredContent returns as e.g "{Personal/Medical/Drug/Lab}{Title [length=17]:Title goes here}{Content [lenght=42]:Content goes here}"
                        String StoredContent = Child["description"].ToString();


                        String CurrentRecordType = StoredContent.Substring((StoredContent.IndexOf('{') + 1), ((StoredContent.IndexOf('}') - 1)));

                        ///if record isnt personal when user clicks "Personal Record" skip
                        if (UserRecordType == RecordType.Personal)
                        {
                            if (CurrentRecordType != Enum.GetName(typeof(RecordType), UserRecordType))
                            {
                                continue;
                            }
                        }
                        else if (UserRecordType == RecordType.Medical)
                        {
                            if (CurrentRecordType != Enum.GetName(typeof(RecordType), UserRecordType))
                            {
                                continue;
                            }
                        }



                        ///strip out the record type
                        StoredContent = StoredContent.Replace("{" + CurrentRecordType + "}", "");

                        ///{Title [length=17]:Title goes here}


                        ///Title = "Title [length=17]:Title goes here"
                        String Title = StoredContent.Substring(StoredContent.IndexOf('{') + 1, ((StoredContent.IndexOf('}') - 1)));

                        ///get the length of the title e.g "Title goes here" == 17 i.e [length=17]
                        int TitleLength = Convert.ToInt32(Title.Substring(Title.IndexOf('[') + 1, ((Title.IndexOf(']')) - (Title.IndexOf('[') + 1))).Replace("length=", ""));

                        ///Title = Title goes here
                        Title = StoredContent.Substring((StoredContent.IndexOf(':') + 1), TitleLength);

                        ///strip out title
                        StoredContent = StoredContent.Replace("{Title [length=" + TitleLength + "]:" + Title + "}", "");

                        String Content = StoredContent.Substring(StoredContent.IndexOf('{') + 1, ((StoredContent.IndexOf('}') - 1)));

                        int ContentLength = Convert.ToInt32(Content.Substring(Content.IndexOf('[') + 1, ((Content.IndexOf(']')) - (Content.IndexOf('[') + 1))).Replace("length=", ""));

                        Content = StoredContent.Substring((StoredContent.IndexOf(':') + 1), ContentLength);

                        NoOfChangesMade++;

                        Device.BeginInvokeOnMainThread(() =>
                        {
                            ParentStack.Children.Add(RecordTemplate.RecordTemplate01((int)Child["medic"]["id"], Title, Content, false));
                        });
                    }

                    if (NoOfChangesMade == 0)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            ParentStack.Children.Add(new Label {
                                Text = "No Records in this section currently.", Style = App.Current.Resources["_EmptyLabelTemplate"] as Style
                            });
                        });
                    }
                }
                else
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        ParentStack.Children.Add(new Label {
                            Text = "No Records in this section currently.", Style = App.Current.Resources["_EmptyLabelTemplate"] as Style
                        });
                    });
                }
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Alert", ex.StackTrace, "Ok");
            }
        }