From 67cb5fea72d651c0b8aad2845b9ff05e3bc45adf Mon Sep 17 00:00:00 2001 From: Joshua Mills Date: Thu, 6 Mar 2025 09:33:34 -0500 Subject: [PATCH 1/7] CNDE-2351: update to join logic, v_rdb_obs_mapping --- .../rdb_modern/views/001-v_getobscode.sql | 7 ++++-- .../rdb_modern/views/004-v_getobstxt.sql | 5 +++- .../views/013-v_rdb_obs_mapping.sql | 23 +++++++++++++++---- .../db.rdb_modern.changelog-16.1.yaml | 4 ++-- .../rdb_modern/views/001-v_getobscode-001.sql | 7 ++++-- .../rdb_modern/views/004-v_getobstxt-001.sql | 5 +++- .../views/013-v_rdb_obs_mapping-001.sql | 23 +++++++++++++++---- 7 files changed, 56 insertions(+), 18 deletions(-) diff --git a/db/upgrade/rdb_modern/views/001-v_getobscode.sql b/db/upgrade/rdb_modern/views/001-v_getobscode.sql index 20c11cbe..791e410f 100644 --- a/db/upgrade/rdb_modern/views/001-v_getobscode.sql +++ b/db/upgrade/rdb_modern/views/001-v_getobscode.sql @@ -51,7 +51,10 @@ WITH InvFormQObservations AS FROM dbo.nrt_investigation_observation tnio with (nolock) inner join dbo.nrt_observation_coded ovc with (nolock) ON ovc.observation_uid = tnio.branch_id - inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid + inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid and + CASE WHEN ovc.batch_id IS NOT NULL and o.batch_id = ovc.batch_id then 1 + WHEN ovc.batch_id IS NULL then 1 + else 0 end = 1 WHERE branch_type_cd = 'InvFrmQ' ) @@ -80,7 +83,7 @@ SELECT END AS response_cd, label FROM InvFormQObservations obs - LEFT JOIN dbo.codeset cs with (nolock) on cs.cd = obs.cd + LEFT JOIN dbo.v_codeset cs with (nolock) on cs.cd = obs.cd LEFT JOIN nbs_srte.dbo.code_value_general cvg with (nolock) on cvg.code_set_nm = cs.CODE_SET_NM and cvg.code = obs.ovc_code LEFT JOIN nbs_srte.dbo.Country_code cc with (nolock) on cc.code = obs.ovc_code diff --git a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql index 71371da7..20106383 100644 --- a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql +++ b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql @@ -10,5 +10,8 @@ SELECT FROM dbo.nrt_investigation_observation tnio with (nolock) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id - LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid + LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid and + CASE WHEN ovt.batch_id IS NOT NULL and o.batch_id = ovt.batch_id then 1 + WHEN ovt.batch_id IS NULL then 1 + else 0 end = 1 WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1; \ No newline at end of file diff --git a/db/upgrade/rdb_modern/views/013-v_rdb_obs_mapping.sql b/db/upgrade/rdb_modern/views/013-v_rdb_obs_mapping.sql index cb8cb492..8dc6dedc 100644 --- a/db/upgrade/rdb_modern/views/013-v_rdb_obs_mapping.sql +++ b/db/upgrade/rdb_modern/views/013-v_rdb_obs_mapping.sql @@ -1,3 +1,8 @@ +/* + CNDE-2531: + Added CROSS JOIN with two dummy rows. This allows for a code to ALWAYS be represented alongside a null PHC_UID. + This is important for ensuring that when a selection is removed from the UI +*/ CREATE OR ALTER VIEW dbo.v_rdb_obs_mapping AS SELECT imrdb.RDB_table, @@ -24,8 +29,16 @@ SELECT imrdb.RDB_table, ELSE NULL END AS date_response, ovc.label -FROM nbs_srte.dbo.imrdbmapping imrdb - LEFT JOIN dbo.v_getobscode ovc ON imrdb.unique_cd = ovc.cd - LEFT JOIN dbo.v_getobsnum ovn ON imrdb.unique_cd = ovn.cd - LEFT JOIN dbo.v_getobstxt ovt ON imrdb.unique_cd = ovt.cd - LEFT JOIN dbo.v_getobsdate ovd ON imrdb.unique_cd = ovd.cd; \ No newline at end of file +FROM (SELECT + RDB_table, + unique_cd, + RDB_attribute, + db_field, + r.n + FROM nbs_srte.dbo.imrdbmapping +CROSS JOIN (SELECT 1 AS n UNION ALL SELECT 2) r) imrdb + LEFT JOIN dbo.v_getobscode ovc ON imrdb.unique_cd = ovc.cd and imrdb.n = 2 + LEFT JOIN dbo.v_getobsnum ovn ON imrdb.unique_cd = ovn.cd and imrdb.n = 2 + LEFT JOIN dbo.v_getobstxt ovt ON imrdb.unique_cd = ovt.cd and imrdb.n = 2 + LEFT JOIN dbo.v_getobsdate ovd ON imrdb.unique_cd = ovd.cd and imrdb.n = 2 +where (imrdb.n = 1 or COALESCE(ovc.public_health_case_uid, ovn.public_health_case_uid, ovt.public_health_case_uid, ovd.public_health_case_uid) IS NOT NULL); \ No newline at end of file diff --git a/liquibase-service/src/main/resources/db/changelog/db.rdb_modern.changelog-16.1.yaml b/liquibase-service/src/main/resources/db/changelog/db.rdb_modern.changelog-16.1.yaml index d777d1dc..5cce79a6 100644 --- a/liquibase-service/src/main/resources/db/changelog/db.rdb_modern.changelog-16.1.yaml +++ b/liquibase-service/src/main/resources/db/changelog/db.rdb_modern.changelog-16.1.yaml @@ -445,7 +445,7 @@ databaseChangeLog: runOnChange: true changes: - sqlFile: - path: 001-v_getobscode-001.sql + path: 009-v_codeset-001.sql splitStatements: false - changeSet: id: 72 @@ -621,7 +621,7 @@ databaseChangeLog: runOnChange: true changes: - sqlFile: - path: 009-v_codeset-001.sql + path: 001-v_getobscode-001.sql splitStatements: false - changeSet: id: 95 diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql index 20c11cbe..791e410f 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql @@ -51,7 +51,10 @@ WITH InvFormQObservations AS FROM dbo.nrt_investigation_observation tnio with (nolock) inner join dbo.nrt_observation_coded ovc with (nolock) ON ovc.observation_uid = tnio.branch_id - inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid + inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid and + CASE WHEN ovc.batch_id IS NOT NULL and o.batch_id = ovc.batch_id then 1 + WHEN ovc.batch_id IS NULL then 1 + else 0 end = 1 WHERE branch_type_cd = 'InvFrmQ' ) @@ -80,7 +83,7 @@ SELECT END AS response_cd, label FROM InvFormQObservations obs - LEFT JOIN dbo.codeset cs with (nolock) on cs.cd = obs.cd + LEFT JOIN dbo.v_codeset cs with (nolock) on cs.cd = obs.cd LEFT JOIN nbs_srte.dbo.code_value_general cvg with (nolock) on cvg.code_set_nm = cs.CODE_SET_NM and cvg.code = obs.ovc_code LEFT JOIN nbs_srte.dbo.Country_code cc with (nolock) on cc.code = obs.ovc_code diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql index 71371da7..20106383 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql @@ -10,5 +10,8 @@ SELECT FROM dbo.nrt_investigation_observation tnio with (nolock) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id - LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid + LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid and + CASE WHEN ovt.batch_id IS NOT NULL and o.batch_id = ovt.batch_id then 1 + WHEN ovt.batch_id IS NULL then 1 + else 0 end = 1 WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1; \ No newline at end of file diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/013-v_rdb_obs_mapping-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/013-v_rdb_obs_mapping-001.sql index cb8cb492..8dc6dedc 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/013-v_rdb_obs_mapping-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/013-v_rdb_obs_mapping-001.sql @@ -1,3 +1,8 @@ +/* + CNDE-2531: + Added CROSS JOIN with two dummy rows. This allows for a code to ALWAYS be represented alongside a null PHC_UID. + This is important for ensuring that when a selection is removed from the UI +*/ CREATE OR ALTER VIEW dbo.v_rdb_obs_mapping AS SELECT imrdb.RDB_table, @@ -24,8 +29,16 @@ SELECT imrdb.RDB_table, ELSE NULL END AS date_response, ovc.label -FROM nbs_srte.dbo.imrdbmapping imrdb - LEFT JOIN dbo.v_getobscode ovc ON imrdb.unique_cd = ovc.cd - LEFT JOIN dbo.v_getobsnum ovn ON imrdb.unique_cd = ovn.cd - LEFT JOIN dbo.v_getobstxt ovt ON imrdb.unique_cd = ovt.cd - LEFT JOIN dbo.v_getobsdate ovd ON imrdb.unique_cd = ovd.cd; \ No newline at end of file +FROM (SELECT + RDB_table, + unique_cd, + RDB_attribute, + db_field, + r.n + FROM nbs_srte.dbo.imrdbmapping +CROSS JOIN (SELECT 1 AS n UNION ALL SELECT 2) r) imrdb + LEFT JOIN dbo.v_getobscode ovc ON imrdb.unique_cd = ovc.cd and imrdb.n = 2 + LEFT JOIN dbo.v_getobsnum ovn ON imrdb.unique_cd = ovn.cd and imrdb.n = 2 + LEFT JOIN dbo.v_getobstxt ovt ON imrdb.unique_cd = ovt.cd and imrdb.n = 2 + LEFT JOIN dbo.v_getobsdate ovd ON imrdb.unique_cd = ovd.cd and imrdb.n = 2 +where (imrdb.n = 1 or COALESCE(ovc.public_health_case_uid, ovn.public_health_case_uid, ovt.public_health_case_uid, ovd.public_health_case_uid) IS NOT NULL); \ No newline at end of file From 213544cf5d4324cc3bb8b128dcd411b76bbda6b3 Mon Sep 17 00:00:00 2001 From: Joshua Mills Date: Thu, 6 Mar 2025 10:43:03 -0500 Subject: [PATCH 2/7] CNDE-2351: change case to ISNULL --- db/upgrade/rdb_modern/views/001-v_getobscode.sql | 6 ++---- db/upgrade/rdb_modern/views/004-v_getobstxt.sql | 10 +++++----- .../db/rdb_modern/views/001-v_getobscode-001.sql | 6 ++---- .../db/rdb_modern/views/004-v_getobstxt-001.sql | 10 +++++----- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/db/upgrade/rdb_modern/views/001-v_getobscode.sql b/db/upgrade/rdb_modern/views/001-v_getobscode.sql index 791e410f..6866ef9e 100644 --- a/db/upgrade/rdb_modern/views/001-v_getobscode.sql +++ b/db/upgrade/rdb_modern/views/001-v_getobscode.sql @@ -51,10 +51,8 @@ WITH InvFormQObservations AS FROM dbo.nrt_investigation_observation tnio with (nolock) inner join dbo.nrt_observation_coded ovc with (nolock) ON ovc.observation_uid = tnio.branch_id - inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid and - CASE WHEN ovc.batch_id IS NOT NULL and o.batch_id = ovc.batch_id then 1 - WHEN ovc.batch_id IS NULL then 1 - else 0 end = 1 + inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid + AND ISNULL(ovc.batch_id, 1) = ISNULL(o.batch_id, 1) WHERE branch_type_cd = 'InvFrmQ' ) diff --git a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql index 20106383..d1df7fa8 100644 --- a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql +++ b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql @@ -7,11 +7,11 @@ SELECT ,tnio.branch_type_cd ,o.cd ,ovt.ovt_value_txt as response + ,ovt.batch_id FROM dbo.nrt_investigation_observation tnio with (nolock) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id - LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid and - CASE WHEN ovt.batch_id IS NOT NULL and o.batch_id = ovt.batch_id then 1 - WHEN ovt.batch_id IS NULL then 1 - else 0 end = 1 -WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1; \ No newline at end of file + LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid + AND ISNULL(ovt.batch_id, 1) = ISNULL(o.batch_id, 1) +WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1; + diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql index 791e410f..6866ef9e 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql @@ -51,10 +51,8 @@ WITH InvFormQObservations AS FROM dbo.nrt_investigation_observation tnio with (nolock) inner join dbo.nrt_observation_coded ovc with (nolock) ON ovc.observation_uid = tnio.branch_id - inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid and - CASE WHEN ovc.batch_id IS NOT NULL and o.batch_id = ovc.batch_id then 1 - WHEN ovc.batch_id IS NULL then 1 - else 0 end = 1 + inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid + AND ISNULL(ovc.batch_id, 1) = ISNULL(o.batch_id, 1) WHERE branch_type_cd = 'InvFrmQ' ) diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql index 20106383..d1df7fa8 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql @@ -7,11 +7,11 @@ SELECT ,tnio.branch_type_cd ,o.cd ,ovt.ovt_value_txt as response + ,ovt.batch_id FROM dbo.nrt_investigation_observation tnio with (nolock) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id - LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid and - CASE WHEN ovt.batch_id IS NOT NULL and o.batch_id = ovt.batch_id then 1 - WHEN ovt.batch_id IS NULL then 1 - else 0 end = 1 -WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1; \ No newline at end of file + LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid + AND ISNULL(ovt.batch_id, 1) = ISNULL(o.batch_id, 1) +WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1; + From a5b9691c935c8bb1c2ff2b7eea062a0abcd5c4dc Mon Sep 17 00:00:00 2001 From: Joshua Mills Date: Thu, 6 Mar 2025 10:54:53 -0500 Subject: [PATCH 3/7] CNDE-2531: documentation --- db/upgrade/rdb_modern/views/013-v_rdb_obs_mapping.sql | 3 ++- .../db/rdb_modern/views/013-v_rdb_obs_mapping-001.sql | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/db/upgrade/rdb_modern/views/013-v_rdb_obs_mapping.sql b/db/upgrade/rdb_modern/views/013-v_rdb_obs_mapping.sql index 8dc6dedc..42efab67 100644 --- a/db/upgrade/rdb_modern/views/013-v_rdb_obs_mapping.sql +++ b/db/upgrade/rdb_modern/views/013-v_rdb_obs_mapping.sql @@ -1,7 +1,8 @@ /* CNDE-2531: Added CROSS JOIN with two dummy rows. This allows for a code to ALWAYS be represented alongside a null PHC_UID. - This is important for ensuring that when a selection is removed from the UI + This is important for ensuring that when a selection is removed from the UI, it is properly represented and set + to null in the target table. */ CREATE OR ALTER VIEW dbo.v_rdb_obs_mapping AS diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/013-v_rdb_obs_mapping-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/013-v_rdb_obs_mapping-001.sql index 8dc6dedc..42efab67 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/013-v_rdb_obs_mapping-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/013-v_rdb_obs_mapping-001.sql @@ -1,7 +1,8 @@ /* CNDE-2531: Added CROSS JOIN with two dummy rows. This allows for a code to ALWAYS be represented alongside a null PHC_UID. - This is important for ensuring that when a selection is removed from the UI + This is important for ensuring that when a selection is removed from the UI, it is properly represented and set + to null in the target table. */ CREATE OR ALTER VIEW dbo.v_rdb_obs_mapping AS From d5e72a7b82d43f7df4abe49291f60ee88b496fe8 Mon Sep 17 00:00:00 2001 From: Joshua Mills Date: Thu, 6 Mar 2025 14:33:03 -0500 Subject: [PATCH 4/7] CNDE-2351: fix removal of old records --- db/upgrade/rdb_modern/views/001-v_getobscode.sql | 3 ++- db/upgrade/rdb_modern/views/004-v_getobstxt.sql | 3 +-- .../resources/db/rdb_modern/views/001-v_getobscode-001.sql | 3 ++- .../main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql | 3 +-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/upgrade/rdb_modern/views/001-v_getobscode.sql b/db/upgrade/rdb_modern/views/001-v_getobscode.sql index 6866ef9e..d93252ce 100644 --- a/db/upgrade/rdb_modern/views/001-v_getobscode.sql +++ b/db/upgrade/rdb_modern/views/001-v_getobscode.sql @@ -3,7 +3,7 @@ AS WITH InvFormQObservations AS ( SELECT - public_health_case_uid + tnio.public_health_case_uid ,observation_id ,branch_id ,branch_type_cd @@ -50,6 +50,7 @@ WITH InvFormQObservations AS ELSE 'cvg_code' END AS label FROM dbo.nrt_investigation_observation tnio with (nolock) + INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) inner join dbo.nrt_observation_coded ovc with (nolock) ON ovc.observation_uid = tnio.branch_id inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid AND ISNULL(ovc.batch_id, 1) = ISNULL(o.batch_id, 1) diff --git a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql index d1df7fa8..517f5f1f 100644 --- a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql +++ b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql @@ -7,11 +7,10 @@ SELECT ,tnio.branch_type_cd ,o.cd ,ovt.ovt_value_txt as response - ,ovt.batch_id FROM dbo.nrt_investigation_observation tnio with (nolock) + INNER JOIN dbo.nrt_investigation inv on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid AND ISNULL(ovt.batch_id, 1) = ISNULL(o.batch_id, 1) WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1; - diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql index 6866ef9e..d93252ce 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql @@ -3,7 +3,7 @@ AS WITH InvFormQObservations AS ( SELECT - public_health_case_uid + tnio.public_health_case_uid ,observation_id ,branch_id ,branch_type_cd @@ -50,6 +50,7 @@ WITH InvFormQObservations AS ELSE 'cvg_code' END AS label FROM dbo.nrt_investigation_observation tnio with (nolock) + INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) inner join dbo.nrt_observation_coded ovc with (nolock) ON ovc.observation_uid = tnio.branch_id inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid AND ISNULL(ovc.batch_id, 1) = ISNULL(o.batch_id, 1) diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql index d1df7fa8..517f5f1f 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql @@ -7,11 +7,10 @@ SELECT ,tnio.branch_type_cd ,o.cd ,ovt.ovt_value_txt as response - ,ovt.batch_id FROM dbo.nrt_investigation_observation tnio with (nolock) + INNER JOIN dbo.nrt_investigation inv on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid AND ISNULL(ovt.batch_id, 1) = ISNULL(o.batch_id, 1) WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1; - From 15424d9502d2240bd9d5fcbf9b392ee9a933526e Mon Sep 17 00:00:00 2001 From: Joshua Mills Date: Thu, 6 Mar 2025 14:38:01 -0500 Subject: [PATCH 5/7] CNDE-2351: add nolock to nrt references --- db/upgrade/rdb_modern/views/004-v_getobstxt.sql | 2 +- .../main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql index 7a161bc4..36015fa9 100644 --- a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql +++ b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql @@ -10,7 +10,7 @@ SELECT ,ovt.batch_id FROM dbo.nrt_investigation_observation tnio with (nolock) - INNER JOIN dbo.nrt_investigation inv on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) + INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid AND ISNULL(ovt.batch_id, 1) = ISNULL(o.batch_id, 1) diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql index 7a161bc4..36015fa9 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql @@ -10,7 +10,7 @@ SELECT ,ovt.batch_id FROM dbo.nrt_investigation_observation tnio with (nolock) - INNER JOIN dbo.nrt_investigation inv on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) + INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid AND ISNULL(ovt.batch_id, 1) = ISNULL(o.batch_id, 1) From 56a1d0b25295317c3db021291db181bb5cb59121 Mon Sep 17 00:00:00 2001 From: Joshua Mills Date: Thu, 6 Mar 2025 16:13:39 -0500 Subject: [PATCH 6/7] CNDE-2351: remove unnecessary join condition --- db/upgrade/rdb_modern/views/001-v_getobscode.sql | 1 - db/upgrade/rdb_modern/views/004-v_getobstxt.sql | 1 - .../main/resources/db/rdb_modern/views/001-v_getobscode-001.sql | 1 - .../main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql | 1 - 4 files changed, 4 deletions(-) diff --git a/db/upgrade/rdb_modern/views/001-v_getobscode.sql b/db/upgrade/rdb_modern/views/001-v_getobscode.sql index d93252ce..883a081e 100644 --- a/db/upgrade/rdb_modern/views/001-v_getobscode.sql +++ b/db/upgrade/rdb_modern/views/001-v_getobscode.sql @@ -53,7 +53,6 @@ WITH InvFormQObservations AS INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) inner join dbo.nrt_observation_coded ovc with (nolock) ON ovc.observation_uid = tnio.branch_id inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid - AND ISNULL(ovc.batch_id, 1) = ISNULL(o.batch_id, 1) WHERE branch_type_cd = 'InvFrmQ' ) diff --git a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql index 36015fa9..0669ef38 100644 --- a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql +++ b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql @@ -13,5 +13,4 @@ FROM INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid - AND ISNULL(ovt.batch_id, 1) = ISNULL(o.batch_id, 1) WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1; diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql index d93252ce..883a081e 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql @@ -53,7 +53,6 @@ WITH InvFormQObservations AS INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) inner join dbo.nrt_observation_coded ovc with (nolock) ON ovc.observation_uid = tnio.branch_id inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid - AND ISNULL(ovc.batch_id, 1) = ISNULL(o.batch_id, 1) WHERE branch_type_cd = 'InvFrmQ' ) diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql index 36015fa9..0669ef38 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql @@ -13,5 +13,4 @@ FROM INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid - AND ISNULL(ovt.batch_id, 1) = ISNULL(o.batch_id, 1) WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1; From bedb0f438a52ed27b31914466af8d21e08262008 Mon Sep 17 00:00:00 2001 From: Joshua Mills Date: Wed, 12 Mar 2025 18:22:41 -0400 Subject: [PATCH 7/7] CNDE-2351: fix join condition in obstxt and obscode views --- db/upgrade/rdb_modern/views/001-v_getobscode.sql | 2 +- db/upgrade/rdb_modern/views/004-v_getobstxt.sql | 2 +- .../main/resources/db/rdb_modern/views/001-v_getobscode-001.sql | 2 +- .../main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/upgrade/rdb_modern/views/001-v_getobscode.sql b/db/upgrade/rdb_modern/views/001-v_getobscode.sql index 883a081e..b1f47aca 100644 --- a/db/upgrade/rdb_modern/views/001-v_getobscode.sql +++ b/db/upgrade/rdb_modern/views/001-v_getobscode.sql @@ -52,7 +52,7 @@ WITH InvFormQObservations AS dbo.nrt_investigation_observation tnio with (nolock) INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) inner join dbo.nrt_observation_coded ovc with (nolock) ON ovc.observation_uid = tnio.branch_id - inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid + inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid and ISNULL(o.batch_id,1) = ISNULL(ovc.batch_id,1) WHERE branch_type_cd = 'InvFrmQ' ) diff --git a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql index 0669ef38..113af63a 100644 --- a/db/upgrade/rdb_modern/views/004-v_getobstxt.sql +++ b/db/upgrade/rdb_modern/views/004-v_getobstxt.sql @@ -12,5 +12,5 @@ FROM dbo.nrt_investigation_observation tnio with (nolock) INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id - LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid + LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid and ISNULL(o.batch_id,1) = ISNULL(ovt.batch_id,1) WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1; diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql index 883a081e..b1f47aca 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/001-v_getobscode-001.sql @@ -52,7 +52,7 @@ WITH InvFormQObservations AS dbo.nrt_investigation_observation tnio with (nolock) INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) inner join dbo.nrt_observation_coded ovc with (nolock) ON ovc.observation_uid = tnio.branch_id - inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid + inner join dbo.nrt_observation o with (nolock) ON o.observation_uid = ovc.observation_uid and ISNULL(o.batch_id,1) = ISNULL(ovc.batch_id,1) WHERE branch_type_cd = 'InvFrmQ' ) diff --git a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql index 0669ef38..113af63a 100644 --- a/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql +++ b/liquibase-service/src/main/resources/db/rdb_modern/views/004-v_getobstxt-001.sql @@ -12,5 +12,5 @@ FROM dbo.nrt_investigation_observation tnio with (nolock) INNER JOIN dbo.nrt_investigation inv with (nolock) on tnio.public_health_case_uid = inv.public_health_case_uid and ISNULL(tnio.batch_id, 1) = ISNULL(inv.batch_id, 1) LEFT JOIN dbo.nrt_observation o with (nolock) ON o.observation_uid = tnio.branch_id - LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid + LEFT JOIN dbo.nrt_observation_txt ovt with (nolock) ON ovt.observation_uid = o.observation_uid and ISNULL(o.batch_id,1) = ISNULL(ovt.batch_id,1) WHERE tnio.branch_type_cd = 'InvFrmQ' AND ovt.ovt_seq = 1;