示例#1
0
        public async Task testValidInteraction()
        {
            // Login to provide DrugAPI with gender + age

            await loginAPI.LoginUser("buzz", "drowssap");

            DrugInteractionResult result = await drugAPI.RetrieveDrugInteractions("Ibuprofen", "Asacol");

            Assert.AreEqual(69, result.ageInteractions.Count);
        }
        /*
         * Event handler to handle when a user selects medications and
         * wishes to compare them, sending a call off to the interactions API.
         */
        async void Handle_ComparePressed(object sender, EventArgs e)
        {
            Console.WriteLine("Compare pressed!");
            DrugInteractionAPI drugInteractionAPI = new DrugInteractionAPI();
            User loggedInUser = UserController.Instance.LoggedInUser;

            DrugInteractionResult retrievedDrugInteractions = await drugInteractionAPI.RetrieveDrugInteractions(selectedItem1.Text, selectedItem2.Text);

            if (!retrievedDrugInteractions.gotInteractions)
            {
                switch (retrievedDrugInteractions.resultStatusCode)
                {
                case HttpStatusCode.Accepted:
                    await DisplayAlert("Failed to get Interactions",
                                       "Interactions yet to be researched",
                                       "OK");

                    return;

                case HttpStatusCode.NotFound:
                    await DisplayAlert("Failed to get Interactions",
                                       "One or both of the drugs are invalid",
                                       "OK");

                    return;

                case HttpStatusCode.BadGateway:
                    await DisplayAlert("Failed to get Interactions",
                                       "The Drug Interactions API is currently down",
                                       "OK");

                    return;

                case HttpStatusCode.BadRequest:
                    await DisplayAlert("Failed to get Interactions",
                                       "Please ensure you are connected to the internet",
                                       "OK");

                    return;
                }
            }



            string interactionsBody = String.Format("{0}y/o {1}\n\n{2}\n\n{3}\n\n{4}",
                                                    loggedInUser.Age,
                                                    loggedInUser.gender,
                                                    string.Join("\r\n", retrievedDrugInteractions.genderInteractions),
                                                    string.Join("\r\n", retrievedDrugInteractions.ageInteractions),
                                                    string.Join("\r\n", retrievedDrugInteractions.durationInteractions));

            await DisplayAlert(String.Format("Interactions between {0} and {1}", selectedItem1.Text, selectedItem2.Text),
                               interactionsBody,
                               "OK");
        }