diff --git a/Scripts/REPORTING/HIVCaseSurveillance/load_cs_TxContinuity.sql b/Scripts/REPORTING/HIVCaseSurveillance/load_cs_TxContinuity.sql index d07d3896..e641f091 100644 --- a/Scripts/REPORTING/HIVCaseSurveillance/load_cs_TxContinuity.sql +++ b/Scripts/REPORTING/HIVCaseSurveillance/load_cs_TxContinuity.sql @@ -8,38 +8,37 @@ BEGIN ,Facility.County ,Facility.SubCounty ,Patient.PatientPKHash + ,Patient.PatientKey ,Patient.Gender ,Patient.DOB - ,[AgeGroup].DATIMAgeGroup + ,FactARTHistory.AgeGroup ,[Partner].PartnerName ,case when ARTOutcome.ARTOutcomeDescription in ('LOSS TO FOLLOW UP','UNDOCUMENTED LOSS') Then 'IIT' when ARTOutcome.ARTOutcomeDescription in ('DEAD') Then 'MORTALITY' else ARTOutcome.ARTOutcomeDescription end ARTOutcome - ,asofdatekey + + ,[Date].[Date] As asofdate ,YEAR(TRY_CAST(DateConfirmedHIVPositiveKey AS DATETIME2)) As CohortYear - ,TRY_CAST(DateConfirmedHIVPositiveKey AS DATETIME2) As CohortYearMonth - ,cast(asofdatekey as datetime2) As OutcomeYearMonth + ,EOMONTH(TRY_CAST(DateConfirmedHIVPositiveKey AS DATETIME2)) As CohortYearMonth ,COUNT(1) AS NoOfClients INTO [HIVCaseSurveillance].[dbo].[CsTxContinuity] - FROM [NDWH].[dbo].[FactARTHistory] FactARTHistory - LEFT OUTER JOIN [NDWH].[dbo].[DimFacility] Facility + FROM [NDWH].[Fact].[FactARTHistory] FactARTHistory + LEFT OUTER JOIN [NDWH].[Dim].[DimFacility] Facility ON FactARTHistory.FacilityKey = Facility.FacilityKey - LEFT OUTER JOIN [NDWH].[dbo].[DimPatient] Patient + LEFT OUTER JOIN [NDWH].[Dim].[DimPatient] Patient on FactARTHistory.PatientKey = Patient.PatientKey - LEFT OUTER JOIN [NDWH].[dbo].[DimPartner] [Partner] + LEFT OUTER JOIN [NDWH].[Dim].[DimPartner] [Partner] on FactARTHistory.PartnerKey = [Partner].PartnerKey - LEFT OUTER JOIN [NDWH].[dbo].[DimAgency] Agency + LEFT OUTER JOIN [NDWH].[Dim].[DimAgency] Agency on FactARTHistory.AgencyKey = Agency.AgencyKey - LEFT OUTER JOIN [NDWH].[dbo].[DimARTOutcome] ARTOutcome + LEFT OUTER JOIN [NDWH].[Dim].[DimARTOutcome] ARTOutcome on FactARTHistory.ARTOutcomeKey = ARTOutcome.ARTOutcomeKey - LEFT OUTER JOIN [NDWH].[dbo].[DimDate] [Date] + LEFT OUTER JOIN [NDWH].[Dim].[DimDate] [Date] ON FactARTHistory.AsOfDateKey = [Date].[Date] - LEFT OUTER JOIN [NDWH].[dbo].[DimAgeGroup] [AgeGroup] - ON FactARTHistory.AgeGroup = [AgeGroup].DATIMAgeGroup WHERE Facility.MFLCode IS NOT NULL AND FactARTHistory.ARTOutcomeKey in (2,3,6,8) -- MORTALITY{2="DEAD"},Txcurr{6="ACTIVE},IIT{8=UNDOCUMENTED LOSS" 3="LOSS TO FOLLOW UP"} - AND YEAR(AsOfDateKey) <= YEAR(GETDATE()) + AND YEAR(AsOfDateKey) <= YEAR(GETDATE()) GROUP BY Facility.FacilityName ,Facility.MFLCode ,Facility.County @@ -49,9 +48,11 @@ BEGIN ,Patient.DOB ,[Partner].PartnerName ,ARTOutcome.ARTOutcomeDescription - ,asofdatekey + ,[Date].[Date] + ,Patient.PatientKey ,DateConfirmedHIVPositiveKey - ,[AgeGroup].DATIMAgeGroup + ,FactARTHistory.AgeGroup ORDER BY DateConfirmedHIVPositiveKey DESC; END +