Ejemplo n.º 1
0
        private void FillValues(string formName)
        {
            DataTable dt = _objSql.ReadSettings(formName);

            if (dt != null && dt.Rows.Count > 0)
            {
                string url      = Convert.ToString(dt.Rows[0]["redcapurl"]);
                string token    = Convert.ToString(dt.Rows[0]["token"]);
                string formname = Convert.ToString(dt.Rows[0]["Form_NM"]);
                _configId   = Convert.ToString(dt.Rows[0]["Config_id"]);
                _datasource = Convert.ToString(dt.Rows[0]["datasource"]);
                if (_datasource == "Epi Info")
                {
                    // var objClient = new Project(url,false);
                    if (unMappedList.Count > 0)
                    {
                        redCapElemList = unMappedList;
                    }
                    else
                    {
                        redCapElemList.Clear();;
                    }
                    // redCapElemList = objClient.GetFields(1);
                }
                else
                {
                    RedCapClient api     = new RedCapClient();
                    DataTable    dataTbl = api.GetData(url, token, formname);
                    if (dataTbl != null && dataTbl.Rows.Count > 0)
                    {
                        foreach (DataColumn clmn in dataTbl.Columns)
                        {
                            string clmName = clmn.ColumnName;
                            redCapElemList.Add(clmName);
                        }
                    }
                }
            }

            FillRedCapListBox();
        }
Ejemplo n.º 2
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            try
            {
                dgvOrders.DataSource = null;
                dgvOrders.Columns.Clear();
                if (cmbConfigList.SelectedIndex == -1)
                {
                    CommonData.ShowMessage("Please select the configuration first.", CommonData.MsgBoxType.Error);
                    UpdateStatus("Please select the configuration first.");
                    return;
                }

                UpdateStatus("Please wait.. it is loading....");
                string    formName = Convert.ToString(cmbConfigList.SelectedItem);
                DataTable tbl      = _objSql.ReadSettings(formName);

                if (tbl != null && tbl.Rows.Count > 0)
                {
                    foreach (DataRow row in tbl.Rows)
                    {
                        string url               = Convert.ToString(row["redcapurl"]);
                        string token             = Convert.ToString(row["token"]);
                        string formname          = Convert.ToString(row["form_nm"]);
                        string excludeConditions = Convert.ToString(row["exclude_conditions"]);
                        string datasource        = Convert.ToString(row["datasource"]);
                        string lastimported      = Convert.ToString(row["LastImported"]);
                        string configid          = Convert.ToString(row["Config_id"]);

                        _siteOid = Convert.ToString(row["site_oid"]);
                        if (datasource == "Epi Info")
                        {
                            var       objClient = new Project(url, false);
                            DataTable datatable = objClient.GetData();

                            if (!string.IsNullOrEmpty(excludeConditions))
                            {
                                string qry  = "condition not in (" + excludeConditions + ")";
                                var    rows = datatable.Select(qry);
                                if (rows.Length > 0)
                                {
                                    DataTable newtbl = datatable.Clone();
                                    foreach (DataRow row1 in rows)
                                    {
                                        if (datatable.Columns.Contains("PAT_NAME_FIRST_TXT") && datatable.Columns.Contains("PAT_NAME_LAST_TXT") && datatable.Columns.Contains("INV_CONDITION_CD"))
                                        {
                                            if (!string.IsNullOrEmpty(row1["PAT_NAME_FIRST_TXT"].ToString()) && !string.IsNullOrEmpty(row1["PAT_NAME_LAST_TXT"].ToString()) && !string.IsNullOrEmpty(row1["INV_CONDITION_CD"].ToString()))
                                            {
                                                newtbl.ImportRow(row1);
                                            }
                                        }
                                        else
                                        {
                                            newtbl.ImportRow(row1);
                                        }
                                    }
                                    dgvOrders.DataSource = newtbl;
                                    if (!string.IsNullOrEmpty(lastimported))
                                    {
                                        DateTime importdt = Convert.ToDateTime(lastimported);
                                        foreach (DataGridViewRow r in dgvOrders.Rows)
                                        {
                                            DateTime lastsave = Convert.ToDateTime(r.Cells["LastSaveTime"].Value.ToString());
                                            if (lastsave <= importdt)
                                            {
                                                r.DefaultCellStyle.ForeColor = Color.Gray;
                                                if (CommonData.Credentials.HideImported != null && CommonData.Credentials.HideImported.ToLower() == "true")
                                                {
                                                    CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dgvOrders.DataSource];
                                                    currencyManager1.SuspendBinding();
                                                    dgvOrders.CurrentCell = null;
                                                    r.Visible             = false;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                dgvOrders.DataSource = datatable;
                                if (!string.IsNullOrEmpty(lastimported))
                                {
                                    DateTime importdt = Convert.ToDateTime(lastimported);
                                    foreach (DataGridViewRow r in dgvOrders.Rows)
                                    {
                                        if (!string.IsNullOrEmpty(r.Cells["LastSaveTime"].Value.ToString()))
                                        {
                                            DateTime lastsave = Convert.ToDateTime(r.Cells["LastSaveTime"].Value.ToString());
                                            if (lastsave <= importdt)
                                            {
                                                r.DefaultCellStyle.ForeColor = Color.Gray;
                                                if (CommonData.Credentials.HideImported != null && CommonData.Credentials.HideImported.ToLower() == "true")
                                                {
                                                    CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dgvOrders.DataSource];
                                                    currencyManager1.SuspendBinding();
                                                    dgvOrders.CurrentCell = null;
                                                    r.Visible             = false;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            var       objClient = new RedCapClient();
                            DataTable apitbl    = objClient.GetData(url, token, formname);
                            if (!string.IsNullOrEmpty(excludeConditions))
                            {
                                string qry = "condition not in (" + excludeConditions + ")";

                                var rows = apitbl.Select(qry);
                                if (rows.Length > 0)
                                {
                                    DataTable newtbl = apitbl.Clone();
                                    foreach (DataRow row1 in rows)
                                    {
                                        if (apitbl.Columns.Contains("patient_fname") && apitbl.Columns.Contains("patient_lname") && apitbl.Columns.Contains("condition"))
                                        {
                                            if (!string.IsNullOrEmpty(row1["patient_fname"].ToString()) && !string.IsNullOrEmpty(row1["patient_lname"].ToString()) && !string.IsNullOrEmpty(row1["condition"].ToString()))
                                            {
                                                newtbl.ImportRow(row1);
                                            }
                                        }
                                        else
                                        {
                                            newtbl.ImportRow(row1);
                                        }
                                    }
                                    newtbl.DefaultView.Sort = "record_id asc";
                                    dgvOrders.DataSource    = newtbl;
                                }
                            }
                            else
                            {
                                dgvOrders.DataSource = apitbl;
                            }
                            string locId = "";
                            foreach (DataGridViewRow r in dgvOrders.Rows)
                            {
                                string recId = Convert.ToString(r.Cells["record_id"].Value);
                                locId = "REDCap_" + configid + "_" + recId;
                                if (_objSql.Get_MSG_CONTAINER_Qry1(locId))
                                {
                                    r.DefaultCellStyle.ForeColor = Color.Gray;
                                    if (CommonData.Credentials.HideImported != null && CommonData.Credentials.HideImported.ToLower() == "true")
                                    {
                                        CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dgvOrders.DataSource];
                                        currencyManager1.SuspendBinding();
                                        dgvOrders.CurrentCell = null;
                                        r.Visible             = false;
                                    }
                                }
                            }
                        }
                        InsertCheckBoxColumn();
                        UpdateStatus("Completed.");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteToErrorLog(ex);
            }
        }