...
Code Block |
---|
rule "PTSD therapy must be provided either by a Therapist (non-MD) or a Psychiatrist (MD)" salience 10 when $vis : Visit( type == VisitType.THERAPY, $pro : provider) Provider( this == $pro, role != ProviderRole.THERAPIST && != ProviderRole.PSYCHIATRIST ) then insertLogical( new IntConstraintOccurrence( drools.getRule().getName(), ConstraintType.NEGATIVE_HARD, 1, $vis, $pro ) ); end rule "Therapy sessions must be scheduled regularly" when $vis : Visit( type == VisitType.THERAPY, $date : date != null, $expectedWeek : expectedWeek > 0, $actualWeek : date.weekIndex, date.weekIndex != $expectedWeek ) then insertLogical( new IntConstraintOccurrence( drools.getRule().getName(), ConstraintType.NEGATIVE_HARD, 10, $vis ) ); end rule "A patient getting Group Therapy should receive 6 sessions total @ 1/wk" when $vis1 : Visit( type == VisitType.GROUP, $date1 : date != null, $seqNum : seqNum, $pat : patient, $onWeek : date.weekIndex ) $vis2 : Visit( this != $vis1, type == VisitType.GROUP, $date2 : date != null, patient == $pat, seqNum == $seqNum + 1, $nextWeek : date.weekIndex, date.weekIndex != $onWeek + 1 ) then insertLogical( new IntConstraintOccurrence( drools.getRule().getName(), ConstraintType.NEGATIVE_HARD, 10, $vis1, $vis2 ) ); end rule "No two therapy visits on the same day in the same week (for severe cases)" when $vis1 : Visit( type == VisitType.THERAPY, $date1 : date != null, $pro : provider, $pat : patient, $onWeek : date.weekIndex, $onDay : date.dayIndex ) $vis2 : Visit( this != $vis1, type == VisitType.THERAPY, $date2 : date != null, provider == $pro, patient == $pat, date.weekIndex == $onWeek, date.dayIndex == $onDay ) then insertLogical( new IntConstraintOccurrence( drools.getRule().getName(), ConstraintType.NEGATIVE_HARD, 1, $vis1, $vis2 ) ); end rule "Therapist and Psychiatrists can see a maximum of 8 PTSD therapy patients a week" when $bus : BusyWeek( $pro : provider, $week : weekIndex ) accumulate ( $vis : Visit( type == VisitType.THERAPY, provider == $pro, $date : date != null, date.weekIndex == $week ), $num : count( $vis ); $num > 8 ) then insertLogical( new IntConstraintOccurrence( drools.getRule().getName(), ConstraintType.NEGATIVE_HARD, 1, $bus ) ); end |
Soft Constraints
Code Block |
---|
rule "Patient should see the same provider" |
...
when $vis1 : Visit( $type : type, $pro : provider != null, $pat : patient ) |
...
$vis2 : Visit( this != $vis1, $date2 : date != null, type == |
...
$type, patient == $pat, provider != null, provider != $pro ) then insertLogical( new IntConstraintOccurrence( drools.getRule().getName(), |
...
ConstraintType.NEGATIVE_SOFT, |
...
4, |
...
$vis1, |
...
$vis2 ) ); |
...
end |
...
rule "Therapy sessions should be scheduled at the same day and time over weeks" |
...
when $vis1 : Visit( type == VisitType.THERAPY, $date1 : date != null, $pro : provider, $pat : patient, |
...
$onWeek : date.weekIndex, $onDay : date.dayIndex, $morn : date.morning ) |
...
$vis2 : Visit( this != $vis1, type == VisitType.THERAPY, $date2 : date != null, provider == $pro, patient == $pat, |
...
date.weekIndex != $onWeek, date.dayIndex != $onDay || date.morning != $morn ) |
...
then insertLogical( new IntConstraintOccurrence( drools.getRule().getName(), |
...
ConstraintType.NEGATIVE_SOFT, |
...
10, |
...
$vis1, |
...
$vis2 ) ); |
...
end |
...
rule "a patient being seen for Group Therapy should not have their session on the same day as Individual therapy" |
...
when $vis1 : Visit( type == VisitType.GROUP, $date1 : date != |
...
null, $pat : patient, $onWeek : date.weekIndex, $onDay : date.dayIndex ) |
...
$vis2 : Visit( type == VisitType.THERAPY, $date2 : date != null, patient == $pat, |
...
date.weekIndex == $onWeek, date.dayIndex == $onDay ) |
...
then insertLogical( new IntConstraintOccurrence( drools.getRule().getName(), |
...
ConstraintType.NEGATIVE_SOFT, |
...
3, |
...
$vis1, |
...
$vis2 ) ); end |
end
Initial State Sample vs. Final State Sample
...