-
Notifications
You must be signed in to change notification settings - Fork 7
APP-926: optimize sp_morbidity_report_datamart_postprocessing #980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nullflux
merged 18 commits into
rel-7.13
from
aw/app-926/optimize-morbidity-datamart-sp
Aug 11, 2026
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b7a9f50
APP-926: optimize sp_morbidity_report_datamart_postprocessing
nullflux 2035045
APP-926: batch-scope morbidity SP (candidate pre-filter) -> ~114ms
nullflux 5300e72
APP-926: add DataDrivenUnitTests cases for the morbidity datamart SP
nullflux 16de693
APP-926: remove one-off equivalence/perf harness
nullflux f755dd0
Merge branch 'rel-7.13' into aw/app-926/optimize-morbidity-datamart-sp
nullflux 58a7e43
Creating the uid_obs temp table to hold numeric(18,0) values for fast…
ericnagel 2b13ecd
We don't need to cast this now, either.
ericnagel 86879ef
Reuse the already parsed/typed/indexed UID temp table and avoid re-sp…
ericnagel e8de3e7
Added a nonclustered index immediately after creating #MORB_TO_LAB_KE…
ericnagel cee4c7c
Added index on #MORB_LAB_RESULTS. This supports the downstream flatte…
ericnagel ae69058
Add index on #MORB_TREATMENTS. This aligns with the flattening patter…
ericnagel 3c9199c
Changed an UPDATE join from LEFT JOIN to INNER JOIN. This is now alig…
ericnagel ea7f7ad
Merge remote-tracking branch 'origin/rel-7.13' into aw/app-926/optimi…
nullflux dcc1227
Merge remote-tracking branch 'origin/rel-7.13' into aw/app-926/optimi…
nullflux c37e0b0
Merge remote-tracking branch 'origin/rel-7.13' into aw/app-926/optimi…
nullflux 9f7de44
APP-926: remove test fixture README
nullflux 65b60ac
Merge branch 'rel-7.13' into aw/app-926/optimize-morbidity-datamart-sp
nullflux 725aa56
Update reporting-pipeline-service/src/main/resources/db/changelog/mig…
nullflux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...ources/db/changelog/migrations/v7.13/rdb/tables/265-add_ix_event_metric_event_uid-001.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| -- APP-926: covering index on EVENT_METRIC(EVENT_UID). | ||
| -- sp_morbidity_report_datamart_postprocessing builds #MORB_EVENT_INIT with | ||
| -- LEFT JOIN dbo.EVENT_METRIC EM ON MR.MORB_RPT_UID = EM.EVENT_UID | ||
| -- but the clustered PK is (EVENT_TYPE, EVENT_UID), so a join on EVENT_UID alone cannot seek and | ||
| -- degrades to a full scan of EVENT_METRIC. This covering | ||
| -- index turns that scan into a seek (the plan's own missing-index hint, 32.7% impact). Idempotent. | ||
| IF NOT EXISTS ( | ||
| SELECT 1 FROM sys.indexes | ||
| WHERE name = 'IX_EVENT_METRIC_EVENT_UID' AND object_id = OBJECT_ID('dbo.EVENT_METRIC') | ||
| ) | ||
| BEGIN | ||
| CREATE NONCLUSTERED INDEX IX_EVENT_METRIC_EVENT_UID | ||
| ON dbo.EVENT_METRIC (EVENT_UID) | ||
| INCLUDE (PROG_AREA_DESC_TXT, ADD_TIME, ADD_USER_ID, LAST_CHG_TIME, LAST_CHG_USER_ID, ADD_USER_NAME, LAST_CHG_USER_NAME); | ||
| END |
7 changes: 7 additions & 0 deletions
7
...ne-service/src/test/resources/testData/unit/app926_morbidity_datamart_empty/expected.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "0": [ | ||
| { | ||
| "QUALIFYING_ROWS": 0 | ||
| } | ||
| ] | ||
| } |
8 changes: 8 additions & 0 deletions
8
...peline-service/src/test/resources/testData/unit/app926_morbidity_datamart_empty/query.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| -- Empty params must produce no datamart rows in this case's key range. | ||
| -- A COUNT is used instead of a bare row SELECT because the framework requires the | ||
| -- query to return at least one row, so the assertion is that the count equals 0. | ||
| -- NOTE keep query.sql comments free of the statement separator character, since the | ||
| -- QueryRunner splits the file on that character before it strips comment lines. | ||
| SELECT COUNT(*) AS QUALIFYING_ROWS | ||
| FROM RDB_MODERN.dbo.MORBIDITY_REPORT_DATAMART | ||
| WHERE MORBIDITY_REPORT_KEY BETWEEN 9268000 AND 9268999; |
25 changes: 25 additions & 0 deletions
25
...peline-service/src/test/resources/testData/unit/app926_morbidity_datamart_empty/setup.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| -- APP-926: empty-parameter guard. Valid, ACTIVE report data is present but every UID | ||
| -- list is empty, so no branch of the qualifying WHERE can match and the datamart gains | ||
| -- no rows in this case's key range. STRING_SPLIT('', ',') yields a single '' token that | ||
| -- casts to 0, and no seeded UID is 0, so nothing qualifies. Key range 9268xxx. | ||
| -- (query.sql asserts a COUNT of 0; the framework requires a query to return a row, so a | ||
| -- zero-row datamart SELECT can't be used here.) | ||
| USE RDB_MODERN; | ||
|
|
||
| INSERT INTO dbo.D_PATIENT (PATIENT_KEY, PATIENT_UID, PATIENT_LOCAL_ID) | ||
| VALUES (9268010, 9268010, 'PAT9268010'); | ||
|
|
||
| INSERT INTO dbo.MORBIDITY_REPORT | ||
| (MORB_RPT_KEY, MORB_RPT_UID, MORB_RPT_LOCAL_ID, JURISDICTION_NM, ELECTRONIC_IND, RECORD_STATUS_CD) | ||
| VALUES | ||
| (9268001, 9268001, 'MOR9268001', 'Empty County', NULL, 'ACTIVE'); | ||
|
|
||
| INSERT INTO dbo.MORBIDITY_REPORT_EVENT | ||
| (MORB_RPT_KEY, PATIENT_KEY, PHYSICIAN_KEY, REPORTER_KEY, MORB_RPT_SRC_ORG_KEY, HSPTL_KEY, | ||
| INVESTIGATION_KEY, CONDITION_KEY, NURSING_HOME_KEY, HEALTH_CARE_KEY, LDF_GROUP_KEY, | ||
| MORB_RPT_CREATE_DT_KEY, HSPTL_DISCHARGE_DT_KEY, ILLNESS_ONSET_DT_KEY, MORB_RPT_DT_KEY, RECORD_STATUS_CD) | ||
| VALUES | ||
| (9268001, 9268010, 1,1,1,1, 1,1,1,1,1, 1,1,1,1, 'ACTIVE'); | ||
|
|
||
| EXEC dbo.sp_morbidity_report_datamart_postprocessing | ||
| @obs_uids=N'', @pat_uids=N'', @prov_uids=N'', @org_uids=N'', @inv_uids=N'', @debug=0; |
20 changes: 20 additions & 0 deletions
20
...line-service/src/test/resources/testData/unit/app926_morbidity_datamart_inv/expected.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "0": [ | ||
| { | ||
| "CASE_STATUS": "C", | ||
| "EXTERNAL_IND": "No", | ||
| "HOSPITAL_FAC_NAME": null, | ||
| "INVESTIGATION_CREATED_IND": "Yes", | ||
| "INVESTIGATION_KEY": 9265010, | ||
| "JURISDICTION_NAME": "Inv County", | ||
| "MORBIDITY_REPORT_KEY": 9265001, | ||
| "MORBIDITY_REPORT_LOCAL_ID": "MOR9265001", | ||
| "PATIENT_LOCAL_ID": null, | ||
| "PROGRAM_AREA_DESCRIPTION": "Enteric", | ||
| "PROVIDER_LAST_NAME": null, | ||
| "REPORTER_LAST_NAME": null, | ||
| "REPORTING_FACILITY_UID": null, | ||
| "REPORT_FAC_NAME": null | ||
| } | ||
| ] | ||
| } |
19 changes: 19 additions & 0 deletions
19
...pipeline-service/src/test/resources/testData/unit/app926_morbidity_datamart_inv/query.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| -- Scoped to the 9265000..9265999 key range so only this case's rows are asserted. | ||
| SELECT | ||
| MORBIDITY_REPORT_KEY, | ||
| MORBIDITY_REPORT_LOCAL_ID, | ||
| JURISDICTION_NAME, | ||
| PATIENT_LOCAL_ID, | ||
| PROVIDER_LAST_NAME, | ||
| REPORTER_LAST_NAME, | ||
| REPORT_FAC_NAME, | ||
| REPORTING_FACILITY_UID, | ||
| HOSPITAL_FAC_NAME, | ||
| INVESTIGATION_KEY, | ||
| INVESTIGATION_CREATED_IND, | ||
| CASE_STATUS, | ||
| PROGRAM_AREA_DESCRIPTION, | ||
| EXTERNAL_IND | ||
| FROM RDB_MODERN.dbo.MORBIDITY_REPORT_DATAMART | ||
| WHERE MORBIDITY_REPORT_KEY BETWEEN 9265000 AND 9265999 | ||
| ORDER BY MORBIDITY_REPORT_KEY; |
32 changes: 32 additions & 0 deletions
32
...pipeline-service/src/test/resources/testData/unit/app926_morbidity_datamart_inv/setup.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| -- APP-926: @inv_uids branch. A report qualifies when MRE.INVESTIGATION_KEY resolves | ||
| -- to an INVESTIGATION whose CASE_UID is in @inv_uids. This also exercises the | ||
| -- INVESTIGATION_CREATED_IND / INVESTIGATION_KEY / CASE_STATUS output columns | ||
| -- (NULLIF(inv.INVESTIGATION_KEY, 1) and IIF(COALESCE(...,1)=1,'No','Yes')). | ||
| -- Key range 9265xxx. | ||
| -- report 9265001 -> INVESTIGATION_KEY 9265010 (CASE_UID 9265010, in @inv) -> qualifies | ||
| -- report 9265002 -> INVESTIGATION_KEY 9265011 (CASE_UID 9265011, NOT in @inv) -> excluded | ||
| USE RDB_MODERN; | ||
|
|
||
| INSERT INTO dbo.INVESTIGATION (INVESTIGATION_KEY, CASE_UID, INV_CASE_STATUS, RECORD_STATUS_CD) | ||
| VALUES (9265010, 9265010, 'C', 'ACTIVE'), | ||
| (9265011, 9265011, 'P', 'ACTIVE'); | ||
|
|
||
| INSERT INTO dbo.MORBIDITY_REPORT | ||
| (MORB_RPT_KEY, MORB_RPT_UID, MORB_RPT_LOCAL_ID, JURISDICTION_NM, ELECTRONIC_IND, RECORD_STATUS_CD) | ||
| VALUES | ||
| (9265001, 9265001, 'MOR9265001', 'Inv County', NULL, 'ACTIVE'), | ||
| (9265002, 9265002, 'MOR9265002', 'Inv County', NULL, 'ACTIVE'); | ||
|
|
||
| INSERT INTO dbo.MORBIDITY_REPORT_EVENT | ||
| (MORB_RPT_KEY, PATIENT_KEY, PHYSICIAN_KEY, REPORTER_KEY, MORB_RPT_SRC_ORG_KEY, HSPTL_KEY, | ||
| INVESTIGATION_KEY, CONDITION_KEY, NURSING_HOME_KEY, HEALTH_CARE_KEY, LDF_GROUP_KEY, | ||
| MORB_RPT_CREATE_DT_KEY, HSPTL_DISCHARGE_DT_KEY, ILLNESS_ONSET_DT_KEY, MORB_RPT_DT_KEY, RECORD_STATUS_CD) | ||
| VALUES | ||
| (9265001, 1,1,1,1,1, 9265010, 1,1,1,1, 1,1,1,1, 'ACTIVE'), | ||
| (9265002, 1,1,1,1,1, 9265011, 1,1,1,1, 1,1,1,1, 'ACTIVE'); | ||
|
|
||
| INSERT INTO dbo.EVENT_METRIC (EVENT_TYPE, EVENT_UID, PROG_AREA_DESC_TXT) | ||
| VALUES ('Observation', 9265001, 'Enteric'); | ||
|
|
||
| EXEC dbo.sp_morbidity_report_datamart_postprocessing | ||
| @obs_uids=N'', @pat_uids=N'', @prov_uids=N'', @org_uids=N'', @inv_uids=N'9265010', @debug=0; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.