C# Source Object - Patient Class
using System;
using System.Collections.Generic;
using CodeEffects.Rule.Attributes;
using CodeEffects.Rule.Common;
namespace CodeEffects.Rule.Site.Models
{
public class Patient
{
public Patient() { }
[Field(DisplayName = "First Name", Max = 30, Description = "Patient's first name")]
public string FirstName { get; set; }
[Field(DisplayName = "Last Name", Max = 30, Description = "Patient's last name")]
public string LastName { get; set; }
[Field(DisplayName = "Date of Birth", DateTimeFormat = "MMMM dd, yyyy", Description = "Patient's date of birth")]
public DateTime? DOB { get; set; }
[Field(ValueInputType = ValueInputType.User, Description = "Patient's gender")]
public Gender Gender { get; set; } = Gender.Unknown;
[Field(Max = 200, Description = "Patient's email address")]
public string Email { get; set; }
[Field(Max = 12, Description = "Patient's phone number")]
public string Phone { get; set; }
[Field(Min = 0, Max = 200, Description = "Patient's current pulse")]
public int? Pulse { get; set; }
[Field(Min = 0, Max = 110, Description = "Patient's current temperature")]
public decimal? Temperature { get; set; }
[Field(Min = 0, Max = 1000, Description = "Patient's weight")]
public decimal? Weight { get; set; }
[Field(DisplayName = "Smoking History", Description = "Does the patient have a smoking history?")]
public bool Smoker { get; set; } = false;
[Field(DisplayName = "High Blood Pressure", Description = "Does the patient currently have high blood pressure?")]
public bool HighPressure { get; set; } = false;
public Address Home { get; set; }
[Field(CollectionItemName = "Visit")]
public List Visits { get; set; } = new List();
[ExcludeFromEvaluation]
public string Output { get; set; }
[ExcludeFromEvaluation]
public NotificationType NotificationType { get; set; } = NotificationType.Undefined;
// In-rule method that concatenates FirstName and LastName
// properties and returns the result
[Method("Full Name", "In-rule method that joins together first and last names")]
public string FullName()
{
return string.Format("{0} {1}", this.FirstName, this.LastName);
}
// In-rule method that returns the age of the patient
[Method("Age", "In-rule method that returns the age of the patient")]
public int GetAge()
{
if(!this.DOB.HasValue)
throw new Exception("The DOB value is required to determine the age of the patient");
else
{
var now = DateTime.Today;
var dob = (DateTime)this.DOB;
int age = now.Year - dob.Year;
if(dob > now.AddYears(-age)) age--;
return age;
}
}
[Action(DisplayName = "Add a Visit", Description = "Action method that adds a new visit to the list of patient's visits")]
public void AddVisit(DateTime date, [Parameter(DataSourceName = "Physicians", Description = "Action method that adds a new visit to the list of patient's visits")]int physicianID)
{
this.Visits.Add(new Visit { Date = date, PhysicianID = physicianID });
}
[Action(DisplayName = "Display Confirmation", Description = "Action method that displays a custom message confirmation")]
public void Confirm(string message)
{
this.Output = message;
this.NotificationType = NotificationType.Confirmation;
}
[Action(DisplayName = "Display Warning", Description = "Action method that displays a custom message warning")]
public void Warn(string message)
{
this.Output = message;
this.NotificationType = NotificationType.Warning;
}
}
[Data("Physicians", typeof(Physician), "List")]
public class Visit
{
[Field(DateTimeFormat = "MMMM dd, yyyy", ValueInputType = ValueInputType.All, Description = "Visit's date")]
public DateTime Date { get; set; } = DateTime.MinValue;
[Field(DisplayName = "Physician", DataSourceName = "Physicians", Description = "Visit's physician")]
public int PhysicianID { get; set; } = 0;
public Visit() { }
}
public class Address
{
[Parent("Home", "Home Street", "Current home street")]
[Field(Max = 50)]
public string Street { get; set; }
[Parent("Home", "Home Apt #", "Current home street")]
[Field(Max = 50)]
public string Street2 { get; set; }
[Parent("Home", "Home City", "Current home city")]
[Field(Max = 30)]
public string City { get; set; }
[Parent("Home", "Home State", "Current home state")]
public State State { get; set; }
[Parent("Home", "Home ZIP Code", "Current home zip code")]
[Field(Max = 5)]
public string Zip { get; set; }
public Address() { this.State = State.Unknown; }
}
public enum Gender
{
[ExcludeFromEvaluation]
Unknown = 0,
Male = 1,
Female = 2
}
public enum State
{
[ExcludeFromEvaluation]
Unknown = 0,
// Using just several US states to make the list shorter
Alabama = 1,
Arizona = 2,
California = 3,
Florida = 4,
Georgia = 5,
[EnumItem("New Jersey")]
NewJersey = 6,
[EnumItem("New York")]
NewYork = 7,
[EnumItem("North Carolina")]
NothCarolina = 8,
[EnumItem("South Carolina")]
SouthCarolina = 9
}
public class Physician
{
public static List List()
{
var physicians = new List();
// This method hard-codes physicians' values. In real-life scenario
// values would come from some kind of storage such as db or a file system
physicians.Add(new Rule.Common.DataSourceItem(1, "John Smith"));
physicians.Add(new Rule.Common.DataSourceItem(2, "Anna Taylor"));
physicians.Add(new Rule.Common.DataSourceItem(3, "Robert Brown"));
physicians.Add(new Rule.Common.DataSourceItem(4, "Stephen Lee"));
physicians.Add(new Rule.Common.DataSourceItem(5, "Joe Wilson"));
physicians.Add(new Rule.Common.DataSourceItem(6, "Samuel Thompson"));
return physicians;
}
}
public enum NotificationType : int
{
Undefined = 0,
Warning = 1,
Error = 2,
Confirmation = 3
}
}
XML of the Complex Evaluation Type Rule
<?xml version="1.0" encoding="utf-8"?>
<codeeffects xmlns="https://codeeffects.com/schemas/rule/41" xmlns:ui="https://codeeffects.com/schemas/ui/4">
<rule id="7178ae92-0230-4f3f-a9db-eb5717a01f37" webrule="5.1.16.4" utc="2025-06-16T00:08:02.7283"
type="CodeEffects.Rule.Site.Models.Patient, CodeEffects.Rule.Site, Version=4.0.7.2, Culture=neutral, PublicKeyToken=null" eval="true">
<name>Evaluation Type Rule - Complex</name>
<description>Example of a complex rule of evaluation type</description>
<definition>
<or>
<rule id="d4f186bb-fcc7-4e64-8fc9-7039e9bed537" operator="exists">
<property name="Visits" />
</rule>
<condition type="equal">
<rule id="e992d5b2-9ac2-46fa-abb6-7c574d059f08" />
<value type="System.Boolean">true</value>
</condition>
<and ui:block="true">
<condition type="startsWith" stringComparison="OrdinalIgnoreCase">
<property name="FirstName" />
<value>Josh</value>
</condition>
<condition type="isNotNull">
<property name="LastName" />
</condition>
</and>
</or>
</definition>
<format>
<lines>
<line index="0" tabs="1" />
<line index="5" tabs="1" />
<line index="26" tabs="2" />
<line index="30" tabs="3" />
<line index="37" tabs="2" />
<line index="41" tabs="1" />
<line index="44" tabs="3" />
<line index="52" tabs="3" />
<line index="58" tabs="1" />
</lines>
</format>
</rule>
<rule id="d4f186bb-fcc7-4e64-8fc9-7039e9bed537" webrule="5.1.16.4" utc="2025-06-16T00:08:02.7369"
type="CodeEffects.Rule.Site.Models.Visit, CodeEffects.Rule.Site, Version=4.0.7.2, Culture=neutral, PublicKeyToken=null" eval="true">
<definition>
<and>
<condition type="greaterOrEqual">
<property name="Date" />
<value type="System.DateTime">2025-05-05T00:00:00.0000</value>
</condition>
<condition type="notEqual">
<property name="PhysicianID" />
<value type="numeric">3</value>
</condition>
</and>
</definition>
<format>
<lines>
<line index="0" tabs="3" />
<line index="8" tabs="3" />
<line index="15" tabs="1" />
</lines>
</format>
</rule>
</codeeffects>
XML of the Simple Evaluation Type Rule
<?xml version="1.0" encoding="utf-8"?>
<codeeffects xmlns="https://codeeffects.com/schemas/rule/41" xmlns:ui="https://codeeffects.com/schemas/ui/4">
<rule id="93ffb67d-ab75-4336-96dd-b5222a92478d" webrule="5.1.16.4" utc="2025-06-15T23:50:31.8647"
type="CodeEffects.Rule.Site.Models.Patient, CodeEffects.Rule.Site, Version=4.0.7.2, Culture=neutral, PublicKeyToken=null" eval="true">
<name>Evaluation Type Rule - Simple</name>
<description>Example of a simple rule of evaluation type</description>
<definition>
<and>
<condition type="equal">
<property name="Home.State" />
<value type="CodeEffects.Rule.Site.Models.State, CodeEffects.Rule.Site, Version=4.0.7.2, Culture=neutral, PublicKeyToken=null">5</value>
</condition>
<condition type="equal">
<property name="Gender" />
<value type="CodeEffects.Rule.Site.Models.Gender, CodeEffects.Rule.Site, Version=4.0.7.2, Culture=neutral, PublicKeyToken=null">1</value>
</condition>
</and>
</definition>
<format>
<lines>
<line index="0" tabs="1" />
<line index="6" tabs="1" />
</lines>
</format>
</rule>
</codeeffects>
XML of the Complex Execution Type Rule
<?xml version="1.0" encoding="utf-8"?>
<codeeffects xmlns="https://codeeffects.com/schemas/rule/41" xmlns:ui="https://codeeffects.com/schemas/ui/4">
<rule id="15b1f3bf-f037-488d-a42e-bd6c5912add6" webrule="5.1.16.4" utc="2025-06-16T00:41:25.5019"
type="CodeEffects.Rule.Site.Models.Patient, CodeEffects.Rule.Site, Version=4.0.7.2, Culture=neutral, PublicKeyToken=null" eval="false">
<name>Execution Type Rule - Complex</name>
<description>Example of a complex rule of execution type</description>
<definition>
<if>
<clause>
<and>
<rule id="df3d762f-f1fd-4da2-8500-022d0119b6d1" operator="exists">
<property name="Visits" />
</rule>
<condition type="equal">
<rule id="10d922e4-c29b-40cb-9360-49a9a8d84909" />
<value type="System.Boolean">true</value>
</condition>
<or ui:block="true">
<condition type="equal">
<property name="Home.State" />
<value type="CodeEffects.Rule.Site.Models.State, CodeEffects.Rule.Site, Version=4.0.7.2, Culture=neutral, PublicKeyToken=null">6</value>
</condition>
<condition type="equal">
<property name="Home.State" />
<value type="CodeEffects.Rule.Site.Models.State, CodeEffects.Rule.Site, Version=4.0.7.2, Culture=neutral, PublicKeyToken=null">7</value>
</condition>
</or>
<condition type="less">
<property name="Weight" />
<expression>
<add>
<method name="GetAge" />
<value type="numeric">20</value>
</add>
</expression>
</condition>
</and>
</clause>
<then>
<method name="AddVisit">
<value type="System.DateTime">2025-06-25T00:00:00.0000</value>
<value type="System.Int32">4</value>
</method>
<method name="Confirm">
<value>All conditions are met</value>
</method>
</then>
<else>
<if>
<clause>
<and>
<or ui:block="true">
<condition type="startsWith" stringComparison="OrdinalIgnoreCase">
<property name="Phone" />
<value>404</value>
</condition>
<condition type="startsWith" stringComparison="OrdinalIgnoreCase">
<property name="Phone" />
<value>678</value>
</condition>
<condition type="startsWith" stringComparison="OrdinalIgnoreCase">
<property name="Phone" />
<value>770</value>
</condition>
</or>
<condition type="startsWith" stringComparison="OrdinalIgnoreCase">
<property name="Home.Zip" />
<value>30</value>
</condition>
</and>
</clause>
<then>
<set>
<property name="Home.State" />
<value type="CodeEffects.Rule.Site.Models.State, CodeEffects.Rule.Site, Version=4.0.7.2, Culture=neutral, PublicKeyToken=null">5</value>
</set>
<method name="Confirm">
<value>Patient is a Georgia resident</value>
</method>
</then>
<else>
<set>
<property name="FirstName" />
<value>John</value>
</set>
<set>
<property name="LastName" />
<value>Doe</value>
</set>
<method name="Warn">
<value>None of the conditions are met</value>
</method>
</else>
</if>
</else>
</if>
</definition>
<format>
<lines>
<line index="0" tabs="1" />
<line index="15" tabs="1" />
<line index="21" tabs="1" />
<line index="33" tabs="1" />
<line index="43" tabs="2" />
<line index="47" tabs="3" />
<line index="57" tabs="3" />
<line index="64" tabs="0" />
<line index="66" tabs="1" />
<line index="82" tabs="1" />
<line index="87" tabs="2" />
<line index="91" tabs="3" />
<line index="100" tabs="3" />
<line index="107" tabs="0" />
<line index="109" tabs="3" />
<line index="118" tabs="3" />
<line index="127" tabs="3" />
</lines>
</format>
</rule>
<rule id="df3d762f-f1fd-4da2-8500-022d0119b6d1" webrule="5.1.16.4" utc="2025-06-16T00:41:25.5214"
type="CodeEffects.Rule.Site.Models.Visit, CodeEffects.Rule.Site, Version=4.0.7.2, Culture=neutral, PublicKeyToken=null" eval="true">
<definition>
<or>
<condition type="equal">
<property name="PhysicianID" />
<value type="numeric">2</value>
</condition>
<condition type="less">
<property name="Date" />
<value type="System.DateTime">2025-05-05T00:00:00.0000</value>
</condition>
</or>
</definition>
<format>
<lines />
</format>
</rule>
</codeeffects>
XML of the Simple Execution Type Rule
<?xml version="1.0" encoding="utf-8"?>
<codeeffects xmlns="https://codeeffects.com/schemas/rule/41" xmlns:ui="https://codeeffects.com/schemas/ui/4">
<rule id="f5bd0d01-8c03-45ec-900b-f027c16a6d5b" webrule="5.1.16.4" utc="2025-06-16T00:21:11.9972"
type="CodeEffects.Rule.Site.Models.Patient, CodeEffects.Rule.Site, Version=4.0.7.2, Culture=neutral, PublicKeyToken=null" eval="false">
<name>Execution Type Rule - Simple</name>
<description>Example of a simple rule of execution type</description>
<definition>
<if>
<clause>
<condition type="greaterOrEqual">
<property name="DOB" />
<value type="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]">2025-05-05T00:00:00.0000</value>
</condition>
</clause>
<then>
<method name="Confirm">
<value>Rule evaluated to True</value>
</method>
</then>
<else>
<method name="Warn">
<value>Rule evaluated to False</value>
</method>
</else>
</if>
</definition>
<format>
<lines>
<line index="0" tabs="0" />
<line index="4" tabs="1" />
<line index="7" tabs="2" />
<line index="13" tabs="0" />
<line index="15" tabs="2" />
</lines>
</format>
</rule>
</codeeffects>