コード例 #1
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);
            }
        }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool anyerrors = false;
                if (dgvOrders.Rows.Count > 0)
                {
                    DataTable tbl = _objSql.LoadFieldMappings1(Convert.ToString(cmbConfigList.SelectedItem));
                    if (tbl != null && tbl.Rows.Count > 0)
                    {
                        var rows =
                            dgvOrders.Rows.OfType <DataGridViewRow>().Where(row => Convert.ToBoolean(row.Cells[0].Value));
                        if (rows.Any())
                        {
                            foreach (DataGridViewRow dgrow in rows)
                            {
                                var mapList = new List <Settings.Mappings>();
                                foreach (DataRow drow in tbl.Rows)
                                {
                                    try
                                    {
                                        string tblName      = Convert.ToString(drow["Table_NM"]);
                                        string columnNm     = Convert.ToString(drow["Column_NM"]);
                                        string apiFieldName = Convert.ToString(drow["Source_Fld_NM"]);
                                        string nbsFldNm     = Convert.ToString(drow["NBS_Fld_NM"]);
                                        string datasource   = Convert.ToString(drow["DataSource"]);
                                        string configid     = Convert.ToString(drow["Config_id"]);
                                        string value        = Convert.ToString(dgrow.Cells[apiFieldName].Value);
                                        string modvalue     = value;
                                        if (tblName == "MSG_PATIENT" && datasource == "Epi Info" && columnNm == "PAT_ETHNIC_GROUP_IND_CD" || columnNm == "PAT_RACE_CATEGORY_CD" && !string.IsNullOrEmpty(value))
                                        {
                                            modvalue = value.Replace(":", "-");
                                        }
                                        if (!string.IsNullOrEmpty(value))
                                        {
                                            var mapping = new Settings.Mappings
                                            {
                                                TableName  = tblName,
                                                ColumnName = columnNm,
                                                ApiValue   = modvalue.Replace("_", "-")
                                            };
                                            mapping.NbsFieldName = nbsFldNm;
                                            mapping.RecordId     = Convert.ToString(dgrow.Cells["record_id"].Value);
                                            mapping.DocumentId   = _siteOid + "^" +
                                                                   Convert.ToString(dgrow.Cells["record_id"].Value);
                                            mapping.DocTypeCd           = _siteOid + "^" + DateTime.Now.ToString("yyyy-MM-dd");
                                            mapping.EffectiveTime       = DateTime.Now.ToString();
                                            mapping.RecordStatusCd      = CommonData.Credentials.RecordStatus;
                                            mapping.RecordStatusTime    = DateTime.Now.ToString();
                                            mapping.MsgContainerStartId = CommonData.Credentials.MsgContainerStartId;
                                            mapping.PatLocalId          = CommonData.Credentials.PatLocalId;
                                            mapping.InvLocalId          = CommonData.Credentials.InvLocalId;
                                            mapping.HideImported        = CommonData.Credentials.HideImported;
                                            mapping.DataSource          = datasource;
                                            mapping.ConfigId            = configid;
                                            mapping.Ongoing_case        = toStringYesNo(Convert.ToBoolean(dgrow.Cells[2].Value));
                                            mapList.Add(mapping);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }

                                if (_objSql.InsertApiValues1(mapList))
                                {
                                    string    formName = Convert.ToString(cmbConfigList.SelectedItem);
                                    DataTable dt       = _objSql.ReadSettings(formName);
                                    if (dt != null && dt.Rows.Count > 0)
                                    {
                                        foreach (DataRow row in dt.Rows)
                                        {
                                            string formname   = Convert.ToString(row["form_nm"]);
                                            string datasource = Convert.ToString(row["datasource"]);
                                            string id         = Convert.ToString(row["Config_id"]);
                                            _objSql.UpdateConfig(id);
                                            dgrow.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;
                                                dgrow.Visible         = false;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    anyerrors = true;
                                }

                                dgrow.Cells[0].Value = false;
                            }
                        }
                    }
                    else
                    {
                        CommonData.ShowMessage("Not all the selected records were exported successfully. See error log.",
                                               CommonData.MsgBoxType.Error);
                        UpdateStatus("No Mappings creatd. See error log.");
                    }
                }

                if (anyerrors)
                {
                    CommonData.ShowMessage("Not all the selected records were exported successfully. See error log.",
                                           CommonData.MsgBoxType.Error);
                    UpdateStatus("Not all the selected records were exported successfully. See error log.");
                }
                else
                {
                    CommonData.ShowMessage("All the selected records were successfully exported to NBS database.",
                                           CommonData.MsgBoxType.Info);
                    UpdateStatus("All the selected records were successfully exported to NBS database.");
                }
            }
            catch (Exception ex)
            {
                Log.WriteToErrorLog(ex);
            }
        }