Ejemplo n.º 1
0
        public static bool AddSenorData(string studyId, SSInsertionData ssInsert)
        {
            //A lookup is used in the strored procedure to store the study id (int) in the database
            var strConn = ConfigurationManager.ConnectionStrings["Halfpint"].ToString();

            using (var conn = new SqlConnection(strConn))
            {
                try
                {
                    var cmd = new SqlCommand("", conn)
                    {
                        CommandType = System.Data.CommandType.StoredProcedure,
                        CommandText = ("AddSensorData")
                    };

                    var param = new SqlParameter("@studyID", studyId);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Monitor_Date", ssInsert.MonitorDate);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Monitor_Time", ssInsert.MonitorTime);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Monitor_ID", ssInsert.MonitorId);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Transmitter_ID", ssInsert.TransmitterId);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Lot", ssInsert.SensorLot);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Inserter_First_Name", ssInsert.InserterFirstName);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Inserter_Last_Name", ssInsert.InserterLastName);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Location", ssInsert.SensorLocation);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@P_SensorType", ssInsert.SensorType);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Expire_Date", ssInsert.ExpirationDate);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Reason", 1);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Date_Created", DateTime.Now);
                    cmd.Parameters.Add(param);
                    param = new SqlParameter("@Sensor_Row", "1");
                    cmd.Parameters.Add(param);


                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Nlogger.LogError(ex);
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static bool IsValidInitialize(NameValueCollection formParams, out List <ValidationMessages> messages, out SSInsertionData insertData)
        {
            messages   = new List <ValidationMessages>();
            insertData = new SSInsertionData();

            //cafpint
            bool useCafpint = bool.Parse(formParams["cafpint"]);
            bool useVampjr  = bool.Parse(formParams["vampjr"]);

            if (formParams["onInsulinYesNo"] == null)
            {
                messages.Add(new ValidationMessages
                {
                    FieldName   = "onInsulinInfusion",
                    DisplayName = "Is patient currently on insulin infusion",
                    Message     = "is required"
                });
            }

            if (useCafpint)
            {
                //see if they answered the first question
                if (formParams["cafpintYesNo"] == null)
                {
                    messages.Add(new ValidationMessages
                    {
                        FieldName   = "cafpintYesNo",
                        DisplayName = "CAF-Pint question",
                        Message     = "is required"
                    });
                }
                else
                {
                    //if yes - check for required second answer
                    if (formParams["cafpintYesNo"] == "yes")
                    {
                        if (formParams["cafpintYes"] == null)
                        {
                            messages.Add(new ValidationMessages
                            {
                                FieldName   = "cafpintYes",
                                DisplayName = "All CAF-Pint questions",
                                Message     = "are required"
                            });
                        }
                        else
                        {
                            if (formParams["cafpintYes"] != "yes")
                            {
                                if (formParams["cafPintId"] == null || formParams["cafPintId"] == "")
                                {
                                    messages.Add(new ValidationMessages
                                    {
                                        FieldName   = "cafPintId",
                                        DisplayName = "CAF-Pint Id",
                                        Message     = "is required"
                                    });
                                }
                                else
                                {
                                    var cafpintId = formParams["cafPintId"];
                                    var match     = Regex.Match(cafpintId, "^(\\d{2}\\-\\d{3})$", RegexOptions.None);
                                    if (!match.Success)
                                    {
                                        messages.Add(new ValidationMessages
                                        {
                                            FieldName   = "cafPintId",
                                            DisplayName = "CAF-Pint Id",
                                            Message     = "is not a valid Id (example of a valid Id: 01-123)"
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
            }

            int sensorType = int.Parse(formParams["sensorType"]);

            if (sensorType > 0)
            {
                insertData.SensorType = sensorType;

                string monitorDate = formParams["MonitorDate"];
                monitorDate = monitorDate.Trim();

                if (monitorDate.Length == 0)
                {
                    messages.Add(new ValidationMessages
                    {
                        FieldName = "MonitorDate", DisplayName = "Monitor Date", Message = "is required"
                    });
                }
                else
                {
                    try
                    {
                        var dtMonitorDate = DateTime.Parse(monitorDate);
                    }
                    catch (Exception ex)
                    {
                        string eMsg = ex.Message;
                        messages.Add(new ValidationMessages {
                            FieldName = "MonitorDate", Message = "is not a valid date"
                        });
                    }
                }
                insertData.MonitorDate = monitorDate;

                string monitorTime = formParams["MonitorTime"];
                monitorTime = monitorTime.Trim();
                if (monitorTime.Length == 0)
                {
                    messages.Add(new ValidationMessages
                    {
                        FieldName = "MonitorTime", DisplayName = "Monitor Time", Message = "is required"
                    });
                }
                else
                {
                    if (!IsValidTime(monitorTime))
                    {
                        messages.Add(new ValidationMessages
                        {
                            FieldName   = "MonitorTime",
                            DisplayName = "Monitor Time",
                            Message     = "is not a valid time"
                        });
                    }
                }
                insertData.MonitorTime = monitorTime;

                string monitorID = formParams["MonitorID"];
                monitorID = monitorID.Trim();
                if (monitorID.Length == 0)
                {
                    messages.Add(new ValidationMessages
                    {
                        FieldName = "MonitorID", DisplayName = "Monitor ID", Message = "is required"
                    });
                }
                insertData.MonitorId = monitorID;

                string transmitterID = formParams["TransmitterID"];
                transmitterID = transmitterID.Trim();
                if (transmitterID.Length == 0)
                {
                    messages.Add(new ValidationMessages
                    {
                        FieldName   = "TransmitterID",
                        DisplayName = "Transmitter ID",
                        Message     = "is required"
                    });
                }
                insertData.TransmitterId = transmitterID;

                string sensorLot = formParams["SensorLot"];
                sensorLot = sensorLot.Trim();
                if (sensorLot.Length == 0)
                {
                    messages.Add(new ValidationMessages
                    {
                        FieldName = "SensorLot", DisplayName = "Sensor Lot", Message = "is required"
                    });
                }
                insertData.SensorLot = sensorLot;

                string expirationDate = formParams["ExpirationDate"];
                sensorLot = sensorLot.Trim();
                if (sensorLot.Length == 0)
                {
                    messages.Add(new ValidationMessages {
                        FieldName = "ExpirationDate", DisplayName = "Expiration date", Message = "is required"
                    });
                }
                insertData.ExpirationDate = expirationDate;

                var today   = DateTime.Today.Date;
                var expDate = DateTime.Parse(expirationDate).Date;
                if (expDate.CompareTo(today) < 0)
                {
                    messages.Add(new ValidationMessages
                    {
                        FieldName   = "ExpirationDate",
                        DisplayName = "The sensor ",
                        Message     = "has expired"
                    });
                }

                string inserterFirstName = formParams["InserterFirstName"];
                inserterFirstName = inserterFirstName.Trim();
                if (inserterFirstName.Length == 0)
                {
                    messages.Add(new ValidationMessages
                    {
                        FieldName   = "InserterFirstName",
                        DisplayName = "Inserter First Name",
                        Message     = "is required"
                    });
                }
                insertData.InserterFirstName = inserterFirstName;

                string inserterLastName = formParams["InserterLastName"];
                inserterLastName = inserterLastName.Trim();
                if (inserterLastName.Length == 0)
                {
                    messages.Add(new ValidationMessages
                    {
                        FieldName   = "InserterLastName",
                        DisplayName = "Inserter Last Name",
                        Message     = "is required"
                    });
                }
                insertData.InserterLastName = inserterLastName;

                string sensorLocations = formParams["SensorLocations"];
                if (sensorLocations == "0")
                {
                    messages.Add(new ValidationMessages
                    {
                        FieldName   = "SensorLocations",
                        DisplayName = "Sensor Location",
                        Message     = "is required"
                    });
                }
                insertData.SensorLocation = sensorLocations;
            }//if userSensor == 1

            string bodyWeight = formParams["BodyWeight"];

            bodyWeight = bodyWeight.Trim();
            if (bodyWeight.Length == 0)
            {
                messages.Add(new ValidationMessages {
                    FieldName = "BodyWeight", DisplayName = "Body Weight", Message = "is required"
                });
            }
            else
            {
                insertData.BodyWeight = bodyWeight;
            }

            string insulinConcentration = formParams["Concentrations"];

            if (insulinConcentration == "")
            {
                messages.Add(new ValidationMessages {
                    FieldName = "SensorLocations", DisplayName = "Sensor Location", Message = "is required"
                });
            }
            else
            {
                insertData.InsulinConcentration = insulinConcentration;
            }

            if (messages.Count > 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static bool InitializeSs(string physicalAppPath, string studyId, SSInsertionData ssInsert, int sensorType, int language)
        {
            physicalAppPath = Encoder.HtmlEncode(physicalAppPath);
            studyId         = Encoder.HtmlEncode(studyId);
            if (DbUtils.IsStudyIdValid(studyId) != 1)
            {
                return(false);
            }

            Nlogger.LogInfo("SsUtils.InitializeSS: " + studyId);

            var path          = physicalAppPath + "sstemplate\\";
            var file          = path + "Checks_tmpl.xlsm";
            var file2         = path + studyId + ".xlsm";
            var iSensorType   = sensorType;
            var iGGonlyModeOn = 0;

            if (iSensorType == 0)
            {
                iGGonlyModeOn = 1;
            }

            if (!File.Exists(file2))
            {
                File.Copy(file, file2);
            }

            Nlogger.LogInfo("SsUtils.InitializeSS - insert data into ss: " + studyId);

            try
            {
                using (var document = SpreadsheetDocument.Open(file2, true))
                {
                    var wbPart   = document.WorkbookPart;
                    var theSheet =
                        wbPart.Workbook.Descendants <Sheet>().FirstOrDefault(s => s.Name == "ParameterDefaults");

                    //WorksheetPart wsPart = (WorksheetPart)wbPart.GetPartById(theSheet.Id);

                    UpdateValue(wbPart, "D2", studyId, 0, true, "ParameterDefaults");
                    UpdateValue(wbPart, "E2", studyId, 0, true, "ParameterDefaults");
                    UpdateValue(wbPart, "D3", ssInsert.BodyWeight, 0, false, "ParameterDefaults");
                    UpdateValue(wbPart, "E3", ssInsert.BodyWeight, 0, false, "ParameterDefaults");
                    UpdateValue(wbPart, "D4", ssInsert.InsulinConcentration, 0, false, "ParameterDefaults");
                    UpdateValue(wbPart, "E4", ssInsert.InsulinConcentration, 0, false, "ParameterDefaults");
                    UpdateValue(wbPart, "D5", ssInsert.TargetLow, 0, false, "ParameterDefaults");
                    UpdateValue(wbPart, "E5", ssInsert.TargetLow, 0, false, "ParameterDefaults");
                    UpdateValue(wbPart, "D6", ssInsert.TargetHigh, 0, false, "ParameterDefaults");
                    UpdateValue(wbPart, "E6", ssInsert.TargetHigh, 0, false, "ParameterDefaults");

                    UpdateValue(wbPart, "D47", iGGonlyModeOn.ToString(), 0, false, "ParameterDefaults");
                    UpdateValue(wbPart, "D49", iSensorType.ToString(), 0, false, "ParameterDefaults");
                    UpdateValue(wbPart, "D50", "", 0, false, "ParameterDefaults");
                    UpdateValue(wbPart, "D51", "", 0, false, "ParameterDefaults");
                    UpdateValue(wbPart, "D53", language.ToString(), 0, false, "ParameterDefaults");

                    if (sensorType > 0)
                    {
                        UpdateValue(wbPart, "A2", "1", 0, true, "SensorData");
                        UpdateValue(wbPart, "B2", ssInsert.MonitorDate, 0, true, "SensorData");
                        UpdateValue(wbPart, "C2", ssInsert.MonitorTime, 0, true, "SensorData");
                        UpdateValue(wbPart, "D2", ssInsert.MonitorId, 0, true, "SensorData");
                        UpdateValue(wbPart, "E2", ssInsert.TransmitterId, 0, true, "SensorData");
                        UpdateValue(wbPart, "F2", ssInsert.SensorLot, 0, true, "SensorData");
                        UpdateValue(wbPart, "G2", ssInsert.InserterFirstName, 0, true, "SensorData");
                        UpdateValue(wbPart, "H2", ssInsert.InserterLastName, 0, true, "SensorData");
                        UpdateValue(wbPart, "I2", GetSensorLocationString(ssInsert.SensorLocation), 0, true,
                                    "SensorData");
                        UpdateValue(wbPart, "J2", "Initial Insertion", 0, true, "SensorData");
                        UpdateValue(wbPart, "K2", DateTime.Today.ToShortDateString(), 0, true, "SensorData");
                        UpdateValue(wbPart, "L2", ssInsert.ExpirationDate, 0, true, "SensorData");
                    }
                    document.Close();
                }



                //get the path to the site folder
                var siteCode = studyId.Substring(0, 2);
                var sitePath = physicalAppPath + "xcel\\" + siteCode;
                //if it doesn't exist then create it
                if (!Directory.Exists(sitePath))
                {
                    Directory.CreateDirectory(sitePath);
                }

                var file3 = sitePath + "\\" + studyId + ".xlsm";
                if (File.Exists(file3))
                {
                    File.Delete(file3);
                }

                File.Move(file2, file3);
            }
            catch (Exception ex)
            {
                Nlogger.LogError(ex);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public static int SetRandomization(string studyId, bool?cafpintConsent, int?inrGreater3, string cafpintId, ref SSInsertionData ssInsert, string user, DateTime dateRandomized, bool onInsulinInfusion)
        {
            var site            = DbUtils.GetSiteidIdForUser(user);
            var arm             = 0;
            var randomizationId = 0;
            var sArm            = "";

            var strConn = ConfigurationManager.ConnectionStrings["Halfpint"].ToString();

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

                    conn.Open();
                    var rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        var pos = rdr.GetOrdinal("ID");
                        randomizationId = rdr.GetInt32(pos);
                        pos             = rdr.GetOrdinal("Arm");
                        sArm            = rdr.GetString(pos);
                    }
                    rdr.Close();
                    arm = int.Parse(sArm.Substring(4, 1));

                    cmd = new SqlCommand("", conn)
                    {
                        CommandType = System.Data.CommandType.StoredProcedure,
                        CommandText = ("AddStudyInfoToRandomization")
                    };
                    param = new SqlParameter("@id", randomizationId);
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@studyID", studyId);
                    cmd.Parameters.Add(param);

                    if (cafpintConsent == null)
                    {
                        param = new SqlParameter("@cafpintConsent", DBNull.Value);
                    }
                    else
                    {
                        param = new SqlParameter("@cafpintConsent", cafpintConsent.Value);
                    }
                    cmd.Parameters.Add(param);

                    if (inrGreater3 == null)
                    {
                        param = new SqlParameter("@inrGreater3", DBNull.Value);
                    }
                    else
                    {
                        param = new SqlParameter("@inrGreater3", inrGreater3.Value);
                    }
                    cmd.Parameters.Add(param);

                    if (string.IsNullOrEmpty(cafpintId))
                    {
                        param = new SqlParameter("@cafpintId", DBNull.Value);
                    }
                    else
                    {
                        param = new SqlParameter("@cafpintId", cafpintId);
                    }
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@dateRandomized", dateRandomized);
                    cmd.Parameters.Add(param);

                    param = new SqlParameter("@onInsulinInfusion", onInsulinInfusion);
                    cmd.Parameters.Add(param);
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Nlogger.LogError(ex);
                    throw new Exception("There was a problem with the randomization process");
                }
            }

            string appSettingKey = "Arm" + arm.ToString();
            string armVal        = System.Configuration.ConfigurationManager.AppSettings[appSettingKey];

            string[] avParts = armVal.Split(new string[] { ":" }, StringSplitOptions.None);
            ssInsert.TargetLow  = avParts[0];
            ssInsert.TargetHigh = avParts[1];
            ssInsert.Arm        = sArm;
            return(arm);
        }