we have an hims software which will have various modules like Registration, Admission, Billing, Discounts, Referral etc...

Now we are creating a new feature for the Referral Management system.
These are the requirements.

USE-CASES:

  1. Create a referral.
  2. Specify referral bonus as a percentage for a charge.
  3. For a referral, specify the percentage that they are eligible for.
  4. Register a patient with referral other than self.
    i. For Normal Patient.
    ii. For Service Patient.
  5. Create bill for a referral patient with charges which have referral
  bonuses.
  6. Create referral bonus request on billing/collection based on the
  policy defined.
  7. Approve a referral request at the entity level/corporate level based
  on the policy defined.
  8. Generate pay order request based on policy.
  9. View referral bonus status.
  10.View pending referral bonus payouts.
  11.Settle the payout.
  12.Cancel a bill for whom referral bonus has been generated.
    i. Referral bonus request is pending approval.
    ii. Referral bonus request is pending approval.
    iii. Referral bonus payment has been paid.
    iv. Add a negative entry for Referral bonuses that have been
    paid.
    v. Cancel the Referral bonus request if bonus is not paid.
  13.Generate MIS report to handle the following sub-scenarios.
    i. Get the list of all the referral bonuses and their current
      statuses within a specified date range.
    ii. Get the list of all the referral bonuses approved for payout.
    iii. Get report for a particular referral for a specified date range.
    iv. Get month-wise summary of referral payouts.
    v. Reconcile payouts starting from referral source to actual
    payout.
  14.Manage performance of different referrals from a single dashboard.

2. ASSUMPTIONS:

  1. Referral bonus will be given irrespective of discounted bill /
  waived off.
  2. If a referral bonus has already been paid and the bill gets
  cancel, then the amount will be adjusted in the next referral.

3. POLICIES:
  1. Generate referral bonus request at billing/collection.
  2. Referral bonus approval at entity level/corporate level/both.
  3. Applicability criteria for referral bonus.
    i. Once per Patient across all Referrals.
    ii. Once per Patient per Referral.
    iii. For each Referral visit.
    iv. If previous Referral Bonus payouts have not been paid.
  4. Basis for referral bonus should be gross amount or discounted
     amount.

4. AUDIT events to be added
  1. Referral creation/modification.
  2. Referral active/inactive.
  3. Referral bonus request generated/approved/rejected (both levels).
  4. Referral bonus payout request generated.
  5. Referral bonus paid.

  I already have the classes for Billing, patient, visit , discount, policies, audits  so no need to do any changes there
  
  and now we have to do the code and architechture design for this module.
  WHenever a bill is created or any status is changed like modified, cancelled, waived off , an event will be triggered to this new module with the bill details.
  In the bill details we will have different types of charges like services and packages. each charge may or may not have the percentage of referral bonus to be given.
  Based on the entity the respected policies will be selected  and business will be applied based on that
  and the final bonus request will be posted for the respective referral Id
  and then the flow continues

  I have started this by defining the classes like below example

  Class ReferralMaster:

public class ReferralMasterImpl extends EntitySpecificBusinessObjectImpl implements ReferralMaster {

   private String code;
   private String name;
   private String email;
   private String address;
   private String contactName;
   private ObjectId discount;
   private boolean isActive;
   private String phone;
   private ReferralType type;
   private String loginId;
   private boolean isEmpanelled;

 }

Like this help me to do the design