Skip to content
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

Hiv cs tx continuity #451

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
33 changes: 17 additions & 16 deletions Scripts/REPORTING/HIVCaseSurveillance/load_cs_TxContinuity.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,37 @@ BEGIN
,Facility.County
,Facility.SubCounty
,Patient.PatientPKHash
,Patient.PatientKey
,Patient.Gender
,Patient.DOB
,[AgeGroup].DATIMAgeGroup
,FactARTHistory.AgeGroup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DennisGibz not sure, I thought since this is a Fact we should be using an AgeGroupKey?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DennisGibz please recheck on this.

,[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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DennisGibz, do we need this column here since this is a patient level dataset ?

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
Expand All @@ -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