Skip to content

Commit 51597a4

Browse files
committed
Fix RTR bug #3: rewrite morbidity report user comment join via NRT staging CSV
The step "Generating ##SAS_morb_Rpt_User_Comment" joined the Order observation to itself via root.morb_rpt_uid = obs.observation_uid and then filtered obs.obs_domain_cd_st_1 IN ('C_Order','C_Result'), which is impossible because the Order row's obs_domain_cd_st_1 is 'Order'. The temp table was therefore always empty and MORB_RPT_USER_COMMENT never populated. Replaced the broken self-join with a staging-side walk: the upstream NRT row #nrt_morbidity_observation already carries followup_observation_uid as a CSV of the Order's children (mixed C_Order / C_Result / Result), so this step expands that CSV via CROSS APPLY string_split and joins to #morb_obs_reference filtered to obs_domain_cd_st_1 = 'C_Result' to pull the user-comment row. Stays entirely within RDB_MODERN staging — no cross-DB read of nbs_odse.dbo.act_relationship, consistent with the sp_nrt_*_postprocessing layer's "NRT-only" convention (cross-DB ODSE joins live exclusively in sp_*_event SPs). Verified locally: applied the routine, truncated MORB_RPT_USER_COMMENT, ran sp_d_morbidity_report_postprocessing for the seeded morb (uid 20080010), confirmed 1 row populated with the seeded user-comment text. job_flow_log shows step 19 (build ##SAS_morb_Rpt_User_Comment) and step 27 (Insert into morb_Rpt_User_Comment) both at row_count=1 with no errors.
1 parent 3ef27ab commit 51597a4

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

liquibase-service/src/main/resources/db/005-rdb_modern/routines/016-sp_nrt_morbidity_report_postprocessing-001.sql

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -799,21 +799,33 @@ BEGIN
799799
END;')
800800

801801

802+
-- Find the morb Order's C_Result child (user-comment row) via the
803+
-- staging-side projection of the act_relationship graph. The upstream
804+
-- NRT row #nrt_morbidity_observation already carries
805+
-- followup_observation_uid as a CSV of the Order's children
806+
-- (mixed C_Order / C_Result / Result), so this step stays in
807+
-- RDB_MODERN staging — no cross-DB read of nbs_odse.dbo.act_relationship.
808+
-- The C_Result domain code is what distinguishes the user-comment row
809+
-- from lab-result and C_Order siblings.
802810
SET @sql = N'
803811
SELECT root.morb_Rpt_Key,
804812
root.morb_rpt_uid,
805-
obs.activity_to_time AS user_comments_dt,
806-
obs.add_user_id AS user_comments_by,
813+
cr.activity_to_time AS user_comments_dt,
814+
cr.add_user_id AS user_comments_by,
807815
REPLACE(REPLACE(ovt.ovt_value_txt, CHAR(13) + CHAR(10),'' ''), CHAR(10), '' '') AS external_morb_rpt_comments,
808816
root.record_status_cd
809817
INTO '+@SAS_morb_Rpt_User_Comment+'
810818
FROM '+@tmp_Morbidity_Report+' as root
811-
INNER JOIN #morb_obs_reference AS obs ON root.morb_rpt_uid = obs.observation_uid
812-
INNER JOIN #updated_morb_observation_list AS ls ON ls.observation_uid = obs.observation_uid
813-
INNER JOIN #tmp_nrt_observation_txt AS ovt ON ovt.observation_uid = obs.observation_uid
819+
INNER JOIN #nrt_morbidity_observation AS nmo
820+
ON nmo.observation_uid = root.morb_rpt_uid
821+
CROSS APPLY string_split(rtrim(ltrim(nmo.followup_observation_uid)), '','') AS followupObs
822+
INNER JOIN #morb_obs_reference AS cr
823+
ON cr.observation_uid = TRY_CAST(followupObs.value AS bigint)
824+
AND cr.obs_domain_cd_st_1 = ''C_Result''
825+
INNER JOIN #tmp_nrt_observation_txt AS ovt
826+
ON ovt.observation_uid = cr.observation_uid
814827
WHERE
815-
ovt.ovt_value_txt IS NOT NULL
816-
AND obs.obs_domain_cd_st_1 IN (''C_Order'', ''C_Result'');';
828+
ovt.ovt_value_txt IS NOT NULL;';
817829

818830
IF @debug = 'true' print @sql;
819831
EXEC sp_executesql @sql;

0 commit comments

Comments
 (0)