Skip to main content

Random

📘 Random Pool Selection Engine

This document defines the technical and functional logic of the Random Pool Selection engine,engine designed(RandomPoolServiceImp), to ensure total transparency and mathematical determinism in audit processes, validatedcovered by the RandomPoolServiceImpTest suite. Its goal is audit transparency: every number shown before a run can be traced back to a concrete rule below.

Last reviewed: 2026-12-01 — includes the Secondary Organization rule change (double random allowed).


1. Pool Universe (who can be selected)

A random always runs for the organization selected in the session, but its pool spans every organization that shares the same Group Random value. The pool is built in this order:

    Active DOT employees (type = DOT, enabled = true) whose primary organization belongs to the group. Rescued inactive employees, according to the RANDOM_POOL_INCLUDE_INACTIVE_EMPLOYEE parameter (see §3). Secondary organization employees: active DOT employees whose secondary organization belongs to the group (see §2).

    Each person enters the pool once. If someone is already in the pool by step 1 or 2, step 3 does not add them again.

    The same eligibility service (IPersonEligibilityService) feeds the Distribution List, Preview and Run, so the list on screen and the pool used by the engine always contain the same people.


    2. Secondary Organization Rule

    ⚠️ Rule changed (2026-12-01). The previous rule ("an employee is excluded from their primary organization if they have an active pool record in their secondary organization") no longer applies and was removed from the engine.

    Current rule: double random is allowed.

      An employee with a secondary organization stays in the pool of both organizations: the primary and the secondary one. They can be selected in both randoms independently, even if one of them is still NEW or RUNNING. There is no check that blocks a person from being in two active randoms; this is intended. An employee can have only one secondary organization. Only active employees enter through a secondary organization (inactive rescue does not apply to secondary org). When a person enters by secondary organization, the engine uses the secondary organization's TypeFormGroupRandom (Solo Drug / Solo Alcohol / ALL) to decide whether they are eligible for Drug, Alcohol or both — not the one of their primary organization. In the summary, they are counted in the 2nd ORG column under the secondary organization's row.

      Business context: used when the same employer has sub-companies per DOT mode (e.g., FMCSA + PHMSA). Before running a random, the admin can temporarily set a secondary organization on the employees that must be covered, and remove it afterwards. Because randoms often stay open for months while data is completed, overlaps between randoms are expected.

      DOT multi-agency guidance generally suggests one pool per employee. Allowing double random was reviewed and accepted as a business decision.

      Where it shows in the UI:

        Distribution List → "Pool Source" column: badge Secondary org · Primary: <primary org name> for people who entered by secondary organization. Empty for everyone else. Activation headers (HUB popovers, services panel, Employee forms modal): show · Random from: <org> when the random that activated the test belongs to a different organization than the employee's form record. HUB: changing Organization (Reg Mode) or Secondary Organization asks for confirmation (showing old → new value), because it changes which random pools the employee enters. The organizations offered as secondary are limited by the SHOW_SECONDARY_ORGANIZATION parameter.

        3. Inactive Rescue Parameter

        Parameter: RANDOM_POOL_INCLUDE_INACTIVE_EMPLOYEE (global, configured in the database).

        ValueBehavior
        Empty / not configuredNo inactive employee is rescued.
        trueAll inactive DOT employees of the group are rescued.
        {COLUMN_CODE;VALUE}Only employees whose custom column matches that value are rescued. Example: {EE_STATUS;L} (Leave of Absence).

        Inactive employees that are not rescued are reported in the IGNORED column.


        4. Audit Transparency Structure (Preview)

        The enginePreview generatesshows anone executionrow summaryper segmentedorganization intowith 6 key columns, each with a D|A (Drug | Alcohol) breakdown:

        Column Functional Definition **ELIGIBLE (D|A)** Active DOT employees (DOT)counted inunder their primary organization,organization (any organization of the Group Random), filtered by organizationthe organization's type (Solo Drug, Solo Alcohol,Alcohol or ALL). Excludes rescued inactives and secondary-org entries. **INACTIVE (D|A)** "Rescued" inactiveInactive employees whenrescued theby INCLUDE_INACTIVE_EMPLOYEERANDOM_POOL_INCLUDE_INACTIVE_EMPLOYEE parameter is active.(§3). **2nd ORG (D|A)** Employees includedwho inentered the pool due to havingbecause this organization asis atheir secondary associationorganization. inCounted theirunder profile.the secondary organization's row, using its type (§2). **IGNORED (D|A)** Inactive employees existing in the database who were NOT rescuedrescued. (usedInformational foronly; accountingthey integrity).are not part of the pool. **C/O (D|A)** **Carry-Over:** Selectiontests carriedmarked forwardCARRY_OVER fromin the organization's most recent previous cyclerandom (by start date), regardless ofwhatever its completion status (RUNNING§6). orCounted FINISHED).under the employee's current primary organization. **TARGET (D|A)**Per Formula:organization: ceil((Eligible + Inactive + 2nd Org) *× %) + Carry-Over. Carry-Over is added only if the organization's pool for that test is greater than 0. In fixed-quantity mode, see §8.

        After a real Run, the results modal shows per organization: ONLY DRUG, ONLY ALC, BOTH and TOTAL selected.


        5. Selection Logic

          Percentage or fixed quantity: the admin chooses either a percentage (0–100) or a fixed number of employees for Drug and for Alcohol. Draw scope: the draw is done once for the whole Group Random pool, separately for Drug and for Alcohol. Each draw only considers people whose organization type allows that test (ALL or the matching Solo type). Rounding: percentage draws use Math.ceil (round up). A fixed quantity
          larger

          2.than Exclusionthe Logicpool &is Eligibility

          capped

          Theat systemthe appliespool exclusion filters to prevent duplicate testing based on organization settings:

            size. Secondary Org Priority:Randomness: Anthe employeepool is excludedshuffled fromwith their primary organization only if they have an active pool recordSecureRandom (NEWcryptographic-grade). orOnly RUNNING)counts inare theirlogged secondary(RANDOM_SELECTION organization.universe=… Ifrequested=… noselected=…), activenever conflictthe exists,list theyof remain in their primary pool.people. Group Respect: D|A quotas are assigned strictly according to the TypeFormGroupRandom of each organization. Ifif an organization is "SOLOSolo DRUG",Drug, its Alcohol columns will always reportshow 0|0 (and vice versa). DeterministicPreview Selection:vs. Run: Theboth Previewuse the same engine and the Realsame Executionpool processrules, shareso the counts and targets match as long as the data does not change between them. The people selected are not the same: engine,Preview ensuringis thata visualizedsimulation resultsand areevery identicaldraw is random. Preview does not save anything. Other random forms: besides Drug and Alcohol, any other form linked to thosethe processed.Random Pool test type in the company is activated for every person selected by the draw.

            3.6. Carry-Over

            Automatic (on Run): the engine takes the organization's most recent previous random (ordered by start date, any status, including CANCELED) and adds every test marked CARRY_OVER in it to the new random.

              Carry-over is additive: if a person is selected in the new draw and has a carry-over, they get two tests (one from the draw, one from the carry-over with a reference to the original record). The carry-over keeps the employee type recorded on the original test, even if the employee's type has changed since. Carry-overs for forms other than Drug/Alcohol (e.g., Medical) are also carried.

              Manual Pull Carry-Over: from an existing random, the admin can pull carry-overs from another random of the same organization.

                Target random must be NEW or RUNNING. Source random must be FINISHED or RUNNING. A read-only preview lists the people and forms that will be pulled before confirming. Carry-overs already pulled (into this random or any other) are skipped. If nothing is left, the user gets an informational message instead of an error. Both randoms must belong to the organization selected in the session; otherwise the system answers "not found".

                7. Data Integrity & Constraints

                  UniquenessOne record per person per random (Double-Dip Protection): Whena an employee isperson selected for both Drug and Alcohol (ALL mode), the system generatesgets a single physicalRandomPoolPerson selectionrecord, recordand is counted as BOTH in the summary. Each test (RandomPoolPerson)form) still gets its own record. Full pool snapshot: people in the pool who were not selected are also saved in the random with included = false, so the random keeps evidence of the full universe it was drawn from. Run parameters saved for audit: drug value, alcohol value and whether it was a percentage are stored on the random. Name: RNDMPL-<ORG CODE>-<MMMdd>-<YYYY>. Atomic run: the run is transactional; if any step fails, nothing is saved.

                  8. Known Limitations

                    TARGET vs. actual selection: TARGET is calculated per organization, while the draw runs over the whole group. With several organizations in the group, the sum of per-organization ceil values can be slightly higher than the number actually drawn. Fixed-quantity mode: each organization's TARGET shows the full fixed quantity, but the draw takes that quantity once for the whole group. Inactive rescue parameter is global, not per organization. Migration mode does not validate person IDs against the company or organization: the caller must make sure every ID belongs to preventthe databaseorganization violations,being whilemigrated maintaining(§11). traceabilityMigration for both categories inmode summary counters (ELIGIBLE, INACTIVE, 2nd ORG, TARGET) are not meaningful: they mix the provided distribution list with the regular pool rules. Use the ONLY DRUG / ONLY ALC / BOTH Category).results instead.

                    4.9. SecurityLifecycle

                    StatusMeaning
                    **NEW**Created by a Run.
                    **RUNNING**Tests in progress.
                    **FINISHED**Closed with the Finish button. Only allowed when every selected employee has completed their test.
                    **CANCELED**Any non-finished random can be canceled; its incomplete tests are canceled too.

                    10. Validations

                    The process will abortstops with a controlled RuntimeExceptionerror (no data saved) if:

                      WhenConditionHTTP
                      Preview / RunNo stakeholder (service provider) assigned to the Random Pool test type for the organization. Checked first.409
                      Preview / RunPercentage mode with a Drug or Alcohol value outside 0–100.400
                      Preview / RunThe total eligible populationpool (Active + Rescued Inactive + 2nd Org) is zero.empty.409
                      FinishSome Noselected Stakeholdersemployees (Servicehave Providers)not arecompleted assignedtheir totest.409
                      Pull performCarry-OverTarget "Randomrandom Pool"not NEW/RUNNING, or source random not FINISHED/RUNNING.409
                      RunFailure activating tests for the organizations.selected employees (whole run is rolled back).500

                      11. Migration Mode (historical load)

                      Migration mode loads into Nexus33 a random that was already drawn outside the system (e.g., historical randoms from before onboarding). It does not perform a draw: it records exactly the people provided.

                      Not available in the UI. It is triggered only through the Run endpoint with migration = true, by the development/support team.

                      Input (Run request):

                      FieldMeaning
                      migrationtrue to enable the mode.
                      distributionListIdsComma-separated person IDs: the full universe of the historical random. Replaces the calculated pool.
                      drugIdsComma-separated person IDs selected for Drug.
                      alcoholIdsComma-separated person IDs selected for Alcohol.
                      startDate / finishDateHistorical dates of the random. startDate is also used as the tests' activation date and in the random's name.

                      Behavior:

                        Drug and Alcohol selections are taken exactly from drugIds / alcoholIds: no shuffle, no percentage, no TypeFormGroupRandom filter. People in distributionListIds who are not in either list are saved with included = false, the same as a normal run. The selectionstandard percentagesvalidations exceedstill allowedapply: limitsa stakeholder must be assigned, the regular pool must not be empty, and, if percentage = true, the values must be between 0 and 100. Carry-over from the organization's previous random is still added (0-100%)§6). The random is created as NEW, the same as a normal run, and its tests are activated and notified the same way.