Skip to content

Commit

Permalink
resolving merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
nobert-mumo committed Aug 2, 2024
2 parents 8463c50 + f8bcab0 commit 7049439
Show file tree
Hide file tree
Showing 59 changed files with 1,098 additions and 704 deletions.
58 changes: 44 additions & 14 deletions Scripts/NDWH/ALL DIMENSIONS/load_DimPatient.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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,
Expand All @@ -56,7 +56,7 @@ BEGIN
nupihash,
clients.voided
FROM ods.dbo.hts_clients AS clients

),
prep_patient_source
AS (SELECT DISTINCT patientpkhash,
Expand All @@ -70,7 +70,7 @@ BEGIN
maritalstatus
,voided
FROM ods.dbo.prep_patient),

pmtct_patient_source
AS (SELECT DISTINCT patientpkhash,
patientpk,
Expand Down Expand Up @@ -126,7 +126,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)
Expand Down Expand Up @@ -174,7 +174,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)
Expand Down Expand Up @@ -220,7 +220,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,
Expand All @@ -232,11 +232,32 @@ 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

) ,

) ,
Disclosure as (
Select
row_number() OVER (PARTITION BY SiteCode,PatientPKHash ORDER BY VisitDate DESC) AS NUM,
PatientPKHash,
Sitecode,
PaedsDisclosure,
PwP
from ODS.dbo.CT_PatientVisits as visits
WHERE PwP LIKE '%|disclosure|%'
OR PwP LIKE 'disclosure|%'
OR PwP LIKE '%|disclosure'
OR PwP = 'disclosure'
or PaedsDisclosure ='full disclosure' or PwP='Disclosure'
),
LatestDisclosure as (
SELECT
PatientPKHash,
SiteCode,
Coalesce (PaedsDisclosure, PWP) as Disclosure
From Disclosure
where NUM=1
),
combined_data_ct_hts_prep_pmtct_Ushauri
as(
SELECT combined_data_ct_hts_prep_pmtct.patientpkhash AS PatientPKHash,
Expand All @@ -257,13 +278,15 @@ BEGIN
combined_data_ct_hts_prep_pmtct.EverOnART,
combined_data_ct_hts_prep_pmtct.htsnumberhash,
NUll As sitetype,
LatestDisclosure.Disclosure,
Cast(Getdate() AS DATE) AS LoadDate,
combined_data_ct_hts_prep_pmtct.Voided,
combined_data_ct_hts_prep_pmtct.PrepNumber,
combined_data_ct_hts_prep_pmtct.PrepEnrollmentDateKey,
combined_data_ct_hts_prep_pmtct.PatientMnchIDHash,
combined_data_ct_hts_prep_pmtct.FirstEnrollmentAtMnchDateKey
FROM combined_data_ct_hts_prep_pmtct
left join LatestDisclosure on LatestDisclosure.patientpkhash=combined_data_ct_hts_prep_pmtct.patientpkhash and LatestDisclosure.sitecode=combined_data_ct_hts_prep_pmtct.sitecode

UNION
SELECT concat(ushauri.UshauriPatientPKHash,'_Ushauri') AS PatientPKHash,
Expand All @@ -284,15 +307,17 @@ BEGIN
Null EverOnART,
Null htsnumberhash,
sitetype,
LatestDisclosure.Disclosure,
Null LoadDate,
Null Voided,
Null PrepNumber,
Null PrepEnrollmentDateKey,
Null PatientMnchIDHash,
Null FirstEnrollmentAtMnchDateKey
FROM ushauri_patient_source_nonEMR ushauri
where sitecode is not null

left join LatestDisclosure on LatestDisclosure.patientpkhash=ushauri.UshauriPatientPKHash and LatestDisclosure.sitecode=ushauri.sitecode

where ushauri.SiteCode is not null

)

Expand Down Expand Up @@ -321,14 +346,15 @@ BEGIN
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.Disclosure,
combined_data_ct_hts_prep_pmtct_Ushauri.patientmnchidhash,
combined_data_ct_hts_prep_pmtct_Ushauri.firstenrollmentatmnchdatekey,
combined_data_ct_hts_prep_pmtct_Ushauri.loaddate,
combined_data_ct_hts_prep_pmtct_Ushauri.voided
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,
Expand All @@ -344,10 +370,12 @@ BEGIN
patientsource,
enrollmentwhokey,
datebaselinewhokey,
baselinewhokey,PrepEnrollmentDateKey,
baselinewhokey,
PrepEnrollmentDateKey,
istxcurr,
DateConfirmedHIVPositiveKey,
EverOnART,
disclosure,
loaddate,
voided)
VALUES(patientidhash,
Expand All @@ -368,6 +396,7 @@ BEGIN
istxcurr,
DateConfirmedHIVPositiveKey,
EverOnART,
disclosure,
loaddate,
voided)
WHEN matched THEN
Expand All @@ -385,5 +414,6 @@ BEGIN
a.PrepEnrollmentDateKey = b.PrepEnrollmentDateKey,
a.voided = b.voided,
a.DateConfirmedHIVPositiveKey = b.DateConfirmedHIVPositiveKey,
a.EverOnART = b.EverOnART;
a.EverOnART = b.EverOnART,
a.Disclosure = b.Disclosure;
END
68 changes: 68 additions & 0 deletions Scripts/NDWH/C&T FACT TABLES/load_FactContactElicitation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
IF OBJECT_ID(N'[NDWH].[dbo].[FactContactElicitation]', N'U') IS NOT NULL
DROP TABLE [NDWH].[dbo].[FactContactElicitation];

BEGIN

with MFL_partner_agency_combination as (
select
distinct MFL_Code,
SDP,
[SDP_Agency] as Agency
from ODS.dbo.All_EMRSites
),
subset_data as (
select
PatientPK,
CONVERT(NVARCHAR(64), HASHBYTES('SHA2_256', CAST(PatientPK as NVARCHAR(36))), 2) as PatientPKHash,
SiteCode,
ContactPatientPK,
CONVERT(NVARCHAR(64), HASHBYTES('SHA2_256', CAST(ContactPatientPK as NVARCHAR(36))), 2) as ContactPatientPKHash,
ContactSex,
ContactAge,
ContactMaritalStatus,
RelationshipWithPatient,
DateCreated
from ODS.dbo.CT_ContactListing
where voided = 0
),
tested_contacts as(
select
distinct ContactPatientPK,
subset_data.SiteCode,
TestDate
from subset_data
inner join ODS.dbo.HTS_ClientTests as tests on tests.PatientPk = subset_data.ContactPatientPK
and tests.SiteCode =subset_data.SiteCode
)
select
Factkey = IDENTITY(INT, 1, 1),
index_pat.PatientKey as IndexPatientKey,
contact_pat.PatientKey as ContactPatientKey,
facility.FacilityKey,
age_group.AgeGroupKey,
partner.PartnerKey,
agency.AgencyKey,
ContactSex,
ContactAge,
ContactMaritalStatus,
RelationshipWithPatient,
created.DateKey as DateCreatedKey,
case when tested_contacts.ContactPatientPK is not null then 1 else 0 end as Tested
into [NDWH].[dbo].[FactContactElicitation]
from subset_data
left join tested_contacts on tested_contacts.ContactPatientPK = subset_data.ContactPatientPK
and tested_contacts.SiteCode = subset_data.SiteCode
left join NDWH.dbo.DimPatient as index_pat on index_pat.PatientPKHash = subset_data.PatientPKHash
and index_pat.SiteCode = subset_data.SiteCode
left join NDWH.dbo.DimPatient as contact_pat on contact_pat.PatientPKHash = subset_data.ContactPatientPKHash
and contact_pat.SiteCode = subset_data.SiteCode
left join NDWH.dbo.DimFacility as facility on facility.MFLCode = subset_data.SiteCode
left join NDWH.dbo.DimAgeGroup as age_group on age_group.Age = datediff(year, index_pat.DOB,eomonth(dateadd(mm,-1,getdate())))
left join MFL_partner_agency_combination on MFL_partner_agency_combination.MFL_Code = subset_data.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
left join NDWH.dbo.DimDate as created on created.[Date] = subset_data.DateCreated

alter table [NDWH].[dbo].[FactContactElicitation] add primary key(FactKey);

END
4 changes: 2 additions & 2 deletions Scripts/NDWH/C&T FACT TABLES/load_FactUshauriAppointments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -101,4 +101,4 @@ BEGIN

ALTER TABLE Ndwh.Dbo.FactUshauriAppointments
ADD PRIMARY KEY(Factkey);
END
END
29 changes: 10 additions & 19 deletions Scripts/ODS/CT_DOCKET/CT_AdverseEvents.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BEGIN ;

DECLARE @MaxAdverseEventStartDate DATETIME,
@AdverseEventStartDate DATETIME,
@MaxCreatedDate DATETIME
Expand Down Expand Up @@ -46,10 +46,10 @@ using(SELECT DISTINCT P.[patientcccnumber] AS PatientID,
PA.[date_last_modified],
PA.recorduuid,
PA.voided,
VoidingSource = Case
VoidingSource = Case
when PA.voided = 1 Then 'Source'
Else Null
END
END
FROM [DWAPICentral].[dbo].[patientextract](nolock) P
INNER JOIN [DWAPICentral].[dbo].patientadverseeventextract(nolock) PA
ON PA.[patientid] = P.id
Expand All @@ -72,20 +72,20 @@ using(SELECT DISTINCT P.[patientcccnumber] AS PatientID,
,InnerPA.AdverseEvent
,VisitDate
,InnerPA.voided
) tm
ON f.code = tm.[SiteCode] and
p.PatientPID=tm.PatientPK and
) tm
ON f.code = tm.[SiteCode] and
p.PatientPID=tm.PatientPK and
PA.VisitDate = tm.VisitDate and
cast(PA.created as date) = tm.Maxdatecreated and
PA.ID = tm.Max_ID
PA.ID = tm.Max_ID


) AS b
ON( a.sitecode = b.sitecode AND
a.patientpk = b.patientpk AND
a.AdverseEvent = b.AdverseEvent AND
a.visitdate = b.visitdate AND
a.voided = b.voided
a.voided = b.voided
)
WHEN NOT matched THEN
INSERT(patientid,
Expand Down Expand Up @@ -155,14 +155,5 @@ SET loadenddatetime = Getdate()
WHERE maxadverseeventstartdate = @AdverseEventStartDate;


INSERT INTO [ODS_Logs].[dbo].[ct_adverseeventcount_log]
([sitecode],
[createddate],
[adverseeventcount])
SELECT sitecode,
Getdate(),
Count(Concat(sitecode, patientpk)) AS AdverseEventCount
FROM [ODS].[dbo].[ct_adverseevents]
GROUP BY sitecode;

END

END
Loading

0 comments on commit 7049439

Please sign in to comment.