Skip to content

Commit

Permalink
Merge pull request #409 from palladiumkenya/Feauture--Add-PrepCT,Exit…
Browse files Browse the repository at this point in the history
…Reason,ExitDate,turned-positive-into-linelist-Prep

Adding PrepVariables into Preplinelist
  • Loading branch information
Marymary-dev authored Apr 23, 2024
2 parents edf1153 + 3698603 commit da9270b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
12 changes: 7 additions & 5 deletions Scripts/NDWH/PREP_FACT_TABLES/load_FACTPrepVisits.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ BEGIN
(
select
distinct convert(nvarchar(64), hashbytes('SHA2_256', cast(PatientPK as nvarchar(36))), 2) as PatientPK,
SiteCode
SiteCode,
PrepEnrollmentDate
from ODS.dbo.PrEP_Patient
where ODS.dbo.PrEP_Patient.PrepNumber is not null
),

PrepVisits as (
select
convert(nvarchar(64), hashbytes('SHA2_256', cast(PatientPK as nvarchar(36))), 2) as PatientPK,
SiteCode,
convert(nvarchar(64), hashbytes('SHA2_256', cast(prepvisits.PatientPK as nvarchar(36))), 2) as PatientPK,
prepvisits.SiteCode,
VisitID,
VisitDate,
BloodPressure,
Expand Down Expand Up @@ -68,7 +69,7 @@ PrepVisits as (
TreatedForHepC,
NextAppointment,
ClinicalNotes
from ODS.DBO.PrEP_Visits
from ODS.DBO.PrEP_Visits as prepvisits
where VisitDate is not null

)
Expand Down Expand Up @@ -129,6 +130,7 @@ PrepVisits as (
PrepVisits.TreatedForHepC,
PrepVisits.NextAppointment,
PrepVisits.ClinicalNotes,
pat.PrepEnrollmentDateKey,
cast(getdate() as date) as LoadDate
into NDWH.dbo.FactPrepVisits
from prep_patients
Expand All @@ -144,9 +146,9 @@ PrepVisits as (
left join NDWH.dbo.DimDate as visit on visit.Date = PrepVisits.VisitDate
left join NDWH.dbo.DimDate as pregnancy on pregnancy.Date = PrepVisits.PregnancyEndDate
left join NDWH.dbo.DimDate as appointment on appointment.Date= PrepVisits.NextAppointment

WHERE patient.voided =0;

alter table NDWH.dbo.FactPrepVisits add primary key(FactKey);

END

22 changes: 19 additions & 3 deletions Scripts/REPORTING/load_Linelist_Prep.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ WITH prepCascade AS (
EOMONTH(ass.Date) as AsofDate,
EligiblePrep,
ScreenedPrep,
prepEnrol.Date as PrepEnrollmentDate
prepEnrol.Date as PrepEnrollmentDate,
ass.Date as VisitDate
FROM NDWH.dbo.FactPrepAssessments prep
LEFT JOIN NDWH.dbo.DimFacility f on f.FacilityKey = prep.FacilityKey
LEFT JOIN NDWH.dbo.DimAgency a on a.AgencyKey = prep.AgencyKey
Expand All @@ -45,6 +45,14 @@ latest_risk_category as (
*
from risk_category_ordering
where num = 1
),
TurnedPositive as (
Select distinct
PatientKey,
FinalTestResult
from
NDWH.dbo.FactHTSClientTests
where FinalTestResult='Positive' and TestType='Initial Test'
)
select
Prep.PatientPKHash,
Expand All @@ -58,12 +66,20 @@ select
AgeGroup,
AssessmentMonth,
AssessmentYear,
PrepEnrollmentDate ,
prep.PrepEnrollmentDate ,
AsofDate,
EligiblePrep,
ScreenedPrep,
HIVRiskCategory as LatestHIVRiskCategory,
ExitDate,
ExitReason,
case when VisitDate is not null and VisitDate > PrepEnrollmentDate Then 1 else 0 End as PrepCT,
case when TurnedPositive.PatientKey is not null then 1 else 0 End as TurnedPositive,
CAST(GETDATE() AS DATE) AS LoadDate
INTO REPORTING.dbo.LinelistPrep
from prepCascade prep
left join latest_risk_category on latest_risk_category.PatientKey = prep.PatientKey
left join NDWH.dbo.FactPrepDiscontinuation as disc on disc.PatientKey=prep.PatientKey
left join NDWH.dbo.FactPrepVisits as visits on visits.PatientKey=prep.PatientKey
left join TurnedPositive on TurnedPositive.PatientKey=prep.PatientKey

2 changes: 1 addition & 1 deletion Scripts/REPORTING/load_aggregate_prep_PrepCascade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ prep_ct as (
left join NDWH.dbo.DimFacility as facility on facility.FacilityKey = visits.FacilityKey
left join NDWH.dbo.DimDate as prep_enroll on prep_enroll.Datekey = patient.PrepEnrollmentDatekey
where VisitDateKey is not null
and date_visit.Date <> prep_enroll.Date
and date_visit.Date > prep_enroll.Date
group by
facility.MFLCode,
facility.FacilityName,
Expand Down
2 changes: 2 additions & 0 deletions Scripts/REPORTING/load_linelist_hts_eligibility.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ SELECT
SubCounty,
p.PartnerName,
a.AgencyName,
pat.PatientPKHash,
pat.NUPI,
pat.Gender,
age_group.Age,
age_group.DATIMAgeGroup AgeGroup,
Expand Down
3 changes: 3 additions & 0 deletions Scripts/REPORTING/load_linelist_trans_hts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ SELECT DISTINCT
MonthsLastTest,
TestedBefore,
MaritalStatus,
pat.NUPI,
CAST(GETDATE() AS DATE) AS LoadDate
INTO REPORTING.dbo.LineListTransHTS
FROM NDWH.dbo.FactHTSClientTests hts
Expand All @@ -56,3 +57,5 @@ left join NDWH.dbo.FactHTSPartnerNotificationServices pns on pns.PatientKey=hts.
WHERE ( DATEDIFF ( MONTH, DOB, d.Date ) > 18 AND DATEDIFF ( MONTH, DOB, d.Date ) <= 1500 )
AND FinalTestResult IS NOT NULL
AND d.[Date] >= CAST ( '2015-01-01' AS DATE )


5 changes: 4 additions & 1 deletion Scripts/REPORTING/load_linelist_trans_pns.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ With cte1 as (
a.CccNumber,
c.FinalTestResult as FinalResult,
e.Date DateElicited,
f.Date TestDate
f.Date TestDate,
b.NupiHash
FROM NDWH.dbo.FactHTSPartnerNotificationServices a
LEFT JOIN NDWH.dbo.DimFacility fac on fac.FacilityKey = a.FacilityKey
INNER JOIN ODS.dbo.HTS_clients b on b.PatientPkHash=a.PartnerPatientPk and b.SiteCode= fac.[MFLCode]
Expand All @@ -30,6 +31,7 @@ With cte1 as (
a.ScreenedForIpv,
a.CccNumber,
c.FinalTestResult as FinalResult,
b.NupiHash,
e.Date DateElicited,
f.Date TestDate,
d.ReportedCCCNumber
Expand All @@ -53,6 +55,7 @@ With cte1 as (
j.Date HIVDiagnosisDate,
PartnerPersonID,
b.PartnerPatientPk,
pat.NUPI,
Gender,
Age,
DATIMAgeGroup Agegroup,
Expand Down

0 comments on commit da9270b

Please sign in to comment.