Beispiel #1
0
        public static IList<DrugFormulation> FindByDrug(Drug d)
        {
            if( d == null || d.ID == null )
                return new List<DrugFormulation>();

            return FindByDrug(d.ID.Value);
        }
Beispiel #2
0
        public static IList<DrugVersion> FindByDrug(Drug d)
        {
            if(d == null || d.ID == null)
                return new List<DrugVersion>();

            return FindAllBy<DrugVersion>( new Dictionary<string, object> {
                { "DrugID", d.ID.Value }
            }, new [] { "-Version" } );
        }
Beispiel #3
0
        public static ReturnObject Edit(HttpContext context, Dictionary<string, object> drug_selection)
        {
            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");

                    // check for an existing selection (update)
                    var drugSelection = DrugSelection.Find(prescriber.ID ?? 0, drug.ID ?? 0)
                        ?? new DrugSelection
                        {
                            PrescriberID = prescriber.ID ?? 0,
                            DrugID = drug.ID ?? 0
                        };

                    // record the selected value
                    drugSelection.Prescribes = ((string)drug_selection[key]).ToLower() == "yes";
                    drugSelection.DateRecorded = DateTime.Now;

                    drugSelection.Save();

                    // now add the drug to the prescriber
                    if(drugSelection.Prescribes)
                        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.",
                null,
                "Default.aspx#dashboard");
        }
Beispiel #4
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)
                        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.",
                "prescriber/wizards/non-etasu-selections");
        }
        public override void Run()
        {
            Lib.Data.Drug drug = new Lib.Data.Drug(DrugId);
            Prescriber prescriber = new Prescriber(PrescriberId);
            User user = new User(prescriber.Profile.UserID);

            StringBuilder message = new StringBuilder();

            message.Append("Your certification for ");
            message.Append(drug.GenericName);
            message.Append(" needs to be renewed.");

            Notification n = NotificationService.Create(
                "Certification renewal notice",
                message.ToString(),
                true,
                NotificationService.DataType.Drug,
                DrugId);

            NotificationService.Send(n, user, NotificationService.Templates.HCOReminder);
        }
Beispiel #6
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)
                {
                    Lib.Data.Drug drug = new Lib.Data.Drug(long.Parse(selection));

                    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();
            }
            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");
        }
Beispiel #7
0
 public static DrugVersion FindLatestByDrug(Drug d)
 {
     return FindLatestByDrug(d.ID);
 }
Beispiel #8
0
        public static ReturnObject DenyVersion(HttpContext context, long drug_id, long drug_version_id, string message)
        {
            var drug = new Lib.Data.Drug(drug_id);
            var drug_version = new Lib.Data.DrugVersion(drug_version_id);

            if (!drug.ID.HasValue || drug.ID.Value != drug_id || drug.ID.Value != drug_version.DrugID)
                return new ReturnObject { Error = true, Message = "Invalid Drug Version." };

            if (drug_version.Status != "Pending")
                return new ReturnObject { Error = true, Message = "Can not deny versions that are not pending." };

            var u = Framework.Security.Manager.GetUser();

            drug_version.Status = "Denied";
            drug_version.ReviewedBy = u.ID;
            drug_version.Reviewed = DateTime.Now;
            drug_version.DenyReason = message;
            drug_version.Save();

            var n = NotificationService.Create(
                        drug.GenericName + " Denied",
                        "You changes were denied, please see below.<br /><br />" + message,
                        true,
                        NotificationService.DataType.Drug,
                        drug.ID.Value );
            NotificationService.Send( n, new Framework.Security.User( drug_version.UpdatedBy ), NotificationService.Templates.NewsAndUpdates );

            return new ReturnObject
            {
                Result = null,
                Growl = new ReturnGrowlObject
                {
                    Type = "default",
                    Vars = new ReturnGrowlVarsObject
                    {
                        text = "You have denied the pending changes to this drug.",
                        title = "Changes Denied"
                    }
                },
                Redirect = new ReturnRedirectObject
                {
                    Hash = "admin/drugs/drugs/list?pending=true"
                }
            };
        }
Beispiel #9
0
        public static ReturnObject ApproveVersion(HttpContext context, long drug_id, long drug_version_id, string message = null)
        {
            var drug = new Lib.Data.Drug(drug_id);
            var drug_version = new Lib.Data.DrugVersion(drug_version_id);

            if( !drug.ID.HasValue || drug.ID.Value != drug_id || drug.ID.Value != drug_version.DrugID )
                return new ReturnObject { Error = true, Message = "Invalid Drug Version." };

            if( drug_version.Status != "Pending" )
                return new ReturnObject { Error = true, Message = "Can not approve versions that are not pending." };

            var u = Framework.Security.Manager.GetUser();

            var changes = Lib.Data.DSQ.AnswerVersion.FindByDrugVersion(drug.ID.Value, drug_version.Version);

            foreach( var change in changes )
            {
                var ans = new Lib.Data.DSQ.Answer(change.DSQAnswerID);
                ans.Value = change.Value;
                ans.Save();
            }

            drug_version.Status = "Approved";
            drug_version.ReviewedBy = u.ID;
            drug_version.Reviewed = DateTime.Now;
            drug_version.Save();

            drug.DetermineEOC();

            Lib.Systems.Lists.UpdateDrugLists( drug );
            SendNotification(drug);

            if( !string.IsNullOrWhiteSpace( message ) )
            {
                var n = NotificationService.Create(
                        drug.GenericName + " Approved",
                        "You changes were approved, <br /><br />" + message,
                        true,
                        NotificationService.DataType.Drug,
                        drug.ID.Value );
                NotificationService.Send( n, new Framework.Security.User( drug_version.UpdatedBy ), NotificationService.Templates.NewsAndUpdates );
            }

            return new ReturnObject()
            {
                Result = null,
                Growl = new ReturnGrowlObject
                {
                    Type = "default",
                    Vars = new ReturnGrowlVarsObject
                    {
                        text = "You have successfully approved changes to this drug.",
                        title = "Changes Approved"
                    }
                },
                Redirect = new ReturnRedirectObject
                {
                    Hash = "admin/drugs/drugs/list?pending=true"
                }
            };
        }
Beispiel #10
0
        public static ReturnObject Edit(HttpContext context, string generic_name, long class_id, long? id = null, string rems_reason = null, string indication = null, long? system_id = null, string rems_website = null, string fda_number = null, DateTime? rems_approved = null, DateTime? rems_updated = null, bool active = false, bool new_version = false, string message = null, Newtonsoft.Json.Linq.JArray questions = null)
        {
            Lib.Data.Drug item = null;
            if (id > 0)
                item = new Lib.Data.Drug(id);
            else
                item = new Lib.Data.Drug();

            var u = Framework.Security.Manager.GetUser();
            bool approved = true;

            if( u.IsInGroup(Framework.Security.Group.FindByName("drugcompany")) )
            {
                approved = false;
                new_version = true;
            }

            if (new_version && string.IsNullOrEmpty(message))
                return new ReturnObject { Error = true, Message = "You must enter a message when you save a new version." };

            if( Lib.Systems.Drugs.HasPendingChanges(item) )
                return new ReturnObject { Error = true, Message = "You can not modify a drug that has pending changes." };

            item.GenericName = generic_name;
            item.RemsReason = rems_reason;
            item.Indication = indication;
            item.ClassID = class_id;
            item.SystemID = system_id;
            item.RemsProgramUrl = rems_website;
            item.FdaApplicationNumber = fda_number;
            item.RemsApproved = rems_approved;
            item.RemsUpdated = rems_updated;
            item.Active = active;
            item.UpdatedByID = u.ID.Value;
            item.Updated = DateTime.Now;

            item.Save();

            if (id <= 0)
            {
                new_version = true;
                message = "New Drug Created.";
            }

            Data.DrugVersion ver = null;
            if (new_version)
            {
                var last_version = Data.DrugVersion.FindLatestByDrug(item);

                ver = new Data.DrugVersion();
                ver.DrugID = item.ID.Value;
                ver.Message = message;
                ver.Version = ((last_version == null) ? 1 : last_version.Version + 1);
                ver.Updated = DateTime.Now;
                ver.UpdatedBy = u.ID.Value;
                ver.Status = (approved ? "Approved" : "Pending");

                if( approved )
                {
                    ver.Reviewed = DateTime.Now;
                    ver.ReviewedBy = u.ID.Value;
                }

                // MJL - changed to always send notification no matter what (even if
                // it was auto approved.
                StringBuilder notificationMsg = new StringBuilder();

                notificationMsg.Append(item.GenericName);
                notificationMsg.Append(" has new pending changes for you to review (version ");
                notificationMsg.Append(ver.Version);
                notificationMsg.Append(" - ");
                notificationMsg.Append(ver.Updated.ToShortDateString());
                notificationMsg.Append(")");

                // MJL - if the version was auto-approved (because user is admin), note
                // that in the message.
                if(approved)
                    notificationMsg.Append(". This version was automatically approved.");

                var n = NotificationService.Create(
                    item.GenericName + " Update",
                    notificationMsg.ToString(),
                    true,
                    NotificationService.DataType.Drug,
                    item.ID.Value);
                NotificationService.Send(n, Group.FindByName("admin"), NotificationService.Templates.NewsAndUpdates);

                ver.Save();
            }

            if (questions != null)
            {
                var ids = new List<long>();

                foreach (var o in questions)
                {
                    var oid = o.Value<string>("id");
                    var ovalue = o.Value<object>("value");

                    long lid;
                    if (!long.TryParse(oid, out lid))
                        continue;

                    var question = new Lib.Data.DSQ.Question(lid);
                    if (!question.ID.HasValue || question.ID.Value != lid)
                        continue;

                    ids.Add(lid);

                    string v;

                    #region Parse Value from Request
                    if (ovalue == null)
                    {
                        v = null;
                    }
                    else if (ovalue.GetType() == typeof(string))
                    {
                        v = (string)ovalue;
                    }
                    else if (ovalue.GetType() == typeof(Newtonsoft.Json.Linq.JValue))
                    {
                        var t = (Newtonsoft.Json.Linq.JValue)ovalue;

                        v = (string)t.Value;
                    }
                    else if (ovalue.GetType() == typeof(Newtonsoft.Json.Linq.JArray))
                    {
                        var t = (Newtonsoft.Json.Linq.JArray)ovalue;

                        v = "";

                        for (int i = 0; i < t.Count; i++)
                        {
                            if (!string.IsNullOrEmpty(v))
                                v += "\n";

                            v += (string)t[i];
                        }
                    }
                    else
                    {
                        return new ReturnObject() { Result = ovalue, Error = true, Message = "Invalid value for question [" + oid + "]. {" + question.Text + "} {" + ovalue.GetType().FullName + "}" };
                    }

                    if (v != null && v.Trim() == "")
                        v = null;
                    #endregion

                    var answer = Lib.Data.DSQ.Answer.FindByDrug(item, question);

                    /*
                    // if it's a text area, process any Markdown that might be present
                    if(question.FieldType == "TextArea")
                        v = markdownSvc.ToHtml(v);
                    */

                    if (answer == null || answer.DrugID != item.ID.Value || answer.QuestionID != lid)
                    {
                        answer = new Data.DSQ.Answer();
                        answer.DrugID = item.ID.Value;
                        answer.QuestionID = lid;
                        answer.Value = null;
                        answer.Save();
                    }

                    if( new_version && answer.Value != v )
                    {
                        var av = new Lib.Data.DSQ.AnswerVersion();
                        av.DSQAnswerID = answer.ID.Value;
                        av.Value = v;
                        av.Version = ver.Version;
                        av.Save();
                    }

                    if( approved )
                    {
                        answer.Value = v;
                        answer.Save();
                    }
                }

                if( approved )
                {
                    var lqs = Lib.Data.DSQ.Question.FindAll();

                    foreach (var lq in lqs)
                    {
                        if (lq == null || lq.ID == null || ids.Contains(lq.ID.Value))
                            continue;

                        var a = Lib.Data.DSQ.Answer.FindByDrug(item, lq);

                        if (a == null)
                            continue;

                        a.Delete();
                    }
                }
            }

            if( approved )
            {
                item.DetermineEOC();
                Lib.Systems.Lists.UpdateDrugLists( item );
            }

            return new ReturnObject()
            {
                Result = item,
                Redirect = new ReturnRedirectObject
                {
                    Hash = "admin/dsq/edit?id=" + item.ID.Value.ToString(CultureInfo.InvariantCulture)
                },
                Growl = new ReturnGrowlObject
                {
                    Type = "default",
                    Vars = new ReturnGrowlVarsObject
                    {
                        text = "You have successfully saved this drug.",
                        title = "Drug Saved"
                    }
                },
                Actions = new List<ReturnActionObject>
                {
                    new ReturnActionObject
                    {
                        Type = "reset-unsaved"
                    }
                }
            };
        }