From 7faf18ca355877e9a765169b10375c9a1f82745b Mon Sep 17 00:00:00 2001 From: NewtonMutugi Date: Tue, 23 Jul 2024 14:39:02 +0300 Subject: [PATCH 1/5] Updated table names for Mhealth applications --- .../ODS/Mhealth/Load_UShauri_PatientLabs.sql | 4 +-- Scripts/ODS/Mhealth/Load_Ushauri_HEI.sql | 24 ++++++++--------- .../ODS/Mhealth/Load_Ushauri_HW_Exposures.sql | 4 +-- Scripts/ODS/Mhealth/Load_Ushauri_Patient.sql | 26 +++++++++---------- .../Load_Ushauri_PatientAppointments.sql | 22 ++++++++-------- .../Mhealth/Load_Ushauri_PatientReferral.sql | 18 ++++++------- 6 files changed, 49 insertions(+), 49 deletions(-) diff --git a/Scripts/ODS/Mhealth/Load_UShauri_PatientLabs.sql b/Scripts/ODS/Mhealth/Load_UShauri_PatientLabs.sql index 48dc2fa9..1ea02dfc 100644 --- a/Scripts/ODS/Mhealth/Load_UShauri_PatientLabs.sql +++ b/Scripts/ODS/Mhealth/Load_UShauri_PatientLabs.sql @@ -1,8 +1,8 @@ ---- Loads data from MhealthCentral to ODS ------truncate table[ODS].[dbo].[Ushauri_PatientLabs] +-----truncate table[ODS].[dbo].[Mhealth_mLab_PatientLab] BEGIN - MERGE [ODS].[dbo].[Ushauri_PatientLabs] AS a + MERGE [ODS].[dbo].[Mhealth_mLab_PatientLab] AS a USING ( SELECT DISTINCT [PatientPK] ,[PatientPKHash] diff --git a/Scripts/ODS/Mhealth/Load_Ushauri_HEI.sql b/Scripts/ODS/Mhealth/Load_Ushauri_HEI.sql index 92cdd491..8e080743 100644 --- a/Scripts/ODS/Mhealth/Load_Ushauri_HEI.sql +++ b/Scripts/ODS/Mhealth/Load_Ushauri_HEI.sql @@ -1,6 +1,6 @@ BEGIN - MERGE [ODS].[dbo].[Ushauri_HEI] AS a + MERGE [ODS].[dbo].[Mhealth_Ushauri_HEI] AS a USING(SELECT Distinct PatientPK As UshauriPatientPK,PatientPKHash As UshauriPatientPKHash,PartnerName,SiteCode,SiteType,Emr,Project, FacilityName,PatientMNCH_ID,PatientHEI_ID,[1stDNAPCRDate],[2ndDNAPCRDate], @@ -10,20 +10,20 @@ BEGIN HEIExitDate_Date,DateCreated_Date,DateModified_Date FROM [MhealthCentral].[dbo].[pmtct_MNCH_HEI](NoLock) P - ) AS b + ) AS b ON( - a.[UshauriPatientPK] = b.UshauriPatientPK - and a.SiteCode = b.SiteCode + a.[UshauriPatientPK] = b.UshauriPatientPK + and a.SiteCode = b.SiteCode and a.PatientHEI_ID = b.PatientHEI_ID - + ) - - WHEN NOT MATCHED THEN - INSERT(UshauriPatientPK,UshauriPatientPKHash,PartnerName,SiteCode,SiteType,Emr,Project,FacilityName,PatientMNCH_ID,PatientHEI_ID,[1stDNAPCRDate],[2ndDNAPCRDate],[3rdDNAPCRDate],ConfirmatoryPCRDate,BasellineVLDate,FinalyAntibodyDate,[1stDNAPCR],[2ndDNAPCR],[3rdDNAPCR],ConfirmatoryPCR,BasellineVL,FinalyAntibody,HEIExitDate,HEIHIVStatus,HEIExitCriteria,DateCreated,DateModified,[1stDNAPCRDate_Date],[2ndDNAPCRDate_Date],[3rdDNAPCRDate_Date],ConfirmatoryPCRDate_Date,BasellineVLDate_Date,FinalyAntibodyDate_Date,HEIExitDate_Date,DateCreated_Date,DateModified_Date,LoadDate) + + WHEN NOT MATCHED THEN + INSERT(UshauriPatientPK,UshauriPatientPKHash,PartnerName,SiteCode,SiteType,Emr,Project,FacilityName,PatientMNCH_ID,PatientHEI_ID,[1stDNAPCRDate],[2ndDNAPCRDate],[3rdDNAPCRDate],ConfirmatoryPCRDate,BasellineVLDate,FinalyAntibodyDate,[1stDNAPCR],[2ndDNAPCR],[3rdDNAPCR],ConfirmatoryPCR,BasellineVL,FinalyAntibody,HEIExitDate,HEIHIVStatus,HEIExitCriteria,DateCreated,DateModified,[1stDNAPCRDate_Date],[2ndDNAPCRDate_Date],[3rdDNAPCRDate_Date],ConfirmatoryPCRDate_Date,BasellineVLDate_Date,FinalyAntibodyDate_Date,HEIExitDate_Date,DateCreated_Date,DateModified_Date,LoadDate) VALUES(UshauriPatientPK,UshauriPatientPKHash,PartnerName,SiteCode,SiteType,Emr,Project,FacilityName,PatientMNCH_ID,PatientHEI_ID,[1stDNAPCRDate],[2ndDNAPCRDate],[3rdDNAPCRDate],ConfirmatoryPCRDate,BasellineVLDate,FinalyAntibodyDate,[1stDNAPCR],[2ndDNAPCR],[3rdDNAPCR],ConfirmatoryPCR,BasellineVL,FinalyAntibody,HEIExitDate,HEIHIVStatus,HEIExitCriteria,DateCreated,DateModified,[1stDNAPCRDate_Date],[2ndDNAPCRDate_Date],[3rdDNAPCRDate_Date],ConfirmatoryPCRDate_Date,BasellineVLDate_Date,FinalyAntibodyDate_Date,HEIExitDate_Date,DateCreated_Date,DateModified_Date,Getdate()) - + WHEN MATCHED THEN - UPDATE SET + UPDATE SET a.[PartnerName] = b.[PartnerName], a.[SiteType] = b.[SiteType], a.[Emr] = b.[Emr], @@ -57,5 +57,5 @@ BEGIN a.[DateModified_Date] = b.[DateModified_Date] ; - - END \ No newline at end of file + + END diff --git a/Scripts/ODS/Mhealth/Load_Ushauri_HW_Exposures.sql b/Scripts/ODS/Mhealth/Load_Ushauri_HW_Exposures.sql index cb19ffc2..b4258965 100644 --- a/Scripts/ODS/Mhealth/Load_Ushauri_HW_Exposures.sql +++ b/Scripts/ODS/Mhealth/Load_Ushauri_HW_Exposures.sql @@ -1,7 +1,7 @@ ---- Loads Ushauri_HW_Exposures data from MhealthCentral to ODS --- truncate table [ODS].[dbo].[Ushauri_HW_Exposure] +-- truncate table [ODS].[dbo].[Mhealth_Ushauri_HWExposure] BEGIN - MERGE [ODS].[dbo].[Ushauri_HW_Exposure] + MERGE [ODS].[dbo].[Mhealth_Ushauri_HWExposure] AS a USING ( SELECT DISTINCT diff --git a/Scripts/ODS/Mhealth/Load_Ushauri_Patient.sql b/Scripts/ODS/Mhealth/Load_Ushauri_Patient.sql index 59e0c390..39775652 100644 --- a/Scripts/ODS/Mhealth/Load_Ushauri_Patient.sql +++ b/Scripts/ODS/Mhealth/Load_Ushauri_Patient.sql @@ -1,7 +1,7 @@ BEGIN - MERGE [ODS].[dbo].[Ushauri_Patient] AS a + MERGE [ODS].[dbo].[Mhealth_Ushauri_Patient] AS a USING(SELECT Distinct PatientPK,MPIPKV,null PatientPKHash,PartnerName,SiteCode,SiteType,PatientID,null PatientIDHash,FacilityID,Emr,Project,FacilityName, Gender,DOB_Date AS DOB,RegistrationDate_Date As RegistrationDate,RegistrationAtCCC_Date As RegistrationAtCCC,RegistrationAtPMTCT_Date As RegistrationAtPMTCT,RegistrationAtTBClinic,PatientSource,Region,District, @@ -11,18 +11,18 @@ BEGIN PatientResidentWard,PatientType,PopulationType,TransferInDate,Occupation,DateCreated_Date As DateCreated,DateModified_Date As DateModified,StatelitteName, Date_Created_Date As Date_Created,Date_Modified_Date As Date_Modified,PKV,NUPI FROM [mhealthCentral].[dbo].[CT_Patient](NoLock) P - ) AS b + ) AS b ON( - a.[UshauriPatientPK] = b.PatientPK - and a.SiteCode = b.SiteCode + a.[UshauriPatientPK] = b.PatientPK + and a.SiteCode = b.SiteCode ) - - WHEN NOT MATCHED THEN - INSERT([UshauriPatientPK],MPIPKV,PatientPKHash,PartnerName,SiteCode,SiteType,PatientID,PatientIDHash,FacilityID,Emr,Project,FacilityName,Gender,DOB,RegistrationDate,RegistrationAtCCC,RegistrationAtPMTCT,RegistrationAtTBClinic,PatientSource,Region,District,Village,ContactRelation,LastVisit,MaritalStatus,EducationLevel,DateConfirmedHIVPositive,PreviousARTExposure,PreviousARTStartDate,StatusAtCCC,StatusAtPMTCT,StatusAtTBClinic,Inschool,KeyPopulationType,Orphan,County,PatientResidentLocation,PatientResidentSubCounty,PatientResidentSubLocation,PatientResidentVillage,PatientResidentWard,PatientType,PopulationType,TransferInDate,Occupation,DateCreated,DateModified,StatelitteName,Date_Created,Date_Modified,PKV,NUPI,LoadDate) + + WHEN NOT MATCHED THEN + INSERT([UshauriPatientPK],MPIPKV,PatientPKHash,PartnerName,SiteCode,SiteType,PatientID,PatientIDHash,FacilityID,Emr,Project,FacilityName,Gender,DOB,RegistrationDate,RegistrationAtCCC,RegistrationAtPMTCT,RegistrationAtTBClinic,PatientSource,Region,District,Village,ContactRelation,LastVisit,MaritalStatus,EducationLevel,DateConfirmedHIVPositive,PreviousARTExposure,PreviousARTStartDate,StatusAtCCC,StatusAtPMTCT,StatusAtTBClinic,Inschool,KeyPopulationType,Orphan,County,PatientResidentLocation,PatientResidentSubCounty,PatientResidentSubLocation,PatientResidentVillage,PatientResidentWard,PatientType,PopulationType,TransferInDate,Occupation,DateCreated,DateModified,StatelitteName,Date_Created,Date_Modified,PKV,NUPI,LoadDate) VALUES(PatientPK,MPIPKV,PatientPKHash,PartnerName,SiteCode,SiteType,PatientID,PatientIDHash,FacilityID,Emr,Project,FacilityName,Gender,DOB,RegistrationDate,RegistrationAtCCC,RegistrationAtPMTCT,RegistrationAtTBClinic,PatientSource,Region,District,Village,ContactRelation,LastVisit,MaritalStatus,EducationLevel,DateConfirmedHIVPositive,PreviousARTExposure,PreviousARTStartDate,StatusAtCCC,StatusAtPMTCT,StatusAtTBClinic,Inschool,KeyPopulationType,Orphan,County,PatientResidentLocation,PatientResidentSubCounty,PatientResidentSubLocation,PatientResidentVillage,PatientResidentWard,PatientType,PopulationType,TransferInDate,Occupation,DateCreated,DateModified,StatelitteName,Date_Created,Date_Modified,PKV,NUPI,Getdate()) - + WHEN MATCHED THEN - UPDATE SET + UPDATE SET a.[MPIPKV] = b.[MPIPKV], a.[PartnerName] = b.[PartnerName], a.[SiteType] = b.[SiteType], @@ -77,13 +77,13 @@ BEGIN Select Sitecode, UshauriPatientPK, - + ROW_NUMBER() OVER (PARTITION BY UshauriPatientPK,Sitecode ORDER BY UshauriPatientPK) Row_Num - FROM [ODS].[dbo].[Ushauri_Patient](NoLock) + FROM [ODS].[dbo].[Mhealth_Ushauri_Patient](NoLock) ) - delete from cte + delete from cte Where Row_Num >1 ; - + END diff --git a/Scripts/ODS/Mhealth/Load_Ushauri_PatientAppointments.sql b/Scripts/ODS/Mhealth/Load_Ushauri_PatientAppointments.sql index 864630fd..73cef494 100644 --- a/Scripts/ODS/Mhealth/Load_Ushauri_PatientAppointments.sql +++ b/Scripts/ODS/Mhealth/Load_Ushauri_PatientAppointments.sql @@ -1,6 +1,6 @@ BEGIN - MERGE [ODS].[dbo].[Ushauri_PatientAppointments] AS a + MERGE [ODS].[dbo].[Mhealth_Ushauri_PatientAppointments] AS a USING(SELECT Distinct PatientPK,Null As PatientPKHash,SiteCode,SiteType,PatientID,Null As PatientIDHash, NUPI,PartnerName,FacilityID,FacilityName, DOB_Date As DOB,Gender,MaritalStatus,PatientResidentCounty,PatientResidentLocation,PatientResidentSubCounty, @@ -15,20 +15,20 @@ BEGIN MissedAppointmentSMSSent,MissedAppointmentSMSSendDate_Date As MissedAppointmentSMSSendDate,MissedAppointmentSMSDeliveryStatus,MissedAppointmentSMSDeliveryFailureReason, TracingCost,TracingOutcome,TracingOutcomeDate_Date As TracingOutcomeDate,DateReturnedToCare_Date As DateReturnedToCare,DaysDefaulted FROM [mhealthCentral].[dbo].[CT_PatientAppointments](NoLock) P - ) AS b + ) AS b ON( - a.SiteCode = b.SiteCode + a.SiteCode = b.SiteCode and a.[AppointmentID] = b.[AppointmentID] ) - - WHEN NOT MATCHED THEN - INSERT([UshauriPatientPK],PatientPKHash,SiteCode,SiteType,PatientID,PatientIDHash,NUPI,PartnerName,FacilityID,FacilityName,DOB,Gender,MaritalStatus,PatientResidentCounty,PatientResidentLocation,PatientResidentSubCounty,PatientResidentSubLocation,PatientResidentVillage,PatientResidentWard,RegistrationDate,RegistrationAtCCC,RegistrationAtPMTCT,RegistrationAtTBClinic,StatusAtCCC,StatusAtPMTCT,StatusAtTBClinic,AgeAtAppointment,AppointmentID,AppointmentDate,AppointmentType,AppointmentStatus,EntryPoint,VisitType,DateAttended,ConsentForSMS,SMSLanguage,SMSTargetGroup,SMSPreferredSendTime,FourWeekSMSSent,FourWeekSMSSendDate,FourWeekSMSDeliveryStatus,FourWeekSMSDeliveryFailureReason,ThreeWeekSMSSent,ThreeWeekSMSSendDate,ThreeWeekSMSDeliveryStatus,ThreeWeekSMSDeliveryFailureReason,TwoWeekSMSSent,TwoWeekSMSSendDate,TwoWeekSMSDeliveryStatus,TwoWeekSMSDeliveryFailureReason,OneWeekSMSSent,OneWeekSMSSendDate,OneWeekSMSDeliveryStatus,OneWeekSMSDeliveryFailureReason,OneDaySMSSent,OneDaySMSSendDate,OneDaySMSDeliveryStatus,OneDaySMSDeliveryFailureReason,MissedAppointmentSMSSent,MissedAppointmentSMSSendDate,MissedAppointmentSMSDeliveryStatus,MissedAppointmentSMSDeliveryFailureReason,TracingOutCost,TracingOutcome,TracingOutcomeDate,DateReturnedToCare,DaysDefaulted,LoadDate) + + WHEN NOT MATCHED THEN + INSERT([UshauriPatientPK],PatientPKHash,SiteCode,SiteType,PatientID,PatientIDHash,NUPI,PartnerName,FacilityID,FacilityName,DOB,Gender,MaritalStatus,PatientResidentCounty,PatientResidentLocation,PatientResidentSubCounty,PatientResidentSubLocation,PatientResidentVillage,PatientResidentWard,RegistrationDate,RegistrationAtCCC,RegistrationAtPMTCT,RegistrationAtTBClinic,StatusAtCCC,StatusAtPMTCT,StatusAtTBClinic,AgeAtAppointment,AppointmentID,AppointmentDate,AppointmentType,AppointmentStatus,EntryPoint,VisitType,DateAttended,ConsentForSMS,SMSLanguage,SMSTargetGroup,SMSPreferredSendTime,FourWeekSMSSent,FourWeekSMSSendDate,FourWeekSMSDeliveryStatus,FourWeekSMSDeliveryFailureReason,ThreeWeekSMSSent,ThreeWeekSMSSendDate,ThreeWeekSMSDeliveryStatus,ThreeWeekSMSDeliveryFailureReason,TwoWeekSMSSent,TwoWeekSMSSendDate,TwoWeekSMSDeliveryStatus,TwoWeekSMSDeliveryFailureReason,OneWeekSMSSent,OneWeekSMSSendDate,OneWeekSMSDeliveryStatus,OneWeekSMSDeliveryFailureReason,OneDaySMSSent,OneDaySMSSendDate,OneDaySMSDeliveryStatus,OneDaySMSDeliveryFailureReason,MissedAppointmentSMSSent,MissedAppointmentSMSSendDate,MissedAppointmentSMSDeliveryStatus,MissedAppointmentSMSDeliveryFailureReason,TracingOutCost,TracingOutcome,TracingOutcomeDate,DateReturnedToCare,DaysDefaulted,LoadDate) VALUES(PatientPK,PatientPKHash,SiteCode,SiteType,PatientID,PatientIDHash,NUPI,PartnerName,FacilityID,FacilityName,DOB,Gender,MaritalStatus,PatientResidentCounty,PatientResidentLocation,PatientResidentSubCounty,PatientResidentSubLocation,PatientResidentVillage,PatientResidentWard,RegistrationDate,RegistrationAtCCC,RegistrationAtPMTCT,RegistrationAtTBClinic,StatusAtCCC,StatusAtPMTCT,StatusAtTBClinic,AgeAtAppointment,AppointmentID,AppointmentDate,AppointmentType,AppointmentStatus,EntryPoint,VisitType,DateAttended,ConsentForSMS,SMSLanguage,SMSTargetGroup,SMSPreferredSendTime,FourWeekSMSSent,FourWeekSMSSendDate,FourWeekSMSDeliveryStatus,FourWeekSMSDeliveryFailureReason,ThreeWeekSMSSent,ThreeWeekSMSSendDate,ThreeWeekSMSDeliveryStatus,ThreeWeekSMSDeliveryFailureReason,TwoWeekSMSSent,TwoWeekSMSSendDate,TwoWeekSMSDeliveryStatus,TwoWeekSMSDeliveryFailureReason,OneWeekSMSSent,OneWeekSMSSendDate,OneWeekSMSDeliveryStatus,OneWeekSMSDeliveryFailureReason,OneDaySMSSent,OneDaySMSSendDate,OneDaySMSDeliveryStatus,OneDaySMSDeliveryFailureReason,MissedAppointmentSMSSent,MissedAppointmentSMSSendDate,MissedAppointmentSMSDeliveryStatus,MissedAppointmentSMSDeliveryFailureReason,TracingCost,TracingOutcome,TracingOutcomeDate,DateReturnedToCare,DaysDefaulted,Getdate()) - + WHEN MATCHED THEN - UPDATE SET + UPDATE SET a.[SiteType] = b.[SiteType], - a.[PatientID] = b.[PatientID], + a.[PatientID] = b.[PatientID], a.[NUPI] = b.[NUPI], a.[PartnerName] = b.[PartnerName], a.[FacilityName] = b.[FacilityName], @@ -88,5 +88,5 @@ BEGIN a.[DateReturnedToCare] = b.[DateReturnedToCare], a.[DaysDefaulted] = b.[DaysDefaulted]; - - END \ No newline at end of file + + END diff --git a/Scripts/ODS/Mhealth/Load_Ushauri_PatientReferral.sql b/Scripts/ODS/Mhealth/Load_Ushauri_PatientReferral.sql index 62e3a06b..241a0452 100644 --- a/Scripts/ODS/Mhealth/Load_Ushauri_PatientReferral.sql +++ b/Scripts/ODS/Mhealth/Load_Ushauri_PatientReferral.sql @@ -1,7 +1,7 @@ BEGIN - MERGE [ODS].[dbo].[Ushauri_PatientReferral] AS a + MERGE [ODS].[dbo].[Mhealth_FacilityReferral_Patient] AS a USING(SELECT DISTINCT [ReferralPK] ,[ReferralPKHash] ,[PatientID] @@ -17,18 +17,18 @@ BEGIN ,[TransferInFacilityName] ,[TransferStatus] FROM [MhealthCentral].[dbo].[CT_PatientReferral] - ) AS b + ) AS b ON( a.[UshauriReferralPK] = b.[ReferralPK] and - a.TransferoutDate = b.TransferoutDate + a.TransferoutDate = b.TransferoutDate ) - - WHEN NOT MATCHED THEN - INSERT([UshauriReferralPK],[UshauriReferralPKHash],PatientID,PatientIDHash,ReferralType,TransferOutDate,TransferOutPartnerName,TransferOutSiteCode,TransferOutFacilityName,TransferInDate,TransferInPartnerName,TransferInSiteCode,TransferInFacilityName,TransferStatus,LoadDate) + + WHEN NOT MATCHED THEN + INSERT([UshauriReferralPK],[UshauriReferralPKHash],PatientID,PatientIDHash,ReferralType,TransferOutDate,TransferOutPartnerName,TransferOutSiteCode,TransferOutFacilityName,TransferInDate,TransferInPartnerName,TransferInSiteCode,TransferInFacilityName,TransferStatus,LoadDate) VALUES(ReferralPK,ReferralPKHash,PatientID,PatientIDHash,ReferralType,TransferOutDate,TransferOutPartnerName,TransferOutSiteCode,TransferOutFacilityName,TransferInDate,TransferInPartnerName,TransferInSiteCode,TransferInFacilityName,TransferStatus,getdate()) - + WHEN MATCHED THEN - UPDATE SET + UPDATE SET a.[ReferralType]=b.[ReferralType], a.[TransferOutDate]=b.[TransferOutDate], a.[TransferOutPartnerName]=b.[TransferOutPartnerName], @@ -39,5 +39,5 @@ BEGIN a.[TransferInSiteCode]=b.[TransferInSiteCode], a.[TransferInFacilityName]=b.[TransferInFacilityName], a.[TransferStatus]=b.[TransferStatus]; - + END From 826d7ff5bb8478a5e47e32c4bf2e3d36b56ee5b7 Mon Sep 17 00:00:00 2001 From: NewtonMutugi Date: Tue, 23 Jul 2024 15:05:44 +0300 Subject: [PATCH 2/5] Update table names for Mhealth applications (post load scripts) --- .../1_RecreatePatient_PatientPKColumns.sql | 40 +++++++++--------- ...tePatientAppointments_PatientPKColumns.sql | 36 ++++++++-------- .../Post_Load/3_Update_PatientPatientPK.sql | 4 +- ...4_Update_PatientAppointments_PatientPK.sql | 4 +- .../5_Recreate_Hei_PatientPKColumn.sql | 42 +++++++++---------- .../Post_Load/6_Update_HEI_PatientPK.sql | 6 +-- ...PatientPK_ReferralPatientPKHashcolumns.sql | 34 +++++++-------- ...date_PatientReferral_ReferralPatientPK.sql | 2 +- .../Post_Load/9_Update_CT_PatientLabs.sql | 4 +- 9 files changed, 86 insertions(+), 86 deletions(-) diff --git a/Scripts/ODS/Mhealth/Post_Load/1_RecreatePatient_PatientPKColumns.sql b/Scripts/ODS/Mhealth/Post_Load/1_RecreatePatient_PatientPKColumns.sql index 7b53d5bf..9df6b275 100644 --- a/Scripts/ODS/Mhealth/Post_Load/1_RecreatePatient_PatientPKColumns.sql +++ b/Scripts/ODS/Mhealth/Post_Load/1_RecreatePatient_PatientPKColumns.sql @@ -1,46 +1,46 @@ /* Renaming patientPK column coming from mhealth to UshauriPatientPK for the purpose of matching patient from C&T to ones coming from ushauri. */ BEGIN - - IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the PatientPK column exists on [ODS].[dbo].[Ushauri_Patient] exists on ODS */ - WHERE Name = N'PatientPK' - AND Object_ID = Object_ID(N'[ODS].[dbo].[Ushauri_Patient]')) + + IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the PatientPK column exists on [ODS].[dbo].[Mhealth_Ushauri_Patient] exists on ODS */ + WHERE Name = N'PatientPK' + AND Object_ID = Object_ID(N'[ODS].[dbo].[Mhealth_Ushauri_Patient]')) BEGIN IF NOT EXISTS (SELECT * /* If above condition is met, check if Ushauri_Patient exists. If it exists escape. If it doesn't exist create it*/ FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Ushauri_Patient' - AND COLUMN_NAME = 'UshauriPatientPK') + AND COLUMN_NAME = 'UshauriPatientPK') BEGIN - EXEC sp_rename '[ODS].[dbo].[Ushauri_Patient].PatientPK', 'UshauriPatientPK', 'COLUMN'; + EXEC sp_rename '[ODS].[dbo].[Mhealth_Ushauri_Patient].PatientPK', 'UshauriPatientPK', 'COLUMN'; END END - IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the PatientPK column exists on [ODS].[dbo].[Ushauri_Patient] exists on ODS */ - WHERE Name = N'PatientPKHash' - AND Object_ID = Object_ID(N'[ODS].[dbo].[Ushauri_Patient]')) + IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the PatientPK column exists on [ODS].[dbo].[Mhealth_Ushauri_Patient] exists on ODS */ + WHERE Name = N'PatientPKHash' + AND Object_ID = Object_ID(N'[ODS].[dbo].[Mhealth_Ushauri_Patient]')) BEGIN IF NOT EXISTS (SELECT * /* If above condition is met, check if Ushauri_Patient exists. If it exists escape. If it doesn't exist create it*/ FROM INFORMATION_SCHEMA.COLUMNS - WHERE TABLE_NAME = 'Ushauri_Patient' - AND COLUMN_NAME = 'PatientPKHash') + WHERE TABLE_NAME = 'Mhealth_Ushauri_Patient' + AND COLUMN_NAME = 'PatientPKHash') BEGIN - EXEC sp_rename '[ODS].[dbo].[Ushauri_Patient].PatientPKHash', 'PatientPKHash', 'COLUMN'; + EXEC sp_rename '[ODS].[dbo].[Mhealth_Ushauri_Patient].PatientPKHash', 'PatientPKHash', 'COLUMN'; END END - + IF NOT EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE - TABLE_NAME = 'Ushauri_Patient' AND COLUMN_NAME = 'patientPK') + TABLE_NAME = 'Mhealth_Ushauri_Patient' AND COLUMN_NAME = 'patientPK') BEGIN - ALTER TABLE [ODS].[dbo].[Ushauri_Patient] + ALTER TABLE [ODS].[dbo].[Mhealth_Ushauri_Patient] ADD patientPK int NULL END; @@ -50,9 +50,9 @@ BEGIN FROM INFORMATION_SCHEMA.COLUMNS WHERE - TABLE_NAME = 'Ushauri_Patient' AND COLUMN_NAME = 'PatientPKHash') + TABLE_NAME = 'Mhealth_Ushauri_Patient' AND COLUMN_NAME = 'PatientPKHash') BEGIN - alter table [ODS].[dbo].[Ushauri_Patient] + alter table [ODS].[dbo].[Mhealth_Ushauri_Patient] add PatientPKHash nvarchar(150) null END; @@ -62,10 +62,10 @@ BEGIN FROM INFORMATION_SCHEMA.COLUMNS WHERE - TABLE_NAME = 'Ushauri_Patient' AND COLUMN_NAME = 'UshauriPatientPKHash') + TABLE_NAME = 'Mhealth_Ushauri_Patient' AND COLUMN_NAME = 'UshauriPatientPKHash') BEGIN - alter table [ODS].[dbo].[Ushauri_Patient] + alter table [ODS].[dbo].[Mhealth_Ushauri_Patient] add UshauriPatientPKHash nvarchar(150) null END; -END \ No newline at end of file +END diff --git a/Scripts/ODS/Mhealth/Post_Load/2_RecreatePatientAppointments_PatientPKColumns.sql b/Scripts/ODS/Mhealth/Post_Load/2_RecreatePatientAppointments_PatientPKColumns.sql index a40cc460..1657f387 100644 --- a/Scripts/ODS/Mhealth/Post_Load/2_RecreatePatientAppointments_PatientPKColumns.sql +++ b/Scripts/ODS/Mhealth/Post_Load/2_RecreatePatientAppointments_PatientPKColumns.sql @@ -3,45 +3,45 @@ BEGIN IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the PatientPK column exists on [ODS].[dbo].[Ushauri_Patient] exists on ODS */ - WHERE Name = N'PatientPK' - AND Object_ID = Object_ID(N'[ODS].[dbo].[Ushauri_PatientAppointments]')) + WHERE Name = N'PatientPK' + AND Object_ID = Object_ID(N'[ODS].[dbo].[Mhealth_Ushauri_PatientAppointments]')) BEGIN IF NOT EXISTS (SELECT * /* If above condition is met, check if Ushauri_Patient exists. If it exists escape. If it doesn't exist create it*/ FROM INFORMATION_SCHEMA.COLUMNS - WHERE TABLE_NAME = 'Ushauri_PatientAppointments' - AND COLUMN_NAME = 'UshauriPatientPK') + WHERE TABLE_NAME = 'Mhealth_Ushauri_PatientAppointments' + AND COLUMN_NAME = 'UshauriPatientPK') BEGIN - EXEC sp_rename '[ODS].[dbo].[Ushauri_PatientAppointments].PatientPK', 'UshauriPatientPK', 'COLUMN'; + EXEC sp_rename '[ODS].[dbo].[Mhealth_Ushauri_PatientAppointments].PatientPK', 'UshauriPatientPK', 'COLUMN'; END END IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the PatientPK column exists on [ODS].[dbo].[Ushauri_Patient] exists on ODS */ - WHERE Name = N'PatientPKHash' - AND Object_ID = Object_ID(N'[ODS].[dbo].[Ushauri_PatientAppointments]')) + WHERE Name = N'PatientPKHash' + AND Object_ID = Object_ID(N'[ODS].[dbo].[Mhealth_Ushauri_PatientAppointments]')) BEGIN IF NOT EXISTS (SELECT * /* If above condition is met, check if Ushauri_Patient exists. If it exists escape. If it doesn't exist create it*/ FROM INFORMATION_SCHEMA.COLUMNS - WHERE TABLE_NAME = 'Ushauri_PatientAppointments' - AND COLUMN_NAME = 'PatientPKHash') + WHERE TABLE_NAME = 'Mhealth_Ushauri_PatientAppointments' + AND COLUMN_NAME = 'PatientPKHash') BEGIN - EXEC sp_rename '[ODS].[dbo].[Ushauri_PatientAppointments].PatientPKHash', 'PatientPKHash', 'COLUMN'; + EXEC sp_rename '[ODS].[dbo].[Mhealth_Ushauri_PatientAppointments].PatientPKHash', 'PatientPKHash', 'COLUMN'; END END - + IF NOT EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE - TABLE_NAME = 'Ushauri_PatientAppointments' AND COLUMN_NAME = 'patientPK') + TABLE_NAME = 'Mhealth_Ushauri_PatientAppointments' AND COLUMN_NAME = 'patientPK') BEGIN - ALTER TABLE [ODS].[dbo].[Ushauri_PatientAppointments] + ALTER TABLE [ODS].[dbo].[Mhealth_Ushauri_PatientAppointments] ADD patientPK int NULL END; @@ -51,9 +51,9 @@ BEGIN FROM INFORMATION_SCHEMA.COLUMNS WHERE - TABLE_NAME = 'Ushauri_PatientAppointments' AND COLUMN_NAME = 'PatientPKHash') + TABLE_NAME = 'Mhealth_Ushauri_PatientAppointments' AND COLUMN_NAME = 'PatientPKHash') BEGIN - alter table [ODS].[dbo].[Ushauri_PatientAppointments] + alter table [ODS].[dbo].[Mhealth_Ushauri_PatientAppointments] add PatientPKHash nvarchar(150) null END; @@ -63,10 +63,10 @@ BEGIN FROM INFORMATION_SCHEMA.COLUMNS WHERE - TABLE_NAME = 'Ushauri_PatientAppointments' AND COLUMN_NAME = 'UshauriPatientPKHash') + TABLE_NAME = 'Mhealth_Ushauri_PatientAppointments' AND COLUMN_NAME = 'UshauriPatientPKHash') BEGIN - alter table [ODS].[dbo].[Ushauri_PatientAppointments] + alter table [ODS].[dbo].[Mhealth_Ushauri_PatientAppointments] add UshauriPatientPKHash nvarchar(150) null END; -END \ No newline at end of file +END diff --git a/Scripts/ODS/Mhealth/Post_Load/3_Update_PatientPatientPK.sql b/Scripts/ODS/Mhealth/Post_Load/3_Update_PatientPatientPK.sql index cbc7eb43..a8941a38 100644 --- a/Scripts/ODS/Mhealth/Post_Load/3_Update_PatientPatientPK.sql +++ b/Scripts/ODS/Mhealth/Post_Load/3_Update_PatientPatientPK.sql @@ -3,11 +3,11 @@ registered in the EMR. Indentified using the patientCCCNumber */ UPDATE a SET a.PatientPK = null,a.PatientPKHash =null -FROM [ODS].[dbo].[Ushauri_Patient] a; +FROM [ODS].[dbo].[Mhealth_Ushauri_Patient] a; UPDATE a SET a.PatientPK = p.PatientPK -FROM [ODS].[dbo].[Ushauri_Patient] a +FROM [ODS].[dbo].[Mhealth_Ushauri_Patient] a JOIN [ODS].[dbo].[CT_Patient] p ON a.sitecode = p.sitecode AND a.patientID = p.patientID; diff --git a/Scripts/ODS/Mhealth/Post_Load/4_Update_PatientAppointments_PatientPK.sql b/Scripts/ODS/Mhealth/Post_Load/4_Update_PatientAppointments_PatientPK.sql index 12ee9f4c..c67b81d3 100644 --- a/Scripts/ODS/Mhealth/Post_Load/4_Update_PatientAppointments_PatientPK.sql +++ b/Scripts/ODS/Mhealth/Post_Load/4_Update_PatientAppointments_PatientPK.sql @@ -1,12 +1,12 @@ UPDATE a SET a.PatientPK = null,a.PatientPKHash =null -FROM [ODS].[dbo].[Ushauri_PatientAppointments] a; +FROM [ODS].[dbo].[Mhealth_Ushauri_PatientAppointments] a; /* Update of the PatientPK from the C&T patients.This are for the patients who are in ushauri and have been registered in the EMR. Indentified using the patientCCCNumber */ UPDATE a SET a.PatientPK = p.PatientPK -FROM [ODS].[dbo].[Ushauri_PatientAppointments] a +FROM [ODS].[dbo].[Mhealth_Ushauri_PatientAppointments] a JOIN [ODS].[dbo].[CT_Patient] p ON a.sitecode = p.sitecode AND a.patientID = p.patientID; diff --git a/Scripts/ODS/Mhealth/Post_Load/5_Recreate_Hei_PatientPKColumn.sql b/Scripts/ODS/Mhealth/Post_Load/5_Recreate_Hei_PatientPKColumn.sql index 039e1140..264892ac 100644 --- a/Scripts/ODS/Mhealth/Post_Load/5_Recreate_Hei_PatientPKColumn.sql +++ b/Scripts/ODS/Mhealth/Post_Load/5_Recreate_Hei_PatientPKColumn.sql @@ -1,46 +1,46 @@ /* Renaming patientPK column coming from mhealth to UshauriPatientPK for the purpose of matching patient from C&T to ones coming from ushauri. */ BEGIN - + IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the PatientPK column exists on [ODS].[dbo].[Ushauri_Patient] exists on ODS */ - WHERE Name = N'PatientPK' - AND Object_ID = Object_ID(N'[ODS].[dbo].[Ushauri_HEI]')) + WHERE Name = N'PatientPK' + AND Object_ID = Object_ID(N'[ODS].[dbo].[Mhealth_Ushauri_HEI]')) BEGIN - IF NOT EXISTS (SELECT * /* If above condition is met, check if [ODS].[dbo].[Ushauri_HEI] exists. If it exists escape. If it doesn't exist create it*/ + IF NOT EXISTS (SELECT * /* If above condition is met, check if [ODS].[dbo].[Mhealth_Ushauri_HEI] exists. If it exists escape. If it doesn't exist create it*/ FROM INFORMATION_SCHEMA.COLUMNS - WHERE TABLE_NAME = 'Ushauri_Patient' - AND COLUMN_NAME = 'UshauriPatientPK') + WHERE TABLE_NAME = 'Mhealth_Ushauri_Patient' + AND COLUMN_NAME = 'UshauriPatientPK') BEGIN - EXEC sp_rename '[ODS].[dbo].[Ushauri_HEI].PatientPK', 'UshauriPatientPK', 'COLUMN'; + EXEC sp_rename '[ODS].[dbo].[Mhealth_Ushauri_HEI].PatientPK', 'UshauriPatientPK', 'COLUMN'; END END - IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the PatientPK column exists on [ODS].[dbo].[Ushauri_HEI] exists on ODS */ - WHERE Name = N'PatientPKHash' - AND Object_ID = Object_ID(N'[ODS].[dbo].[Ushauri_HEI]')) + IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the PatientPK column exists on [ODS].[dbo].[Mhealth_Ushauri_HEI] exists on ODS */ + WHERE Name = N'PatientPKHash' + AND Object_ID = Object_ID(N'[ODS].[dbo].[Mhealth_Ushauri_HEI]')) BEGIN IF NOT EXISTS (SELECT * /* If above condition is met, check if Ushauri_Patient exists. If it exists escape. If it doesn't exist create it*/ FROM INFORMATION_SCHEMA.COLUMNS - WHERE TABLE_NAME = 'Ushauri_HEI' - AND COLUMN_NAME = 'PatientPKHash') + WHERE TABLE_NAME = 'Mhealth_Ushauri_HEI' + AND COLUMN_NAME = 'PatientPKHash') BEGIN - EXEC sp_rename '[ODS].[dbo].[Ushauri_HEI].PatientPKHash', 'PatientPKHash', 'COLUMN'; + EXEC sp_rename '[ODS].[dbo].[Mhealth_Ushauri_HEI].PatientPKHash', 'PatientPKHash', 'COLUMN'; END END - + IF NOT EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE - TABLE_NAME = 'Ushauri_HEI' AND COLUMN_NAME = 'patientPK') + TABLE_NAME = 'Mhealth_Ushauri_HEI' AND COLUMN_NAME = 'patientPK') BEGIN - ALTER TABLE [ODS].[dbo].[Ushauri_HEI] + ALTER TABLE [ODS].[dbo].[Mhealth_Ushauri_HEI] ADD patientPK int NULL END; @@ -50,9 +50,9 @@ BEGIN FROM INFORMATION_SCHEMA.COLUMNS WHERE - TABLE_NAME = 'Ushauri_HEI' AND COLUMN_NAME = 'PatientPKHash') + TABLE_NAME = 'Mhealth_Ushauri_HEI' AND COLUMN_NAME = 'PatientPKHash') BEGIN - alter table [ODS].[dbo].[Ushauri_HEI] + alter table [ODS].[dbo].[Mhealth_Ushauri_HEI] add PatientPKHash nvarchar(150) null END; @@ -62,11 +62,11 @@ BEGIN FROM INFORMATION_SCHEMA.COLUMNS WHERE - TABLE_NAME = 'Ushauri_HEI' AND COLUMN_NAME = 'UshauriPatientPKHash') + TABLE_NAME = 'Mhealth_Ushauri_HEI' AND COLUMN_NAME = 'UshauriPatientPKHash') BEGIN - alter table [ODS].[dbo].[Ushauri_HEI] + alter table [ODS].[dbo].[Mhealth_Ushauri_HEI] add UshauriPatientPKHash nvarchar(150) null END; END -------------------------------------------------------- \ No newline at end of file +------------------------------------------------------- diff --git a/Scripts/ODS/Mhealth/Post_Load/6_Update_HEI_PatientPK.sql b/Scripts/ODS/Mhealth/Post_Load/6_Update_HEI_PatientPK.sql index a80efe3f..25c41ee9 100644 --- a/Scripts/ODS/Mhealth/Post_Load/6_Update_HEI_PatientPK.sql +++ b/Scripts/ODS/Mhealth/Post_Load/6_Update_HEI_PatientPK.sql @@ -3,11 +3,11 @@ registered in the EMR. There seem to be no match. Need to know the link from the UPDATE a SET a.PatientPK = null,a.PatientPKHash =null -FROM [ODS].[dbo].[Ushauri_HEI] a; +FROM [ODS].[dbo].[Mhealth_Ushauri_HEI] a; --Lanyo to advice on the leankage between Ushauri Hei and MNCH_Heis --UPDATE a --SET a.PatientPK = p.PatientPK ---FROM [ODS].[dbo].[Ushauri_HEI] a +--FROM [ODS].[dbo].[Mhealth_Ushauri_HEI] a -- JOIN ods.dbo.MNCH_HEIs p ---ON a.sitecode = p.sitecode AND a.UshauriPatientPK = p.PatientPk; \ No newline at end of file +--ON a.sitecode = p.sitecode AND a.UshauriPatientPK = p.PatientPk; diff --git a/Scripts/ODS/Mhealth/Post_Load/7_RecreateReferralPatientPK_ReferralPatientPKHashcolumns.sql b/Scripts/ODS/Mhealth/Post_Load/7_RecreateReferralPatientPK_ReferralPatientPKHashcolumns.sql index bad8fd1e..de44183f 100644 --- a/Scripts/ODS/Mhealth/Post_Load/7_RecreateReferralPatientPK_ReferralPatientPKHashcolumns.sql +++ b/Scripts/ODS/Mhealth/Post_Load/7_RecreateReferralPatientPK_ReferralPatientPKHashcolumns.sql @@ -2,46 +2,46 @@ BEGIN - IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the ReferralPK column exists on [ODS].[dbo].[Ushauri_PatientReferral] exists on ODS */ - WHERE Name = N'ReferralPK' - AND Object_ID = Object_ID(N'[ODS].[dbo].[Ushauri_PatientReferral]')) + IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the ReferralPK column exists on [ODS].[dbo].[Mhealth_FacilityReferral_Patient] exists on ODS */ + WHERE Name = N'ReferralPK' + AND Object_ID = Object_ID(N'[ODS].[dbo].[Mhealth_FacilityReferral_Patient]')) BEGIN IF NOT EXISTS (SELECT * /* If above condition is met, check if Ushauri_PatientReferral exists. If it exists escape. If it doesn't exist create it*/ FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Ushauri_PatientReferral' - AND COLUMN_NAME = 'UshauriReferralPK') + AND COLUMN_NAME = 'UshauriReferralPK') BEGIN - EXEC sp_rename '[ODS].[dbo].[Ushauri_PatientReferral].ReferralPK', 'UshauriReferralPK', 'COLUMN'; + EXEC sp_rename '[ODS].[dbo].[Mhealth_FacilityReferral_Patient].ReferralPK', 'UshauriReferralPK', 'COLUMN'; END END - IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the ReferralPKHash column exists on [ODS].[dbo].[Ushauri_PatientReferral] exists on ODS */ - WHERE Name = N'ReferralPKHash' - AND Object_ID = Object_ID(N'[ODS].[dbo].[Ushauri_PatientReferral]')) + IF EXISTS (SELECT * FROM sys.columns /* 1st if confirms if the ReferralPKHash column exists on [ODS].[dbo].[Mhealth_FacilityReferral_Patient] exists on ODS */ + WHERE Name = N'ReferralPKHash' + AND Object_ID = Object_ID(N'[ODS].[dbo].[Mhealth_FacilityReferral_Patient]')) BEGIN IF NOT EXISTS (SELECT * /* If above condition is met, check if Ushauri_PatientReferral exists. If it exists escape. If it doesn't exist create it*/ FROM INFORMATION_SCHEMA.COLUMNS - WHERE TABLE_NAME = 'Ushauri_PatientReferral' - AND COLUMN_NAME = 'UshariReferralPKHash') + WHERE TABLE_NAME = 'Mhealth_FacilityReferral_Patient' + AND COLUMN_NAME = 'UshariReferralPKHash') BEGIN - EXEC sp_rename '[ODS].[dbo].[Ushauri_PatientReferral].ReferralPKHash', 'UshauriReferralPKHash', 'COLUMN'; + EXEC sp_rename '[ODS].[dbo].[Mhealth_FacilityReferral_Patient].ReferralPKHash', 'UshauriReferralPKHash', 'COLUMN'; END END - + IF NOT EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE - TABLE_NAME = 'Ushauri_PatientReferral' AND COLUMN_NAME = 'ReferralpatientPK') + TABLE_NAME = 'Mhealth_FacilityReferral_Patient' AND COLUMN_NAME = 'ReferralpatientPK') BEGIN - ALTER TABLE [ODS].[dbo].[Ushauri_PatientReferral] + ALTER TABLE [ODS].[dbo].[Mhealth_FacilityReferral_Patient] ADD ReferralpatientPK int NULL END; @@ -51,10 +51,10 @@ BEGIN FROM INFORMATION_SCHEMA.COLUMNS WHERE - TABLE_NAME = 'Ushauri_PatientReferral' AND COLUMN_NAME = 'ReferralPatientPKHash') + TABLE_NAME = 'Mhealth_FacilityReferral_Patient' AND COLUMN_NAME = 'ReferralPatientPKHash') BEGIN - alter table [ODS].[dbo].[Ushauri_PatientReferral] + alter table [ODS].[dbo].[Mhealth_FacilityReferral_Patient] add ReferralPatientPKHash nvarchar(150) null END; -END \ No newline at end of file +END diff --git a/Scripts/ODS/Mhealth/Post_Load/8_Update_PatientReferral_ReferralPatientPK.sql b/Scripts/ODS/Mhealth/Post_Load/8_Update_PatientReferral_ReferralPatientPK.sql index eba9e4af..f57c479a 100644 --- a/Scripts/ODS/Mhealth/Post_Load/8_Update_PatientReferral_ReferralPatientPK.sql +++ b/Scripts/ODS/Mhealth/Post_Load/8_Update_PatientReferral_ReferralPatientPK.sql @@ -3,6 +3,6 @@ registered in the EMR. Indentified using the patientCCCNumber */ UPDATE a SET a.ReferralpatientPK = p.PatientPK -FROM [ODS].[dbo].[Ushauri_PatientReferral] a +FROM [ODS].[dbo].[Mhealth_FacilityReferral_Patient] a JOIN [ODS].[dbo].[CT_Patient] p ON a.PatientID = p.PatientID; diff --git a/Scripts/ODS/Mhealth/Post_Load/9_Update_CT_PatientLabs.sql b/Scripts/ODS/Mhealth/Post_Load/9_Update_CT_PatientLabs.sql index 3ecd0f53..67a1c11e 100644 --- a/Scripts/ODS/Mhealth/Post_Load/9_Update_CT_PatientLabs.sql +++ b/Scripts/ODS/Mhealth/Post_Load/9_Update_CT_PatientLabs.sql @@ -4,12 +4,12 @@ SET a.PatientPK = NULL, a.PatientPKHash = NULL FROM - [ODS].[dbo].[Ushauri_PatientLabs] a; + [ODS].[dbo].[Mhealth_mLab_PatientLab] a; UPDATE a SET a.PatientPK = p.PatientPK FROM - [ODS].[dbo].[Ushauri_PatientLabs] a + [ODS].[dbo].[Mhealth_mLab_PatientLab] a JOIN [ODS].[dbo].[CT_Patient] p ON a.PatientID = p.PatientID; From 1f627ffc04be71a4f142794bca7b9f62f09913ea Mon Sep 17 00:00:00 2001 From: NewtonMutugi Date: Tue, 23 Jul 2024 15:10:38 +0300 Subject: [PATCH 3/5] Refactored remaining table names that were not updated --- .../Mhealth/Post_Load/1_RecreatePatient_PatientPKColumns.sql | 2 +- ...7_RecreateReferralPatientPK_ReferralPatientPKHashcolumns.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Scripts/ODS/Mhealth/Post_Load/1_RecreatePatient_PatientPKColumns.sql b/Scripts/ODS/Mhealth/Post_Load/1_RecreatePatient_PatientPKColumns.sql index 9df6b275..45258836 100644 --- a/Scripts/ODS/Mhealth/Post_Load/1_RecreatePatient_PatientPKColumns.sql +++ b/Scripts/ODS/Mhealth/Post_Load/1_RecreatePatient_PatientPKColumns.sql @@ -8,7 +8,7 @@ BEGIN BEGIN IF NOT EXISTS (SELECT * /* If above condition is met, check if Ushauri_Patient exists. If it exists escape. If it doesn't exist create it*/ FROM INFORMATION_SCHEMA.COLUMNS - WHERE TABLE_NAME = 'Ushauri_Patient' + WHERE TABLE_NAME = 'Mhealth_Ushauri_Patient' AND COLUMN_NAME = 'UshauriPatientPK') BEGIN diff --git a/Scripts/ODS/Mhealth/Post_Load/7_RecreateReferralPatientPK_ReferralPatientPKHashcolumns.sql b/Scripts/ODS/Mhealth/Post_Load/7_RecreateReferralPatientPK_ReferralPatientPKHashcolumns.sql index de44183f..59ad53a1 100644 --- a/Scripts/ODS/Mhealth/Post_Load/7_RecreateReferralPatientPK_ReferralPatientPKHashcolumns.sql +++ b/Scripts/ODS/Mhealth/Post_Load/7_RecreateReferralPatientPK_ReferralPatientPKHashcolumns.sql @@ -8,7 +8,7 @@ BEGIN BEGIN IF NOT EXISTS (SELECT * /* If above condition is met, check if Ushauri_PatientReferral exists. If it exists escape. If it doesn't exist create it*/ FROM INFORMATION_SCHEMA.COLUMNS - WHERE TABLE_NAME = 'Ushauri_PatientReferral' + WHERE TABLE_NAME = 'Mhealth_FacilityReferral_Patient' AND COLUMN_NAME = 'UshauriReferralPK') BEGIN From 4d31e25b6810f59985f4767bbc635707a397843f Mon Sep 17 00:00:00 2001 From: NewtonMutugi Date: Tue, 23 Jul 2024 15:48:13 +0300 Subject: [PATCH 4/5] Updated Mhealth table names in utils column hashing --- .../mhealth/Ushauri_PatientPK_PatientCCCNumber.sql | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Scripts/ODS/utils/COLUMN_HASHING/mhealth/Ushauri_PatientPK_PatientCCCNumber.sql b/Scripts/ODS/utils/COLUMN_HASHING/mhealth/Ushauri_PatientPK_PatientCCCNumber.sql index 01d918d3..5fa7a118 100644 --- a/Scripts/ODS/utils/COLUMN_HASHING/mhealth/Ushauri_PatientPK_PatientCCCNumber.sql +++ b/Scripts/ODS/utils/COLUMN_HASHING/mhealth/Ushauri_PatientPK_PatientCCCNumber.sql @@ -1,20 +1,20 @@ ---Ushauri_PatientAppointments UPDATE a SET PatientPKHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(PatientPk as nvarchar(36))), 2) -FROM [ODS].[dbo].[Ushauri_PatientAppointments] a +FROM [ODS].[dbo].[Mhealth_Ushauri_PatientAppointments] a WHERE PatientPKHash IS NULL; UPDATE a SET UshauriPatientPKHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(a.[UshauriPatientPk] as nvarchar(36))), 2), PatientIDHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(a.PatientID as nvarchar(36))), 2) , NUPIHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(a.[NUPI] as nvarchar(36))), 2) -FROM [ODS].[dbo].[Ushauri_PatientAppointments] a +FROM [ODS].[dbo].[Mhealth_Ushauri_PatientAppointments] a ----End ---Ushauri_Patient UPDATE a SET PatientPKHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(PatientPk as nvarchar(36))), 2) -FROM [ODS].[dbo].[Ushauri_Patient] a +FROM [ODS].[dbo].[Mhealth_Ushauri_Patient] a WHERE PatientPKHash IS NULL; @@ -22,25 +22,25 @@ UPDATE a SET UshauriPatientPKHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(a.[UshauriPatientPk] as nvarchar(36))), 2), PatientIDHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(a.PatientID as nvarchar(36))), 2) , NUPIHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(a.[NUPI] as nvarchar(36))), 2) -FROM [ODS].[dbo].[Ushauri_Patient] a +FROM [ODS].[dbo].[Mhealth_Ushauri_Patient] a UPDATE a SET UshauriPatientPKHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(a.[UshauriPatientPk] as nvarchar(36))), 2), PatientHEI_IDHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(a.PatientHEI_ID as nvarchar(36))), 2), PatientMNCH_IDHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(a.PatientMNCH_ID as nvarchar(36))), 2) -FROM [ODS].[dbo].[Ushauri_HEI] a +FROM [ODS].[dbo].[Mhealth_Ushauri_HEI] a UPDATE a SET ReferralPatientPKHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(a.ReferralPatientPK as nvarchar(36))), 2) -FROM [ODS].[dbo].[Ushauri_PatientReferral] a +FROM [ODS].[dbo].[Mhealth_FacilityReferral_Patient] a ----End ----Ushauri_PatientLabs UPDATE a SET PatientPKHash = convert(nvarchar(64), hashbytes('SHA2_256', cast(PatientPk as nvarchar(36))), 2) -FROM [ODS].[dbo].[Ushauri_PatientLabs] a +FROM [ODS].[dbo].[Mhealth_mLab_PatientLab] a WHERE PatientPKHash IS NULL; ----End From 3aa4bd99f854149740fbbcd3bee7cb911412de50 Mon Sep 17 00:00:00 2001 From: NewtonMutugi Date: Thu, 25 Jul 2024 10:26:14 +0300 Subject: [PATCH 5/5] Updated ushauri table names on NDWH scripts --- .../NDWH/ALL DIMENSIONS/load_DimPatient.sql | 24 +++++++++---------- .../load_FactUshauriAppointments.sql | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Scripts/NDWH/ALL DIMENSIONS/load_DimPatient.sql b/Scripts/NDWH/ALL DIMENSIONS/load_DimPatient.sql index 52db4aa3..c45935c7 100644 --- a/Scripts/NDWH/ALL DIMENSIONS/load_DimPatient.sql +++ b/Scripts/NDWH/ALL DIMENSIONS/load_DimPatient.sql @@ -43,7 +43,7 @@ BEGIN AND outcomes.sitecode = patients.sitecode LEFT JOIN ODS.dbo.CT_ARTPatients as art on art.PatientPKHash = patients.PatientPKHash AND art.SiteCode = patients.SiteCode - ), + ), hts_patient_source AS (SELECT DISTINCT htsnumberhash, patientpkhash, @@ -55,7 +55,7 @@ BEGIN nupihash, clients.voided FROM ods.dbo.hts_clients AS clients - + ), prep_patient_source AS (SELECT DISTINCT patientpkhash, @@ -69,7 +69,7 @@ BEGIN maritalstatus ,voided FROM ods.dbo.prep_patient), - + pmtct_patient_source AS (SELECT DISTINCT patientpkhash, patientpk, @@ -124,7 +124,7 @@ BEGIN AND ct_patient_source.sitecode = hts_patient_source.sitecode), - + combined_data_ct_hts_prep AS (SELECT COALESCE(combined_data_ct_hts.patientpkhash, prep_patient_source.patientpkhash) @@ -171,7 +171,7 @@ BEGIN AND prep_patient_source.sitecode = combined_data_ct_hts.sitecode), - + combined_data_ct_hts_prep_pmtct AS (SELECT COALESCE(combined_data_ct_hts_prep.patientpkhash, pmtct_patient_source.patientpkhash) @@ -216,7 +216,7 @@ BEGIN AND combined_data_ct_hts_prep.sitecode = pmtct_patient_source.sitecode), ushauri_patient_source_nonEMR - AS (SELECT DISTINCT + AS (SELECT DISTINCT ushauri.UshauriPatientPkHash, ushauri.PatientIDHash, ushauri.patientpk, @@ -228,9 +228,9 @@ BEGIN ushauri.maritalstatus, ushauri.nupihash, ushauri.SiteType - FROM ods.dbo.Ushauri_Patient AS ushauri + FROM [ODS].[dbo].[Mhealth_Ushauri_Patient] AS ushauri where ushauri.PatientPKHash is null and SiteCode is not null - + ) , combined_data_ct_hts_prep_pmtct_Ushauri @@ -286,8 +286,8 @@ BEGIN Null FirstEnrollmentAtMnchDateKey FROM ushauri_patient_source_nonEMR ushauri where sitecode is not null - - + + ) MERGE NDWH.[dbo].[DimPatient] AS a @@ -321,7 +321,7 @@ BEGIN FROM combined_data_ct_hts_prep_pmtct_Ushauri) AS b ON ( a.sitecode = b.sitecode AND a.patientpkhash = b.patientpkhash - + ) WHEN NOT matched THEN INSERT(patientidhash, @@ -376,4 +376,4 @@ BEGIN a.PrepEnrollmentDateKey = b.PrepEnrollmentDateKey, a.voided = b.voided, a.DateConfirmedHIVPositiveKey = b.DateConfirmedHIVPositiveKey; -END \ No newline at end of file +END diff --git a/Scripts/NDWH/C&T FACT TABLES/load_FactUshauriAppointments.sql b/Scripts/NDWH/C&T FACT TABLES/load_FactUshauriAppointments.sql index aa2a711e..f6fe56f7 100644 --- a/Scripts/NDWH/C&T FACT TABLES/load_FactUshauriAppointments.sql +++ b/Scripts/NDWH/C&T FACT TABLES/load_FactUshauriAppointments.sql @@ -55,7 +55,7 @@ BEGIN Daysdefaulted, Nupihash INTO NDWH.dbo.FactUshauriAppointments - FROM Ods.Dbo.Ushauri_patientappointments AS Apt + FROM [ODS].[dbo].[Mhealth_Ushauri_PatientAppointments] AS Apt LEFT JOIN Ndwh.Dbo.Dimfacility AS Facility ON Facility.Mflcode = Apt.Sitecode LEFT JOIN Mfl_partner_agency_combination @@ -101,4 +101,4 @@ BEGIN ALTER TABLE Ndwh.Dbo.FactUshauriAppointments ADD PRIMARY KEY(Factkey); -END \ No newline at end of file +END