public void Where_Clause_Added_If_Panel_Has_Where() { var panel = MockPanel.Panel(); var pi = MockPanel.EdEnc(); /* * No WHERE clause */ pi.Concept.SqlSetWhere = null; panel.SubPanels.ElementAt(0).PanelItems = new[] { pi }; var ob = new SubPanelSqlSet(panel, Options); Assert.DoesNotContain("WHERE", ob.ToString()); /* * One WHERE clause */ pi.Concept.SqlSetWhere = "1 = 1"; ob = new SubPanelSqlSet(panel, Options); Assert.Contains("WHERE 1 = 1", ob.ToString()); /* * Two WHERE clauses */ pi.Concept.SqlFieldNumeric = "Num"; pi.NumericFilter = new NumericFilter { Filter = new[] { 5.0M }, FilterType = NumericFilterType.EqualTo }; ob = new SubPanelSqlSet(panel, Options); Assert.Contains("WHERE 1 = 1 AND Num = 5.0", ob.ToString()); }
public void Person_Level_Query_Returns_Single_Column() { var panel = MockPanel.Panel(); var ob = new SubPanelSqlSet(panel, Options); var sql = ob.ToString(); var cols = GetColumns(sql); var col = StripSetAlias(cols[0]).Trim(); Assert.Single(cols); Assert.Equal(Options.FieldPersonId, col); }
public void Multiple_Panel_Items_In_Subpanel_Returns_Union() { var panel = MockPanel.Panel(); panel.SubPanels.ElementAt(0).PanelItems = new List <PanelItem>() { MockPanel.EdEnc(), MockPanel.HmcEnc() }; var ob = new SubPanelSqlSet(panel, Options); var sql = ob.ToString(); Assert.Contains("UNION ALL", sql); }
public void Alias_Placeholder_Filled() { var panel = MockPanel.Panel(); var pi = MockPanel.EdEnc(); var expectedAlias = "_S000"; pi.Concept.SqlSetWhere = "@.X != @.Y"; panel.SubPanels.ElementAt(0).PanelItems = new[] { pi }; var ob = new SubPanelSqlSet(panel, Options); Assert.Contains($"{expectedAlias}.X != {expectedAlias}.Y", ob.ToString()); }
/// <summary> /// Builds the SQL statement for the given Panel /// </summary> /// <returns>The panel sql.</returns> /// <param name="panel">Panel.</param> public string BuildPanelSql(Panel panel) { string sql; switch (panel.PanelType) { case PanelType.Patient: sql = new SubPanelSqlSet(panel, compilerOptions).ToString(); break; case PanelType.Sequence: sql = new PanelSequentialSqlSet(panel, compilerOptions).ToString(); break; default: return(string.Empty); } ValidateSql(sql); return(sql); }
public void Specialization_Where_Clauses_Added() { var panel = MockPanel.Panel(); var pi = MockPanel.EdEnc(); var specs = new List <ConceptSpecialization> { new ConceptSpecialization { Id = Guid.NewGuid(), SpecializationGroupId = 1, SqlSetWhere = "2 = 2" } }; pi.Concept.SqlSetWhere = null; panel.SubPanels.ElementAt(0).PanelItems = new[] { pi }; pi.Specializations = specs; /* * One specialization */ var ob = new SubPanelSqlSet(panel, Options); Assert.Contains("WHERE 2 = 2", ob.ToString()); /* * Two specializations */ specs.Add(new ConceptSpecialization { Id = Guid.NewGuid(), SpecializationGroupId = 2, SqlSetWhere = "'A' = 'A'" }); ob = new SubPanelSqlSet(panel, Options); Assert.Contains("WHERE 2 = 2 AND 'A' = 'A'", ob.ToString()); /* * Two specializations with a normal WHERE clause */ pi.Concept.SqlSetWhere = "1 = 1"; ob = new SubPanelSqlSet(panel, Options); Assert.Contains("WHERE 1 = 1 AND 2 = 2 AND 'A' = 'A'", ob.ToString()); }