예제 #1
0
        private Content.Reports.ResidentialReport ResidentialReport(long id)
        {
            API.ReportsController       reportsController       = new API.ReportsController();
            API.ProgramsController      programsController      = new API.ProgramsController();
            API.TypesController         typesController         = new API.TypesController();
            API.RestraintsController    restraintsController    = new API.RestraintsController();
            API.DetailsController       detailsController       = new API.DetailsController();
            API.MedicalsController      medicalsController      = new API.MedicalsController();
            API.SignaturesController    signaturesController    = new API.SignaturesController();
            API.UsersController         usersContoller          = new API.UsersController();
            API.StaffController         staffController         = new API.StaffController();
            API.NotificationsController notificationsController = new API.NotificationsController();
            API.NotifyPartiesController notifyPartiesController = new API.NotifyPartiesController();
            API.CommentsController      commentsController      = new API.CommentsController();
            API.AttachmentsController   attachmentsController   = new API.AttachmentsController();

            var reportHeader     = Models.Converters.ListToDataSet.ToDataTable <Models.IncidentReport>(reportsController.Print_GetIncidentReport(id).ToList());
            var programs         = Models.Converters.ListToDataSet.ToDataTable <Models.IncidentProgram>(programsController.Get().ToList());
            var incidentTypes    = Models.Converters.ListToDataSet.ToDataTable <Models.IncidentType>(typesController.Get().ToList());
            var reportIncidents  = Models.Converters.ListToDataSet.ToDataTable <Models.ReportIncident>(typesController.Print_GetReportIncidents(id).ToList());
            var restraints       = Models.Converters.ListToDataSet.ToDataTable <Models.Restraint>(restraintsController.Get(id).ToList());
            var incidentDetails  = Models.Converters.ListToDataSet.ToDataTable <Models.IncidentDetail>(detailsController.Print(id).ToList());
            var medicals         = Models.Converters.ListToDataSet.ToDataTable <Models.Medical>(medicalsController.Print_GetMedicals(id).ToList());
            var reportSignatures = Models.Converters.ListToDataSet.ToDataTable <Models.Presentation.ReportSignsViewModel>(signaturesController.Print(id).ToList());
            var reportSigTypes   = Models.Converters.ListToDataSet.ToDataTable <Models.ReportSigType>(signaturesController.GetTypes().ToList());
            var users            = Models.Converters.ListToDataSet.ToDataTable <Models.User>(usersContoller.Get().ToList());
            var incidentStaff    = Models.Converters.ListToDataSet.ToDataTable <Models.IncidentStaff>(staffController.Get(id).ToList());
            var notifications    = Models.Converters.ListToDataSet.ToDataTable <Models.Notification>(notificationsController.Print(id).ToList());
            var notifyParties    = Models.Converters.ListToDataSet.ToDataTable <Models.NotifyParty>(notifyPartiesController.Print().ToList());
            var adminComments    = Models.Converters.ListToDataSet.ToDataTable <Models.AdminComment>(commentsController.Print(id).ToList());
            var attachments      = Models.Converters.ListToDataSet.ToDataTable <Models.IncidentAttachment>(attachmentsController.Print(id).ToList());



            reportsController.Dispose();
            programsController.Dispose();
            typesController.Dispose();
            restraintsController.Dispose();
            detailsController.Dispose();
            medicalsController.Dispose();
            signaturesController.Dispose();
            usersContoller.Dispose();
            staffController.Dispose();
            notificationsController.Dispose();
            notifyPartiesController.Dispose();
            commentsController.Dispose();
            attachmentsController.Dispose();


            Reports.ResidentialReport report = new Reports.ResidentialReport();
            report.Load();


            report.Database.Tables["IncidentReport"].SetDataSource(reportHeader);
            report.Database.Tables["IncidentPrograms"].SetDataSource(programs);

            var reportableIncidentsSubreport  = report.Subreports["ReportableIncidentsSubreport"];
            var significantIncidentsSubreport = report.Subreports["SignificantIncidentsSubreport"];
            var internalEventsSubreport       = report.Subreports["InternalEventsSubreport"];
            var restraintsSubreport           = report.Subreports["RestraintsSubreport"];
            var incidentDetailsSubreport      = report.Subreports["IncidentDetailsSubreport"];
            var notificationsSubreport        = report.Subreports["NotificationsSubreport"];
            var medicalsSubreport             = report.Subreports["MedicalsSubreport"];
            var staffSubreport         = report.Subreports["StaffSubreport"];
            var adminCommentsSubreport = report.Subreports["AdminCommentsSubreport"];
            var signaturesSubreport    = report.Subreports["SignaturesSubreport"];
            var attachmentsSubreport   = report.Subreports["AttachmentsSubreport"];

            reportableIncidentsSubreport.Database.Tables["IncidentTypes"].SetDataSource(incidentTypes);
            reportableIncidentsSubreport.Database.Tables["ReportIncidents"].SetDataSource(reportIncidents);

            significantIncidentsSubreport.Database.Tables["IncidentTypes"].SetDataSource(incidentTypes);
            significantIncidentsSubreport.Database.Tables["ReportIncidents"].SetDataSource(reportIncidents);

            internalEventsSubreport.Database.Tables["IncidentTypes"].SetDataSource(incidentTypes);
            internalEventsSubreport.Database.Tables["ReportIncidents"].SetDataSource(reportIncidents);

            restraintsSubreport.Database.Tables["Restraints"].SetDataSource(restraints);

            incidentDetailsSubreport.Database.Tables["IncidentDetails"].SetDataSource(incidentDetails);

            notificationsSubreport.Database.Tables["Notifications"].SetDataSource(notifications);
            notificationsSubreport.Database.Tables["NotifyParties"].SetDataSource(notifyParties);
            notificationsSubreport.Database.Tables["Users"].SetDataSource(users);

            medicalsSubreport.Database.Tables["Medicals"].SetDataSource(medicals);
            medicalsSubreport.Database.Tables["Users"].SetDataSource(users);
            medicalsSubreport.Database.Tables["ReportSigns"].SetDataSource(reportSignatures);

            staffSubreport.Database.Tables["IncidentStaff"].SetDataSource(incidentStaff);

            adminCommentsSubreport.Database.Tables["AdminComments"].SetDataSource(adminComments);
            adminCommentsSubreport.Database.Tables["Users"].SetDataSource(users);

            signaturesSubreport.Database.Tables["ReportSigns"].SetDataSource(reportSignatures);
            signaturesSubreport.Database.Tables["ReportSigTypes"].SetDataSource(reportSigTypes);

            attachmentsSubreport.Database.Tables["IncidentAttachments"].SetDataSource(attachments);

            report.SetParameterValue("incidentId", id);

            return(report);
        }
        public void FinalApprove([FromBody] Models.Presentation.ReportSignatureModel signatureInfo)
        {
            Models.IncidentReport report = this._db.IncidentReports.Where(r => r.incidentId == signatureInfo.incidentId).SingleOrDefault();

            if (report != null)
            {
                string userName = System.Web.HttpContext.Current.User.Identity.Name.Substring(5).ToLower();
                if (userName.ToLower() != signatureInfo.userName.ToLower())
                {
                    throw new Exception("Current user information is not synchronized.  Cannot approve report.");
                }

                SessionController session = new SessionController();

                bool userVerified = session.VerifyPassword(userName, signatureInfo.signature);
                session.Dispose();

                if (userVerified)
                {
                    Models.ReportSign staffSignature = new Models.ReportSign();

                    staffSignature.incidentId        = signatureInfo.incidentId;
                    staffSignature.incidentMedicalId = 0;
                    staffSignature.reportSigType     = "E";
                    staffSignature.reportSigUserId   = signatureInfo.currentUser;
                    staffSignature.staffName         = signatureInfo.staffName;
                    staffSignature.staffTitle        = signatureInfo.staffTitle;
                    staffSignature.approvalStatusId  = 3;
                    staffSignature.reportSigStamp    = DateTime.Now;
                    staffSignature.reportSigStation  = signatureInfo.stationName;

                    this._db.ReportSigns.Add(staffSignature);



                    StaffController staffs     = new StaffController();
                    Models.User     supervisor = staffs.GetStaffSupervisor(signatureInfo.currentUser);
                    staffs.Dispose();


                    Models.ReportSign supervisorSignature = new Models.ReportSign();

                    supervisorSignature.incidentId        = signatureInfo.incidentId;
                    supervisorSignature.incidentMedicalId = 0;
                    supervisorSignature.reportSigType     = "S";
                    supervisorSignature.reportSigUserId   = supervisor.userId;
                    supervisorSignature.staffName         = supervisor.firstName + " " + supervisor.lastName;
                    supervisorSignature.staffTitle        = supervisor.jobTitle;
                    supervisorSignature.approvalStatusId  = 1;

                    this._db.ReportSigns.Add(supervisorSignature);



                    // WRITE CHANGES TO LOG

                    Models.ReportLog log = new Models.ReportLog();

                    log.incidentId  = signatureInfo.incidentId;
                    log.userId      = signatureInfo.currentUser;
                    log.userStation = signatureInfo.stationName;
                    log.logDateTime = DateTime.Now;
                    log.logDetails  = "Report signed by staff.";

                    this._db.ReportLogs.Add(log);



                    // EMAIL SUPERVISOR!!!! (INCLUDE ADMINS?)


                    MailController mailer      = new MailController();
                    StringBuilder  messageBody = new StringBuilder();
                    messageBody.Append("<p>A new incident report for <b>" + report.clientName + "</b> has been posted by " + report.staffName + ".</p>");
                    messageBody.Append("<p><a href=\"http://cfs-incidents/report/residential/" + report.incidentId.ToString() + "\">Click here to view the report.</a></p>");

                    mailer.SendMail(
                        new List <string>()
                    {
                        supervisor.eMail, "*****@*****.**"
                    },
                        "*****@*****.**",
                        "Incident Report Posted",
                        System.Net.Mail.MailPriority.High,
                        messageBody
                        );

                    mailer.Dispose();



                    report.statusId       = signatureInfo.statusId;
                    report.currentUser    = signatureInfo.currentUser;
                    report.lastModified   = DateTime.Now;
                    report.lastModifiedBy = signatureInfo.currentUser;

                    this._db.IncidentReports.Attach(report);
                    this._db.Entry(report).State = System.Data.Entity.EntityState.Modified;



                    this._db.SaveChanges();
                }
                else
                {
                    throw new Exception("Unable to validate signature.  Please use your current CFS account password to sign.");
                }
            }
        }