Beispiel #1
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 #2
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"
                }
            };
        }