Пример #1
0
        /// <summary>
        /// 根据方案管理者ID,生成记录包括完成与未完成的(按循环条件)
        /// </summary>
        public void Procedure()
        {
            if (myRow != null)
            {
                string    quryRec = "select * from T_FOLLOW_RECORD where patient_id=" + pid + " and solution_id=" + sid + " order by id";
                DataTable recTb   = App.GetDataSet(quryRec).Tables[0];
                myRec = GetRecords(recTb);
            }

            string uid = App.UserAccount.UserInfo.User_id;
            string tempSql;

            if (sid != "")
            {
                tempSql = "select * from T_FOLLOW_INFO where id =" + sid + "";
                DataSet dsTemp = App.GetDataSet(tempSql);
                myInfo = GetInfo(dsTemp);
            }
            //全部插入,然后遍历现有Record表去除已有的记录
            ArrayList Batch = new ArrayList();

            Batch.Clear();
            Class_FollowInfo info = myInfo[0];

            //参考时间默认为出院时间
            DateTime myTime = Convert.ToDateTime(myRow.Cells["参考时间"].Value.ToString());
            string   sql    = "";

            try
            {
                //先考虑是否为手动控制启用病人

                string Manual = App.ReadSqlVal("select * from T_FOLLOW_MANUALPATIENT where patient_id=" + pid + " and solution_id=" + info.Id + " and isadd=1   ", 0, "definefollows");

                #region Manual
                if (Manual != "" && Manual != null)
                {
                    string   ExistRecord = App.ReadSqlVal("select max(requested_time) 完成时间 from T_FOLLOW_RECORD where patient_id=" + pid + " and solution_id=" + info.Id + " ", 0, "完成时间");
                    DateTime NowTime     = App.GetSystemTime().Date;
                    DateTime RefTime     = Convert.ToDateTime(myRow.Cells["参考时间"].Value.ToString());
                    DateTime RecordTime;
                    if (ExistRecord != "")
                    {
                        RecordTime = Convert.ToDateTime(ExistRecord);
                    }
                    else
                    {
                        RecordTime = RefTime;
                    }
                    TimeSpan tSpan1     = RecordTime - RefTime;
                    TimeSpan tSpan2     = NowTime - RecordTime;
                    int      MinusTime1 = (int)tSpan1.TotalDays;
                    int      MinusTime2 = (int)tSpan2.TotalDays;
                    if (Manual.IndexOf(",") != -1)
                    {
                        string[] Items = Manual.Split(',');
                        for (int i = 0; i < Items.Length; i++)
                        {
                            string Span = Items[i];
                            if (MinusTime2 < 0)
                            {
                                break;
                            }
                            if (Span.IndexOf("年") != -1)
                            {
                                if (MinusTime1 > 0)
                                {
                                    MinusTime1 -= Convert.ToInt32(Span.Substring(0, Span.IndexOf("年"))) * 365;
                                }
                                else
                                {
                                    MinusTime2 -= Convert.ToInt32(Span.Substring(0, Span.IndexOf("年"))) * 365;
                                    RecordTime  = RecordTime.AddYears(Convert.ToInt32(Span.Substring(0, Span.IndexOf("年"))));
                                    if (MinusTime2 >= 0)
                                    {
                                        sql = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",'" + RecordTime.ToShortDateString() + "')";
                                        Batch.Add(sql);
                                    }
                                }
                            }
                            if (Span.IndexOf("月") != -1)
                            {
                                if (MinusTime1 > 0)
                                {
                                    MinusTime1 -= Convert.ToInt32(Span.Substring(0, Span.IndexOf("月"))) * 30;
                                }
                                else
                                {
                                    MinusTime2 -= Convert.ToInt32(Span.Substring(0, Span.IndexOf("月"))) * 30;
                                    RecordTime  = RecordTime.AddMonths(Convert.ToInt32(Span.Substring(0, Span.IndexOf("月"))));
                                    if (MinusTime2 >= 0)
                                    {
                                        sql = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",'" + RecordTime.ToShortDateString() + "')";
                                        Batch.Add(sql);
                                    }
                                }
                            }
                            if (Span.IndexOf("天") != -1)
                            {
                                if (MinusTime1 > 0)
                                {
                                    MinusTime1 -= Convert.ToInt32(Span.Substring(0, Span.IndexOf("天")));
                                }
                                else
                                {
                                    MinusTime2 -= Convert.ToInt32(Span.Substring(0, Span.IndexOf("天")));
                                    RecordTime  = RecordTime.AddDays(Convert.ToInt32(Span.Substring(0, Span.IndexOf("天"))));
                                    if (MinusTime2 >= 0)
                                    {
                                        sql = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",'" + RecordTime.ToShortDateString() + "')";
                                        Batch.Add(sql);
                                    }
                                }
                            }
                            if (i == Items.Length - 1)
                            {
                                i--;
                            }
                        }
                    }
                    else
                    {
                        while (true)
                        {
                            if (MinusTime2 < 0)
                            {
                                break;
                            }
                            if (Manual.IndexOf("年") != -1)
                            {
                                if (MinusTime1 > 0)
                                {
                                    MinusTime1 -= Convert.ToInt32(Manual.Substring(0, Manual.IndexOf("年"))) * 365;
                                }
                                else
                                {
                                    MinusTime2 -= Convert.ToInt32(Manual.Substring(0, Manual.IndexOf("年"))) * 365;
                                    RecordTime  = RecordTime.AddYears(Convert.ToInt32(Manual.Substring(0, Manual.IndexOf("年"))));
                                    if (MinusTime2 >= 0)
                                    {
                                        sql = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                                        Batch.Add(sql);
                                    }
                                }
                            }
                            if (Manual.IndexOf("月") != -1)
                            {
                                if (MinusTime1 > 0)
                                {
                                    MinusTime1 -= Convert.ToInt32(Manual.Substring(0, Manual.IndexOf("月"))) * 30;
                                }
                                else
                                {
                                    MinusTime2 -= Convert.ToInt32(Manual.Substring(0, Manual.IndexOf("月"))) * 30;
                                    RecordTime  = RecordTime.AddMonths(Convert.ToInt32(Manual.Substring(0, Manual.IndexOf("月"))));
                                    if (MinusTime2 >= 0)
                                    {
                                        sql = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                                        Batch.Add(sql);
                                    }
                                }
                            }
                            if (Manual.IndexOf("天") != -1)
                            {
                                if (MinusTime1 > 0)
                                {
                                    MinusTime1 -= Convert.ToInt32(Manual.Substring(0, Manual.IndexOf("天")));
                                }
                                else
                                {
                                    MinusTime2 -= Convert.ToInt32(Manual.Substring(0, Manual.IndexOf("天")));
                                    RecordTime  = RecordTime.AddDays(Convert.ToInt32(Manual.Substring(0, Manual.IndexOf("天"))));
                                    if (MinusTime2 >= 0)
                                    {
                                        sql = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                                        Batch.Add(sql);
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion
                /**************************************************************************************************************************************************************************************/
                /***************************************************************************************完成手动添加病人的记录插入***********************************************************************************************/
                #region Auto
                else
                {
                    string   ExistRecord = "";
                    int      ExistTimes  = 0; //计数用来查看是否超过方案规定次数
                    int      TimesCount  = 0; //计数当前已生成记录
                    DateTime NowTime     = DateTime.Today;
                    DateTime RefTime     = Convert.ToDateTime(myRow.Cells["参考时间"].Value.ToString());
                    DateTime RecordTime;
                    //判断是否已存在记录,若已存在则时间点以当前最大应随访时间开始计算
                    if (myRec != null)
                    {
                        ExistRecord = myRec[myRec.Length - 1].Requested_time;
                        ExistTimes  = TimesCount = myRec.Length;
                        RecordTime  = Convert.ToDateTime(ExistRecord);
                    }
                    else
                    {
                        RecordTime = RefTime;
                        if (info.Defaultdays != "0")
                        {
                            RecordTime = RecordTime.AddDays(Convert.ToInt32(info.Defaultdays));
                            sql        = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                            Batch.Add(sql);
                            ExistTimes++;
                        }
                    }

                    int MinusTime2 = (int)(NowTime - RecordTime).TotalDays;


                    if (info.Definefollows != "")
                    {
                        string[] Items = info.Definefollows.Split(',');
                        for (int i = 0; i < Items.Length; i++)
                        {
                            if (MinusTime2 < 0)
                            {
                                break;
                            }
                            if (TimesCount != 0)
                            {
                                //若最后一条记录设置了下次随访时间
                                if (TimesCount == 1)
                                {
                                    if (myRec[myRec.Length - 1].Next_time != "")
                                    {
                                        if (myRec[myRec.Length - 1].Is_timeset == "1")
                                        {
                                            RecordTime = Convert.ToDateTime(myRec[myRec.Length - 1].Next_time);
                                            sql        = "insert into t_follow_record(patient_id,solution_id,creator_id,requested_time) values(" + pid + "," + sid + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                                            Batch.Add(sql);
                                            ExistTimes++;
                                        }
                                        if (myRec[myRec.Length - 1].Is_timeset == "0")
                                        {
                                            RecordTime = Convert.ToDateTime(myRec[myRec.Length - 1].Next_time);
                                        }
                                    }
                                    MinusTime2 = (int)(NowTime - RecordTime).TotalDays;
                                }
                                if (i >= Items.Length - 1)
                                {
                                    i--;
                                }
                                TimesCount--;
                                continue;
                            }
                            //判断是否符合方案的结束条件
                            if (info.FinishType != "")
                            {
                                if (info.FinishType.IndexOf("次") != -1)
                                {
                                    if (ExistTimes >= Convert.ToInt32(info.FinishType.Substring(0, info.FinishType.IndexOf("次"))))
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    int      span2    = 0;
                                    TimeSpan tempSpan = RecordTime - RefTime;
                                    span2 = (int)tempSpan.TotalDays + Convert.ToInt32(info.Defaultdays);
                                    int span1 = 0;
                                    if (info.FinishType.IndexOf("年") != -1)
                                    {
                                        span1 = Convert.ToInt32(info.FinishType.Substring(0, info.FinishType.IndexOf("年"))) * 365;
                                    }
                                    if (info.FinishType.IndexOf("月") != -1)
                                    {
                                        span1 = Convert.ToInt32(info.FinishType.Substring(0, info.FinishType.IndexOf("月"))) * 30;
                                    }
                                    if (info.FinishType.IndexOf("天") != -1)
                                    {
                                        span1 = Convert.ToInt32(info.FinishType.Substring(0, info.FinishType.IndexOf("天")));
                                    }
                                    if (span1 <= span2)
                                    {
                                        break;
                                    }
                                }
                            }

                            string Span = "";
                            if (i >= Items.Length)
                            {
                                i = Items.Length - 1;
                            }
                            Span = Items[i];
                            if (Span.IndexOf("年") != -1)
                            {
                                RecordTime = RecordTime.AddYears(Convert.ToInt32(Span.Substring(0, Span.IndexOf("年"))));
                                sql        = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                                Batch.Add(sql);
                                ExistTimes++;
                                MinusTime2 = (int)(NowTime - RecordTime).TotalDays;
                            }
                            if (Span.IndexOf("月") != -1)
                            {
                                RecordTime = RecordTime.AddMonths(Convert.ToInt32(Span.Substring(0, Span.IndexOf("月"))));
                                sql        = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                                Batch.Add(sql);
                                ExistTimes++;
                                MinusTime2 = (int)(NowTime - RecordTime).TotalDays;
                            }
                            if (Span.IndexOf("天") != -1)
                            {
                                RecordTime = RecordTime.AddDays(Convert.ToInt32(Span.Substring(0, Span.IndexOf("天"))));
                                sql        = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                                Batch.Add(sql);
                                ExistTimes++;
                                MinusTime2 = (int)(NowTime - RecordTime).TotalDays;
                            }
                            if (i >= Items.Length - 1)
                            {
                                i--;
                            }
                        }
                    }
                    else
                    {
                        while (true)
                        {
                            string Span = info.Followtype;
                            if (MinusTime2 < 0)
                            {
                                break;
                            }
                            if (TimesCount != 0)
                            {
                                //若最后一条记录设置了下次随访时间
                                if (TimesCount == 1)
                                {
                                    if (myRec[myRec.Length - 1].Next_time != "")
                                    {
                                        RecordTime = Convert.ToDateTime(myRec[myRec.Length - 1].Next_time);
                                        sql        = "insert into t_follow_record(patient_id,solution_id,creator_id,requested_time) values(" + pid + "," + sid + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                                        Batch.Add(sql);
                                        ExistTimes++;
                                    }
                                    MinusTime2 = (int)(NowTime - RecordTime).TotalDays;
                                }
                                TimesCount--;
                                continue;
                            }
                            if (info.FinishType != "")
                            {
                                if (info.FinishType.IndexOf("次") != -1)
                                {
                                    if (ExistTimes >= Convert.ToInt32(info.FinishType.Substring(0, info.FinishType.IndexOf("次"))))
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    int      span2    = 0;
                                    TimeSpan tempSpan = RecordTime - RefTime;
                                    span2 = (int)tempSpan.TotalDays + Convert.ToInt32(info.Defaultdays);
                                    int span1 = 0;
                                    if (info.FinishType.IndexOf("年") != -1)
                                    {
                                        span1 = Convert.ToInt32(info.FinishType.Substring(0, info.FinishType.IndexOf("年"))) * 365;
                                    }
                                    if (info.FinishType.IndexOf("月") != -1)
                                    {
                                        span1 = Convert.ToInt32(info.FinishType.Substring(0, info.FinishType.IndexOf("月"))) * 30;
                                    }
                                    if (info.FinishType.IndexOf("天") != -1)
                                    {
                                        span1 = Convert.ToInt32(info.FinishType.Substring(0, info.FinishType.IndexOf("天")));
                                    }
                                    if (span1 <= span2)
                                    {
                                        break;
                                    }
                                }
                            }

                            if (info.Followtype.IndexOf("年") != -1)
                            {
                                RecordTime = RecordTime.AddYears(Convert.ToInt32(info.Followtype.Substring(0, info.Followtype.IndexOf("年"))));
                                sql        = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                                Batch.Add(sql);
                                ExistTimes++;
                                MinusTime2 = (int)(NowTime - RecordTime).TotalDays;
                            }
                            if (info.Followtype.IndexOf("月") != -1)
                            {
                                RecordTime = RecordTime.AddMonths(Convert.ToInt32(info.Followtype.Substring(0, info.Followtype.IndexOf("月"))));
                                sql        = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                                Batch.Add(sql);
                                ExistTimes++;
                                MinusTime2 = (int)(NowTime - RecordTime).TotalDays;
                            }
                            if (info.Followtype.IndexOf("天") != -1)
                            {
                                RecordTime = RecordTime.AddDays(Convert.ToInt32(info.Followtype.Substring(0, info.Followtype.IndexOf("天"))));
                                sql        = "insert into T_FOLLOW_RECORD(PATIENT_ID,SOLUTION_ID,CREATOR_ID,REQUESTED_TIME) VALUES(" + pid + "," + info.Id + "," + App.UserAccount.UserInfo.User_id + ",to_date('" + RecordTime.ToShortDateString() + "','yyyy-MM-dd'))";
                                Batch.Add(sql);
                                ExistTimes++;
                                MinusTime2 = (int)(NowTime - RecordTime).TotalDays;
                            }
                        }
                    }
                }

                #endregion
                string[] final = new string[Batch.Count];
                for (int j = 0; j < Batch.Count; j++)
                {
                    final[j] = Batch[j].ToString();
                }

                App.ExecuteBatch(final);
            }
            catch (Exception ex)
            {
                App.MsgErr(ex.Message);
            }
        }