Example #1
0
        public static DataTable GetStateData(string NoPatID, string noofinpat, string outwarddate, string admitdate)
        {
            if (string.IsNullOrEmpty(noofinpat) || string.IsNullOrEmpty(admitdate))
            {
                return(null);
            }
            DataTable inHosDetails = DS_SqlService.GetInHosDetails(int.Parse(noofinpat));

            if (null == inHosDetails || inHosDetails.Rows.Count == 0)
            {
                string serchsql = string.Format(@" select distinct a.noofinpat,a.id,a.dotime,a.ccode,c.name,b.name as patname 
                                                from PatientStatus a join inpatient b 
                                                on a.noofinpat=b.patid join THREE_CHECK_EVENT c
                                                on a.ccode=c.id
                                                where a.noofinpat='{0}' order by dotime desc ", NoPatID);//categoryid要是id的前两位
                return(sql_Helper.ExecuteDataTable(serchsql, CommandType.Text));
            }
            else
            {
                DataRow thisInpatient = inHosDetails.Select(" NOOFINPAT = " + noofinpat).FirstOrDefault();
                string  startTime     = admitdate;
                string  endTime       = outwarddate;
                if (null != thisInpatient && (thisInpatient["STATUS"].ToString() == "1502" || thisInpatient["STATUS"].ToString() == "1503"))
                {//病人已出院
                    if (!string.IsNullOrEmpty(thisInpatient["outwarddate"].ToString().Trim()))
                    {
                        endTime = thisInpatient["outwarddate"].ToString();
                    }
                    else
                    {
                        //当前入院记录之后的入院记录
                        var afterInHos = inHosDetails.Select(" admitdate > '" + DateTime.Parse(admitdate).ToString("yyyy-MM-dd HH:mm:ss") + "'");
                        if (null != afterInHos && afterInHos.Count() > 0)
                        {
                            var nextInHos = afterInHos.OrderBy(q => DateTime.Parse(q["admitdate"].ToString())).FirstOrDefault();
                            endTime = null == nextInHos ? endTime : DateTime.Parse(nextInHos["admitdate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        else
                        {
                            endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                    }
                }
                else
                {
                    endTime = null;
                }
                StringBuilder str      = new StringBuilder();
                string        serchsql = string.Format(@"select distinct  a.noofinpat,a.id,a.dotime,a.ccode,c.name,b.name as patname ,b.noofinpat 
                                                from PatientStatus a  join inpatient b 
                                                on a.noofinpat=b.patid  join THREE_CHECK_EVENT c
                                                on a.ccode=c.id
                                                where b.noofinpat='{0}' and a.noofinpat='{1}' and a.dotime>='{2}' ",
                                                       noofinpat, NoPatID, startTime);
                str.Append(serchsql);
                if (endTime != null)
                {
                    string appendsql = string.Format(@"a.dotime<'{0}' ", endTime);
                    str.Append(appendsql);
                }

                return(sql_Helper.ExecuteDataTable(str.ToString(), CommandType.Text));
            }
        }