diff --git a/reporting-pipeline-service/src/main/resources/db/changelog/migrations/v7.13/rdb/rdb.changelog-7.13.yaml b/reporting-pipeline-service/src/main/resources/db/changelog/migrations/v7.13/rdb/rdb.changelog-7.13.yaml index 9886f8fb2..4a029cd5b 100644 --- a/reporting-pipeline-service/src/main/resources/db/changelog/migrations/v7.13/rdb/rdb.changelog-7.13.yaml +++ b/reporting-pipeline-service/src/main/resources/db/changelog/migrations/v7.13/rdb/rdb.changelog-7.13.yaml @@ -3329,3 +3329,11 @@ databaseChangeLog: - sqlFile: path: db/changelog/migrations/v7.13/rdb/tables/265-add_ix_event_metric_event_uid-001.sql splitStatements: false + - changeSet: + id: app-925-add_ix_lab_test_type_status_root + author: liquibase + runOnChange: false + changes: + - sqlFile: + path: db/changelog/migrations/v7.13/rdb/tables/266-add_ix_lab_test_type_status_root-001.sql + splitStatements: false diff --git a/reporting-pipeline-service/src/main/resources/db/changelog/migrations/v7.13/rdb/routines/017-sp_d_labtest_result_postprocessing-001.sql b/reporting-pipeline-service/src/main/resources/db/changelog/migrations/v7.13/rdb/routines/017-sp_d_labtest_result_postprocessing-001.sql index 45785fcb9..6df9f5eaf 100644 --- a/reporting-pipeline-service/src/main/resources/db/changelog/migrations/v7.13/rdb/routines/017-sp_d_labtest_result_postprocessing-001.sql +++ b/reporting-pipeline-service/src/main/resources/db/changelog/migrations/v7.13/rdb/routines/017-sp_d_labtest_result_postprocessing-001.sql @@ -1782,10 +1782,16 @@ BEGIN SET @PROC_STEP_NAME = 'Update Inactive LAB_TEST_RESULT Records'; /* Update record status for Inactive Orders and associated observations. */ - SELECT ltr.LAB_TEST_UID + /* APP-925: SELECT DISTINCT + a clustered PK make #Inactive_Obs seekable so the + three UPDATEs below can nested-loop seek into it instead of scan-joining a + ~200k-row heap. DISTINCT is equivalence-safe: the UPDATEs set the constant + 'INACTIVE' and an UPDATE...FROM affects each qualifying target row at most once, + so collapsing duplicate LAB_TEST_UID matches changes neither the rows written + nor @@ROWCOUNT. */ + SELECT DISTINCT ltr.LAB_TEST_UID INTO #Inactive_Obs FROM [dbo].LAB_TEST lt WITH (NOLOCK) - INNER JOIN [dbo].LAB_TEST_RESULT ltr WITH (NOLOCK) + INNER JOIN [dbo].LAB_TEST_RESULT ltr WITH (NOLOCK) ON ltr.LAB_TEST_UID = lt.LAB_TEST_UID WHERE ROOT_ORDERED_TEST_PNTR IN (SELECT ROOT_ORDERED_TEST_PNTR @@ -1794,6 +1800,12 @@ BEGIN AND RECORD_STATUS_CD = 'INACTIVE') AND ltr.RECORD_STATUS_CD <> 'INACTIVE'; + /* SELECT INTO infers LAB_TEST_UID as NULLABLE; the inner join on LAB_TEST_UID + guarantees no NULLs reach #Inactive_Obs, so forcing NOT NULL is a no-op on the + data and lets us build a clustered PRIMARY KEY the UPDATEs can seek. */ + ALTER TABLE #Inactive_Obs ALTER COLUMN LAB_TEST_UID BIGINT NOT NULL; + ALTER TABLE #Inactive_Obs ADD PRIMARY KEY CLUSTERED (LAB_TEST_UID); + UPDATE lrc SET RECORD_STATUS_CD = 'INACTIVE' FROM [dbo].LAB_RESULT_COMMENT lrc diff --git a/reporting-pipeline-service/src/main/resources/db/changelog/migrations/v7.13/rdb/tables/266-add_ix_lab_test_type_status_root-001.sql b/reporting-pipeline-service/src/main/resources/db/changelog/migrations/v7.13/rdb/tables/266-add_ix_lab_test_type_status_root-001.sql new file mode 100644 index 000000000..850c65e42 --- /dev/null +++ b/reporting-pipeline-service/src/main/resources/db/changelog/migrations/v7.13/rdb/tables/266-add_ix_lab_test_type_status_root-001.sql @@ -0,0 +1,18 @@ +-- APP-925: covering index on LAB_TEST(LAB_TEST_TYPE, RECORD_STATUS_CD) INCLUDE (ROOT_ORDERED_TEST_PNTR). +-- sp_d_labtest_result_postprocessing's "Update Inactive LAB_TEST_RESULT Records" step (line ~1785) +-- finds inactive orders via +-- SELECT ROOT_ORDERED_TEST_PNTR FROM LAB_TEST WHERE LAB_TEST_TYPE='Order' AND RECORD_STATUS_CD='INACTIVE' +-- which, without this index, is a full scan of LAB_TEST. This is the exec plan's own missing-index hint +-- (77% impact); it turns that scan into a seek. Idempotent. +-- NOTE: the plan's OTHER hint (LAB_TEST_RESULT(RECORD_STATUS_CD) INCLUDE (LAB_TEST_UID)) is intentionally +-- NOT created: it is maintained on the very column the downstream UPDATE flips, so it was measured +-- net-negative across the step. +IF NOT EXISTS ( + SELECT 1 FROM sys.indexes + WHERE name = 'IX_LAB_TEST_type_status_root' AND object_id = OBJECT_ID('dbo.LAB_TEST') +) +BEGIN + CREATE NONCLUSTERED INDEX IX_LAB_TEST_type_status_root + ON dbo.LAB_TEST (LAB_TEST_TYPE, RECORD_STATUS_CD) + INCLUDE (ROOT_ORDERED_TEST_PNTR); +END diff --git a/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_active_order/expected.json b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_active_order/expected.json new file mode 100644 index 000000000..9fae28275 --- /dev/null +++ b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_active_order/expected.json @@ -0,0 +1,16 @@ +{ + "0": [ + { + "SRC": "LAB_RESULT_COMMENT", + "RECORD_STATUS_CD": "ACTIVE" + }, + { + "SRC": "LAB_RESULT_VAL", + "RECORD_STATUS_CD": "ACTIVE" + }, + { + "SRC": "LAB_TEST_RESULT", + "RECORD_STATUS_CD": "ACTIVE" + } + ] +} diff --git a/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_active_order/query.sql b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_active_order/query.sql new file mode 100644 index 000000000..a90ac99e0 --- /dev/null +++ b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_active_order/query.sql @@ -0,0 +1,10 @@ +-- GREEN when the Result under the ACTIVE Order is left ACTIVE in all three tables +-- (no false inactivation). Scoped to the 925102xxx band. Single statement -> key "0". +SELECT SRC, RECORD_STATUS_CD FROM ( + SELECT 'LAB_TEST_RESULT' AS SRC, RECORD_STATUS_CD FROM RDB_MODERN.dbo.LAB_TEST_RESULT WHERE LAB_TEST_UID = 925102001 + UNION ALL + SELECT 'LAB_RESULT_VAL' AS SRC, RECORD_STATUS_CD FROM RDB_MODERN.dbo.LAB_RESULT_VAL WHERE LAB_TEST_UID = 925102001 + UNION ALL + SELECT 'LAB_RESULT_COMMENT' AS SRC, RECORD_STATUS_CD FROM RDB_MODERN.dbo.LAB_RESULT_COMMENT WHERE LAB_TEST_UID = 925102001 +) x +ORDER BY SRC diff --git a/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_active_order/setup.sql b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_active_order/setup.sql new file mode 100644 index 000000000..ba1761b70 --- /dev/null +++ b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_active_order/setup.sql @@ -0,0 +1,47 @@ +-- APP-925: negative case. An ACTIVE Order plus its ACTIVE Result must NOT be flipped. +-- The inactive-order subquery selects only LAB_TEST_TYPE='Order' AND +-- RECORD_STATUS_CD='INACTIVE'; with the Order ACTIVE, its ROOT_ORDERED_TEST_PNTR never +-- enters that set, so #Inactive_Obs is empty for this band and the Result stays ACTIVE. +-- Guards against false inactivation. Band 925102xxx. +-- +-- Order 925102000: LAB_TEST_TYPE='Order', RECORD_STATUS_CD='ACTIVE', root -> itself. +-- Result 925102001: LAB_TEST_TYPE='Result', same root; LAB_TEST_RESULT + LAB_RESULT_VAL +-- + LAB_RESULT_COMMENT start ACTIVE and must stay ACTIVE. +USE RDB_MODERN; + +DELETE FROM dbo.LAB_RESULT_COMMENT WHERE LAB_RESULT_COMMENT_KEY BETWEEN 925102000 AND 925102999; +DELETE FROM dbo.LAB_RESULT_VAL WHERE TEST_RESULT_GRP_KEY BETWEEN 925102000 AND 925102999; +DELETE FROM dbo.LAB_TEST_RESULT WHERE LAB_TEST_KEY BETWEEN 925102000 AND 925102999; +DELETE FROM dbo.RESULT_COMMENT_GROUP WHERE RESULT_COMMENT_GRP_KEY BETWEEN 925102000 AND 925102999; +DELETE FROM dbo.TEST_RESULT_GROUPING WHERE TEST_RESULT_GRP_KEY BETWEEN 925102000 AND 925102999; +DELETE FROM dbo.LAB_TEST WHERE LAB_TEST_KEY BETWEEN 925102000 AND 925102999; + +INSERT INTO dbo.LAB_TEST (LAB_TEST_KEY, LAB_TEST_UID, ROOT_ORDERED_TEST_PNTR, LAB_TEST_TYPE, RECORD_STATUS_CD) +VALUES (925102000, 925102000, 925102000, 'Order', 'ACTIVE'), + (925102001, 925102001, 925102000, 'Result', 'ACTIVE'); + +INSERT INTO dbo.TEST_RESULT_GROUPING (TEST_RESULT_GRP_KEY) VALUES (925102001); +INSERT INTO dbo.RESULT_COMMENT_GROUP (RESULT_COMMENT_GRP_KEY) VALUES (925102001); + +INSERT INTO dbo.LAB_TEST_RESULT + (LAB_TEST_KEY, LAB_TEST_UID, RESULT_COMMENT_GRP_KEY, TEST_RESULT_GRP_KEY, + PERFORMING_LAB_KEY, PATIENT_KEY, COPY_TO_PROVIDER_KEY, LAB_TEST_TECHNICIAN_KEY, + SPECIMEN_COLLECTOR_KEY, ORDERING_ORG_KEY, REPORTING_LAB_KEY, CONDITION_KEY, + LAB_RPT_DT_KEY, MORB_RPT_KEY, INVESTIGATION_KEY, LDF_GROUP_KEY, + ORDERING_PROVIDER_KEY, RECORD_STATUS_CD) +VALUES (925102001, 925102001, 925102001, 925102001, + 1, 1, 1, 1, + 1, 1, 1, 1, + 1, 1, 1, 1, + 1, 'ACTIVE'); + +INSERT INTO dbo.LAB_RESULT_VAL (TEST_RESULT_GRP_KEY, TEST_RESULT_VAL_KEY, LAB_TEST_UID, RECORD_STATUS_CD) +VALUES (925102001, 925102001, 925102001, 'ACTIVE'); + +INSERT INTO dbo.LAB_RESULT_COMMENT (LAB_RESULT_COMMENT_KEY, RESULT_COMMENT_GRP_KEY, LAB_TEST_UID, RECORD_STATUS_CD) +VALUES (925102001, 925102001, 925102001, 'ACTIVE'); + +-- Non-existent UID (925102999): the mutation step is parameter-independent and scans all +-- of LAB_TEST/LAB_TEST_RESULT, so the empty input list keeps every upstream key-allocation +-- INSERT a no-op (no collisions) while the global flip still evaluates this band. +EXEC dbo.sp_d_labtest_result_postprocessing @pLabResultList = N'925102999', @pDebug = 0; diff --git a/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_already_inactive/expected.json b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_already_inactive/expected.json new file mode 100644 index 000000000..28a078386 --- /dev/null +++ b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_already_inactive/expected.json @@ -0,0 +1,16 @@ +{ + "0": [ + { + "SRC": "LAB_RESULT_COMMENT", + "RECORD_STATUS_CD": "INACTIVE" + }, + { + "SRC": "LAB_RESULT_VAL", + "RECORD_STATUS_CD": "INACTIVE" + }, + { + "SRC": "LAB_TEST_RESULT", + "RECORD_STATUS_CD": "INACTIVE" + } + ] +} diff --git a/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_already_inactive/query.sql b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_already_inactive/query.sql new file mode 100644 index 000000000..a8f7e0bdf --- /dev/null +++ b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_already_inactive/query.sql @@ -0,0 +1,11 @@ +-- GREEN when the already-INACTIVE Result stays INACTIVE in all three tables after the +-- SP runs (the <> 'INACTIVE' guards make the step a no-op on these rows). Scoped to the +-- 925103xxx band. Single statement -> key "0". +SELECT SRC, RECORD_STATUS_CD FROM ( + SELECT 'LAB_TEST_RESULT' AS SRC, RECORD_STATUS_CD FROM RDB_MODERN.dbo.LAB_TEST_RESULT WHERE LAB_TEST_UID = 925103001 + UNION ALL + SELECT 'LAB_RESULT_VAL' AS SRC, RECORD_STATUS_CD FROM RDB_MODERN.dbo.LAB_RESULT_VAL WHERE LAB_TEST_UID = 925103001 + UNION ALL + SELECT 'LAB_RESULT_COMMENT' AS SRC, RECORD_STATUS_CD FROM RDB_MODERN.dbo.LAB_RESULT_COMMENT WHERE LAB_TEST_UID = 925103001 +) x +ORDER BY SRC diff --git a/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_already_inactive/setup.sql b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_already_inactive/setup.sql new file mode 100644 index 000000000..f8909d5fc --- /dev/null +++ b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_already_inactive/setup.sql @@ -0,0 +1,46 @@ +-- APP-925: idempotency case. The Result under an INACTIVE Order is ALREADY INACTIVE. +-- Every UPDATE in the step carries an `AND .RECORD_STATUS_CD <> 'INACTIVE'` +-- guard, so already-inactive rows are skipped: no re-write, no error, stays INACTIVE. +-- Band 925103xxx. +-- +-- Order 925103000: LAB_TEST_TYPE='Order', RECORD_STATUS_CD='INACTIVE', root -> itself. +-- Result 925103001: LAB_TEST_TYPE='Result', same root; LAB_TEST_RESULT + LAB_RESULT_VAL +-- + LAB_RESULT_COMMENT start INACTIVE and must remain INACTIVE. +USE RDB_MODERN; + +DELETE FROM dbo.LAB_RESULT_COMMENT WHERE LAB_RESULT_COMMENT_KEY BETWEEN 925103000 AND 925103999; +DELETE FROM dbo.LAB_RESULT_VAL WHERE TEST_RESULT_GRP_KEY BETWEEN 925103000 AND 925103999; +DELETE FROM dbo.LAB_TEST_RESULT WHERE LAB_TEST_KEY BETWEEN 925103000 AND 925103999; +DELETE FROM dbo.RESULT_COMMENT_GROUP WHERE RESULT_COMMENT_GRP_KEY BETWEEN 925103000 AND 925103999; +DELETE FROM dbo.TEST_RESULT_GROUPING WHERE TEST_RESULT_GRP_KEY BETWEEN 925103000 AND 925103999; +DELETE FROM dbo.LAB_TEST WHERE LAB_TEST_KEY BETWEEN 925103000 AND 925103999; + +INSERT INTO dbo.LAB_TEST (LAB_TEST_KEY, LAB_TEST_UID, ROOT_ORDERED_TEST_PNTR, LAB_TEST_TYPE, RECORD_STATUS_CD) +VALUES (925103000, 925103000, 925103000, 'Order', 'INACTIVE'), + (925103001, 925103001, 925103000, 'Result', 'INACTIVE'); + +INSERT INTO dbo.TEST_RESULT_GROUPING (TEST_RESULT_GRP_KEY) VALUES (925103001); +INSERT INTO dbo.RESULT_COMMENT_GROUP (RESULT_COMMENT_GRP_KEY) VALUES (925103001); + +INSERT INTO dbo.LAB_TEST_RESULT + (LAB_TEST_KEY, LAB_TEST_UID, RESULT_COMMENT_GRP_KEY, TEST_RESULT_GRP_KEY, + PERFORMING_LAB_KEY, PATIENT_KEY, COPY_TO_PROVIDER_KEY, LAB_TEST_TECHNICIAN_KEY, + SPECIMEN_COLLECTOR_KEY, ORDERING_ORG_KEY, REPORTING_LAB_KEY, CONDITION_KEY, + LAB_RPT_DT_KEY, MORB_RPT_KEY, INVESTIGATION_KEY, LDF_GROUP_KEY, + ORDERING_PROVIDER_KEY, RECORD_STATUS_CD) +VALUES (925103001, 925103001, 925103001, 925103001, + 1, 1, 1, 1, + 1, 1, 1, 1, + 1, 1, 1, 1, + 1, 'INACTIVE'); + +INSERT INTO dbo.LAB_RESULT_VAL (TEST_RESULT_GRP_KEY, TEST_RESULT_VAL_KEY, LAB_TEST_UID, RECORD_STATUS_CD) +VALUES (925103001, 925103001, 925103001, 'INACTIVE'); + +INSERT INTO dbo.LAB_RESULT_COMMENT (LAB_RESULT_COMMENT_KEY, RESULT_COMMENT_GRP_KEY, LAB_TEST_UID, RECORD_STATUS_CD) +VALUES (925103001, 925103001, 925103001, 'INACTIVE'); + +-- Non-existent UID (925103999): the mutation step is parameter-independent and scans all +-- of LAB_TEST/LAB_TEST_RESULT, so the empty input list keeps every upstream key-allocation +-- INSERT a no-op (no collisions) while the global flip still evaluates this band. +EXEC dbo.sp_d_labtest_result_postprocessing @pLabResultList = N'925103999', @pDebug = 0; diff --git a/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_inactive_order/expected.json b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_inactive_order/expected.json new file mode 100644 index 000000000..28a078386 --- /dev/null +++ b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_inactive_order/expected.json @@ -0,0 +1,16 @@ +{ + "0": [ + { + "SRC": "LAB_RESULT_COMMENT", + "RECORD_STATUS_CD": "INACTIVE" + }, + { + "SRC": "LAB_RESULT_VAL", + "RECORD_STATUS_CD": "INACTIVE" + }, + { + "SRC": "LAB_TEST_RESULT", + "RECORD_STATUS_CD": "INACTIVE" + } + ] +} diff --git a/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_inactive_order/query.sql b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_inactive_order/query.sql new file mode 100644 index 000000000..b25161c1f --- /dev/null +++ b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_inactive_order/query.sql @@ -0,0 +1,12 @@ +-- GREEN when the ACTIVE Result under the INACTIVE Order has been flipped to INACTIVE +-- in all three tables. Scoped to the 925101xxx band so the parameter-independent, +-- whole-table mutation step's writes to other cases' bands cannot leak into the assert. +-- Single statement (no inner semicolons) so it maps to result key "0". +SELECT SRC, RECORD_STATUS_CD FROM ( + SELECT 'LAB_TEST_RESULT' AS SRC, RECORD_STATUS_CD FROM RDB_MODERN.dbo.LAB_TEST_RESULT WHERE LAB_TEST_UID = 925101001 + UNION ALL + SELECT 'LAB_RESULT_VAL' AS SRC, RECORD_STATUS_CD FROM RDB_MODERN.dbo.LAB_RESULT_VAL WHERE LAB_TEST_UID = 925101001 + UNION ALL + SELECT 'LAB_RESULT_COMMENT' AS SRC, RECORD_STATUS_CD FROM RDB_MODERN.dbo.LAB_RESULT_COMMENT WHERE LAB_TEST_UID = 925101001 +) x +ORDER BY SRC diff --git a/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_inactive_order/setup.sql b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_inactive_order/setup.sql new file mode 100644 index 000000000..0425fbfeb --- /dev/null +++ b/reporting-pipeline-service/src/test/resources/testData/unit/app925_labtest_inactive_order/setup.sql @@ -0,0 +1,62 @@ +-- APP-925: sp_d_labtest_result_postprocessing "Update Inactive LAB_TEST_RESULT +-- Records" step. An INACTIVE Order plus its ACTIVE Result: the SP builds +-- #Inactive_Obs = active LAB_TEST_RESULT rows whose LAB_TEST.ROOT_ORDERED_TEST_PNTR +-- resolves to an INACTIVE LAB_TEST_TYPE='Order', then flips LAB_TEST_RESULT, +-- LAB_RESULT_VAL and LAB_RESULT_COMMENT for those UIDs to INACTIVE. +-- +-- That step scans ALL of LAB_TEST/LAB_TEST_RESULT (parameter-independent), and the +-- SP COMMITs internally so seeded rows persist past the harness rollback. Each case +-- therefore lives in a distinct key band (925101xxx here) and query.sql scopes to it. +-- +-- Order 925101000: LAB_TEST_TYPE='Order', RECORD_STATUS_CD='INACTIVE', root -> itself. +-- Result 925101001: LAB_TEST_TYPE='Result', same root; its LAB_TEST_RESULT + +-- LAB_RESULT_VAL + LAB_RESULT_COMMENT start ACTIVE. +-- Expected post-run: all three of the Result's rows are INACTIVE. +-- +-- NOT-NULL columns seeded per sys.columns: LAB_TEST(LAB_TEST_KEY, RECORD_STATUS_CD); +-- LAB_TEST_RESULT(all *_KEY + RECORD_STATUS_CD); LAB_RESULT_VAL(TEST_RESULT_GRP_KEY, +-- TEST_RESULT_VAL_KEY, RECORD_STATUS_CD); LAB_RESULT_COMMENT(LAB_RESULT_COMMENT_KEY, +-- RESULT_COMMENT_GRP_KEY, RECORD_STATUS_CD). Grouping FK parents seeded too. +USE RDB_MODERN; + +-- Idempotent reset of this band (SP commits, so rows survive prior runs). Child-first. +DELETE FROM dbo.LAB_RESULT_COMMENT WHERE LAB_RESULT_COMMENT_KEY BETWEEN 925101000 AND 925101999; +DELETE FROM dbo.LAB_RESULT_VAL WHERE TEST_RESULT_GRP_KEY BETWEEN 925101000 AND 925101999; +DELETE FROM dbo.LAB_TEST_RESULT WHERE LAB_TEST_KEY BETWEEN 925101000 AND 925101999; +DELETE FROM dbo.RESULT_COMMENT_GROUP WHERE RESULT_COMMENT_GRP_KEY BETWEEN 925101000 AND 925101999; +DELETE FROM dbo.TEST_RESULT_GROUPING WHERE TEST_RESULT_GRP_KEY BETWEEN 925101000 AND 925101999; +DELETE FROM dbo.LAB_TEST WHERE LAB_TEST_KEY BETWEEN 925101000 AND 925101999; + +INSERT INTO dbo.LAB_TEST (LAB_TEST_KEY, LAB_TEST_UID, ROOT_ORDERED_TEST_PNTR, LAB_TEST_TYPE, RECORD_STATUS_CD) +VALUES (925101000, 925101000, 925101000, 'Order', 'INACTIVE'), + (925101001, 925101001, 925101000, 'Result', 'ACTIVE'); + +INSERT INTO dbo.TEST_RESULT_GROUPING (TEST_RESULT_GRP_KEY) VALUES (925101001); +INSERT INTO dbo.RESULT_COMMENT_GROUP (RESULT_COMMENT_GRP_KEY) VALUES (925101001); + +INSERT INTO dbo.LAB_TEST_RESULT + (LAB_TEST_KEY, LAB_TEST_UID, RESULT_COMMENT_GRP_KEY, TEST_RESULT_GRP_KEY, + PERFORMING_LAB_KEY, PATIENT_KEY, COPY_TO_PROVIDER_KEY, LAB_TEST_TECHNICIAN_KEY, + SPECIMEN_COLLECTOR_KEY, ORDERING_ORG_KEY, REPORTING_LAB_KEY, CONDITION_KEY, + LAB_RPT_DT_KEY, MORB_RPT_KEY, INVESTIGATION_KEY, LDF_GROUP_KEY, + ORDERING_PROVIDER_KEY, RECORD_STATUS_CD) +VALUES (925101001, 925101001, 925101001, 925101001, + 1, 1, 1, 1, + 1, 1, 1, 1, + 1, 1, 1, 1, + 1, 'ACTIVE'); + +INSERT INTO dbo.LAB_RESULT_VAL (TEST_RESULT_GRP_KEY, TEST_RESULT_VAL_KEY, LAB_TEST_UID, RECORD_STATUS_CD) +VALUES (925101001, 925101001, 925101001, 'ACTIVE'); + +INSERT INTO dbo.LAB_RESULT_COMMENT (LAB_RESULT_COMMENT_KEY, RESULT_COMMENT_GRP_KEY, LAB_TEST_UID, RECORD_STATUS_CD) +VALUES (925101001, 925101001, 925101001, 'ACTIVE'); + +-- The "Update Inactive LAB_TEST_RESULT Records" step is parameter-independent: it scans +-- ALL of LAB_TEST/LAB_TEST_RESULT regardless of @pLabResultList. Passing a NON-EXISTENT +-- UID (925101999) leaves every upstream temp table empty, so the SP's key-allocation +-- INSERTs (into TEST_RESULT_GROUPING / nrt_*_key) touch nothing and cannot collide, +-- while the global mutation step still runs and flips this band. This isolates the +-- APP-925 change from unrelated upstream key-generation state, mirroring the datamart-SP +-- pattern (seed the dims the step reads, skip the upstream chain). +EXEC dbo.sp_d_labtest_result_postprocessing @pLabResultList = N'925101999', @pDebug = 0;