Random
📘 Random Pool Selection Engine
This document outlinesdefines the technical and functional logic governingof the Random Pool Selection process,engine, asdesigned to ensure total transparency and mathematical determinism in audit processes, validated by the project's comprehensive unit testing suite (RandomPoolServiceImpTest). suite.
1. SelectionAudit StrategyTransparency &Structure Quota(Super LogicTable)
The systemengine 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 usingMath.ceilto ensure minimum compliance.Fixed Quantity Selection:Allows administrators to specifygenerates anexactexecutionnumbersummaryofsegmentedemployeesintoto6bekeyselected,columns,regardlesseachof the total population size.
2. Organization Grouping System
The logic supports multi-organizational pools through the GroupRandom attribute:
Grouped Scenarios:Organizations sharingwith aD|AGroupRandomidentifier(Drugare|treated as a single unified pool for selection purposes.Standalone Scenarios:Alcohol)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:breakdown:
| Functional |
|
|---|---|
INCLUDE_INACTIVE_EMPLOYEE |
|
2nd ORG ( |
Employees included in the pool due to having this organization as a secondary association in their profile. |
| IGNORED (D|A) | Inactive employees existing in the database who were NOT rescued (used for accounting integrity). |
| TARGET (D|A) | Formula: (Eligible + Inactive + 2nd Org) * % + Carry-Over. Rounding: Math.ceil. |
4.2. Exclusion Logic & Eligibility
The system applies exclusion filters to prevent duplicate testing based on organization settings:
- Secondary Org Priority: An employee is excluded from their primary organization only if they have an active pool record (NEW or RUNNING) in their secondary organization. If no active conflict exists, they remain in their primary pool.
- Group Respect: D|A quotas are assigned strictly according to the
TypeFormGroupRandomof each organization. If an organization is "SOLO DRUG", its Alcohol columns will always report 0|0. - Deterministic Selection: The Preview and the Real Execution process share the same engine, ensuring that visualized results are identical to those processed.
3. Data Integrity & Constraints
Uniqueness (Double-Dip Protection:Protection): TheWhen system ensures that a single physicalan employee is selected for both Drug and Alcohol tests(ALL resultsmode), inthe system generates a single physical selection record within the execution logs(RandomPoolPerson) to prevent database constraint violations, while correctlymaintaining reportingtraceability themfor inboth the "BOTH" categorycategories in summary tables.counters (BOTH Category).
5.4. ErrorSecurity Handling & ValidationValidations
The process will abort and throwwith a controlled RuntimeException if:
- The total eligible population (Active + Rescued Inactive + 2nd Org) is
empty for the selected criteria.zero. - No
Clinical Service Providers (Stakeholders)(Service Providers) are assigned totheperformorganizations"RandominPool" tests for thepool.organizations. - The selection percentages exceed allowed limits (0-100%).