Skip to main content

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 using Math.ceil to ensure minimum compliance.
  • Fixed Quantity Selection: Allows administrators to specifygenerates an exactexecution numbersummary ofsegmented employeesinto to6 bekey selected,columns, regardlesseach of the total population size.

2. Organization Grouping System

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

  • Grouped Scenarios: Organizations sharingwith a GroupRandomD|A identifier(Drug are| 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:

parameters
ScenarioColumn Functional DescriptionDefinition
Carry-OverELIGIBLE (D|A) Automatically includesActive employees who were selected(DOT) in previoustheir cyclesprimary butorganization, werefiltered flaggedby fororganization deferred testingtype (Carry-OverSolo Status)Drug, Solo Alcohol, or ALL).
InactiveINACTIVE Inclusion(D|A) Supports manual inclusion of"Rescued" inactive employees (e.g.,when studentthe lists)INCLUDE_INACTIVE_EMPLOYEE viaparameter customis filteractive.
2nd ORG ({c};t)D|A)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).
SecondaryC/O Org(D|A) IdentifiesCarry-Over: andSelection includesstrictly employeescarried whoforward belong primarily to another organization but have a secondary association withfrom the currentlast pool.finished cycle (Status: FINISHED).
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 TypeFormGroupRandom of 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:

  1. The total eligible population (Active + Rescued Inactive + 2nd Org) is empty for the selected criteria.zero.
  2. No Clinical Service Providers (Stakeholders) (Service Providers) are assigned to theperform organizations"Random inPool" tests for the pool.organizations.
  3. The selection percentages exceed allowed limits (0-100%).