public ActionResult CompleteSubject(SubjectCompleted model, HttpPostedFileBase file)
        {
            ViewBag.Confirmation = "true";
            //file upload
            if (model.NotCompletedReason == null)
            {
                model.NotCompletedReason = "";
            }

            string path = Request.PhysicalApplicationPath;

            //don't upload if hpTest - this could overwrite a production file
            if (!path.Contains("Prod"))
            {
                model.CgmUpload = true;
            }
            else
            {
                if (file != null && file.ContentLength > 0)
                {
                    //validate file size must be less than 500000 bytes
                    if (file.ContentLength > 500000)
                    {
                        ModelState.AddModelError("",
                                                 "*The file being uploaded is too large, make sure you selected the correct file to upload");
                    }
                    else
                    {
                        //validate file type
                        var fileName = Path.GetFileName(file.FileName);
                        _nlogger.LogInfo("CGM Upload - fileName: " + fileName);
                        var extension = Path.GetExtension(file.FileName).ToUpper();
                        if (extension != ".TXT")
                        {
                            ModelState.AddModelError("", "*The file being uploaded must end with .txt");
                        }
                        else
                        {
                            var folderPath     = ConfigurationManager.AppSettings["CgmUploadPath"].ToString();
                            var folderSitePath = Path.Combine(folderPath, model.SiteName);
                            _nlogger.LogInfo("CGM Upload - path: " + folderSitePath);
                            if (!Directory.Exists(folderSitePath))
                            {
                                Directory.CreateDirectory(folderSitePath);
                            }

                            var newName  = model.StudyID.Trim() + "_CGM.csv";
                            var fullPath = Path.Combine(folderSitePath, newName);
                            file.SaveAs(fullPath);
                            model.CgmUpload = true;
                        }
                    }
                }
            }

            bool isOkToClear = true;

            if (!model.CgmUpload)
            {
                isOkToClear = false;
                ModelState["CgmUpload"].Errors.Clear();
                //ModelState["CgmUpload"].Errors.Add("*The CGM file upload is required.  Enter a reason if you can not provide this data.");
                ModelState.AddModelError("", "*The CGM file upload is required.  Enter a reason if you can not provide this data.");
            }
            if (model.DateCompleted == null)
            {
                isOkToClear = false;
                ModelState["DateCompleted"].Errors.Clear();
                //ModelState["DateCompleted"].Errors.Add("*Date completed  is required.  Enter a reason if you can not provide this data.");
                ModelState.AddModelError("", "*Date completed  is required.  Enter a reason if you can not provide this data.");
            }
            if (model.RowsCompleted == null)
            {
                isOkToClear = false;
                ModelState["RowsCompleted"].Errors.Clear();
                //ModelState["DateCompleted"].Errors.Add("*Date completed  is required.  Enter a reason if you can not provide this data.");
                ModelState.AddModelError("", "*Number of CHECKS rows completed  is required.  Enter a reason if you can not provide this data.");
            }
            if (model.Age2to16)
            {
                if (!model.CBCL)
                {
                    isOkToClear = false;
                    ModelState["CBCL"].Errors.Clear();
                    ModelState.AddModelError("", "You must certify with a check mark that CBCL has been collected and sent to the CCC.  Enter a reason if you can not provide this data.");
                }
                if (!model.Demographics)
                {
                    isOkToClear = false;
                    ModelState["Demographics"].Errors.Clear();
                    ModelState.AddModelError("", "You must certify with a check mark that subject demographics has been collected and sent to the CCC.  Enter a reason if you can not provide this data.");
                }
                if (!model.PedsQL)
                {
                    isOkToClear = false;
                    ModelState["PedsQL"].Errors.Clear();
                    ModelState.AddModelError("", "You must certify with a check mark that Peds-QL has been collected and sent to the CCC.  Enter a reason if you can not provide this data.");
                }
                if (!model.ContactInfo)
                {
                    isOkToClear = false;
                    ModelState["ContactInfo"].Errors.Clear();
                    ModelState.AddModelError("", "You must certify with a check mark that subject contact information has been collected.  Enter a reason if you can not provide this data.");
                }
            }

            if (!isOkToClear)
            {
                //the client shoud catch this - if we get this far then
                //the user did not provide all required fields and didn't
                //give a reason
                bool isReason = false;
                if (model.NotCompletedReason != null)
                {
                    if (model.NotCompletedReason.Trim().Length > 0)
                    {
                        isReason = true;
                    }
                }

                if (!isReason)
                {
                    string role = "";
                    if (HttpContext.User.IsInRole("Admin"))
                    {
                        role = "Admin";
                    }
                    ViewBag.Role         = role;
                    ViewBag.Confirmation = "false";

                    return(View(model));
                }
            }

            if (isOkToClear)
            {
                model.Cleared = true;
            }

            DbUtils.SaveRandomizedSubjectActive(model, User.Identity.Name);

            //send email for non completion
            var siteId = DbUtils.GetSiteidIdForUser(User.Identity.Name);
            var staff  = NotificationUtils.GetStaffForEvent(2, siteId);

            var    u   = new UrlHelper(this.Request.RequestContext);
            string url = "http://" + Request.Url.Host + u.RouteUrl("Default", new { Controller = "Home", Action = "Index" });

            Utility.SendCompleteSubjectMail(staff.ToArray(), null, url, Server, model, User.Identity.Name);

            return(View(model));
        }
Exemple #2
0
        public static void SendCompleteSubjectMail(string[] toAddress, string[] ccAddress, string url, HttpServerUtilityBase server, SubjectCompleted sc, string user)
        {
            string subject = "";
            string yesNo = "";
            if (sc.Cleared)
                subject = "Subject completed - " + sc.SiteName + " - SubjectID: " + sc.StudyID;
            else
                subject = "Subject completed (did not enter all required info) - " + sc.SiteName + " - SubjectID: " + sc.StudyID;
            
            StringBuilder sbBody = new StringBuilder("<div>Site: " + sc.SiteName + " - Subject ID: " + sc.StudyID + " - User name: " + user + "</div>");
            
            sbBody.Append("<br/>");
            sbBody.Append("Date Completed: " + (sc.DateCompleted !=null ? sc.DateCompleted.Value.ToString("MM/dd/yyyy") : ""));
            sbBody.Append("<br/>");

            if (sc.CgmUpload)
                yesNo = "yes";
            else
                yesNo = "no";
            sbBody.Append("CGM file upload: " + yesNo);
            sbBody.Append("<br/>");
                        
            if (sc.Age2to16)
                yesNo = "yes";
            else
                yesNo = "no";
            sbBody.Append("Older than 2 and less than 17: " + yesNo);
            sbBody.Append("<br/>");
            if (sc.Age2to16)
            {
                sbBody.Append("The following have been collected and sent to the CCC:");
                sbBody.Append("<br/>");
                
                if (sc.CBCL)
                    yesNo = "yes";
                else
                    yesNo = "no";
                sbBody.Append("CBCL: " + yesNo);
                sbBody.Append("<br/>");

                if (sc.PedsQL)
                    yesNo = "yes";
                else
                    yesNo = "no";
                sbBody.Append("PedsQL: " + yesNo);
                sbBody.Append("<br/>");

                if (sc.Demographics)
                    yesNo = "yes";
                else
                    yesNo = "no";
                sbBody.Append("Subject demographics: " + yesNo);
                sbBody.Append("<br/>");

                
                if (sc.ContactInfo)
                    yesNo = "yes";
                else
                    yesNo = "no";
                sbBody.Append("Subject contact information has been collected and stored at site: " + yesNo);
                sbBody.Append("<br/>");
            }
            if (sc.NotCompletedReason.Trim().Length > 0)
            {
                sbBody.Append("Reason for Not providing all required data:");
                sbBody.Append("<br/>");
                sbBody.Append(sc.NotCompletedReason);
            }
            string siteUrl = "Click here to logon to the website: <a href='" + url + "'>HalfpintStudy.org</a>";
            SendHtmlEmail(subject, toAddress, ccAddress, sbBody.ToString(), server, siteUrl, "");
        }