public void TestShouldMatchSimpleXmlLinq() { Expression <Func <Patient, bool> > filterCondition = (data) => data.DeceasedDate == null; ProtocolWhenClauseCollection when = new ProtocolWhenClauseCollection() { Clause = new List <Object>() { XmlExpression.FromExpression(filterCondition) } }; Assert.IsFalse(when.Evaluate(this.m_patientUnderTest, new Dictionary <string, Delegate>())); }
public void TestShouldMatchSimpleXmlLinq() { Expression <Func <CdssContext <Patient>, bool> > filterCondition = (data) => data.Target.DeceasedDate == null; ProtocolWhenClauseCollection when = new ProtocolWhenClauseCollection() { Clause = new List <Object>() { XmlExpression.FromExpression(filterCondition) } }; Assert.IsFalse(when.Evaluate(new CdssContext <Patient>(this.m_patientUnderTest))); }
public void TestGuardNoPolioDose0() { Expression <Func <Patient, bool> > filterCondition = (data) => !data.Participations.Where(guard => guard.ParticipationRoleKey == ActParticipationKey.RecordTarget).Any(o => o.SourceEntity is SubstanceAdministration && (o.SourceEntity as SubstanceAdministration).SequenceId == 0 && o.SourceEntity.Participations.Any(p => p.PlayerEntity.TypeConcept.Mnemonic == "VaccineType-OralPolioVaccine")); XmlExpression xmlExpr = XmlExpression.FromExpression(filterCondition); var xml = this.ToXmlString(xmlExpr); Trace.TraceInformation(xml); var parsed = this.FromXmlString(xml, typeof(XmlLambdaExpression)); parsed.InitializeContext(null); var expression = parsed.ToExpression(); var compile = (expression as LambdaExpression).Compile(); }
public void TestGuardMinimumAgeCondition() { Expression <Func <Patient, bool> > filterAge = (data) => DateTime.Now.Subtract(data.DateOfBirth.Value).TotalDays >= 42; XmlExpression xmlExpr = XmlExpression.FromExpression(filterAge); Assert.IsInstanceOf <XmlLambdaExpression>(xmlExpr); Assert.AreEqual(typeof(bool), xmlExpr.Type); Assert.AreEqual("data", (xmlExpr as XmlLambdaExpression).Parameters[0].ParameterName); // Serialize var xml = this.ToXmlString(xmlExpr); Trace.TraceInformation(xml); var parsed = this.FromXmlString(xml, typeof(XmlLambdaExpression)); var expression = parsed.ToExpression(); }
public void TestSerializeWhereCondition() { Expression <Func <Patient, bool> > filterGender = (o) => o.Names.Where(g => g.NameUseKey == NameUseKeys.OfficialRecord).Any(n => n.Component.Where(g => g.ComponentTypeKey == NameComponentKeys.Family).Any(c => c.Value == "Smith")); XmlExpression xmlExpr = XmlExpression.FromExpression(filterGender); Assert.IsInstanceOfType(xmlExpr, typeof(XmlLambdaExpression)); Assert.AreEqual(typeof(bool), xmlExpr.Type); Assert.AreEqual("o", (xmlExpr as XmlLambdaExpression).Parameters[0].ParameterName); // Serialize var xml = this.ToXmlString(xmlExpr); Trace.TraceInformation(xml); var parsed = this.FromXmlString(xml, typeof(XmlLambdaExpression)); var expression = parsed.ToExpression(); }
public void TestSerializeLambda() { Expression <Func <Patient, bool> > filterGender = (o) => o.GenderConcept.Mnemonic == "Male"; XmlExpression xmlExpr = XmlExpression.FromExpression(filterGender); Assert.IsInstanceOfType(xmlExpr, typeof(XmlLambdaExpression)); Assert.AreEqual(typeof(bool), xmlExpr.Type); Assert.AreEqual("o", (xmlExpr as XmlLambdaExpression).Parameters[0].ParameterName); // Serialize var xml = this.ToXmlString(xmlExpr); Trace.TraceInformation(xml); var parsed = this.FromXmlString(xml, typeof(XmlLambdaExpression)); var expression = parsed.ToExpression(); }
public void TestAgeSelector() { Expression <Func <Patient, double> > filterCondition = (data) => DateTime.Now.Subtract(data.DateOfBirth.Value).TotalDays; XmlExpression xmlExpr = XmlExpression.FromExpression(filterCondition); // Serialize var xml = this.ToXmlString(xmlExpr); Trace.TraceInformation(xml); var parsed = this.FromXmlString(xml, typeof(XmlLambdaExpression)); parsed.InitializeContext(null); var expression = parsed.ToExpression(); var compile = (expression as LambdaExpression).Compile(); }
public void TestPropertyAddDays() { Expression <Func <Patient, DateTime?> > filterCondition = (data) => data.DateOfBirth.Value.AddDays(7); XmlExpression xmlExpr = XmlExpression.FromExpression(filterCondition); // Serialize var xml = this.ToXmlString(xmlExpr); Trace.TraceInformation(xml); var parsed = this.FromXmlString(xml, typeof(XmlLambdaExpression)); parsed.InitializeContext(null); var expression = parsed.ToExpression(); var compile = (expression as LambdaExpression).Compile(); }
public void TestGuardNotImmunoSuppressed() { Expression <Func <Patient, bool> > filterCondition = (data) => data.Participations.Where(o => o.ParticipationRoleKey == ActParticipationKey.RecordTarget).Any(o => o.SourceEntity is Observation && !o.SourceEntity.IsNegated && o.SourceEntity.TypeConcept.Mnemonic == "Diagnosis" && (o.SourceEntity as CodedObservation).Value.ConceptSets.Any(s => s.Mnemonic == "ImmunoSuppressionDiseases")); XmlExpression xmlExpr = XmlExpression.FromExpression(filterCondition); Assert.IsInstanceOfType(xmlExpr, typeof(XmlLambdaExpression)); Assert.AreEqual(typeof(bool), xmlExpr.Type); Assert.AreEqual("data", (xmlExpr as XmlLambdaExpression).Parameters[0].ParameterName); // Serialize var xml = this.ToXmlString(xmlExpr); Trace.TraceInformation(xml); var parsed = this.FromXmlString(xml, typeof(XmlLambdaExpression)); parsed.InitializeContext(null); var expression = parsed.ToExpression(); var compile = (expression as LambdaExpression).Compile(); }
public void TestShouldMatchAllCondition() { Expression <Func <Patient, bool> > filterCondition = (data) => data.DateOfBirth <= DateTime.Now; ProtocolWhenClauseCollection when = new ProtocolWhenClauseCollection() { Operator = BinaryOperatorType.AndAlso, Clause = new List <Object>() { XmlExpression.FromExpression(filterCondition), new WhenClauseImsiExpression() { Expression = "tag[hasBirthCertificate].value=true" }, "StatusConceptKey.Value == Guid.Parse(\"" + StatusKeys.Active + "\")" } }; Assert.IsTrue(when.Evaluate(this.m_patientUnderTest, new Dictionary <string, Delegate>())); when.Clause.Add("Tags.Count == 0"); when.Compile <Patient>(new Dictionary <string, Delegate>()); Assert.IsFalse(when.Evaluate(this.m_patientUnderTest, new Dictionary <string, Delegate>())); }