Skip to content

Commit db2e1d0

Browse files
Merge pull request #1 from Mingxihuang954/main
Add Constraint Rule Engine Examples and Documentation for Digital Insurance
2 parents 5626fdb + 578f0bf commit db2e1d0

11 files changed

Lines changed: 1684 additions & 350 deletions

File tree

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
@(contextPath = "SalesTransaction.UserProfile", attributeSource = "ST")
2+
extern string UserProfile;
3+
4+
type AutoSilver {
5+
@(closeRelation = true, propagateUp = true, sequence = 1)
6+
relation auto : Vehicle {
7+
@(defaultValue = 0)
8+
maxAutoValue = max(Auto_Value);
9+
@(defaultValue = 0)
10+
minAutoYear = min(Year);
11+
@(defaultValue = 0)
12+
aggDriverAccPoint = max(maxDriverAccPoint);
13+
@(defaultValue = 0)
14+
autoHasAntiTheft = count(Has_Anti_Theft > 0);
15+
}
16+
17+
@(sequence = 2)
18+
relation bodilyinjurypropertydamage : BodilyInjuryPropertyDamage[0..1];
19+
20+
@(sequence = 3)
21+
relation medicalpayments : MedicalPayments[0..1] {
22+
medicalLimit = Limit;
23+
medicalDeductible = Deductible;
24+
}
25+
26+
@(defaultValue = 0, tagName = "NetUnitPrice")
27+
decimal(2) unitPrice;
28+
29+
boolean autoCondition = auto[Vehicle] > 0 && !auto.autoHasAntiTheft;
30+
31+
boolean driverCondition = auto.aggDriverAccPoint > 5;
32+
33+
boolean unitPriceCondition = unitPrice > 100;
34+
35+
boolean condition5 = autoCondition && driverCondition && unitPriceCondition;
36+
37+
// constraint #1
38+
39+
require(auto.maxAutoValue >= 50000 && auto.minAutoYear < 2020, medicalpayments[MedicalPayments], "Auto add Medical Payments");
40+
constraint(auto.maxAutoValue >= 50000 && auto.minAutoYear < 2020 -> medicalpayments[MedicalPayments].Limit == 2000);
41+
42+
// constraint #5
43+
require(condition5, bodilyinjurypropertydamage[BodilyInjuryPropertyDamage], "BIPD is required when Auto IsElectricVehicle and Antitheft is false and Driver accident points > 5 and Collision is selected and MedicalPayments is NOT selected");
44+
45+
// constraint #6
46+
require(medicalpayments[MedicalPayments] == 1 && medicalpayments.medicalDeductible == 500 && UserProfile == "Custom Standard User", bodilyinjurypropertydamage[BodilyInjuryPropertyDamage] { Bodily_Injury_Per_Person_Limit = 1000 }, "BIPD is required when MedicalPayments is selected at 1k limit");
47+
48+
49+
}
50+
51+
type Auto {
52+
@(configurable = false)
53+
int Auto_Value;
54+
55+
@(configurable = false)
56+
int Year;
57+
58+
string Colour;
59+
60+
@(configurable = "false")
61+
string Make;
62+
63+
string License_State;
64+
65+
@(configurable = "false")
66+
string Model;
67+
68+
@(configurable = false)
69+
boolean Is_Electric_Vehicle;
70+
71+
@(configurable = false)
72+
boolean Has_Anti_Theft;
73+
74+
string AssetRecordName;
75+
76+
77+
}
78+
79+
type Vehicle : Auto {
80+
@(sequence = 1)
81+
relation collision : Collision[0..1];
82+
83+
@(sequence = 2)
84+
relation comprehensive : Comprehensive[0..1];
85+
86+
@(sequence = 3)
87+
relation uninsuredMotorist : UninsuredMotorist[0..1];
88+
89+
@(closeRelation = true, propagateUp = true, sequence = 1)
90+
relation driver : AutoDriver[0..5] {
91+
@(defaultValue = 0)
92+
maxDriverAccPoint = max(Driver_Accident_Points);
93+
}
94+
95+
int maxDriverAccPoint = driver.maxDriverAccPoint;
96+
97+
// constraint #2
98+
require(Year > 2023, collision[Collision], "auto add collision coverage if year > 2023");
99+
constraint(collision[Collision] > 0 && Year > 2023 -> collision[Collision].Limit == 5000);
100+
101+
// constraint #3
102+
exclude(collision[Collision] > 0 && collision[Collision].Deductible == 200 && Year < 2020, uninsuredMotorist[UninsuredMotorist]);
103+
104+
}
105+
106+
type Driver {
107+
@(configurable = false)
108+
int Driver_Accident_Points = [0..10];
109+
110+
@(configurable = false)
111+
int Driver_MVR_Points = [0..10];
112+
113+
string Driving_License;
114+
115+
@(configurable = false)
116+
int Age_First_Licensed = [0..100];
117+
118+
@(configurable = false)
119+
string E_Mail;
120+
121+
@(configurable = false)
122+
string State;
123+
124+
@(configurable = false)
125+
int Age = [0..100];
126+
127+
@(configurable = false)
128+
string First_Name;
129+
130+
@(configurable = false)
131+
string Last_Name;
132+
133+
// constraint #4
134+
message(Age_First_Licensed != 0 && Age_First_Licensed < 16, "Warning: Age First License can't be lower than 16", "Warning");
135+
message(Age != 0 && Age < 16, "Driver is underaged to be added to the quote", "Error");
136+
137+
}
138+
139+
type AutoDriver : Driver;
140+
141+
@(split = false)
142+
type UninsuredMotorist {
143+
int Deductible = [0, 50, 100, 200, 500];
144+
145+
int Property_Damage_Per_Accident_Limit = [500, 1000, 1500, 2000];
146+
147+
int Bodily_Injury_Per_Person_Limit = [500, 1000, 1500, 2000];
148+
149+
int Bodily_Injury_Per_Accident_Limit = [500, 1000, 1500, 2000];
150+
151+
int Limit = [1000, 2000, 5000, 10000, 25000, 50000];
152+
153+
154+
}
155+
156+
@(split = false)
157+
type Collision {
158+
@(domainComputation = "false")
159+
int Deductible = [0, 50, 100, 200, 500];
160+
161+
@(defaultValue = "1000", domainComputation = "false")
162+
int Limit = [1000, 2000, 5000, 10000, 25000, 50000];
163+
164+
165+
}
166+
167+
@(split = false)
168+
type BodilyInjuryPropertyDamage {
169+
@(defaultValue = "100", domainComputation = "false")
170+
int Deductible = [0, 50, 100, 200, 500];
171+
172+
@(defaultValue = "1000", domainComputation = "false")
173+
int Bodily_Injury_Per_Person_Limit = [500, 1000, 1500, 2000];
174+
175+
@(defaultValue = "1000", domainComputation = "false")
176+
int Property_Damage_Per_Accident_Limit = [500, 1000, 1500, 2000];
177+
178+
@(defaultValue = "1000", domainComputation = "false")
179+
int Bodily_Injury_Per_Accident_Limit = [500, 1000, 1500, 2000];
180+
181+
@(defaultValue = "1000", domainComputation = "false")
182+
int Limit = [1000, 2000, 5000, 10000, 25000, 50000];
183+
184+
185+
boolean rootCondition5 = parent(condition5);
186+
187+
rule(rootCondition5, "hide", "attribute", "Property_Damage_Per_Accident_Limit");
188+
189+
rule(rootCondition5, "hide", "attribute", "Bodily_Injury_Per_Accident_Limit", "value", 2000);
190+
191+
}
192+
193+
@(split = false)
194+
type MedicalPayments {
195+
@(defaultValue = "100", domainComputation = "false")
196+
int Deductible = [0, 50, 100, 200, 500];
197+
198+
int Property_Damage_Per_Accident_Limit = [500, 1000, 1500, 2000];
199+
200+
int Bodily_Injury_Per_Person_Limit = [500, 1000, 1500, 2000];
201+
202+
int Bodily_Injury_Per_Accident_Limit = [500, 1000, 1500, 2000];
203+
204+
@(defaultValue = "1000", domainComputation = "false")
205+
int Limit = [1000, 2000, 5000, 10000, 25000, 50000];
206+
207+
208+
}
209+
210+
@(split = false)
211+
type Comprehensive {
212+
@(defaultValue = "100", domainComputation = "false")
213+
int Deductible = [0, 50, 100, 200, 500];
214+
215+
@(defaultValue = "1000", domainComputation = "false")
216+
int Limit = [1000, 2000, 5000, 10000, 25000, 50000];
217+
218+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
@(contextPath = "SalesTransaction.UserProfile", attributeSource = "ST")
2+
extern string UserProfile;
3+
4+
type AutoSilver {
5+
@(closeRelation = true, propagateUp = true)
6+
7+
relation auto : Vehicle;
8+
9+
relation bodilyinjurypropertydamage : BodilyInjuryPropertyDamage[0..1];
10+
11+
relation medicalpayments : MedicalPayments[0..1];
12+
13+
}
14+
15+
type Auto {
16+
@(configurable = false)
17+
int Auto_Value;
18+
19+
@(configurable = false)
20+
int Year;
21+
22+
string Colour;
23+
24+
@(configurable = "false")
25+
string Make;
26+
27+
string License_State;
28+
29+
@(configurable = "false")
30+
string Model;
31+
32+
@(configurable = false)
33+
boolean Is_Electric_Vehicle;
34+
35+
@(configurable = false)
36+
boolean Has_Anti_Theft;
37+
38+
string AssetRecordName;
39+
40+
41+
}
42+
43+
type Vehicle : Auto {
44+
relation collision : Collision[0..1];
45+
46+
relation comprehensive : Comprehensive[0..1];
47+
48+
relation uninsuredMotorist : UninsuredMotorist[0..1];
49+
50+
@(closeRelation = true, propagateUp = true)
51+
relation driver : AutoDriver[0..5];
52+
53+
}
54+
55+
type Driver {
56+
@(configurable = false)
57+
int Driver_Accident_Points = [0..10];
58+
59+
@(configurable = false)
60+
int Driver_MVR_Points = [0..10];
61+
62+
string Driving_License;
63+
64+
@(configurable = false)
65+
int Age_First_Licensed = [0..100];
66+
67+
@(configurable = false)
68+
string E_Mail;
69+
70+
@(configurable = false)
71+
string State;
72+
73+
@(configurable = false)
74+
int Age = [0..100];
75+
76+
@(configurable = false)
77+
string First_Name;
78+
79+
@(configurable = false)
80+
string Last_Name;
81+
}
82+
83+
type AutoDriver : Driver;
84+
85+
@(split = false)
86+
type UninsuredMotorist {
87+
int Deductible = [0, 50, 100, 200, 500];
88+
89+
int Property_Damage_Per_Accident_Limit = [500, 1000, 1500, 2000];
90+
91+
int Bodily_Injury_Per_Person_Limit = [500, 1000, 1500, 2000];
92+
93+
int Bodily_Injury_Per_Accident_Limit = [500, 1000, 1500, 2000];
94+
95+
int Limit = [1000, 2000, 5000, 10000, 25000, 50000];
96+
97+
}
98+
99+
@(split = false)
100+
type Collision {
101+
@(domainComputation = "false")
102+
int Deductible = [0, 50, 100, 200, 500];
103+
104+
@(defaultValue = "1000", domainComputation = "false")
105+
int Limit = [1000, 2000, 5000, 10000, 25000, 50000];
106+
107+
}
108+
109+
@(split = false)
110+
type BodilyInjuryPropertyDamage {
111+
@(defaultValue = "100", domainComputation = "false")
112+
int Deductible = [0, 50, 100, 200, 500];
113+
114+
@(defaultValue = "1000", domainComputation = "false")
115+
int Bodily_Injury_Per_Person_Limit = [500, 1000, 1500, 2000];
116+
117+
@(defaultValue = "1000", domainComputation = "false")
118+
int Property_Damage_Per_Accident_Limit = [500, 1000, 1500, 2000];
119+
120+
@(defaultValue = "1000", domainComputation = "false")
121+
int Bodily_Injury_Per_Accident_Limit = [500, 1000, 1500, 2000];
122+
123+
@(defaultValue = "1000", domainComputation = "false")
124+
int Limit = [1000, 2000, 5000, 10000, 25000, 50000];
125+
126+
}
127+
128+
@(split = false)
129+
type MedicalPayments {
130+
@(defaultValue = "100", domainComputation = "false")
131+
int Deductible = [0, 50, 100, 200, 500];
132+
133+
int Property_Damage_Per_Accident_Limit = [500, 1000, 1500, 2000];
134+
135+
int Bodily_Injury_Per_Person_Limit = [500, 1000, 1500, 2000];
136+
137+
int Bodily_Injury_Per_Accident_Limit = [500, 1000, 1500, 2000];
138+
139+
@(defaultValue = "1000", domainComputation = "false")
140+
int Limit = [1000, 2000, 5000, 10000, 25000, 50000];
141+
142+
}
143+
144+
@(split = false)
145+
type Comprehensive {
146+
@(defaultValue = "100", domainComputation = "false")
147+
int Deductible = [0, 50, 100, 200, 500];
148+
149+
@(defaultValue = "1000", domainComputation = "false")
150+
int Limit = [1000, 2000, 5000, 10000, 25000, 50000];
151+
152+
}

0 commit comments

Comments
 (0)