diff --git a/snprc_ehr/resources/source_queries/create_v_snd_attributeData.sql b/snprc_ehr/resources/source_queries/create_v_snd_attributeData.sql index 33b0ed18..0c6cacb1 100644 --- a/snprc_ehr/resources/source_queries/create_v_snd_attributeData.sql +++ b/snprc_ehr/resources/source_queries/create_v_snd_attributeData.sql @@ -35,6 +35,7 @@ AS -- 05/13/19 Added a REPLACE to numeric/decimal CAST -- Purpose is to handle numeric data with commas (',') ~line 59 srr -- 04/23/2024 Lookup values need to be string values by default. tjh +-- 6/26/2025 Added check for eventId in labkey Events table. tjh -- ========================================================================================== SELECT TOP (99.999999999) PERCENT cp.ANIMAL_EVENT_ID AS EventId, @@ -71,6 +72,8 @@ INNER JOIN dbo.PKG_ATTRIBS AS pa ON pa.PKG_ID = p.PKG_ID AND pa.ATTRIB_KEY = cpa -- select primates only from the TxBiomed colony INNER JOIN labkey_etl.V_DEMOGRAPHICS AS D ON D.id = ae.ANIMAL_ID WHERE LTRIM(RTRIM(cpa.VALUE)) <> '' AND cpa.VALUE IS NOT NULL +-- limit selection to only events that have been imported +AND EXISTS (SELECT 1 FROM labkey.snd.Events AS e WHERE cp.ANIMAL_EVENT_ID = e.EventId) ORDER BY EventDataId GO diff --git a/snprc_ehr/resources/source_queries/create_v_snd_eventData.sql b/snprc_ehr/resources/source_queries/create_v_snd_eventData.sql index 3c1ead80..b73bdd09 100644 --- a/snprc_ehr/resources/source_queries/create_v_snd_eventData.sql +++ b/snprc_ehr/resources/source_queries/create_v_snd_eventData.sql @@ -20,7 +20,7 @@ AS -- Create date: 2/23/2018 -- Description: View provides the datasource for event data with attribute/values -- Changes: 4/12/2018 Added permissions - -- + -- 6/26/2025 Added check for eventId in labkey Events table. tjh -- ========================================================================================== SELECT @@ -42,7 +42,9 @@ AS LEFT OUTER JOIN dbo.TAC_COLUMNS AS tc ON tc.object_id = cp.OBJECT_ID -- select primates only from the TxBiomed colony - INNER JOIN labkey_etl.V_DEMOGRAPHICS AS d ON d.id = ae.ANIMAL_ID; + INNER JOIN labkey_etl.V_DEMOGRAPHICS AS d ON d.id = ae.ANIMAL_ID + -- limit selection to only events that have been imported + WHERE EXISTS (SELECT 1 FROM labkey.snd.Events AS e WHERE cp.ANIMAL_EVENT_ID = e.EventId) GO diff --git a/snprc_ehr/resources/source_queries/create_v_snd_eventNotes.sql b/snprc_ehr/resources/source_queries/create_v_snd_eventNotes.sql index 2f9b0525..e51b527e 100644 --- a/snprc_ehr/resources/source_queries/create_v_snd_eventNotes.sql +++ b/snprc_ehr/resources/source_queries/create_v_snd_eventNotes.sql @@ -19,7 +19,7 @@ ALTER VIEW [labkey_etl].[v_snd_eventNotes] AS -- Create date: 3/23/2018 -- Description: View provides the datasource for event notes -- Changes: 3/28/2018 - Joined with v_demographics to limit the result set to the animal data being exported to LK. tjh --- +-- 6/26/2025 Added check for eventId in labkey Events table. tjh -- ========================================================================================== SELECT @@ -38,6 +38,8 @@ LEFT OUTER JOIN dbo.TAC_COLUMNS AS tc ON tc.object_id = pn.object_id INNER JOIN dbo.animal_events AS ae ON ae.ANIMAL_EVENT_ID = pn.ANIMAL_EVENT_ID -- select primates only from the TxBiomed colony INNER JOIN Labkey_etl.V_DEMOGRAPHICS AS d ON d.id = ae.animal_id +-- limit selection to only events that have been imported +WHERE EXISTS (SELECT 1 FROM labkey.snd.Events AS e WHERE pn.ANIMAL_EVENT_ID = e.EventId) GO