From cdc748a6680f100cb8fe41f433d0a73f1ff8d038 Mon Sep 17 00:00:00 2001 From: Mumo Ngungu Date: Mon, 29 Apr 2024 22:26:41 +0300 Subject: [PATCH] fixing bug on FactART --- Scripts/NDWH/C&T FACT TABLES/load_FactART.sql | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Scripts/NDWH/C&T FACT TABLES/load_FactART.sql b/Scripts/NDWH/C&T FACT TABLES/load_FactART.sql index 4dd7b450..9deb0e6b 100644 --- a/Scripts/NDWH/C&T FACT TABLES/load_FactART.sql +++ b/Scripts/NDWH/C&T FACT TABLES/load_FactART.sql @@ -109,13 +109,21 @@ ncd_screening as ( select patient.PatientPKHash, patient.SiteCode, - ScreenedDiabetes, - ScreenedBPLastVisit + case + when latest_diabetes.Controlled in ('Yes', 'No') then 1 + else 0 + end as ScreenedDiabetes, + case + when latest_hypertension.Controlled in ('Yes', 'No') then 1 + else 0 + end as ScreenedBPLastVisit from Patient - left join ODS.dbo.Intermediate_LatestDiabetesTests as latest_diabetes_test on latest_diabetes_test.PatientPKHash = Patient.PatientPKHash - and latest_diabetes_test.SiteCode = Patient.SiteCode - left join ODS.dbo.Intermediate_LastVisitDate as visit on visit.PatientPK = Patient.PatientPK - and visit.SiteCode = Patient.SiteCode + left join ODS.dbo.Intermediate_NCDControlledStatusLastVisit as latest_diabetes on latest_diabetes.PatientPKHash = Patient.PatientPKHash + and latest_diabetes.SiteCode = Patient.SiteCode + and latest_diabetes.Disease = 'Diabetes' + left join ODS.dbo.Intermediate_NCDControlledStatusLastVisit as latest_hypertension on latest_hypertension.PatientPKHash = Patient.PatientPKHash + and latest_hypertension.SiteCode = Patient.SiteCode + and latest_hypertension.Disease = 'Hypertension' ), rtt_within_last_12_months as ( select