private DataTable GetToData(string fromRecordGuid)
        {
            string uniqueKeys = "";
            string parens     = "";
            string joins      = "";

            foreach (Epi.View epiView in view.Project.Views)
            {
                if (!string.IsNullOrEmpty(epiView.TableName) && db.TableExists(epiView.TableName))
                {
                    uniqueKeys += "t" + epiView.Id + ".UniqueKey as Key" + epiView.Id + ", ";
                    parens     += "(";
                    joins      += "left outer join " + epiView.TableName + " t" + epiView.Id + " on m.ToRecordGuid = t" + epiView.Id + ".GlobalRecordId) ";
                }
            }
            uniqueKeys = uniqueKeys.Substring(0, uniqueKeys.Length - 2) + " ";

            Epi.Data.Query query = db.CreateQuery(@"Select FromRecordGuid, ToRecordGuid, FromViewId, ToViewId, " + uniqueKeys + " from " + parens + "metaLinks m " + joins + " where m.FromRecordGuid = @GlobalRecordId");
            query.Parameters.Add(new Epi.Data.QueryParameter("@GlobalRecordId", DbType.StringFixedLength, fromRecordGuid));
            return(db.Select(query));
        }
예제 #2
0
        public void Initialize()
        {
            try
            {
                IsLegacyDb = this.view.Pages[4].Id > 5;

                string uniqueKeys = "";
                string parens     = "(((";
                string joins      = "";
                foreach (Epi.View epiView in view.Project.Views)
                {
                    uniqueKeys += "t" + epiView.Id + ".UniqueKey as Key" + epiView.Id + ", ";
                    parens     += "(";
                    joins      += "left outer join " + epiView.TableName + " t" + epiView.Id + " on m.ToRecordGuid = t" + epiView.Id + ".GlobalRecordId) ";
                }
                if (IsLegacyDb)
                {
                    parens += "(";
                    joins  += " LEFT JOIN caseinformationform1 AS c ON t1.GlobalRecordId = c.GlobalRecordId) LEFT JOIN caseinformationform9 AS c9 ON t1.GlobalRecordId = c9.GlobalRecordId) LEFT JOIN caseinformationform3 AS c3 ON t1.GlobalRecordId = c3.GlobalRecordId) LEFT JOIN caseinformationform2 AS c2 ON t1.GlobalRecordId = c2.GlobalRecordId)";
                }
                else
                {
                    joins += " LEFT JOIN caseinformationform1 AS c ON t1.GlobalRecordId = c.GlobalRecordId) LEFT JOIN caseinformationform4 AS c9 ON t1.GlobalRecordId = c9.GlobalRecordId) LEFT JOIN caseinformationform3 AS c2 ON t1.GlobalRecordId = c2.GlobalRecordId) ";
                }
                uniqueKeys = uniqueKeys.Substring(0, uniqueKeys.Length - 2) + " ";

                Epi.Data.Query query;
                if (db.ToString().ToLower().Contains("sql"))
                {
                    query = db.CreateQuery(@"Select DateOnset, DateDeath, DateIsolationCurrent, EpiCaseDef, Tentative, Surname, Othernames, ID, Gender, Age, LastContactDate, RelationshipType, HCW, FromRecordGuid, ToRecordGuid, FromViewId, ToViewId, " + uniqueKeys + " from " + parens + "metaLinks m " + joins + " where m.ToRecordGuid not in (select fromrecordguid from metalinks ml inner join caseinformationform1 crf on ml.torecordguid = crf.globalrecordid where crf.epicasedef <> '0' and ToViewId <> 4) and DateOnset is not null and EpiCaseDef <> '0' ORDER BY DateOnset");
                }
                else
                {
                    query = db.CreateQuery(@"Select DateOnset, DateDeath, DateIsolationCurrent, EpiCaseDef, Tentative, Surname, Othernames, ID, Gender, Age, LastContactDate, RelationshipType, HCW, FromRecordGuid, ToRecordGuid, FromViewId, ToViewId, " + uniqueKeys + " from " + parens + "metaLinks m " + joins + " where m.ToRecordGuid not in (select fromrecordguid from metalinks ml inner join caseinformationform1 crf on ml.torecordguid = crf.globalrecordid where crf.epicasedef <> '0' and ToViewId <> 4) and DateOnset <> null and EpiCaseDef <> '0' ORDER BY DateOnset");
                }
                DataTable dt = db.Select(query);

                if (dt.Rows.Count > 0)
                {
                    List <string> uniqueGuids = new List <string>();

                    currentY   = 10;
                    firstOnset = (DateTime)dt.Rows[0]["DateOnset"];
                    for (int days = 0; days < 256; days += 7)
                    {
                        TextBlock tb = new TextBlock();
                        tb.Text       = "|" + firstOnset.AddDays(days).ToString("dd-MMM");
                        tb.FontWeight = FontWeights.SemiBold;
                        tb.Foreground = Brushes.White;
                        tb.FontSize   = 14;
                        Canvas.SetTop(tb, 0);
                        Canvas.SetLeft(tb, (days * Constants.TRANS_CHAIN_SCALE) + 10);
                        transmissionDates.Children.Add(tb);
                    }

                    foreach (DataRow row in dt.Rows)
                    {
                        if (!uniqueGuids.Contains(row["ToRecordGuid"].ToString()))
                        {
                            double dateDiff = ((DateTime)row["DateOnset"]).Subtract(firstOnset).TotalDays;

                            uniqueGuids.Add(row["ToRecordGuid"].ToString());
                            Hashtable     nodes      = new Hashtable();
                            List <string> connectors = new List <string>();
                            counter = 1;
                            bool     derivedOther = false;
                            DateTime otherDate;
                            if (row["DateDeath"] == DBNull.Value && row["DateIsolationCurrent"] != DBNull.Value)
                            {
                                otherDate = (DateTime)row["DateIsolationCurrent"];
                            }
                            else if (row["DateDeath"] != DBNull.Value && row["DateIsolationCurrent"] == DBNull.Value)
                            {
                                otherDate = (DateTime)row["DateDeath"];
                            }
                            else if (row["DateDeath"] != DBNull.Value && row["DateIsolationCurrent"] != DBNull.Value)
                            {
                                otherDate = (DateTime)row["DateDeath"] < (DateTime)row["DateIsolationCurrent"] ? (DateTime)row["DateDeath"] : (DateTime)row["DateIsolationCurrent"];
                            }
                            else
                            {
                                otherDate    = ((DateTime)row["DateOnset"]).AddDays(10);
                                derivedOther = true;
                            }
                            double daysIll = otherDate.Subtract((DateTime)row["DateOnset"]).TotalDays;
                            if (daysIll < 0)
                            {
                                daysIll = 0;
                            }

                            Rectangle center = AddRectangleToCanvas(Colors.Red, daysIll * Constants.TRANS_CHAIN_SCALE / 2, 40, "Current Record: " + row["ToRecordGuid"], true, new SphereInfo(row["ToRecordGuid"].ToString(), view.Id, (int)row["Key1"], (DateTime)row["DateOnset"], otherDate, derivedOther, row["Surname"].ToString() + " " + row["Othernames"].ToString(), row["ID"].ToString(), row["Gender"].ToString(), row["Age"].ToString(), row["DateDeath"] != DBNull.Value, (bool)row["HCW"]));
                            //Rectangle center = AddRectangleToCanvas(Colors.Red, daysIll * Constants.TRANS_CHAIN_SCALE / 2, 40, "Current Record: " + row["ToRecordGuid"], true, new SphereInfo(row["ToRecordGuid"].ToString(), view.Id, (DateTime)row["DateOnset"], otherDate, derivedOther, row["Surname"].ToString() + " " + row["Othernames"].ToString(), row["ID"].ToString(), row["Gender"].ToString(), row["Age"].ToString(), row["DateDeath"] != DBNull.Value, (bool)row["HCW"]));
                            double circleTop  = currentY > 10 ? currentY + 107 : currentY;
                            double circleLeft = 10 + (Constants.TRANS_CHAIN_SCALE * dateDiff);

                            Canvas.SetTop(center, circleTop);   // (MainCanvas.ActualHeight / 2) - 25);
                            Canvas.SetLeft(center, circleLeft); // (MainCanvas.ActualWidth / 2) - 25);
                            nodes.Add(row["ToRecordGuid"].ToString(), center);
                            AddSpheres(false, row["ToRecordGuid"].ToString(), center, nodes, connectors, 175, 40, (DateTime)row["DateOnset"]);
                            AddConnections(nodes, connectors);

                            TextBlock tb1 = new TextBlock();
                            tb1.Text        = row["ID"].ToString();
                            tb1.MouseEnter += new MouseEventHandler(tb_MouseEnter);
                            tb1.MouseLeave += new MouseEventHandler(tb_MouseLeave);
                            tb1.Tag         = center;
                            Canvas.SetTop(tb1, circleTop + 5);
                            Canvas.SetLeft(tb1, circleLeft + 10);
                            Canvas.SetZIndex(tb1, 300);
                            tb1.Cursor = Cursors.Hand;
                            AddVisualToCanvas(tb1);

                            TextBlock tb2 = new TextBlock();
                            tb2.Text        = row["Surname"].ToString() + " " + row["Othernames"].ToString();
                            tb2.MouseEnter += new MouseEventHandler(tb_MouseEnter);
                            tb2.MouseLeave += new MouseEventHandler(tb_MouseLeave);
                            tb2.Tag         = center;
                            Canvas.SetTop(tb2, circleTop + 20);
                            Canvas.SetLeft(tb2, circleLeft + 10);
                            Canvas.SetZIndex(tb2, 300);
                            tb2.Cursor = Cursors.Hand;
                            AddVisualToCanvas(tb2);

                            string sex = string.Empty;
                            if (row["Gender"].ToString().Equals("1"))
                            {
                                sex = ContactTracing.CaseView.Properties.Resources.Male;
                            }
                            else if (row["Gender"].ToString().Equals("2"))
                            {
                                sex = ContactTracing.CaseView.Properties.Resources.Female;
                            }

                            TextBlock tb3 = new TextBlock();
                            tb3.Text        = sex + ", " + Properties.Resources.ColHeaderAge + ": " + row["Age"].ToString();
                            tb3.MouseEnter += new MouseEventHandler(tb_MouseEnter);
                            tb3.MouseLeave += new MouseEventHandler(tb_MouseLeave);
                            tb3.Tag         = center;
                            Canvas.SetTop(tb3, circleTop + 35);
                            Canvas.SetLeft(tb3, circleLeft + 10);
                            Canvas.SetZIndex(tb3, 300);
                            tb3.Cursor = Cursors.Hand;
                            AddVisualToCanvas(tb3);

                            string end;
                            if (row["DateDeath"] != DBNull.Value)
                            {
                                end = " " + Properties.Resources.Death + ": ";
                            }
                            else
                            {
                                end = " Iso: ";
                            }

                            TextBlock tb4 = new TextBlock();
                            if (derivedOther)
                            {
                                tb4.Text = Properties.Resources.Onset + ": " + ((DateTime)row["DateOnset"]).ToString("dd-MM");
                            }
                            else
                            {
                                tb4.Text = Properties.Resources.Onset + ": " + ((DateTime)row["DateOnset"]).ToString("dd-MM") + end + otherDate.ToString("dd-MM");
                            }
                            tb4.MouseEnter += new MouseEventHandler(tb_MouseEnter);
                            tb4.MouseLeave += new MouseEventHandler(tb_MouseLeave);
                            tb4.Tag         = center;
                            Canvas.SetTop(tb4, circleTop + 50);
                            Canvas.SetLeft(tb4, circleLeft + 10);
                            Canvas.SetZIndex(tb4, 300);
                            tb4.Cursor = Cursors.Hand;
                            AddVisualToCanvas(tb4);

                            if (row["DateDeath"] != DBNull.Value)
                            {
                                TextBlock tbd = new TextBlock();
                                tbd.Text       = "+";
                                tbd.FontWeight = FontWeights.UltraBold;
                                tbd.FontSize   = 25;
                                Canvas.SetTop(tbd, circleTop + 50);
                                Canvas.SetLeft(tbd, circleLeft);
                                Canvas.SetZIndex(tbd, 300);
                                tbd.Cursor = Cursors.Hand;
                                AddVisualToCanvas(tbd);
                            }

                            if ((bool)row["HCW"])
                            {
                                TextBlock tbh = new TextBlock();
                                tbh.Text       = "H";
                                tbh.FontWeight = FontWeights.UltraBold;
                                tbh.FontSize   = 16;
                                Canvas.SetTop(tbh, circleTop + 59);
                                if (row["DateDeath"] != DBNull.Value)
                                {
                                    Canvas.SetLeft(tbh, circleLeft + 15);
                                }
                                else
                                {
                                    Canvas.SetLeft(tbh, circleLeft + 2);
                                }
                                Canvas.SetZIndex(tbh, 300);
                                tbh.Cursor = Cursors.Hand;
                                AddVisualToCanvas(tbh);
                            }
                        }
                    }
                    transmissionCanvas.Height = currentY + 200;
                }
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show("An error occurred during production of the transmission chain. Please make sure each case's date of onset occurs prior to any date of death. Exception: " + ex.Message);
            }
            catch (Exception ex)
            {
                int x = 5;
                x++;
            }
        }
예제 #3
0
        /// <summary>
        /// Load the form with the saved data
        /// </summary>
        private new void LoadFormData()
        {
            Configuration config = Configuration.GetNewInstance();
            FontStyle     style  = FontStyle.Regular;

            if (config.Settings.EditorFontBold)
            {
                style |= FontStyle.Bold;
            }
            if (config.Settings.EditorFontItalics)
            {
                style |= FontStyle.Italic;
            }
            field.PromptFont = new Font(config.Settings.EditorFontName, (float)config.Settings.EditorFontSize, style);

            style = FontStyle.Regular;
            if (config.Settings.ControlFontBold)
            {
                style |= FontStyle.Bold;
            }
            if (config.Settings.ControlFontItalics)
            {
                style |= FontStyle.Italic;
            }
            field.ControlFont = new Font(config.Settings.ControlFontName, (float)config.Settings.ControlFontSize, style);

            txtPrompt.Text    = field.PromptText;
            txtFieldName.Text = field.Name;
            if (!string.IsNullOrEmpty(field.SourceTableName))
            {
                this.sourceTableName = field.SourceTableName;
                this.textColumnName  = field.TextColumnName;
                txtDataSource.Text   = field.SourceTableName + " :: " + field.TextColumnName;
            }
            chkReadOnly.Checked   = field.IsReadOnly;
            chkRepeatLast.Checked = field.ShouldRepeatLast;
            chkRequired.Checked   = field.IsRequired;
            promptFont            = field.PromptFont;
            controlFont           = field.ControlFont;
            if (!(String.IsNullOrEmpty(txtPrompt.Text)))
            {
                btnDataSource.Enabled = true;
            }
            else
            {
                btnDataSource.Enabled = false;
            }

            Epi.Data.IDbDriver db    = Epi.Data.DBReadExecute.GetDataDriver(page.view.Project.CollectedDataConnectionString);
            Epi.Data.Query     query = db.CreateQuery("select [Name], [FieldId] " +
                                                      "from metaFields " +
                                                      "where [PageId] = @pageID and [FieldTypeId] in (1,3,4,17, 18, 19, 27) " +
                                                      " and [ViewId] = @viewID " +
                                                      "order by [Name]");
            query.Parameters.Add(new Epi.Data.QueryParameter("@pageID", DbType.Int32, page.Id));
            query.Parameters.Add(new Epi.Data.QueryParameter("@viewID", DbType.Int32, page.view.Id));

            //DataTable textFields = page.GetMetadata().GetTextFieldsForPage(page.GetView().Id, page.Id);
            DataTable textFields = db.Select(query);
            string    expression = "Name = '" + txtFieldName.Text + "'";
            string    sortOrder  = "Name DESC";

            DataRow[] rows = textFields.Select(expression, sortOrder);
            if (rows.Length > 0)
            {
                textFields.Rows.Remove(rows[0]);
            }
            lbxLinkedFields.DataSource    = textFields;
            lbxLinkedFields.DisplayMember = ColumnNames.NAME;

            if (!(string.IsNullOrEmpty(txtDataSource.Text)))
            {
                selectedIndex = page.GetProject().CollectedData.GetTableColumnNames(field.SourceTableName);

                String textFieldName = string.Empty;

                for (int i = 0; i < textFields.Rows.Count; i++)
                {
                    textFieldName = textFields.Rows[i][ColumnNames.NAME].ToString();

                    if (selectedIndex.Contains(textFieldName))
                    {
                        lbxLinkedFields.SetSelected(lbxLinkedFields.FindStringExact(textFieldName), true);
                    }
                    else
                    {
                        lbxLinkedFields.SetSelected(lbxLinkedFields.FindStringExact(textFieldName), false);
                    }
                }
                lbxLinkedFields.Enabled = true;
                lblSelectFields.Enabled = true;
                lbxLinkedFields.Visible = true;
                lblSelectFields.Visible = true;
                btnOk.Enabled           = true;
            }
            else
            {
                btnOk.Enabled = true;
            }
        }