Skip to main content

Random

📘 Random Pool Selection Engine

This document outlines the technical and functional logic governing the Random Pool Selection process, as validated by the project's comprehensive unit testing suite (RandomPoolServiceImpTest).


1. Selection Strategy & Quota Logic

The system supports two primary modes for determining selection quotas, ensuring flexibility for different compliance requirements:

  • Percentage-Based Selection: Calculates the target based on the provided percentage (e.g., 50% of the eligible population). Results are rounded up using Math.ceil to ensure minimum compliance.
  • Fixed Quantity Selection: Allows administrators to specify an exact number of employees to be selected, regardless of the total population size.

2. Organization Grouping System

The logic supports multi-organizational pools through the GroupRandom attribute:

  • Grouped Scenarios: Organizations sharing a GroupRandom identifier are treated as a single unified pool for selection purposes.
  • Standalone Scenarios: Organizations without a group are treated as independent entities with their own specific eligible population.

3. Advanced Inclusion Scenarios (Validated)

The selection engine accounts for specific operational cases confirmed via unit tests:

Scenario Functional Description
Carry-Over Automatically includes employees who were selected in previous cycles but were flagged for deferred testing (Carry-Over Status).
Inactive Inclusion Supports manual inclusion of inactive employees (e.g., student lists) via custom filter parameters ({c};t).
Secondary Org Identifies and includes employees who belong primarily to another organization but have a secondary association with the current pool.

4. Data Integrity & Constraints

Double-Dip Protection: The system ensures that a single physical employee selected for both Drug and Alcohol tests results in a single record within the execution logs to prevent database constraint violations, while correctly reporting them in the "BOTH" category in summary tables.


5. Error Handling & Validation

The process will abort and throw a controlled RuntimeException if:

  1. The eligible population is empty for the selected criteria.
  2. No Clinical Service Providers (Stakeholders) are assigned to the organizations in the pool.