Ejemplo 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);
        }
Ejemplo n.º 2
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)
                {
                    Nlogger.LogError(ex);
                }
                finally
                {
                    if (rdr != null)
                    {
                        rdr.Close();
                    }
                }
            }
        }
Ejemplo n.º 3
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:" + cgmFileInfo.SubjectId;
                return(false);
            }

            var lastCgmGlucoseDate = GetLastCgmGlucoseDate(dbRows);

            if (lastCgmGlucoseDate == null)
            {
                message = "***Invalid date range: Could not get the last glucose date from file:" + cgmFileInfo.SubjectId;
                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:" + cgmFileInfo.SubjectId;
                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() +
                          "):" + cgmFileInfo.SubjectId;
                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() +
                          "):" + cgmFileInfo.SubjectId;
                return(false);
            }
            message = "Valid date range:" + cgmFileInfo.SubjectId;
            return(true);
        }
Ejemplo n.º 4
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');
                    //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 < columns.Length - 1; i++)
                    {
                        var col     = columns[i];
                        var colName = colNameList[i];

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

                        dbRow.ColNameVals.Add(colValName);
                    }
                    dbRows.Add(dbRow);
                }
            }
            return(dbRows);
        }