LogoSupport Hub

Safety Incident Change

Safety Incident Change

Overview

This utility script processes safety incident edits for employees in specific workgroups (WG1 = 10, 62) by converting incident change edits (EDITTYPE 601) to employee state edits (EDITTYPE 404). It handles the transformation of incident types based on predefined business rules, removes conflicting edits, and ensures proper incident tracking based on installation dates. The script is designed to maintain data integrity in the incident management system.

Parameters

The script operates with hardcoded parameters:

  • Target Workgroups: WG1 = 10 (Installation: 6/6/2005), WG1 = 62 (Installation: 3/19/2013)
  • Employee Status: Only active employees (ACTIVESTATUS = 0)
  • Installation Dates: Used to determine which incidents are eligible for processing

Data Components

The script performs several key operations:

  1. Edit Cleanup - Removes existing employee state edits on dates with incident changes
  2. Edit Conversion - Converts incident change edits (601) to employee state edits (404)
  3. Reason Mapping - Maps incident types to appropriate reason codes
  4. Zero Reason Cleanup - Removes employee state edits with reason = 0
  5. Results Tracking - Records processing statistics for each employee

Output Format

The script returns processing results for each affected employee:

ColumnData TypeDescription
EmpvarcharEmployee name (Last, First)
WG1intEmployee workgroup
E404RintNumber of existing employee state edits removed
E601To404intNumber of incident edits converted to state edits
E404R0intNumber of zero-reason edits removed

Technical Implementation

The script uses:

  • Cursor-based processing to iterate through eligible employees
  • Installation date filtering to ensure proper incident calculation
  • Dynamic reason code mapping based on incident types
  • Multi-step edit processing with cleanup and conversion phases
  • Results tracking with table variables for audit purposes

Incident Type Mapping

Original PAYDESNUMNew REASONDescription
220Absent w/o Notify
323Consecutive Absences
520Tardy w/o Notify
720Left Early w/o Notify
922Remove Incident
1021No Incident
41154Abs w Notify
42155Abs wo Notify
43156Consec Abs
44157Tardy w Notify
45158Tardy wo Notify
46159Left Early w Notify
47160Left Early wo Notify
58165Traffic Exclusion

Processing Logic

  1. Employee Selection: Process only active employees in target workgroups
  2. Installation Check: Only process incidents after installation date
  3. Conflict Resolution: Remove existing employee state edits on same dates
  4. Edit Conversion: Convert incident change edits to employee state edits
  5. Cleanup: Remove invalid edits with zero reason codes

Notes

  • Workgroup Specific: Only processes employees in workgroups 10 and 62
  • Installation Date Aware: Respects different installation dates per workgroup
  • Data Integrity: Maintains proper incident tracking and calculation
  • Conflict Resolution: Automatically handles conflicting edits
  • Audit Trail: Provides detailed processing statistics
  • Business Rule Enforcement: Applies standardized incident type mappings
  • Active Employee Focus: Only processes currently active employees
  • Run during maintenance windows to avoid conflicts with payroll processing
  • Verify installation dates are correct for your environment
  • Review incident type mappings to ensure they match current business rules
  • Monitor processing results to identify any unexpected patterns
  • Test thoroughly before running in production environment
  • Consider the impact on incident calculations and reporting

T-SQL

saf_incidentchange.sql
SET NOCOUNT ON;
SET ANSI_WARNINGS OFF;

DECLARE @WG1 INT, @filekey INT;
DECLARE @Results TABLE (
	Filekey INT,
	E404R INT,
	E601To404 INT,
	E404R0 INT
);

DECLARE employees_cursor CURSOR FOR
    SELECT Filekey
FROM EMPLOYEES
WHERE WG1 IN (10, 62)
	AND ACTIVESTATUS = 0
ORDER BY FILEKEY;

OPEN employees_cursor;

FETCH NEXT FROM employees_cursor INTO @filekey;

WHILE @@FETCH_STATUS = 0
BEGIN
	SET @WG1 = (SELECT WG1
	FROM EMPLOYEES
	WHERE FILEKEY = @filekey);

	DECLARE @INSTALLATION DATETIME;
	IF @WG1 = 10 
        BEGIN
		SELECT @INSTALLATION = '6/6/2005';
	END;
	IF @WG1 = 62 
        BEGIN
		SELECT @INSTALLATION = '3/19/2013';
	END;

	-- Installation date is needed because incidents before this date won't be calculated   
	-- so an employee state edit will not do anything to the incident   

	DELETE SUPEDITS   
    FROM SUPEDITS S   
    WHERE S.FILEKEY = @filekey
		AND S.EFFDATE = ISNULL((SELECT effdate
		FROM SUPEDITS
		WHERE filekey = @filekey
			AND EDITTYPE = 601
			AND EFFDATE = s.EFFDATE), '1/1/1900')
		AND S.EDITTYPE = 404
		-- AND I.EDITTYPE = 601   
		AND S.EFFDATE >= @INSTALLATION;

	-- Removes existing Employee State edits on the days that have change incidents being inserted   
	INSERT INTO @Results
	SELECT @filekey, @@ROWCOUNT, NULL, NULL;
	-- insert how many edits were deleted.

	UPDATE SUPEDITS 
    SET EDITTYPE = 404, -- Edittype 404 is the edittype for Employee State edits   
        PAYDESNUM = 0,   
        PREVPAYDES = 0,   
        REASON = CASE   
            -- Paydesnum is the rule that the incident is changed to. The reason will affect the calculation of the incident   
            WHEN PAYDESNUM = 2 THEN 20 -- Absent w/o Notify   
            WHEN PAYDESNUM = 3 THEN 23 -- Consecutive Absences   
            WHEN PAYDESNUM = 5 THEN 20 -- Tardy w/o Notify   
            WHEN PAYDESNUM = 7 THEN 20 -- Left Early w/o Notify   
            WHEN PAYDESNUM = 9 THEN 22 -- Remove Incident   
            WHEN PAYDESNUM = 10 THEN 21 -- No Incident   
            WHEN PAYDESNUM = 41 THEN 154 -- Abs w Notify  
            WHEN PAYDESNUM = 42 THEN 155 -- Abs wo Notify  
            WHEN PAYDESNUM = 43 THEN 156 -- Consec Abs  
            WHEN PAYDESNUM = 44 THEN 157 -- Tardy w Notify  
            WHEN PAYDESNUM = 45 THEN 158 -- Tardy wo Notify  
            WHEN PAYDESNUM = 46 THEN 159 -- Left Early w Notify  
            WHEN PAYDESNUM = 47 THEN 160 -- Left Early wo Notify  
            WHEN PAYDESNUM = 58 THEN 165 -- Traffic Exclusion
            ELSE 0   
        END   
    WHERE EDITTYPE = 601 -- Edittype 601 is the change incident edit.   
		AND FILEKEY = @filekey
		AND EFFDATE >= @INSTALLATION
		AND PAYDESNUM <> PREVPAYDES;

	UPDATE @Results 
    SET E601To404 = @@ROWCOUNT 
    WHERE Filekey = @filekey;
	-- Insert how many edits were changed from 601 to 404

	DELETE FROM SUPEDITS 
    WHERE EDITTYPE = 404
		AND REASON = 0;

	UPDATE @Results 
    SET E404R0 = @@ROWCOUNT 
    WHERE Filekey = @filekey;
	-- Insert how many 0 reason edits were removed.

	FETCH NEXT FROM employees_cursor INTO @filekey;
END;

CLOSE employees_cursor;

DEALLOCATE employees_cursor;

SELECT
	e.LASTNAME + ', ' + e.FIRSTNAME AS Emp,
	e.WG1,
	r.E404R,
	r.E601To404,
	r.E404R0
FROM @Results r
	INNER JOIN EMPLOYEES e
	ON r.Filekey = e.FILEKEY
ORDER BY 2, 1;

Content Inventory

  • Doc File: content/docs/utilities/saf_incidentchange.mdx
  • SQL Script: SQL/utilities/saf_incidentchange.sql