diff --git a/Scripts/NDWH/C&T FACT TABLES/load_FactUshauriAppointments.sql b/Scripts/NDWH/C&T FACT TABLES/load_FactUshauriAppointments.sql index ed29e299..aa2a711e 100644 --- a/Scripts/NDWH/C&T FACT TABLES/load_FactUshauriAppointments.sql +++ b/Scripts/NDWH/C&T FACT TABLES/load_FactUshauriAppointments.sql @@ -48,9 +48,7 @@ BEGIN Missedappointmentdate.Datekey AS MissedAppointmentSMSSendDateKey, Missedappointmentsmsdeliverystatus, Missedappointmentsmsdeliveryfailurereason, - Tracingcalls, - Tracingsms, - Tracinghomevisits, + TracingOutCost, Tracingoutcome, Tracingdate.Datekey AS TracingOutcomeDateKey, Datereturnedtocare.Datekey AS DateReturnedToCareDateKey, diff --git a/Scripts/ODS/Mhealth/Load_Ushauri_HEI.sql b/Scripts/ODS/Mhealth/Load_Ushauri_HEI.sql new file mode 100644 index 00000000..92cdd491 --- /dev/null +++ b/Scripts/ODS/Mhealth/Load_Ushauri_HEI.sql @@ -0,0 +1,61 @@ +BEGIN + + MERGE [ODS].[dbo].[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], + [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 + + FROM [MhealthCentral].[dbo].[pmtct_MNCH_HEI](NoLock) P + ) AS b + ON( + 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) + 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 + a.[PartnerName] = b.[PartnerName], + a.[SiteType] = b.[SiteType], + a.[Emr] = b.[Emr], + a.[Project] = b.[Project], + a.[FacilityName] = b.[FacilityName], + a.[1stDNAPCRDate] = b.[1stDNAPCRDate], + a.[2ndDNAPCRDate] = b.[2ndDNAPCRDate], + a.[3rdDNAPCRDate] = b.[3rdDNAPCRDate], + a.[ConfirmatoryPCRDate] = b.[ConfirmatoryPCRDate], + a.[BasellineVLDate] = b.[BasellineVLDate], + a.[FinalyAntibodyDate] = b.[FinalyAntibodyDate], + a.[1stDNAPCR] = b.[1stDNAPCR], + a.[2ndDNAPCR] = b.[2ndDNAPCR], + a.[3rdDNAPCR] = b.[3rdDNAPCR], + a.[ConfirmatoryPCR] = b.[ConfirmatoryPCR], + a.[BasellineVL] = b.[BasellineVL], + a.[FinalyAntibody] = b.[FinalyAntibody], + a.[HEIExitDate] = b.[HEIExitDate], + a.[HEIHIVStatus] = b.[HEIHIVStatus], + a.[HEIExitCriteria] = b.[HEIExitCriteria], + a.[DateCreated] = b.[DateCreated], + a.[DateModified] = b.[DateModified], + a.[1stDNAPCRDate_Date] = b.[1stDNAPCRDate_Date], + a.[2ndDNAPCRDate_Date] = b.[2ndDNAPCRDate_Date], + a.[3rdDNAPCRDate_Date] = b.[3rdDNAPCRDate_Date], + a.[ConfirmatoryPCRDate_Date] = b.[ConfirmatoryPCRDate_Date], + a.[BasellineVLDate_Date] = b.[BasellineVLDate_Date], + a.[FinalyAntibodyDate_Date] = b.[FinalyAntibodyDate_Date], + a.[HEIExitDate_Date] = b.[HEIExitDate_Date], + a.[DateCreated_Date] = b.[DateCreated_Date], + a.[DateModified_Date] = b.[DateModified_Date] + ; + + + END \ No newline at end of file diff --git a/Scripts/ODS/Mhealth/Load_Ushauri_PatientAppointments.sql b/Scripts/ODS/Mhealth/Load_Ushauri_PatientAppointments.sql index 0c30e9c8..354ff778 100644 --- a/Scripts/ODS/Mhealth/Load_Ushauri_PatientAppointments.sql +++ b/Scripts/ODS/Mhealth/Load_Ushauri_PatientAppointments.sql @@ -13,7 +13,7 @@ BEGIN TwoWeekSMSDeliveryFailureReason,OneWeekSMSSent,OneWeekSMSSendDate_Date As OneWeekSMSSendDate,OneWeekSMSDeliveryStatus, OneWeekSMSDeliveryFailureReason,OneDaySMSSent,OneDaySMSSendDate_Date As OneDaySMSSendDate,OneDaySMSDeliveryStatus,OneDaySMSDeliveryFailureReason, MissedAppointmentSMSSent,MissedAppointmentSMSSendDate_Date As MissedAppointmentSMSSendDate,MissedAppointmentSMSDeliveryStatus,MissedAppointmentSMSDeliveryFailureReason, - TracingCalls,TracingSMS,TracingHomeVisits,TracingOutcome,TracingOutcomeDate_Date As TracingOutcomeDate,DateReturnedToCare_Date As DateReturnedToCare,DaysDefaulted + TracingOutCost,TracingOutcome,TracingOutcomeDate_Date As TracingOutcomeDate,DateReturnedToCare_Date As DateReturnedToCare,DaysDefaulted FROM [mhealthCentral].[dbo].[CT_PatientAppointments](NoLock) P ) AS b ON( @@ -22,8 +22,8 @@ BEGIN ) 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,TracingCalls,TracingSMS,TracingHomeVisits,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,TracingCalls,TracingSMS,TracingHomeVisits,TracingOutcome,TracingOutcomeDate,DateReturnedToCare,DaysDefaulted,Getdate()) + 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,TracingOutCost,TracingOutcome,TracingOutcomeDate,DateReturnedToCare,DaysDefaulted,Getdate()) WHEN MATCHED THEN UPDATE SET @@ -82,9 +82,7 @@ BEGIN a.[MissedAppointmentSMSSendDate] = b.[MissedAppointmentSMSSendDate], a.[MissedAppointmentSMSDeliveryStatus] = b.[MissedAppointmentSMSDeliveryStatus], a.[MissedAppointmentSMSDeliveryFailureReason] = b.[MissedAppointmentSMSDeliveryFailureReason], - a.[TracingCalls] = b.[TracingCalls], - a.[TracingSMS] = b.[TracingSMS], - a.[TracingHomeVisits] = b.[TracingHomeVisits], + a.TracingOutCost = b.TracingOutCost, a.[TracingOutcome] = b.[TracingOutcome], a.[TracingOutcomeDate] = b.[TracingOutcomeDate], a.[DateReturnedToCare] = b.[DateReturnedToCare],