Exemple #1
0
        public static ReturnObject ETASUSelections(HttpContext context, Dictionary<string, object> drug_selection)
        {
            // THIS IMPLELEMTATION WILL NOT WORK LONG TERM.  CHECKBOXES = BAD
            try
            {
                var userProfile = Data.UserProfile.FindByUser(Framework.Security.Manager.GetUser());
                var prescriber = Data.Prescriber.FindByProfile(userProfile);

                // process each drug
                foreach(string key in drug_selection.Keys)
                {
                    long id = long.Parse(key);
                    Lib.Data.Drug drug = new Lib.Data.Drug(id);

                    if(!drug.Active)
                        throw new ArgumentException("That is not a valid drug", "drug_selections");

                    // record the selected value
                    var drugSelection = new DrugSelection
                    {
                        PrescriberID = prescriber.ID ?? 0,
                        DrugID = drug.ID ?? 0,
                        DateRecorded = DateTime.Now,
                        Prescribes = ((string)drug_selection[key]).ToLower() == "yes"
                    };

                    drugSelection.Save();

                    // now add the drug to the prescriber
                    if(drugSelection.Prescribes)
                        Prescriber.Drug.AddDrugToPrescriber(drug.ID ?? 0, 9999);
                }
            }
            catch(FormatException)
            {
                return Failure(404, "The selected drug does not exist in the system.");
            }
            catch(ArgumentException ex)
            {
                return Failure(404, ex.Message);
            }
            catch(SecurityException ex)
            {
                return Failure(403, ex.Message);
            }

            return Success(
                "Drugs Updated",
                "Your drug selections have been updated.",
                "ecommerce/wizards/non-etasu-selections");
        }
Exemple #2
0
        public static ReturnObject NonETASUSelections(HttpContext context, string[] drug_selections)
        {
            User user = Framework.Security.Manager.GetUser();

            // NonETASU seleciton is opitonal.  For this reason checkboxes are used and not radio
            // buttons.  Any drug in drug_selections has been selected by the user.
            try
            {
                var userProfile = Data.UserProfile.FindByUser(user);
                var prescriber = Data.Prescriber.FindByProfile(userProfile);

                // process each drug
                foreach(string selection in drug_selections)
                {
                    long drugId = long.Parse(selection);

                    if(drugId <= 0)
                        continue;

                    Lib.Data.Drug drug = new Lib.Data.Drug(drugId);

                    if(!drug.Active)
                        throw new ArgumentException("That is not a valid drug", "drug_selections");

                    // record the "yes" drug selection
                    var drugSelection = new DrugSelection
                    {
                        PrescriberID = prescriber.ID ?? 0,
                        DrugID = drug.ID ?? 0,
                        DateRecorded = DateTime.Now,
                        Prescribes = true
                    };

                    drugSelection.Save();

                    // now add the drug to the prescriber
                    Drug.AddDrugToPrescriber(drug.ID ?? 0, 9999);
                }

                SetAllRemainingDrugsToNo();

                userProfile.IsWizardComplete = true;
                userProfile.Save();
            }
            catch(FormatException)
            {
                return Failure(404, "The selected drug does not exist in the system.");
            }
            catch(ArgumentException ex)
            {
                return Failure(404, ex.Message);
            }
            catch(SecurityException ex)
            {
                return Failure(403, ex.Message);
            }

            NotificationService.Send(
                NotificationService.Create("Profile Complete", "You have successfully completed filling out your profile", false),
                user
                );

            return Success(
                "Drugs Updated",
                "Your drug selections have been updated.",
                null,
                "Default.aspx#prescriber/drugs/list");
        }