コード例 #1
0
        private DataTable SetFollowUpList()
        {
            // get user input
            DateTime processDate    = Convert.ToDateTime(ProcessDate.Text);
            string   selectedSurvey = ddlSurveyType.SelectedValue;
            string   procedureType  = ddlProcedure.Text;

            _redirectPath += "&proc=" + procedureType + "&processDate=" + processDate.ToShortDateString();


            FollowUpDA da             = new FollowUpDA();
            DataTable  surgPatientsDt = new DataTable();

            // return all patients with PtContactStatus as selected
            surgPatientsDt = da.GetActivePatientsForQOLFollowUp(processDate.ToShortDateString(), procedureType, selectedSurvey);

            DataTable  fuPatientsDt = new DataTable();
            DataColumn dc0          = new DataColumn("PatientId");
            DataColumn dc1          = new DataColumn("PtName");
            DataColumn dc2          = new DataColumn("PtMRN");
            DataColumn dc3          = new DataColumn("DueDate");
            DataColumn dc4          = new DataColumn("FUMonth");
            DataColumn dc5          = new DataColumn("ProcName");
            DataColumn dc6          = new DataColumn("ProcDate");
            DataColumn dc7          = new DataColumn("Surgeon");
            DataColumn dc8          = new DataColumn("SurveyName");
            DataColumn dc9          = new DataColumn("Address1");
            DataColumn dc10         = new DataColumn("Address2");
            DataColumn dc11         = new DataColumn("City");
            DataColumn dc12         = new DataColumn("State");
            DataColumn dc13         = new DataColumn("Zip");
            DataColumn dc14         = new DataColumn("LastName");
            DataColumn dc15         = new DataColumn("FirstName");

            fuPatientsDt.Columns.Add(dc14);
            fuPatientsDt.Columns.Add(dc15);
            fuPatientsDt.Columns.Add(dc0);
            fuPatientsDt.Columns.Add(dc1);
            fuPatientsDt.Columns.Add(dc2);
            fuPatientsDt.Columns.Add(dc3);
            fuPatientsDt.Columns.Add(dc4);
            fuPatientsDt.Columns.Add(dc5);
            fuPatientsDt.Columns.Add(dc6);
            fuPatientsDt.Columns.Add(dc7);
            fuPatientsDt.Columns.Add(dc8);
            fuPatientsDt.Columns.Add(dc9);
            fuPatientsDt.Columns.Add(dc10);
            fuPatientsDt.Columns.Add(dc11);
            fuPatientsDt.Columns.Add(dc12);
            fuPatientsDt.Columns.Add(dc13);

            // remove patients who don't belong;
            foreach (DataRow dr in surgPatientsDt.Rows)
            {
                DateTime surgDate = (DateTime)dr[Procedure.ProcDate];

                int  daysPriorToDueDate = -15;
                int  daysAfterDueDate;
                int  month, previousMonth;
                bool breakLoop = false;

                // TODO: HANDLE PRE_TREATMENT SURVEY
                //-- processingdate < scheduledSurgeryDate
                //-- AND PreOP has not been sent before
                //-- AND processDate is no earlier than 30 days before due date
                //-- AND IF it was sent before, make sure it was not 14 days or less ago
                //-- THEN Send PreOp

                if (processDate < surgDate) //means PRE-OP
                {
                    DateTime dueDate         = surgDate.AddDays(-14);
                    string   surveyShortType = FollowUpUtil.GetSurveyFullName(-1, ddlSurveyType.SelectedValue); //month is -1 since pre-op
                    int      pId             = Int32.Parse(dr[Patient.PatientId].ToString());


                    DataTable dt = GetThisLastSurveySentRecord(surveyShortType, 0, pId);

                    //1. survey has not been sent before and processdate is no earlier than 30 days before duedate
                    //2. survey was sent before, we will send again if it was sent out more than 14 days ago and has not been received yet

                    if ((SurveyAlreadySent(surveyShortType, 0, pId) == false && processDate > dueDate.AddDays(-30)) ||
                        (dt.Rows.Count > 0 && da.GetSurveyByActionItem(pId, dt.Rows[0][Caisis.BOL.Action.ActionItem].ToString()).Rows.Count == 0 && DateTime.Parse(dt.Rows[0][Caisis.BOL.Action.ActionDate].ToString()) < processDate.AddDays(-14)))
                    {
                        string surveyName = FollowUpUtil.GetSurveyFullName(0, surveyShortType);

                        DataRow fuRow = fuPatientsDt.NewRow();
                        fuRow["PatientId"]  = pId.ToString();
                        fuRow["LastName"]   = dr[Patient.PtLastName].ToString();
                        fuRow["FirstName"]  = dr[Patient.PtFirstName].ToString();
                        fuRow["PtName"]     = dr[Patient.PtLastName].ToString() + ", " + dr[Patient.PtFirstName].ToString();
                        fuRow["PtMRN"]      = dr[Patient.PtMRN].ToString();
                        fuRow["DueDate"]    = dueDate.ToShortDateString();
                        fuRow["FUMonth"]    = "Pre-Op";
                        fuRow["ProcName"]   = dr[Procedure.ProcName].ToString();
                        fuRow["ProcDate"]   = surgDate.ToShortDateString();
                        fuRow["Surgeon"]    = da.GetMostRecentTreatingPhysician(pId);
                        fuRow["SurveyName"] = surveyName;

                        // retrieve additional patient data
                        if (!String.IsNullOrEmpty(dr[Patient.PtMRN].ToString()))
                        {
                            PatientDa ptDa     = new PatientDa();
                            DataTable ptInfoDt = ptDa.GetPatientByMRN(dr[Patient.PtMRN].ToString());
                            if (ptInfoDt.Rows.Count > 0)
                            {
                                fuRow["Address1"] = ptInfoDt.Rows[0][Patient.PtAddress1].ToString();
                                fuRow["Address2"] = ptInfoDt.Rows[0][Patient.PtAddress2].ToString();
                                fuRow["City"]     = ptInfoDt.Rows[0][Patient.PtCity].ToString();
                                fuRow["State"]    = ptInfoDt.Rows[0][Patient.PtState].ToString();
                                fuRow["Zip"]      = ptInfoDt.Rows[0][Patient.PtPostalCode].ToString();
                            }
                        }

                        fuPatientsDt.Rows.Add(fuRow);

                        // 0 used for PreTx surveys
                        // _redirectPath += "&" + dr[Patient.PatientId].ToString() + "=0_" + surveyName.Replace(" ", "");
                        _redirectPath += "&" + dr[Patient.PatientId].ToString() + "=0_" + surveyName;
                    }
                }

                // rules for distribution: 1 dimension contains send month; 2 dimension contains number of days before due date in which survey should be received
                //int[,] surveyMonths = { { 1, 21 }, { 3, 30 }, { 6, 45 }, { 12, 60 }, { 18, 75 }, { 24, 75 }, { 30, 75 }, { 36, 75 }, { 48, 75 }, { 60, 75 } };

                // rules for new distribution: 1 dimension contains send month; 2 dimension contains number of days before due date in which survey should be received
                int[,] surveyMonths = { { 1, 21 }, { 3, 21 }, { 6, 21 }, { 12, 21 }, { 18, 30 }, { 24, 30 }, { 30, 30 }, { 36, 30 }, { 48, 30 }, { 60, 30 } };

                for (int i = 0; i < 10; i++)
                {
                    // retrieve send month
                    month = surveyMonths[i, 0];

                    daysAfterDueDate = surveyMonths[i, 1];
                    DateTime dueDate = surgDate.AddMonths(month);

                    if (dueDate >= processDate.AddDays(daysPriorToDueDate) && dueDate <= processDate.AddDays(daysAfterDueDate))
                    {
                        breakLoop = true;

                        string currentSurveyDueName = FollowUpUtil.GetSurveyFullName(month, selectedSurvey);
                        //string previousSurveyName = FollowUpUtil.GetSurveyFullName(previousMonth, selectedSurvey);

                        // if 1) current survey was not already sent AND 2) At least 1 of the previous 3 surveys have been sent AND received
                        if (!SurveyAlreadySent(currentSurveyDueName, month, Int32.Parse(dr[Patient.PatientId].ToString())) &&
                            PassesSurveyReceivedRule(surveyMonths, i, dr[Patient.PatientId].ToString(), selectedSurvey))
                        {
                            // patient is due for a month survey
                            DataRow fuRow = fuPatientsDt.NewRow();
                            string  pId   = dr[Patient.PatientId].ToString();
                            fuRow["PatientId"]  = pId;
                            fuRow["LastName"]   = dr[Patient.PtLastName].ToString();
                            fuRow["FirstName"]  = dr[Patient.PtFirstName].ToString();
                            fuRow["PtName"]     = dr[Patient.PtLastName].ToString() + ", " + dr[Patient.PtFirstName].ToString();
                            fuRow["PtMRN"]      = dr[Patient.PtMRN].ToString();
                            fuRow["DueDate"]    = dueDate.ToShortDateString();
                            fuRow["FUMonth"]    = month.ToString();
                            fuRow["ProcName"]   = dr[Procedure.ProcName].ToString();
                            fuRow["ProcDate"]   = surgDate.ToShortDateString();
                            fuRow["Surgeon"]    = da.GetMostRecentTreatingPhysician(Int32.Parse(pId));
                            fuRow["SurveyName"] = currentSurveyDueName;

                            // retrieve additional patient data
                            if (!String.IsNullOrEmpty(dr[Patient.PtMRN].ToString()))
                            {
                                PatientDa ptDa     = new PatientDa();
                                DataTable ptInfoDt = ptDa.GetPatientByMRN(dr[Patient.PtMRN].ToString());
                                if (ptInfoDt.Rows.Count > 0)
                                {
                                    fuRow["Address1"] = ptInfoDt.Rows[0][Patient.PtAddress1].ToString();
                                    fuRow["Address2"] = ptInfoDt.Rows[0][Patient.PtAddress2].ToString();
                                    fuRow["City"]     = ptInfoDt.Rows[0][Patient.PtCity].ToString();
                                    fuRow["State"]    = ptInfoDt.Rows[0][Patient.PtState].ToString();
                                    fuRow["Zip"]      = ptInfoDt.Rows[0][Patient.PtPostalCode].ToString();
                                }
                            }

                            fuPatientsDt.Rows.Add(fuRow);

                            _redirectPath += "&" + dr[Patient.PatientId].ToString() + "=" + month + "_" + currentSurveyDueName;
                        }
                    }

                    if (breakLoop)
                    {
                        break;
                    }
                }
            }

            CreateBatchButton.Attributes.Add("onclick", "window.location.href='" + _redirectPath + "'");

            return(fuPatientsDt);
        }