Esempio n. 1
0
        private static bool IsValidFile(CgmFileInfo cgmFileInfo)
        {
            var fullFileName = cgmFileInfo.FullName;

            using (var sr = new StreamReader(fullFileName))
            {
                if (sr.Peek() >= 0)
                {
                    //Reads the line, splits on tab and adds the components to the table
                    var line = sr.ReadLine();
                    if (line != null)
                    {
                        if (!line.Contains("PatientInfoField	PatientInfoValue"))
                        {
                            Console.WriteLine("***Invalid file: " + fullFileName);
                            Console.WriteLine(line);
                            return(false);
                        }
                    }
                }
            }

            Console.WriteLine("Valid file: " + fullFileName);
            return(true);
        }
Esempio n. 2
0
        private static List <DbRow> ParseFile(CgmFileInfo cgmFileInfo)
        {
            var dbRows = new List <DbRow>();

            using (var sr = new StreamReader(cgmFileInfo.FullName))
            {
                var      rows = 0;
                string   line;
                string[] colNameList = { };

                while ((line = sr.ReadLine()) != null)
                {
                    var columns = line.Split('\t');
                    if (string.IsNullOrEmpty(columns[2]))
                    {
                        break;
                    }

                    //first row contains the column names
                    if (rows == 0)
                    {
                        colNameList = (string[])columns.Clone();
                        rows++;
                        continue;
                    }

                    var dbRow = new DbRow();
                    //skip the first two columns - don't need - that's why i starts at 2
                    for (int i = 2; i < 13; i++)
                    {
                        var col = columns[i];
                        if (col == "High")
                        {
                            col = "999";
                        }
                        if (col == "Low")
                        {
                            col = "0";
                        }

                        var colName = colNameList[i];

                        var colValName = new DbColNameVal {
                            Name = colName, Value = col
                        };

                        dbRow.ColNameVals.Add(colValName);
                    }
                    dbRows.Add(dbRow);
                }
            }
            return(dbRows);
        }
Esempio n. 3
0
        private static void GetFirstLastChecksSensorDates(CgmFileInfo cgmFileInfo, int studyId)
        {
            String        strConn = ConfigurationManager.ConnectionStrings["Halfpint"].ToString();
            SqlDataReader rdr     = null;

            using (var conn = new SqlConnection(strConn))
            {
                try
                {
                    var cmd = new SqlCommand("", conn)
                    {
                        CommandType = CommandType.StoredProcedure, CommandText = "GetChecksFirstAndLastSensorDateTime"
                    };
                    var param = new SqlParameter("@studyId", studyId);
                    cmd.Parameters.Add(param);

                    conn.Open();
                    rdr = cmd.ExecuteReader();
                    if (rdr.Read())
                    {
                        var pos = rdr.GetOrdinal("firstDate");
                        if (!rdr.IsDBNull(pos))
                        {
                            cgmFileInfo.FirstChecksSensorDateTime = rdr.GetDateTime(pos);
                        }

                        pos = rdr.GetOrdinal("lastDate");
                        if (!rdr.IsDBNull(pos))
                        {
                            cgmFileInfo.LastChecksSensorDateTime = rdr.GetDateTime(pos);
                        }
                    }
                    rdr.Close();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
                finally
                {
                    if (rdr != null)
                    {
                        rdr.Close();
                    }
                }
            }
        }
Esempio n. 4
0
        private static bool IsValidDateRange(List <DbRow> dbRows, CgmFileInfo cgmFileInfo, SubjectImportInfo subjectImportInfo, out string message)
        {
            var firstCgmGlucoseDate = GetFirstCgmGlucoseDate(dbRows);

            if (firstCgmGlucoseDate == null)
            {
                message = "Invalid date range: Could not get the first glucose date from file";
                return(false);
            }

            var lastCgmGlucoseDate = GetLastCgmGlucoseDate(dbRows);

            if (lastCgmGlucoseDate == null)
            {
                message = "Invalid date range: Could not get the last glucose date from file";
                return(false);
            }

            //get checks first and last entries for subject
            GetFirstLastChecksSensorDates(cgmFileInfo, subjectImportInfo.StudyId);
            if ((cgmFileInfo.FirstChecksSensorDateTime == null || cgmFileInfo.LastChecksSensorDateTime == null))
            {
                message = "Invalid date range: Could not get checks first and last glucose entry dates:";
                return(false);
            }


            if ((cgmFileInfo.FirstChecksSensorDateTime.Value.Date.CompareTo(firstCgmGlucoseDate.Value.Date) > 0))
            {
                message = "Invalid date range: The first sensor date(" + firstCgmGlucoseDate.Value.Date.ToShortDateString() +
                          ") is earlier than the first checks date(" +
                          cgmFileInfo.FirstChecksSensorDateTime.Value.ToShortDateString() +
                          ")";
                return(false);
            }

            if ((cgmFileInfo.LastChecksSensorDateTime.Value.Date.CompareTo(lastCgmGlucoseDate.Value.Date) < 0))
            {
                message = "Invalid date range: The last sensor date(" + lastCgmGlucoseDate.Value.Date.ToShortDateString() +
                          ") is later than the last checks date(" +
                          cgmFileInfo.LastChecksSensorDateTime.Value.ToShortDateString() +
                          ")";
                return(false);
            }
            message = "Valid date range:" + cgmFileInfo.SubjectId;
            return(true);
        }
Esempio n. 5
0
        private static List<DbRow> ParseFile(CgmFileInfo cgmFileInfo)
        {
            var dbRows = new List<DbRow>();
            using (var sr = new StreamReader(cgmFileInfo.FullName))
            {
                var rows = 0;
                string line;
                string[] colNameList = { };

                while ((line = sr.ReadLine()) != null)
                {
                    var columns = line.Split('\t');
                    if (string.IsNullOrEmpty(columns[2]))
                    {
                        break;
                    }

                    //first row contains the column names
                    if (rows == 0)
                    {
                        colNameList = (string[])columns.Clone();
                        rows++;
                        continue;
                    }

                    var dbRow = new DbRow();
                    //skip the first two columns - don't need - that's why i starts at 2
                    for (int i = 2; i < 13; i++)
                    {

                        var col = columns[i];
                        if (col == "High")
                            col = "999";
                        if (col == "Low")
                            col = "0";

                        var colName = colNameList[i];

                        var colValName = new DbColNameVal { Name = colName, Value = col };

                        dbRow.ColNameVals.Add(colValName);
                    }
                    dbRows.Add(dbRow);
                }
            }
            return dbRows;
        }
Esempio n. 6
0
        private static bool IsValidFile(CgmFileInfo cgmFileInfo)
        {
            var fullFileName = cgmFileInfo.FullName;
            using (var sr = new StreamReader(fullFileName))
            {
                if (sr.Peek() >= 0)
                {
                    //Reads the line, splits on tab and adds the components to the table
                    var line = sr.ReadLine();
                    if (line != null)
                    {
                        if (!line.Contains("PatientInfoField	PatientInfoValue"))
                        {
                            Console.WriteLine("***Invalid file: " + fullFileName);
                            Console.WriteLine(line);
                            return false;
                        }
                    }
                }
            }

            Console.WriteLine("Valid file: " + fullFileName);
            return true;
        }
Esempio n. 7
0
        private static bool IsValidDateRange(List<DbRow> dbRows, CgmFileInfo cgmFileInfo, SubjectImportInfo subjectImportInfo, out string message)
        {
            var firstCgmGlucoseDate = GetFirstCgmGlucoseDate(dbRows);
            if (firstCgmGlucoseDate == null)
            {
                message = "Invalid date range: Could not get the first glucose date from file";
                return false;
            }

            var lastCgmGlucoseDate = GetLastCgmGlucoseDate(dbRows);
            if (lastCgmGlucoseDate == null)
            {
                message = "Invalid date range: Could not get the last glucose date from file";
                return false;
            }

            //get checks first and last entries for subject
            GetFirstLastChecksSensorDates(cgmFileInfo, subjectImportInfo.StudyId);
            if ((cgmFileInfo.FirstChecksSensorDateTime == null || cgmFileInfo.LastChecksSensorDateTime == null))
            {
                message = "Invalid date range: Could not get checks first and last glucose entry dates:";
                return false;
            }

            if ((cgmFileInfo.FirstChecksSensorDateTime.Value.Date.CompareTo(firstCgmGlucoseDate.Value.Date) > 0))
            {
                message = "Invalid date range: The first sensor date(" + firstCgmGlucoseDate.Value.Date.ToShortDateString() +
                    ") is earlier than the first checks date(" +
                    cgmFileInfo.FirstChecksSensorDateTime.Value.ToShortDateString() +
                    ")";
                return false;
            }

            if ((cgmFileInfo.LastChecksSensorDateTime.Value.Date.CompareTo(lastCgmGlucoseDate.Value.Date) < 0))
            {
                message = "Invalid date range: The last sensor date(" + lastCgmGlucoseDate.Value.Date.ToShortDateString() +
                    ") is later than the last checks date(" +
                    cgmFileInfo.LastChecksSensorDateTime.Value.ToShortDateString() +
                    ")";
                return false;
            }
            message = "Valid date range:" + cgmFileInfo.SubjectId;
            return true;
        }
Esempio n. 8
0
        private static void GetFirstLastChecksSensorDates(CgmFileInfo cgmFileInfo, int studyId)
        {
            String strConn = ConfigurationManager.ConnectionStrings["Halfpint"].ToString();
            SqlDataReader rdr = null;
            using (var conn = new SqlConnection(strConn))
            {
                try
                {
                    var cmd = new SqlCommand("", conn) { CommandType = CommandType.StoredProcedure, CommandText = "GetChecksFirstAndLastSensorDateTime" };
                    var param = new SqlParameter("@studyId", studyId);
                    cmd.Parameters.Add(param);

                    conn.Open();
                    rdr = cmd.ExecuteReader();
                    if (rdr.Read())
                    {
                        var pos = rdr.GetOrdinal("firstDate");
                        if (!rdr.IsDBNull(pos))
                        {
                            cgmFileInfo.FirstChecksSensorDateTime = rdr.GetDateTime(pos);
                        }

                        pos = rdr.GetOrdinal("lastDate");
                        if (!rdr.IsDBNull(pos))
                        {
                            cgmFileInfo.LastChecksSensorDateTime = rdr.GetDateTime(pos);
                        }
                    }
                    rdr.Close();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
                finally
                {
                    if (rdr != null)
                        rdr.Close();
                }
            }
        }