We have some fields (age, visit type, insurance type, city) and some rules:

  1. Some doctors that define weekly schedule template like as:

Doctor D1 works on Monday 7-9 pm , Thursday 7-9 pm.

  1. Some type of Visit Type like as:

Doctor D1 accept Follow up- Laser- Rhinoplasty.

  1. Some type of counters rule in specific time range for doctor:

Doctor D1 accept only 50 patient with insurance type A in 18 to 30 April.

  1. Some type of specific rule:

D1 Accept patient for laser type on Mondays

or for example:

D1 Accept patient only 15-aged patient from New York city

My question is what is the best way for handling this combination of rule for provider (medical) scheduling? (I should combine 4 with 2 in Defining Visit Type form, or maybe firs should define working hour template (1) in one form and then mixing (2, 3, 4) and then add to working hour template?

How I can handle this complex situation for rule based Online appointment booking? I means patient with 16 years not seen time slot that has rule for 15-years patient.

My goal is very simple. just any patient that satisfy rules (that defined in time slots by provider) can see correspond time slot, not all time slots. for reaching to this goal how I can handle this rules (which orders)?


1 Answer 1


Business rules engines allow you to specify your conditions in a (more or less) ad-hoc manner.

Below is an example. Note that this is code, so if your rules must be fluid, you would need a script execution engine to run them.

public class PreferredCustomerDiscountRule : Rule
    public override void Define()
        Customer customer = null;
        IEnumerable<Order> orders = null;

            .Match<Customer>(() => customer, c => c.IsPreferred)
            .Query(() => orders, x => x
                    o => o.Customer == customer,
                    o => o.IsOpen,
                    o => !o.IsDiscounted)
                .Where(c => c.Any()));

            .Do(ctx => ApplyDiscount(orders, 10.0))
            .Do(ctx => ctx.UpdateAll(orders));

    private static void ApplyDiscount(IEnumerable<Order> orders, double discount)
        foreach (var order in orders)

If you don't feel like writing code for your rules, or need the flexibility of storing them as data, not code, you can use an engine that serializes the rules in JSON or XML, like the MicroRule Engine.

  • Dear Robert my main problem is another part. at first we should define doctors working hours? and next we define rules, then update working hours with this rule? or rule should be mixed with counter and then add to working hour.
    – user355834
    Apr 17, 2018 at 15:40
  • I don't know what "rule should be mixed with counter and then add to working hour" means. In general, you should enter the data about each doctor, including hours of doctor availability and rule constraints, and then schedule clients to those doctors based on the rule constraints. Apr 17, 2018 at 16:03
  • I'm sorry for my poor English. you are right. I'm confused about priority of doing these. I means at first define rule and the extend rule into time range and then assign it to doctors, or at first define working hours then define rule then define time range for this rule. is it clear?
    – user355834
    Apr 17, 2018 at 18:35
  • You can't do anything without working hours. Apr 17, 2018 at 18:36
  • so consider you define working hours Monday, Sunday 7-9 PM. then you want define a rule for Monday 8-9 PM (Just accept laser services). I should have a rule engine that create rule and then apply to arbitrary time slot?
    – user355834
    Apr 17, 2018 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.