C# Source Object - Patient Class
using System;
using System.Collections.Generic;
using CodeEffects.Rule.Common.Attributes;
using CodeEffects.Rule.Common.Models;
using CodeEffects.Rule.Editor.Client;
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(CollectionSingleItemDisplayName = "Visit")]
public List<Visit> Visits { get; set; } = new List<Visit>();
[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<DataSourceItem> List()
{
var physicians = new List<DataSourceItem>();
// 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 DataSourceItem(1, "John Smith"));
physicians.Add(new DataSourceItem(2, "Anna Taylor"));
physicians.Add(new DataSourceItem(3, "Robert Brown"));
physicians.Add(new DataSourceItem(4, "Stephen Lee"));
physicians.Add(new DataSourceItem(5, "Joe Wilson"));
physicians.Add(new DataSourceItem(6, "Samuel Thompson"));
return physicians;
}
}
public enum NotificationType : int
{
Undefined = 0,
Warning = 1,
Error = 2,
Confirmation = 3
}
}