From 6cbe44b99c261e4381e9a419b0ed06106779f1a2 Mon Sep 17 00:00:00 2001 From: Marymary-dev Date: Wed, 31 Jul 2024 09:10:47 +0300 Subject: [PATCH 1/2] Adding Fact CTPatients --- .../C&T FACT TABLES/load_FactCTPatients.sql | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Scripts/NDWH/C&T FACT TABLES/load_FactCTPatients.sql diff --git a/Scripts/NDWH/C&T FACT TABLES/load_FactCTPatients.sql b/Scripts/NDWH/C&T FACT TABLES/load_FactCTPatients.sql new file mode 100644 index 00000000..466abf4c --- /dev/null +++ b/Scripts/NDWH/C&T FACT TABLES/load_FactCTPatients.sql @@ -0,0 +1,40 @@ +IF OBJECT_ID(N'[NDWH].[dbo].[FactCTPatients]', N'U') IS NOT NULL + DROP TABLE [NDWH].[dbo].[FactCTPatients]; +BEGIN +with MFL_partner_agency_combination as ( + select + distinct MFL_Code, + SDP, + SDP_Agency as Agency + from ODS.dbo.All_EMRSites +), +CT_Patients as ( + select + distinct + CT_Patients.PatientIDHash, + CT_Patients.PatientPKHash, + CT_Patients.SiteCode + from ODS.dbo.CT_Patient as CT_Patients + where voided=0 + + +) +select + Factkey = IDENTITY(INT, 1, 1), + patient.PatientKey, + facility.FacilityKey, + partner.PartnerKey, + agency.AgencyKey, + cast(getdate() as date) as LoadDate +into NDWH.dbo.FactCTPatients +from CT_Patients +left join NDWH.dbo.DimPatient as patient on patient.PatientPKHash = CT_Patients.PatientPKHash + and patient.SiteCode = CT_Patients.SiteCode +left join NDWH.dbo.DimFacility as facility on facility.MFLCode = CT_Patients.SiteCode +left join MFL_partner_agency_combination on MFL_partner_agency_combination.MFL_Code = CT_Patients.SiteCode +left join NDWH.dbo.DimPartner as partner on partner.PartnerName = MFL_partner_agency_combination.SDP +left join NDWH.dbo.DimAgency as agency on agency.AgencyName = MFL_partner_agency_combination.Agency + + +alter table NDWH.dbo.FactCTPatients add primary key(FactKey); +END \ No newline at end of file From 8463c50f80d33fefc886f91500f9d20bf3769bad Mon Sep 17 00:00:00 2001 From: Mumo Ngungu Date: Fri, 2 Aug 2024 09:01:43 +0300 Subject: [PATCH 2/2] Moving logic for EverOnART to DimPatients --- .../NDWH/ALL DIMENSIONS/load_DimPatient.sql | 14 ++++++- .../C&T FACT TABLES/load_FactCTPatients.sql | 40 ------------------- 2 files changed, 12 insertions(+), 42 deletions(-) delete mode 100644 Scripts/NDWH/C&T FACT TABLES/load_FactCTPatients.sql diff --git a/Scripts/NDWH/ALL DIMENSIONS/load_DimPatient.sql b/Scripts/NDWH/ALL DIMENSIONS/load_DimPatient.sql index 52db4aa3..c32ee1da 100644 --- a/Scripts/NDWH/ALL DIMENSIONS/load_DimPatient.sql +++ b/Scripts/NDWH/ALL DIMENSIONS/load_DimPatient.sql @@ -33,7 +33,8 @@ BEGIN cast(Getdate() AS DATE) AS LoadDate, coalesce(replace(patients.DateConfirmedHIVPositive,'-',''), replace(art.StartARTDate,'-',''),replace(patients.RegistrationAtCCC,'-','')) as DateConfirmedHIVPositiveKey, - patients.voided + patients.voided, + case when art.StartARTDate is not null then 1 else 0 end as EveronART FROM ods.dbo.ct_patient AS patients LEFT JOIN ods.dbo.ct_patientbaselines AS baselines ON patients.patientpkhash = baselines.patientpkhash @@ -113,6 +114,7 @@ BEGIN ct_patient_source.datebaselinewhokey, ct_patient_source.istxcurr, ct_patient_source.DateConfirmedHIVPositiveKey, + ct_patient_source.EveronART, hts_patient_source.htsnumberhash, Cast(Getdate() AS DATE) AS LoadDate @@ -155,6 +157,7 @@ BEGIN combined_data_ct_hts.datebaselinewhokey, combined_data_ct_hts.istxcurr, combined_data_ct_hts.DateConfirmedHIVPositiveKey, + combined_data_ct_hts.EverOnART, combined_data_ct_hts.htsnumberhash, prep_patient_source.prepnumber, Cast(Format(prep_patient_source.prepenrollmentdate, @@ -201,6 +204,7 @@ BEGIN combined_data_ct_hts_prep.datebaselinewhokey, combined_data_ct_hts_prep.istxcurr, combined_data_ct_hts_prep.DateConfirmedHIVPositiveKey, + combined_data_ct_hts_prep.EverOnART, combined_data_ct_hts_prep.htsnumberhash, combined_data_ct_hts_prep.prepenrollmentdatekey, combined_data_ct_hts_prep.prepnumber, @@ -250,6 +254,7 @@ BEGIN combined_data_ct_hts_prep_pmtct.datebaselinewhokey As datebaselinewhokey, combined_data_ct_hts_prep_pmtct.istxcurr As istxcurr, combined_data_ct_hts_prep_pmtct.DateConfirmedHIVPositiveKey, + combined_data_ct_hts_prep_pmtct.EverOnART, combined_data_ct_hts_prep_pmtct.htsnumberhash, NUll As sitetype, Cast(Getdate() AS DATE) AS LoadDate, @@ -276,6 +281,7 @@ BEGIN Null datebaselinewhokey, Null istxcurr, Null DateConfirmedHIVPositiveKey, + Null EverOnART, Null htsnumberhash, sitetype, Null LoadDate, @@ -314,6 +320,7 @@ BEGIN combined_data_ct_hts_prep_pmtct_Ushauri.prepenrollmentdatekey, combined_data_ct_hts_prep_pmtct_Ushauri.istxcurr, combined_data_ct_hts_prep_pmtct_Ushauri.DateConfirmedHIVPositiveKey, + combined_data_ct_hts_prep_pmtct_Ushauri.EverOnART, combined_data_ct_hts_prep_pmtct_Ushauri.patientmnchidhash, combined_data_ct_hts_prep_pmtct_Ushauri.firstenrollmentatmnchdatekey, combined_data_ct_hts_prep_pmtct_Ushauri.loaddate, @@ -340,6 +347,7 @@ BEGIN baselinewhokey,PrepEnrollmentDateKey, istxcurr, DateConfirmedHIVPositiveKey, + EverOnART, loaddate, voided) VALUES(patientidhash, @@ -359,6 +367,7 @@ BEGIN PrepEnrollmentDateKey, istxcurr, DateConfirmedHIVPositiveKey, + EverOnART, loaddate, voided) WHEN matched THEN @@ -375,5 +384,6 @@ BEGIN a.baselinewhokey = b.baselinewhokey, a.PrepEnrollmentDateKey = b.PrepEnrollmentDateKey, a.voided = b.voided, - a.DateConfirmedHIVPositiveKey = b.DateConfirmedHIVPositiveKey; + a.DateConfirmedHIVPositiveKey = b.DateConfirmedHIVPositiveKey, + a.EverOnART = b.EverOnART; END \ No newline at end of file diff --git a/Scripts/NDWH/C&T FACT TABLES/load_FactCTPatients.sql b/Scripts/NDWH/C&T FACT TABLES/load_FactCTPatients.sql deleted file mode 100644 index 466abf4c..00000000 --- a/Scripts/NDWH/C&T FACT TABLES/load_FactCTPatients.sql +++ /dev/null @@ -1,40 +0,0 @@ -IF OBJECT_ID(N'[NDWH].[dbo].[FactCTPatients]', N'U') IS NOT NULL - DROP TABLE [NDWH].[dbo].[FactCTPatients]; -BEGIN -with MFL_partner_agency_combination as ( - select - distinct MFL_Code, - SDP, - SDP_Agency as Agency - from ODS.dbo.All_EMRSites -), -CT_Patients as ( - select - distinct - CT_Patients.PatientIDHash, - CT_Patients.PatientPKHash, - CT_Patients.SiteCode - from ODS.dbo.CT_Patient as CT_Patients - where voided=0 - - -) -select - Factkey = IDENTITY(INT, 1, 1), - patient.PatientKey, - facility.FacilityKey, - partner.PartnerKey, - agency.AgencyKey, - cast(getdate() as date) as LoadDate -into NDWH.dbo.FactCTPatients -from CT_Patients -left join NDWH.dbo.DimPatient as patient on patient.PatientPKHash = CT_Patients.PatientPKHash - and patient.SiteCode = CT_Patients.SiteCode -left join NDWH.dbo.DimFacility as facility on facility.MFLCode = CT_Patients.SiteCode -left join MFL_partner_agency_combination on MFL_partner_agency_combination.MFL_Code = CT_Patients.SiteCode -left join NDWH.dbo.DimPartner as partner on partner.PartnerName = MFL_partner_agency_combination.SDP -left join NDWH.dbo.DimAgency as agency on agency.AgencyName = MFL_partner_agency_combination.Agency - - -alter table NDWH.dbo.FactCTPatients add primary key(FactKey); -END \ No newline at end of file