Building a Custom Rule Engine with Prolog
by Dennis Merritt


Listing One

live_virus ->> 'Varicella'. 
live_virus ->> 'Small Pox'.

'DTaP-HepB-IPV+' ->> 'Pediarix(tm)'.

'Hib' ->> 'HbOC'.
'Hib' ->> 'PRP-OMP'.
'Hib' ->> 'PRP-T'.

'PRP-OMP' ->> 'PRP-OMP & Hep B'.
'PRP-OMP' ->> 'PedvaxHIB(tm)'.
'PRP-OMP' ->> 'HIB-OMP'.

Listing Two

table('Recommended B', [
% Recommended Schedule B from 'DHS Hib 2003Mar' for vaccines
% containing PRP-OMP
%   Dose     Minimum    Minimum    Recommended
%              Age      Spacing       Age
  [  1,      6 weeks,    none,      2 months ],
  [  2,     10 weeks,   4 weeks,    4 months ],
  [  3,     12 months,  8 weeks,   15 months ]  ]).


Listing Three

status :-
   valid_count('Hib') gte 2,
   vaccination(2, 'Hib') *>= 7 months,
   !,
   late_start_status.


Listing Four
(a)

valid_count('Measles') eq Count,
valid_count(live_virus) gt 0,


(b) 

   NextDose is Count + 1,
   get_row('M-M-R':'MMWR Recommended', [NextDose, MinAge, _, RecAge, _]),
   MinDate *= maximum( vaccination(last,live_virus) + 4 weeks,
                       birthday + MinAge),
   RecDate1 *= maximum( vaccination(last,live_virus) + 4 weeks,
                       birthday + lower(RecAge)),
   RecDate2 *= maximum( vaccination(last,live_virus) + 4 weeks,
                       birthday + upper(RecAge)),
   calc_status(MinDate, RecDate1, RecDate2, Status),

(c)
   output('M-M-R', [
      dose = NextDose,
      dates = [MinDate, RecDate1, RecDate2],
      rec_info = RecAge,
      status = Status,
      citation = 'MMWR 2002Feb08',
      note = [
       `Next dose based on standard schedule with `,
       `guaranteed 4 week separation from last `,
       `live virus vaccination.` ]]).

Listing Five

test(mv06, vaccines, ['M-M-R', 'Varicella']).
test(mv06, comment, [`First MMR too early to valid_count, 
                                  ready for real #2; Varicella overdue`]).
test(mv06, age, 18 months).
test(mv06, 'M-M-R', vaccination, 8 months).
test(mv06, 'M-M-R', vaccination, 18 months).


Listing Six

STATUS
  Varicella (if no documented immunity)  #1.
PLANNING
  M-M-R #2 between 05/13/2006 and 05/13/2009, earliest is 12/11/2003
  Varicella #1 recommended now
BEHIND SCHEDULE
  Varicella
HISTORY
  Measles;1;M-M-R;01/13/2003;
      [0 years, 8 months, 0 days];X-: Before min. age
  Measles;1;M-M-R;11/13/2003;
      [1 years, 6 months, 0 days];OK: After recommended range





2



