From 4d43cd0db99f6252bb1eecbdee7fa17e75699674 Mon Sep 17 00:00:00 2001 From: Koske Kimutai Date: Tue, 30 Jun 2020 23:55:09 +0300 Subject: [PATCH 1/3] added IRDO extracts --- .../Seed/DatabaseProtocols.csv | 1 + .../Seed/EmrSystems.csv | 1 + .../Seed/Extracts.csv | 967 ++++++++++++++++++ .../Seed/Resources.csv | 1 + .../Seed/RestProtocols.csv | 2 +- .../SettingsContext.cs | 3 +- src/Dwapi.SharedKernel/Enum/EmrSetup.cs | 5 +- 7 files changed, 976 insertions(+), 4 deletions(-) diff --git a/src/Dwapi.SettingsManagement.Infrastructure/Seed/DatabaseProtocols.csv b/src/Dwapi.SettingsManagement.Infrastructure/Seed/DatabaseProtocols.csv index 63dd027f..73e2705e 100644 --- a/src/Dwapi.SettingsManagement.Infrastructure/Seed/DatabaseProtocols.csv +++ b/src/Dwapi.SettingsManagement.Infrastructure/Seed/DatabaseProtocols.csv @@ -8,3 +8,4 @@ a6221989-0e85-11e8-ba89-0ed5f89f718b|openmrs|2|a6221859-0e85-11e8-ba89-0ed5f89f7 bb254606-38f8-409f-8e36-ab6601139dea|other|2|a6221859-0e85-11e8-ba89-0ed5f89f718b|127.0.0.1|openmrs|3306|root|Allow User Variables=True A6221987-0E85-11E8-BA89-0ED5F89F718B|IQCare_CHAK|1|926f49b8-305d-11ea-978f-2e728ce88125|.|c0nstella||sa| a6221988-0e85-11e8-ba89-0ed5f89f718b|IQTools_CHAK|1|926f49b8-305d-11ea-978f-2e728ce88125|.|c0nstella||sa| +a6221aa6-0e85-11e8-ba89-0ed5f89f718b|openmrs|2|a6221860-0e85-11e8-ba89-0ed5f89f718b|127.0.0.1|openmrs|3306|root|Allow User Variables=True diff --git a/src/Dwapi.SettingsManagement.Infrastructure/Seed/EmrSystems.csv b/src/Dwapi.SettingsManagement.Infrastructure/Seed/EmrSystems.csv index 9943ad94..7e6a32c8 100644 --- a/src/Dwapi.SettingsManagement.Infrastructure/Seed/EmrSystems.csv +++ b/src/Dwapi.SettingsManagement.Infrastructure/Seed/EmrSystems.csv @@ -5,3 +5,4 @@ a6221857-0e85-11e8-ba89-0ed5f89f718b|AMRS|1|0|0|1 a6221858-0e85-11e8-ba89-0ed5f89f718b|ECare|1|0|0|0 a6221859-0e85-11e8-ba89-0ed5f89f718b|FACES|1|0|0|1 926f49b8-305d-11ea-978f-2e728ce88125|CHAK|1|0|0|0 +a6221860-0e85-11e8-ba89-0ed5f89f718b|IRDO|1|0|0|2 diff --git a/src/Dwapi.SettingsManagement.Infrastructure/Seed/Extracts.csv b/src/Dwapi.SettingsManagement.Infrastructure/Seed/Extracts.csv index fe2f5acc..d3a148e4 100644 --- a/src/Dwapi.SettingsManagement.Infrastructure/Seed/Extracts.csv +++ b/src/Dwapi.SettingsManagement.Infrastructure/Seed/Extracts.csv @@ -3057,3 +3057,970 @@ BAB42EA7-E672-4C1B-A1B3-F2160DE40845|Master Patient Index|CBS|A6221859-0E85-11E8 b629ab26-3055-11ea-978f-2e728ce98131|Migration|MGS|a62216ee-0e85-11e8-ba89-0ed5f89f718b|"SELECT ID as MetricId,Dataset,Metric,MetricValue,Stage,SiteCode,Emr,FacilityName,'KenyaHMIS' as Project,CreateDate FROM DWAPI_Migration_Metrics"|MgsStage|1|MetricMigrationExtract|1|a6221983-0e85-11e8-ba89-0ed5f89f718b b629ab27-3055-11ea-978f-2e728ce98132|Migration|MGS|a6221856-0e85-11e8-ba89-0ed5f89f718b|"SELECT ID as MetricId,Dataset,Metric,MetricValue,Stage,SiteCode,Emr,FacilityName,'KenyaHMIS' as Project,CreateDate FROM DWAPI_Migration_Metrics"|MgsStage|1|MetricMigrationExtract|1|a6221aa4-0e85-11e8-ba89-0ed5f89f718b + +ec3d7e10-bb10-11ea-b3de-0242ac130004|Smart Card|PSMART|a6221860-0e85-11e8-ba89-0ed5f89f718b|"select id,shr,date_created,status,status_date,uuid FROM psmart_store where upper(status) = 'PENDING'"|PSmartStage|1|pSmart|1|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e11-bb10-11ea-b3de-0242ac130004|All Patients|NDWH|a6221860-0e85-11e8-ba89-0ed5f89f718b|"select +CASE WHEN prg.program='TB' THEN prg.status ELSE null end AS StatusAtTBClinic, +CASE WHEN prg.program='PMTCT' THEN prg.status ELSE null end AS StatusAtPMTCT, +CASE WHEN prg.program='HIV' THEN prg.status ELSE null end AS StatusATCCC, + +'' AS SatelliteName, +0 AS FacilityId,d.unique_patient_no as PatientID, + d.patient_id as PatientPK, + (select value_reference from location_attribute + where location_id in (select property_value + from global_property + where property='kenyaemr.defaultLocation') and attribute_type_id=1) as siteCode, + (select name from location + where location_id in (select property_value + from global_property + where property='kenyaemr.defaultLocation')) as FacilityName, + case d.gender when 'M' then 'Male' when 'F' then 'Female' end as Gender, + d.dob as DOB, + CAST(min(hiv.visit_date) as Date) as RegistrationDate, + CAST(coalesce(date_first_enrolled_in_care,min(hiv.visit_date)) as Date) as RegistrationAtCCC, + CAST(min(mch.visit_date)as Date) as RegistrationATPMTCT, + CAST(min(tb.visit_date)as Date) as RegistrationAtTBClinic, + case max(hiv.entry_point) + when 160542 then 'OPD' + when 160563 then 'Other' + when 160539 then 'VCT' + when 160538 then 'PMTCT' + when 160541 then 'TB' + when 160536 then 'IPD - Adult' + /*else cn.name*/ + end as PatientSource, + + (select state_province from location + where location_id in (select property_value + from global_property + where property='kenyaemr.defaultLocation')) as Region, + (select county_district from location + where location_id in (select property_value + from global_property + where property='kenyaemr.defaultLocation'))as District, + (select address6 from location + where location_id in (select property_value + from global_property + where property='kenyaemr.defaultLocation')) as Village, + UPPER(ts.name) as ContactRelation, + CAST(GREATEST(coalesce(max(hiv.visit_date),date('1000-01-01')),coalesce(max(de.visit_date),date('1000-01-01')), coalesce(max(enr.visit_date),date('1000-01-01'))) as Date) as LastVisit, + UPPER(d.marital_status) as MaritalStatus, + UPPER(d.education_level) as EducationLevel, + + CAST(min(hiv.date_confirmed_hiv_positive) as Date) as DateConfirmedHIVPositive, + max(hiv.arv_status) as PreviousARTExposure, + NULL as PreviousARTStartDate, + + + 'KenyaEMR' as Emr, + 'Kenya HMIS II' as Project, + + + CASE hiv.patient_type + WHEN 160563 THEN 'Transfer in' + WHEN 164144 THEN 'New client' + WHEN 159833 THEN 'Re-enroll' + ELSE hiv.patient_type + END AS PatientType, + + + + (select CASE + WHEN f.key_population_type IS NOT NULL AND f.key_population_type !=1175 + THEN 'Key population' + WHEN f.key_population_type =1175 THEN 'General Population' + ELSE pt.name END from kenyaemr_etl.etl_patient_hiv_followup f + left join concept_name pt on f.population_type = pt.concept_id AND pt.concept_name_type='FULLY_SPECIFIED' + WHERE f.encounter_id=min(enr.encounter_id)) AS PopulationType, + + (select + case f.key_population_type + WHEN 105 THEN 'PWID' + WHEN 160578 THEN 'MSM' + WHEN 160579 THEN 'FSW' + WHEN 1175 THEN 'N/A' + ELSE null END + + from kenyaemr_etl.etl_patient_hiv_followup f + WHERE f.encounter_id=min(enr.encounter_id)) AS KeyPopulationType, + case orp.value_coded when 1 THEN 'Yes' when 2 THEN 'No' ELSE null END as 'Orphan', + case sch.value_coded when 1 THEN 'Yes' when 2 THEN 'No' ELSE null END as 'InSchool', + patAd.county_district AS PatientResidentCounty, + patAd.state_province AS PatientResidentSubCounty, + patAd.address6 AS PatientResidentLocation, + patAd.address5 AS PatientResidentSubLocation, + patAd.address4 AS PatientResidentWard, + patAd.city_village AS PatientResidentVillage, + cast(min(hiv.transfer_in_date) as Date) as TransferInDate + +from kenyaemr_etl.etl_hiv_enrollment hiv +inner join kenyaemr_etl.etl_patient_demographics d on hiv.patient_id=d.patient_id +left outer join kenyaemr_etl.etl_mch_enrollment mch on mch.patient_id=d.patient_id +left outer join kenyaemr_etl.etl_patient_hiv_followup enr on enr.patient_id=d.patient_id +left outer join kenyaemr_etl.etl_tb_enrollment tb on tb.patient_id=d.patient_id +left outer join kenyaemr_etl.etl_drug_event de on de.patient_id = d.patient_id +left join concept_name ts on ts.concept_id=hiv.relationship_of_treatment_supporter and ts.concept_name_type = 'FULLY_SPECIFIED' and ts.locale='en' +left join person_address patAd ON patAd.person_id=d.patient_id and patAd.voided = 0 +left join (select distinct person_id, value_coded + from obs + where concept_id=5629 and voided=0) sch on sch.person_id = d.patient_id +left join (select distinct person_id, value_coded + from obs + where concept_id=11704 and voided=0) orp on sch.person_id = d.patient_id +left join +( + select Patient_Id, program , + if(mid(max(concat(date_enrolled,date_completed)), 20) is null, 'Active', 'Inactive') as status + from kenyaemr_etl.etl_patient_program + group by Patient_Id,program +) as prg on prg.patient_id = d.patient_id +where unique_patient_no is not null +group by d.patient_id +order by d.patient_id;"|dwhstage|1|PatientExtract|1|a6221aa6-0e85-11e8-ba89-0ed5f89f718b + +ec3d7e12-bb10-11ea-b3de-0242ac130004|ART Patients|NDWH|a6221860-0e85-11e8-ba89-0ed5f89f718b|" select '' AS SatelliteName, 0 AS FacilityId, d.DOB, + d.Gender, '' AS Provider, + d.unique_patient_no as PatientID, + d.patient_id as PatientPK, + timestampdiff(year,d.DOB, hiv.visit_date) as AgeEnrollment, + timestampdiff(year,d.DOB, reg.art_start_date) as AgeARTStart, + timestampdiff(year,d.DOB, reg.latest_vis_date) as AgeLastVisit, + (select value_reference from location_attribute + where location_id in (select property_value + from global_property + where property='kenyaemr.defaultLocation') and attribute_type_id=1) as siteCode, + (select name from location + where location_id in (select property_value + from global_property + where property='kenyaemr.defaultLocation')) as FacilityName, + CAST(coalesce(date_first_enrolled_in_care,min(hiv.visit_date)) as Date) as RegistrationDate, + case max(hiv.entry_point) + when 160542 then 'OPD' + when 160563 then 'Other' + when 160539 then 'VCT' + when 160538 then 'PMTCT' + when 160541 then 'TB' + when 160536 then 'IPD - Adult' + else cn.name + end as PatientSource, + reg.art_start_date as StartARTDate, + hiv.date_started_art_at_transferring_facility as PreviousARTStartDate, + '' as PreviousARTRegimen, + reg.art_start_date as StartARTAtThisFacility, + reg.regimen as StartRegimen, + reg.regimen_line as StartRegimenLine, + -- reg.last_art_date as LastARTDate, + case + when reg.latest_vis_date is not null then reg.latest_vis_date else reg.last_art_date end as LastARTDate, + + reg.last_regimen as LastRegimen, + reg.last_regimen_line as LastRegimenLine, + reg.latest_tca as ExpectedReturn, + reg.latest_vis_date as LastVisit , + timestampdiff(month,reg.art_start_date, reg.latest_vis_date) as duration, + disc.visit_date as ExitDate, + case + when disc.discontinuation_reason is not null then dis_rsn.name + else '' end as ExitReason, + 'KenyaEMR' as Emr, + 'Kenya HMIS II' as Project, + CAST(now() as Date) AS DateExtracted +from kenyaemr_etl.etl_hiv_enrollment hiv + join kenyaemr_etl.etl_patient_demographics d on d.patient_id=hiv.patient_id + left outer join kenyaemr_etl.etl_patient_program_discontinuation disc on disc.patient_id=hiv.patient_id + left outer join (select e.patient_id, + if(enr.date_started_art_at_transferring_facility is not null,enr.date_started_art_at_transferring_facility, + e.date_started)as art_start_date, e.date_started, e.gender,e.dob,d.visit_date as dis_date, if(d.visit_date is not null, 1, 0) as TOut, + e.regimen, e.regimen_line, e.alternative_regimen, max(fup.next_appointment_date) as latest_tca, + last_art_date,last_regimen,last_regimen_line, + if(enr.transfer_in_date is not null, 1, 0) as TIn, max(fup.visit_date) as latest_vis_date + from (select e.patient_id,p.dob,p.Gender,min(e.date_started) as date_started, + max(e.date_started) as last_art_date, + mid(min(concat(e.date_started,e.regimen_name)),11) as regimen, + mid(min(concat(e.date_started,e.regimen_line)),11) as regimen_line, + mid(max(concat(e.date_started,e.regimen_name)),11) as last_regimen, + mid(max(concat(e.date_started,e.regimen_line)),11) as last_regimen_line, + max(if(discontinued,1,0))as alternative_regimen + from kenyaemr_etl.etl_drug_event e + join kenyaemr_etl.etl_patient_demographics p on p.patient_id=e.patient_id + left join kenyaemr_etl.etl_pharmacy_extract ph on ph.patient_id = e.patient_id and is_arv=1 + group by e.patient_id) e + left outer join kenyaemr_etl.etl_patient_program_discontinuation d on d.patient_id=e.patient_id + left outer join kenyaemr_etl.etl_hiv_enrollment enr on enr.patient_id=e.patient_id + left outer join kenyaemr_etl.etl_patient_hiv_followup fup on fup.patient_id=e.patient_id + group by e.patient_id)reg on reg.patient_id=hiv.patient_id + left outer join concept_name dis_rsn on dis_rsn.concept_id=disc.discontinuation_reason and dis_rsn.concept_name_type='FULLY_SPECIFIED' + and dis_rsn.locale='en' + left outer join concept_name cn on cn.concept_id=hiv.entry_point and cn.concept_name_type='FULLY_SPECIFIED' + and cn.locale='en' +where d.unique_patient_no is not null +group by d.patient_id +having min(hiv.visit_date) is not null and reg.art_start_date is not null;"|dwhstage|0|PatientArtExtract|2|a6221aa6-0e85-11e8-ba89-0ed5f89f718b + +ec3d7e13-bb10-11ea-b3de-0242ac130004|Patient Baselines|NDWH|a6221860-0e85-11e8-ba89-0ed5f89f718b|"select distinct '' AS SatelliteName, 0 AS FacilityId, d.unique_patient_no as PatientID, +d.patient_id as PatientPK, +(select value_reference from location_attribute +where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation') and attribute_type_id=1) as facilityId, +(select value_reference from location_attribute +where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation') and attribute_type_id=1) as siteCode, + mid(max(if(l.visit_date<=p_dates.enrollment_date,concat(l.visit_date,test_result),null)),11) as eCd4, + CAST(left(max(if(l.visit_date<=p_dates.enrollment_date,concat(l.visit_date,test_result),null)),10) AS DATE) as eCd4Date, + if(fup.visit_date<=p_dates.enrollment_date, + case who_stage + when 1220 then 'WHO I' + when 1221 then 'WHO II' + when 1222 then 'WHO III' + when 1223 then 'WHO IV' + when 1204 then 'WHO I' + when 1205 then 'WHO II' + when 1206 then 'WHO III' + when 1207 then 'WHO IV' + end,null) as ewho, + CAST(if(fup.visit_date<=p_dates.enrollment_date and who_stage is not null and fup.visit_date>'1900-01-01', +fup.visit_date,null) AS DATE) as ewhodate, +'' as bCD4, +NULL as bCD4Date, +'' as bWHO, +NULL as bWHODate, + mid(max(concat(fup.visit_date,case who_stage + when 1220 then 'WHO I' + when 1221 then 'WHO II' + when 1222 then 'WHO III' + when 1223 then 'WHO IV' + when 1204 then 'WHO I' + when 1205 then 'WHO II' + when 1206 then 'WHO III' + when 1207 then 'WHO IV' + end)),11) as lastwho, + CAST(left(max(concat(fup.visit_date,case who_stage + when 1220 then 'WHO I' + when 1221 then 'WHO II' + when 1222 then 'WHO III' + when 1223 then 'WHO IV' + when 1204 then 'WHO I' + when 1205 then 'WHO II' + when 1206 then 'WHO III' + when 1207 then 'WHO IV' + end)),10) AS DATE) as lastwhodate, + mid(max(concat(l.visit_date,l.test_result)),11) as lastcd4, + CAST(left(max(concat(l.visit_date,l.test_result)),10) AS DATE) as lastcd4date, + mid(max(if(l.visit_date>p_dates.six_month_date and l.visit_date=p_dates.six_month_date and l.visit_date=p_dates.twelve_month_date,concat(l.visit_date,test_result),null)),11) as m6Cd4, + CAST(left(max(if(l.visit_date>p_dates.twelve_month_date,concat(l.visit_date,test_result),null)),10) AS DATE) as m6Cd4Date, + '' as eWAB, NULL as eWABDate,'' as bWAB, NULL as bWABDAte, + 'KenyaEMR' as Emr, + 'Kenya HMIS II' as Project, + '' AS LastWaB,NULL AS LastWABDate, + '' as m12CD4, +NULL as m12CD4Date, +'' AS m6CD4, +NULL m6CD4Date +from kenyaemr_etl.etl_patient_hiv_followup fup +join kenyaemr_etl.etl_patient_demographics d on d.patient_id=fup.patient_id +join (select e.patient_id,date_add(date_add(min(e.visit_date),interval 3 month), interval 1 day) as enrollment_date, +date_add(date_add(min(e.visit_date), interval 6 month),interval 1 day) as six_month_date, +date_add(date_add(min(e.visit_date), interval 12 month),interval 1 day) as twelve_month_date +from kenyaemr_etl.etl_hiv_enrollment e +group by e.patient_id) p_dates on p_dates.patient_id=fup.patient_id +left outer join kenyaemr_etl.etl_laboratory_extract l on l.patient_id=fup.patient_id and l.lab_test in (5497,730) where d.unique_patient_no is not null +group by fup.patient_id +order by m6cd4date desc"|dwhstage|0|PatientBaselineExtract|3|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e14-bb10-11ea-b3de-0242ac130004|Patient Status|NDWH|a6221860-0e85-11e8-ba89-0ed5f89f718b|"select +'' AS SatelliteName, +0 AS FacilityId, +d.unique_patient_no as PatientID, +d.patient_id as PatientPK,(select value_reference from location_attribute +where location_id in (select property_value from global_property where property='kenyaemr.defaultLocation') and attribute_type_id=1) as siteCode, (select name from location where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation')) as FacilityName, +'' as ExitDescription, +/*disc.visit_date as ExitDate, +case +when disc.discontinuation_reason is not null then cn.name +else '' end as ExitReason,*/ + 'KenyaEMR' as Emr, + 'Kenya HMIS II' as Project, +CAST(now() as Date) AS DateExtracted, +max(disc.visit_date) AS ExitDate, +mid(max(concat(disc.visit_date,case when disc.discontinuation_reason is not null then cn.name +else '' end )),20) as ExitReason +from kenyaemr_etl.etl_patient_program_discontinuation disc +join kenyaemr_etl.etl_patient_demographics d on d.patient_id=disc.patient_id +left outer join concept_name cn on cn.concept_id=disc.discontinuation_reason and cn.concept_name_type='FULLY_SPECIFIED' +and cn.locale='en' +where d.unique_patient_no is not null +group by PatientID +order by disc.visit_date ASC;"|dwhstage|0|PatientStatusExtract|4|a6221aa6-0e85-11e8-ba89-0ed5f89f718b + +ec3d7e15-bb10-11ea-b3de-0242ac130004|Patient Labs|NDWH|a6221860-0e85-11e8-ba89-0ed5f89f718b|"select distinct '' AS SatelliteName, 0 AS FacilityId, d.unique_patient_no as patientID, d.patient_id as patientPK, l.encounter_id as visitID, +CAST(l.visit_date AS DATE) as orderedByDate,CAST(l.visit_date AS DATE) as reportedByDate, null as reason, (select value_reference from location_attribute +where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation') and attribute_type_id=1) as facilityID, +(select value_reference from location_attribute +where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation') and attribute_type_id=1) as siteCode, +(select name from location +where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation')) as facilityName, +cn.name as testName, +case +when c.datatype_id=2 then cn2.name +else + l.test_result +end as TestResult, +NULL as enrollmentTest, + 'KenyaEMR' as Emr, + 'Kenya HMIS II' as Project +from kenyaemr_etl.etl_laboratory_extract l +join kenyaemr_etl.etl_patient_demographics d on d.patient_id=l.patient_id +join concept_name cn on cn.concept_id=l.lab_test and cn.concept_name_type='FULLY_SPECIFIED'and cn.locale='en' +join concept c on c.concept_id = l.lab_test +left outer join concept_name cn2 on cn2.concept_id=l.test_result and cn2.concept_name_type='FULLY_SPECIFIED' +and cn2.locale='en' where d.unique_patient_no is not null"|dwhstage|0|PatientLabExtract|5|a6221aa6-0e85-11e8-ba89-0ed5f89f718b + +ec3d7e16-bb10-11ea-b3de-0242ac130004|Patient Pharmacy|NDWH|a6221860-0e85-11e8-ba89-0ed5f89f718b|"select distinct +'' AS Provider,'' AS SatelliteName, 0 AS FacilityId, d.unique_patient_no as PatientID, +d.patient_id as PatientPK, +(select name from location +where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation')) as FacilityName, +(select value_reference from location_attribute +where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation') and attribute_type_id=1) as siteCode, +ph.visit_id as VisitID, +-- if(cn2.name is not null, cn2.name,cn.name) as Drug, +case +when is_arv=1 then ph.drugreg +else if(cn2.name is not null, cn2.name,cn.name) END as Drug, +ph.visit_date as DispenseDate, +ph.duration AS duration, +ph.duration AS PeriodTaken, +fup.next_appointment_date as ExpectedReturn, +'KenyaEMR' as Emr, +'Kenya HMIS II' as Project, +CASE WHEN is_arv=1 THEN 'ARV' +WHEN is_ctx=1 OR is_dapsone= 1 THEN 'Prophylaxis' END AS TreatmentType, +ph.RegimenLine, +CASE WHEN is_ctx=1 THEN 'CTX' +WHEN is_dapsone =1 THEN 'DAPSON' END AS ProphylaxisType, +CAST(now() as Date) AS DateExtracted +from (SELECT * FROM ( +select patient_id, visit_id,visit_date,encounter_id,drug,is_arv, is_ctx,is_dapsone,drug_name as drugreg,frequency, +'' as DispenseDate,duration, duration PeriodTaken, +''ExpectedReturn, CASE WHEN is_ctx=1 OR is_dapsone= 1 THEN 'Prophylaxis' END AS TreatmentType,'' as RegimenLine, +CASE WHEN is_ctx=1 THEN 'CTX' +WHEN is_dapsone =1 THEN 'DAPSON' END AS ProphylaxisType from kenyaemr_etl.etl_pharmacy_extract ph +left outer join concept_name cn2 on cn2.concept_id=ph.drug and cn2.concept_name_type='SHORT' +and cn2.locale='en' where is_ctx=1 OR is_dapsone= 1 +GROUP BY patient_id, visit_id,visit_date,encounter_id +UNION + +SELECT patient_id,''visit_id,visit_date,encounter_id,regimen drug,1 as is_arv, 0 as is_ctx, 0 as is_dapsone, regimen_name as drugreg, '' frequency, date_started as DispenseDate,''duration,''PeriodTaken, +''ExpectedReturn, 'ARV' AS TreatmentType,regimen_line as RegimenLine,NULL as ProphylaxisType FROM kenyaemr_etl.etl_drug_event +GROUP BY patient_id, visit_id,visit_date,encounter_id +)A )ph +join kenyaemr_etl.etl_patient_demographics d on d.patient_id=ph.patient_id +left outer join concept_name cn on cn.concept_id=ph.drug and cn.concept_name_type='FULLY_SPECIFIED' +and cn.locale='en' +left outer join concept_name cn2 on cn2.concept_id=ph.drug and cn2.concept_name_type='SHORT' +and cn.locale='en' +left outer join kenyaemr_etl.etl_patient_hiv_followup fup on fup.encounter_id=ph.encounter_id +and fup.patient_id=ph.patient_id +where unique_patient_no is not null and (is_arv=1 OR is_ctx=1 OR is_dapsone =1 ) and drugreg is not null +order by ph.patient_id,ph.visit_date;"|dwhstage|0|PatientPharmacyExtract|6|a6221aa6-0e85-11e8-ba89-0ed5f89f718b + +ec3d7e17-bb10-11ea-b3de-0242ac130004|Patient Visit|NDWH|a6221860-0e85-11e8-ba89-0ed5f89f718b|"select distinct +'' AS SatelliteName, 0 AS FacilityId, d.unique_patient_no as PatientID, +d.patient_id as PatientPK, +(select name from location +where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation')) as FacilityName, +(select value_reference from location_attribute +where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation') and attribute_type_id=1) as siteCode, +fup.visit_id as VisitID, +case when fup.visit_date < '1990-01-01' then null else CAST(fup.visit_date AS DATE) end AS VisitDate, +'Out Patient' as Service, +fup.visit_scheduled as VisitType, +case fup.who_stage +when 1220 then 'WHO I' +when 1221 then 'WHO II' +when 1222 then 'WHO III' +when 1223 then 'WHO IV' +when 1204 then 'WHO I' +when 1205 then 'WHO II' +when 1206 then 'WHO III' +when 1207 then 'WHO IV' + else '' +end as WHOStage, +'' as WABStage, +case fup.pregnancy_status +when 1065 then 'Yes' +when 1066 then 'No' +end as Pregnant, +CAST(fup.last_menstrual_period AS DATE) as LMP, +CAST(fup.expected_delivery_date AS DATE) as EDD, +fup.height as Height, +fup.weight as Weight, +concat(fup.systolic_pressure,'/',fup.diastolic_pressure) as BP, +'ART|CTX' as AdherenceCategory, +concat( +IF(fup.arv_adherence=159405, 'Good', IF(fup.arv_adherence=159406, 'Fair', IF(fup.arv_adherence=159407, 'Poor', ''))), IF(fup.arv_adherence in (159405,159406,159407), '|','') , +IF(fup.ctx_adherence=159405, 'Good', IF(fup.ctx_adherence=159406, 'Fair', IF(fup.ctx_adherence=159407, 'Poor', ''))) +) AS Adherence, +'' as OI, +NULL as OIDate, +case fup.family_planning_status +when 695 then 'Currently using FP' +when 160652 then 'Not using FP' +when 1360 then 'Wants FP' +else '' +end as FamilyPlanningMethod, +concat( +case fup.condom_provided +when 1065 then 'Condoms,' +else '' +end, +case fup.pwp_disclosure +when 1065 then 'Disclosure|' +else '' +end, +case fup.pwp_partner_tested +when 1065 then 'Partner Testing|' +else '' +end, +case fup.screened_for_sti +when 1065 then 'Screened for STI' +else '' +end )as PWP, +if(fup.last_menstrual_period is not null, timestampdiff(week,fup.last_menstrual_period,fup.visit_date),'') as GestationAge, +case when fup.next_appointment_date < '1990-01-01' then null else CAST(fup.next_appointment_date AS DATE) end AS NextAppointmentDate, +'KenyaEMR' as Emr, +'Kenya HMIS II' as Project, + +CAST(fup.substitution_first_line_regimen_date AS DATE) AS SubstitutionFirstlineRegimenDate, +fup.substitution_first_line_regimen_reason AS SubstitutionFirstlineRegimenReason, +CAST(fup.substitution_second_line_regimen_date AS DATE) AS SubstitutionSecondlineRegimenDate, +fup.substitution_second_line_regimen_reason AS SubstitutionSecondlineRegimenReason, +CAST(fup.second_line_regimen_change_date AS DATE) AS SecondlineRegimenChangeDate, +fup.second_line_regimen_change_reason AS SecondlineRegimenChangeReason, + + + CASE fup.stability + WHEN 1 THEN 'Stable' + WHEN 2 THEN 'Not Stable' END as StabilityAssessment, + +dc.name as DifferentiatedCare, +CASE + WHEN fup.key_population_type IS NOT NULL AND fup.key_population_type !=1175 + THEN 'Key population' + ELSE pt.name END as PopulationType, + +case fup.key_population_type +WHEN 105 THEN 'PWID' +WHEN 160578 THEN 'MSM' +WHEN 160579 THEN 'FSW' +WHEN 1175 THEN 'N/A' +ELSE fup.key_population_type END as KeyPopulationType + +from kenyaemr_etl.etl_patient_demographics d +join kenyaemr_etl.etl_patient_hiv_followup fup on fup.patient_id=d.patient_id +left join concept_name dc on dc.concept_id = fup.differentiated_care and dc.concept_name_type='FULLY_SPECIFIED' +left join concept_name pt on fup.population_type = pt.concept_id AND pt.concept_name_type='FULLY_SPECIFIED' +where d.unique_patient_no is not null and fup.visit_date > '1990-01-01' "|dwhstage|0|PatientVisitExtract|7|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e18-bb10-11ea-b3de-0242ac130004|Patient Adverse Events|NDWH|a6221860-0e85-11e8-ba89-0ed5f89f718b|"SELECT '' AS PatientID, + '' AS PatientPK, + '' AS SiteCode, + '' AS FacilityID, + 'Kenya EMR' AS EMR, + 'Kenya HMIS II' AS Project, + NOW() AS VisitDate, + '' AS AdverseEventRegimen, + '' AS AdverseEvent, + '' AS AdverseEventCause, + '' AS Severity, + '' AS AdverseEventActionTaken, + '' AS AdverseEventClinicalOutcome, + NOW() AS AdverseEventStartDate, + NOW() AS AdverseEventEndDate, + '' AS AdverseEventIsPregnant"|dwhstage|0|PatientAdverseEventExtract|8|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e20-bb10-11ea-b3de-0242ac130004|Master Patient Index|CBS|a6221860-0e85-11e8-ba89-0ed5f89f718b|" +SELECT DISTINCT +-- -----Demographics +X.Ptn_Pk, +X.PatientPK, +siteCode, +FacilityName, +-- a.patient_clinic_number AS Serial +-- X.Ptn_Pk AS Serial +X.Serial +,FirstName +, MiddleName +,LastName +, FirstName_Normalized +, MiddleName_Normalized +,LastName_Normalized +,sxFirstName +,sxLastName +,sxMiddleName +,dmFirstName +, dmLastName +, dmMiddleName +, PatientPhoneNumber +, PatientAlternatePhoneNumber +,Gender +,DOB +,MaritalStatus +-- -----Patient Address +, PatientSource +, PatientCounty +, PatientSubCounty +, PatientVillage +-- -----Patient-Identifiers +,PatientID +,National_ID +,NHIF_Number +,Birth_Certificate +,CCC_Number +,TB_Number +-- -----Next Of Kin +,ContactName +,ContactRelation +, ContactPhoneNumber +,ContactAddress +, NokNationalId +-- -----Additional Variables +, DateConfirmedHIVPositive +,StartARTDate +,StartARTRegimenCode +, StartARTRegimenDesc, +CONCAT(LEFT(Gender ,1), sxFirstName ,sxLastName ,LTRIM(RTRIM(DATE_FORMAT(DOB, '%Y')))) AS sxPKValue, +CONCAT( CAST(LEFT(Gender ,1) AS CHAR CHARACTER SET utf8), +CAST(CASE +WHEN locate(';',dmFirstName )>0 THEN +SUBSTRING(dmFirstName , locate(';',dmFirstName )+1,LENGTH(dmFirstName )) +ELSE +dmFirstName +END AS CHAR CHARACTER SET utf8), +CAST(CASE +WHEN locate(';',dmLastName )>0 THEN +SUBSTRING(dmLastName , locate(';',dmLastName )+1,LENGTH(dmLastName )) +ELSE +dmLastName +END AS CHAR CHARACTER SET utf8), +CAST(LTRIM(RTRIM(DATE_FORMAT(DOB, '%Y')))AS CHAR CHARACTER SET utf8) + +) AS dmPKValue , + +CASE WHEN locate(';',dmLastName )>0 +THEN +CONCAT( +CAST(LEFT(Gender ,1) AS CHAR CHARACTER SET utf8) +, CAST(sxFirstName AS CHAR CHARACTER SET utf8) +, CAST(SUBSTRING(dmLastName , locate(';',dmLastName )+1,LENGTH(dmLastName )) AS CHAR CHARACTER SET utf8) +, CAST(LTRIM(RTRIM(DATE_FORMAT(DOB, '%Y')))AS CHAR CHARACTER SET utf8) +) +ELSE +CONCAT( +CAST(LEFT(Gender ,1)AS CHAR CHARACTER SET utf8) +, CAST(sxFirstName AS CHAR CHARACTER SET utf8) +, CAST(dmLastName AS CHAR CHARACTER SET utf8) +, CAST(LTRIM(RTRIM(DATE_FORMAT(DOB, '%Y'))) AS CHAR CHARACTER SET utf8) +) +END AS sxdmPKValue , +CONCAT( +CAST(LEFT(Gender ,1) AS CHAR CHARACTER SET utf8) +,CAST(sxFirstName AS CHAR CHARACTER SET utf8) +,CAST(sxLastName AS CHAR CHARACTER SET utf8) +,CAST(LTRIM(RTRIM(DATE_FORMAT(DOB, '%Y%m%d')))AS CHAR CHARACTER SET utf8) +) AS sxPKValueDoB , + +CONCAT( + +CAST(LEFT(Gender ,1) AS CHAR CHARACTER SET utf8), +CASE +WHEN locate(';',dmFirstName )>0 THEN +CAST(SUBSTRING(dmFirstName , locate(';',dmFirstName )+1,LENGTH(dmFirstName )) AS CHAR CHARACTER SET utf8) +ELSE +CAST(dmFirstName AS CHAR CHARACTER SET utf8) +END , +CASE +WHEN locate(';',dmLastName )>0 THEN +CAST( SUBSTRING(dmLastName , locate(';',dmLastName )+1,LENGTH(dmLastName )) AS CHAR CHARACTER SET utf8) +ELSE +CAST( dmLastName AS CHAR CHARACTER SET utf8) +END , + +CAST( LTRIM(RTRIM(DATE_FORMAT(DOB, '%Y%m%d'))) AS CHAR CHARACTER SET utf8) +) AS dmPKValueDoB , + +CASE WHEN locate(';',dmLastName )>0 THEN +CONCAT( +CAST( LEFT(Gender ,1) AS CHAR CHARACTER SET utf8) +,CAST( sxFirstName AS CHAR CHARACTER SET utf8) +, CAST( SUBSTRING(dmLastName ,locate(';',dmLastName )+1,LENGTH(dmLastName )) AS CHAR CHARACTER SET utf8) +,CAST( LTRIM(RTRIM(DATE_FORMAT(DOB, '%Y%m%d'))) AS CHAR CHARACTER SET utf8) +) +ELSE +CONCAT( +CAST( LEFT(Gender ,1)AS CHAR CHARACTER SET utf8) +, CAST( sxFirstName AS CHAR CHARACTER SET utf8), +CAST( dmLastName AS CHAR CHARACTER SET utf8), +CAST( LTRIM(RTRIM(DATE_FORMAT(DOB, '%Y%m%d'))) AS CHAR CHARACTER SET utf8) +) +END AS sxdmPKValueDoB +FROM +( +SELECT +-- -----Demographics +a.patient_id as Ptn_Pk, +a.patient_id as PatientPK, +(select value_reference from location_attribute +where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation') and attribute_type_id=1) as siteCode, + +(select name from location +where location_id in (select property_value +from global_property +where property='kenyaemr.defaultLocation')) as FacilityName, +id.identifier AS Serial +-- a.patient_clinic_number AS Serial + +,UPPER(a.given_name ) as FirstName +,UPPER(a.middle_name ) as MiddleName +,UPPER(family_name) as LastName +,UPPER(REPLACE(given_name ,'0','O')) AS FirstName_Normalized +,UPPER(REPLACE(middle_name ,'0','O')) AS MiddleName_Normalized +,UPPER(REPLACE(family_name ,'0','O')) AS LastName_Normalized +,SOUNDEX(UPPER(REPLACE(given_name ,'0','O'))) AS sxFirstName +,SOUNDEX(UPPER(REPLACE(family_name ,'0','O'))) AS sxLastName +,SOUNDEX(UPPER(REPLACE(middle_name ,'0','O'))) AS sxMiddleName +, fn_getPatientNameDoubleMetaphone(UPPER(REPLACE(given_name ,'0','O'))) AS dmFirstName +, fn_getPatientNameDoubleMetaphone(UPPER(REPLACE(family_name ,'0','O'))) AS dmLastName +, fn_getPatientNameDoubleMetaphone(UPPER(REPLACE(middle_name ,'0','O'))) AS dmMiddleName +,a.phone_number AS PatientPhoneNumber +,en.treatment_supporter_telephone AS PatientAlternatePhoneNumber +,a.Gender +,a.DOB +,a.marital_status AS MaritalStatus +-- -----Patient Address +, en.entry_point AS PatientSource +,NULL PatientCounty +,NULL PatientSubCounty +,NULL PatientVillage +-- -----Patient-Identifiers +,patient_clinic_number AS PatientID +,national_id_no AS National_ID +,NULL as NHIF_Number +,NULL as Birth_Certificate +,a.patient_clinic_number AS CCC_Number +,ltrim(rtrim(a.district_reg_no))TB_Number +-- -----Next Of Kin +,LTRIM(RTRIM(next_of_kin)) AS ContactName +,next_of_kin_relationship AS ContactRelation +,treatment_supporter_telephone as ContactPhoneNumber +,treatment_supporter_address as ContactAddress +,NULL AS NokNationalId +-- -----Additional Variables +,date_confirmed_hiv_positive AS DateConfirmedHIVPositive +,X.date_started AS StartARTDate +,X.regimen_name AS StartARTRegimenCode +,X.regimen_line StartARTRegimenDesc + +FROM kenyaemr_datatools.patient_demographics a +INNER JOIN patient_identifier id ON a.patient_id = id.patient_id AND id.identifier_type = (SELECT patient_identifier_type_id FROM openmrs.patient_identifier_type +where name ='OpenMRS ID') +left join ( +SELECT c.patient_id, +c.encounter_id, treatment_supporter_telephone, entry_point , treatment_supporter_address, date_confirmed_hiv_positive +from kenyaemr_datatools.hiv_enrollment c +left JOIN + ( + SELECT patient_id, MAX(encounter_id) max_encounter_id + FROM kenyaemr_datatools.hiv_enrollment + GROUP BY patient_id + ) b ON c.patient_id = b.patient_id AND + c.encounter_id = b.max_encounter_id + + order by patient_id,date_created asc + + + ) en +on a.Patient_Id=en.patient_id +LEFT JOIN +( +SELECT patient_id, MIN(date_started) AS date_started ,MIN(regimen_name) AS regimen_name, MIN(regimen_line) AS regimen_line +FROM kenyaemr_datatools.drug_event GROUP BY patient_id +) X ON X.patient_id = a.Patient_id +) X +INNER JOIN +( +SELECT +a.patient_id as Ptn_Pk, +id.identifier AS Serial +FROM kenyaemr_datatools.patient_demographics a +INNER JOIN patient_identifier id ON a.patient_id = id.patient_id AND id.identifier_type = (SELECT patient_identifier_type_id FROM openmrs.patient_identifier_type +where name ='OpenMRS ID') + +)Y +ON +Y.Ptn_Pk = X.Ptn_Pk AND Y.Serial= X.Serial +"|MPI|1|MasterPatientIndex|1|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e30-bb10-11ea-b3de-0242ac130004|Hts Clients|HTS|a6221860-0e85-11e8-ba89-0ed5f89f718b|"SELECT distinct d.patient_id as PatientPK, + SC.value_reference AS SiteCode, + SN.name as FacilityName, + 'KenyaEMR' as Emr, + 'Kenya HMIS II' AS Project, + id.identifier AS HtsNumber, + d.DOB, + case when d.Gender='M' then 'Male' else 'Female' end as Gender, + d.marital_status as MaritalStatus, + t.population_type as PopulationType, + t.key_population_type as KeyPopulationType, + t.disability_type as PatientDisabled, + A.county_district as County, + A.state_province as SubCounty, + A.address4 as Ward +FROM +kenyaemr_etl.etl_patient_demographics d +INNER JOIN +kenyaemr_etl.etl_hts_test t ON d.patient_id=t.patient_id +LEFT JOIN + location_attribute SC ON SC.location_id = t.encounter_location AND SC.attribute_type_id=1 +LEFT JOIN + location SN ON SN.location_id =t.encounter_location +LEFT JOIN person_address A ON A.person_id=d.patient_id +LEFT JOIN patient_identifier id ON id.patient_id = t.patient_id AND id.identifier_type = (select patient_identifier_type_id +from patient_identifier_type +where name='OpenMRS ID') +group by d.patient_id"|DWHStage|1|HtsClient|1|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e31-bb10-11ea-b3de-0242ac130004|Hts Client Tests|HTS|a6221860-0e85-11e8-ba89-0ed5f89f718b|"SELECT + t.patient_id as PatientPK, + SC.value_reference AS SiteCode, + SN.name as FacilityName, + 'KenyaEMR' as Emr, + 'Kenya HMIS II' AS Project, + id.identifier AS HtsNumber, + t.encounter_id as EncounterId, + t.visit_date as TestDate, + t.ever_tested_for_hiv as EverTestedForHiv, + t.months_since_last_test as MonthsSinceLastTest, + t.client_tested_as as ClientTestedAs, + t.hts_entry_point as EntryPoint, + t.test_strategy as TestStrategy, + t.test_1_result as TestResult1, + t.test_2_result as TestResult2, + t.final_test_result as FinalTestResult, + t.patient_given_result as PatientGivenResult, + t.tb_screening as TbScreening, + t.patient_had_hiv_self_test as ClientSelfTested, + t.couple_discordant as CoupleDiscordant, + CASE t.test_type + WHEN 1 THEN 'Initial' + WHEN 2 THEN 'Repeat' + END AS TestType, + t.patient_consented as Consent +FROM + kenyaemr_etl.etl_hts_test t +inner join + kenyaemr_etl.etl_patient_demographics demographics on t.patient_id=demographics.patient_id +LEFT JOIN + location_attribute SC ON SC.location_id = t.encounter_location AND SC.attribute_type_id=1 +LEFT JOIN + location SN ON SN.location_id =t.encounter_location +LEFT JOIN patient_identifier id ON id.patient_id = t.patient_id AND id.identifier_type = (select patient_identifier_type_id +from patient_identifier_type +where name='OpenMRS ID')"|DWHStage|1|HtsClientTests|2|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e32-bb10-11ea-b3de-0242ac130004|Hts Client Linkage|HTS|a6221860-0e85-11e8-ba89-0ed5f89f718b|"select distinct a.patient_id as PatientPK, +SC.value_reference AS SiteCode, +SN.name as FacilityName, +'KenyaEMR' as Emr, +'Kenya HMIS II' AS Project, +id.identifier AS HtsNumber, +ref.date_to_enrol as DatePrefferedToBeEnrolled, +ref.facility_referred_to as FacilityReferredTo, +a.provider_handed_to as HandedOverTo, +NULL HandedOverToCadre, +a.facility_linked_to as EnrolledFacilityName, +ref.visit_date as ReferralDate, +a.enrollment_date as DateEnrolled, +a.ccc_number as ReportedCCCNumber, +a.art_start_date as ReportedStartARTDate +from (SELECT Distinct patient_id, encounter_id,ccc_number,enrollment_date, +art_start_date,provider_handed_to,facility_linked_to,encounter_location FROM +(SELECT DISTINCT htsrl.patient_id, encounter_id,ccc_number,enrollment_date, +art_start_date,provider_handed_to,facility_linked_to,encounter_location +FROM kenyaemr_etl.etl_hts_referral_and_linkage htsrl +UNION ALL +SELECT DISTINCT t.patient_id,t.encounter_id,unique_patient_no ccc_number,e.visit_date DateEnrolled, +ar.art_start_date,provider_handed_to,facility_linked_to,t.encounter_location +FROM kenyaemr_etl.etl_hts_test t +INNER JOIN kenyaemr_etl.etl_patient_demographics pt ON pt.patient_id=t.patient_id AND pt.voided=0 +INNER JOIN kenyaemr_etl.etl_hiv_enrollment e ON e.patient_id=t.patient_id AND e.voided=0 +LEFT JOIN kenyaemr_etl.etl_hts_referral_and_linkage l ON l.patient_id=t.patient_id +LEFT JOIN (SELECT patient_id,min(date_started) as art_start_date FROM kenyaemr_etl.etl_drug_event +group by patient_id)ar on ar.patient_id=t.patient_id +WHERE t.test_type = 1 AND t.final_test_result='Positive' AND t.voided=0 AND l.patient_id IS NULL)a +) a +left join kenyaemr_etl.etl_hts_referral ref on a.patient_id=ref.patient_id +LEFT JOIN location_attribute SC ON (SC.location_id = a.encounter_location or SC.location_id=ref.encounter_location ) AND SC.attribute_type_id=1 +LEFT JOIN location SN ON (SN.location_id =a.encounter_location or SN.location_id =ref.encounter_location ) +LEFT JOIN patient_identifier id ON (id.patient_id = a.patient_id or id.patient_id = ref.patient_id ) AND id.identifier_type = (select patient_identifier_type_id +from patient_identifier_type +where name='OpenMRS ID') +LEFT JOIN kenyaemr_etl.etl_hiv_enrollment EN ON EN.patient_id =a.patient_id +where a.patient_id in (select patient_id from kenyaemr_etl.etl_hts_test);"|DWHStage|1|HtsClientLinkage|3|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e33-bb10-11ea-b3de-0242ac130004|Hts Test Kits|HTS|a6221860-0e85-11e8-ba89-0ed5f89f718b|"SELECT + t.patient_id AS PatientPK, + SC.value_reference AS SiteCode, + SN.name as FacilityName, + 'KenyaEMR' as Emr, + 'Kenya HMIS II' AS Project, + id.identifier AS HtsNumber, + t.encounter_id AS EncounterId, + t.test_1_kit_name AS TestKitName1, + t.test_1_kit_lot_no AS TestKitLotNumber1, + t.test_1_kit_expiry as TestKitExpiry1, + t.test_1_result as TestResult1, + t.test_2_kit_name as TestKitName2, + t.test_2_kit_lot_no as TestKitLotNumber2, + t.test_2_kit_expiry as TestKitExpiry2, + t.test_2_result as TestResult2 + +FROM + kenyaemr_etl.etl_hts_test t +inner join + kenyaemr_etl.etl_patient_demographics demographics on t.patient_id=demographics.patient_id +LEFT JOIN + location_attribute SC ON SC.location_id = t.encounter_location AND SC.attribute_type_id=1 +LEFT JOIN + location SN ON SN.location_id =t.encounter_location +LEFT JOIN patient_identifier id ON id.patient_id = t.patient_id AND id.identifier_type = (select patient_identifier_type_id +from patient_identifier_type +where name='OpenMRS ID')"|DWHStage|1|HtsTestKits|4|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e34-bb10-11ea-b3de-0242ac130004|Hts Client Tracing|HTS|a6221860-0e85-11e8-ba89-0ed5f89f718b|"SELECT + ht.patient_id as PatientPK, + SC.value_reference AS SiteCode, + htsrl.tracing_type as TracingType, + htsrl.visit_date as TracingDate, + SN.name as FacilityName, + 'KenyaEMR' as Emr, + 'Kenya HMIS II' AS Project, + id.identifier AS HtsNumber, + htsrl.tracing_status as TracingOutcome +FROM + kenyaemr_etl.etl_hts_test ht +INNER JOIN + kenyaemr_etl.etl_hts_test t ON ht.patient_id=t.patient_id +LEFT JOIN + kenyaemr_etl.etl_hts_referral_and_linkage htsrl ON ht.patient_id=htsrl.patient_id +LEFT JOIN + location SN ON SN.location_id =htsrl.encounter_location +LEFT JOIN + location_attribute SC ON SC.location_id = htsrl.encounter_location AND SC.attribute_type_id=1 +LEFT JOIN + patient_identifier id ON id.patient_id = htsrl.patient_id AND id.identifier_type = (select patient_identifier_type_id +from patient_identifier_type +where name='OpenMRS ID') + WHERE SC.value_reference IS NOT NULL"|DWHStage|1|HtsClientTracing|5|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e35-bb10-11ea-b3de-0242ac130004|Hts Partner Tracing|HTS|a6221860-0e85-11e8-ba89-0ed5f89f718b|"select distinct +t.patient_id as PatientPK, +id.identifier as HtsNumber, +client_id as PartnerPersonId, +contact_type as TraceType, +encounter_date as TraceDate, +SN.name as FacilityName, +'KenyaEMR' as Emr, +'Kenya HMIS II' AS Project, +SC.value_reference AS SiteCode, +status as TraceOutcome, +tc.appointment_date as BookingDate +from + kenyaemr_hiv_testing_patient_contact pc +inner join + kenyaemr_etl.etl_hts_test t on pc.patient_related_to=t.patient_id +inner join + kenyaemr_hiv_testing_client_trace tc on pc.id=tc.client_id +LEFT JOIN + patient_identifier id ON id.patient_id = t.patient_id AND id.identifier_type = (select patient_identifier_type_id + from patient_identifier_type where name='OpenMRS ID') +LEFT JOIN + location_attribute SC ON SC.location_id = t.encounter_location AND SC.attribute_type_id=1 +LEFT JOIN + location SN ON SN.location_id =t.encounter_location;" |DWHStage|1|HtsPartnerTracing|6|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e36-bb10-11ea-b3de-0242ac130004|Hts Partner Notification Services|HTS|a6221860-0e85-11e8-ba89-0ed5f89f718b|"SELECT +DISTINCT + t.patient_id AS PatientPK, + SC.value_reference AS SiteCode, + SN.name as FacilityName, + 'KenyaEMR' as Emr, + 'Kenya HMIS II' AS Project, + id.identifier AS HtsNumber, + ohpc.patient_id AS PartnerPatientPk, + ohpc.id AS PartnerPersonId, + YEAR(ohpc.date_created)-YEAR(ohpc.birth_date) AS Age, + ohpc.sex, + CASE ohpc.relationship_type + WHEN 970 THEN 'parent (Mother)' + WHEN 971 THEN 'parent(Father)' + WHEN 972 THEN 'sibling' + WHEN 1528 THEN 'Child' + WHEN 5617 THEN 'spouse' + WHEN 163565 THEN 'partner' + WHEN 162221 THEN 'cowife' + END AS RelationsipToIndexClient, + + /*Screened for IPV? CASE?*/ + CASE WHEN ohpc.ipv_outcome IS NOT NUll THEN 'Yes' ELSE 'No' END AS ScreenedForIpv, + + ohpc.ipv_outcome AS IpvScreeningOutcome, + CASE ohpc.living_with_patient + WHEN 1065 THEN 'Yes' + WHEN 1066 THEN 'No' + END AS CurrentlyLivingWithIndexClient, + /*knowledgeof HIV Status*/ + ohpc.baseline_hiv_status as KnowledgeOfHivStatus, + +pnsApprocah.name AS PnsApproach, +ohpc.consented_contact_listing as PnsConsent, +case when ctrace.status is null then 'N' else 'Y' end as LinkedToCare, +ctrace.encounter_date as LinkDateLinkedToCare, +ctrace.unique_patient_no as CccNumber, +ctrace.facility_linked_to as FacilityLinkedTo, +ohpc.birth_date as DoB, +ohpc.date_created as DateElicited , +marital.name as MaritalStatus + + + FROM + kenyaemr_etl.etl_hts_test t +INNER JOIN + kenyaemr_hiv_testing_patient_contact ohpc ON ohpc.patient_related_to=t.patient_id +LEFT JOIN + location_attribute SC ON SC.location_id = t.encounter_location AND SC.attribute_type_id=1 +LEFT JOIN + location SN ON SN.location_id =t.encounter_location + LEFT JOIN + patient_identifier id ON id.patient_id = t.patient_id AND id.identifier_type = (select patient_identifier_type_id +from patient_identifier_type +where name='OpenMRS ID') +left JOIN patient openmrs ON openmrs.patient_id = id.patient_id +left JOIN kenyaemr_hiv_testing_client_trace ctrace ON ctrace.client_id = ohpc.id and ctrace.status='Contacted and Linked' +left join concept_name marital ON marital.concept_id = ohpc.marital_status and marital.locale='en' and marital.concept_name_type = 'FULLY_SPECIFIED' +left join concept_name pnsApprocah ON pnsApprocah.concept_id = ohpc.pns_approach and pnsApprocah.locale='en' and pnsApprocah.concept_name_type = 'FULLY_SPECIFIED' + "|DWHStage|1|HtsPartnerNotificationServices|7|a6221aa6-0e85-11e8-ba89-0ed5f89f718b +ec3d7e40-bb10-11ea-b3de-0242ac130004|Migration|MGS|a6221860-0e85-11e8-ba89-0ed5f89f718b|"SELECT ID as MetricId,Dataset,Metric,MetricValue,Stage,SiteCode,Emr,FacilityName,'KenyaHMIS' as Project,CreateDate FROM DWAPI_Migration_Metrics"|MgsStage|1|MetricMigrationExtract|1|a6221aa6-0e85-11e8-ba89-0ed5f89f718b diff --git a/src/Dwapi.SettingsManagement.Infrastructure/Seed/Resources.csv b/src/Dwapi.SettingsManagement.Infrastructure/Seed/Resources.csv index b13778a7..e0819a50 100644 --- a/src/Dwapi.SettingsManagement.Infrastructure/Seed/Resources.csv +++ b/src/Dwapi.SettingsManagement.Infrastructure/Seed/Resources.csv @@ -5,3 +5,4 @@ Id|Name|EndPoint|RestProtocolId 35b9c21a-2f89-11e9-b210-d663bd873d93|EMR Metrics|metrics.Json|a6471aa6-0e85-11e8-ba89-0ed5f89f718b 35b9c36e-2f89-11e9-b210-d663bd873d93|EMR Metrics|metrics.Json|a6471aa7-0e85-11e8-ba89-0ed5f89f718b 35b9c37e-2f89-11e9-b210-d663bd873d93|EMR Metrics|metrics.Json|a6471aa8-0e85-11e8-ba89-0ed5f89f718b +35b9c22a-2f89-11e9-b210-d663bd873d93|EMR Metrics|getemrmetrics|a6471aa9-0e85-11e8-ba89-0ed5f89f718b diff --git a/src/Dwapi.SettingsManagement.Infrastructure/Seed/RestProtocols.csv b/src/Dwapi.SettingsManagement.Infrastructure/Seed/RestProtocols.csv index e1bb996e..45bbebd1 100644 --- a/src/Dwapi.SettingsManagement.Infrastructure/Seed/RestProtocols.csv +++ b/src/Dwapi.SettingsManagement.Infrastructure/Seed/RestProtocols.csv @@ -5,4 +5,4 @@ a6471aa5-0e85-11e8-ba89-0ed5f89f718b|https://palladiumkenya.github.io/dwapi/stuf a6471aa8-0e85-11e8-ba89-0ed5f89f718b|https://palladiumkenya.github.io/dwapi/stuff|MAUN-XYZ|||a6221858-0e85-11e8-ba89-0ed5f89f718b a6471aa7-0e85-11e8-ba89-0ed5f89f718b|https://palladiumkenya.github.io/dwapi/stuff|MAUN-XYZ|||a6221859-0e85-11e8-ba89-0ed5f89f718b a6471aa6-0e85-11e8-ba89-0ed5f89f718b|https://palladiumkenya.github.io/dwapi/stuff|MAUN-XYZ|||926f49b8-305d-11ea-978f-2e728ce88125 - +a6471aa9-0e85-11e8-ba89-0ed5f89f718b|http://localhost:8080/openmrs/ws/rest/v1/smartcard|MAUN-XYZ|admin|Admin123|a6221860-0e85-11e8-ba89-0ed5f89f718b diff --git a/src/Dwapi.SettingsManagement.Infrastructure/SettingsContext.cs b/src/Dwapi.SettingsManagement.Infrastructure/SettingsContext.cs index de6e6ab0..442bc2bf 100644 --- a/src/Dwapi.SettingsManagement.Infrastructure/SettingsContext.cs +++ b/src/Dwapi.SettingsManagement.Infrastructure/SettingsContext.cs @@ -47,7 +47,8 @@ public override void EnsureSeeded() new Guid("a62216ee-0e85-11e8-ba89-0ed5f89f718b"), new Guid("a6221856-0e85-11e8-ba89-0ed5f89f718b"), new Guid("a6221857-0e85-11e8-ba89-0ed5f89f718b"), - new Guid("926f49b8-305d-11ea-978f-2e728ce88125") + new Guid("926f49b8-305d-11ea-978f-2e728ce88125"), + new Guid("a6221860-0e85-11e8-ba89-0ed5f89f718b") }; this.SeedMerge(typeof(SettingsContext).Assembly, "|", "Seed", $"{nameof(Dockets)}").Wait(); diff --git a/src/Dwapi.SharedKernel/Enum/EmrSetup.cs b/src/Dwapi.SharedKernel/Enum/EmrSetup.cs index d3fd59d9..5b8a7a00 100644 --- a/src/Dwapi.SharedKernel/Enum/EmrSetup.cs +++ b/src/Dwapi.SharedKernel/Enum/EmrSetup.cs @@ -3,6 +3,7 @@ namespace Dwapi.SharedKernel.Enum public enum EmrSetup { SingleFacility, - MultiFacility + MultiFacility, + Community } -} \ No newline at end of file +} From a7880d23dd42ed7ee161a614d9645ea0180e01b4 Mon Sep 17 00:00:00 2001 From: Koske Kimutai Date: Tue, 7 Jul 2020 14:38:18 +0300 Subject: [PATCH 2/3] added community support --- .../Seed/Extracts.csv | 32 ++++++++--------- .../Packager/Cbs/CbsPackagerTests.cs | 34 ++++++++++++++++++ .../Packager/Dwh/DwhPackagerTests.cs | 35 ++++++++++++++++++ .../Packager/Hts/HtsPackagerTests.cs | 36 +++++++++++++++++++ .../TestInitializer.cs | 2 ++ 5 files changed, 123 insertions(+), 16 deletions(-) diff --git a/src/Dwapi.SettingsManagement.Infrastructure/Seed/Extracts.csv b/src/Dwapi.SettingsManagement.Infrastructure/Seed/Extracts.csv index d3a148e4..896fcbdb 100644 --- a/src/Dwapi.SettingsManagement.Infrastructure/Seed/Extracts.csv +++ b/src/Dwapi.SettingsManagement.Infrastructure/Seed/Extracts.csv @@ -3114,7 +3114,7 @@ CASE WHEN prg.program='HIV' THEN prg.status ELSE null end AS StatusATCCC, 'KenyaEMR' as Emr, - 'Kenya HMIS II' as Project, + 'IRDO' as Project, CASE hiv.patient_type @@ -3224,7 +3224,7 @@ ec3d7e12-bb10-11ea-b3de-0242ac130004|ART Patients|NDWH|a6221860-0e85-11e8-ba89-0 when disc.discontinuation_reason is not null then dis_rsn.name else '' end as ExitReason, 'KenyaEMR' as Emr, - 'Kenya HMIS II' as Project, + 'IRDO' as Project, CAST(now() as Date) AS DateExtracted from kenyaemr_etl.etl_hiv_enrollment hiv join kenyaemr_etl.etl_patient_demographics d on d.patient_id=hiv.patient_id @@ -3315,7 +3315,7 @@ NULL as bWHODate, CAST(left(max(if(l.visit_date>p_dates.twelve_month_date,concat(l.visit_date,test_result),null)),10) AS DATE) as m6Cd4Date, '' as eWAB, NULL as eWABDate,'' as bWAB, NULL as bWABDAte, 'KenyaEMR' as Emr, - 'Kenya HMIS II' as Project, + 'IRDO' as Project, '' AS LastWaB,NULL AS LastWABDate, '' as m12CD4, NULL as m12CD4Date, @@ -3345,7 +3345,7 @@ case when disc.discontinuation_reason is not null then cn.name else '' end as ExitReason,*/ 'KenyaEMR' as Emr, - 'Kenya HMIS II' as Project, + 'IRDO' as Project, CAST(now() as Date) AS DateExtracted, max(disc.visit_date) AS ExitDate, mid(max(concat(disc.visit_date,case when disc.discontinuation_reason is not null then cn.name @@ -3379,7 +3379,7 @@ else end as TestResult, NULL as enrollmentTest, 'KenyaEMR' as Emr, - 'Kenya HMIS II' as Project + 'IRDO' as Project from kenyaemr_etl.etl_laboratory_extract l join kenyaemr_etl.etl_patient_demographics d on d.patient_id=l.patient_id join concept_name cn on cn.concept_id=l.lab_test and cn.concept_name_type='FULLY_SPECIFIED'and cn.locale='en' @@ -3408,7 +3408,7 @@ ph.duration AS duration, ph.duration AS PeriodTaken, fup.next_appointment_date as ExpectedReturn, 'KenyaEMR' as Emr, -'Kenya HMIS II' as Project, +'IRDO' as Project, CASE WHEN is_arv=1 THEN 'ARV' WHEN is_ctx=1 OR is_dapsone= 1 THEN 'Prophylaxis' END AS TreatmentType, ph.RegimenLine, @@ -3509,7 +3509,7 @@ end )as PWP, if(fup.last_menstrual_period is not null, timestampdiff(week,fup.last_menstrual_period,fup.visit_date),'') as GestationAge, case when fup.next_appointment_date < '1990-01-01' then null else CAST(fup.next_appointment_date AS DATE) end AS NextAppointmentDate, 'KenyaEMR' as Emr, -'Kenya HMIS II' as Project, +'IRDO' as Project, CAST(fup.substitution_first_line_regimen_date AS DATE) AS SubstitutionFirstlineRegimenDate, fup.substitution_first_line_regimen_reason AS SubstitutionFirstlineRegimenReason, @@ -3545,8 +3545,8 @@ ec3d7e18-bb10-11ea-b3de-0242ac130004|Patient Adverse Events|NDWH|a6221860-0e85-1 '' AS PatientPK, '' AS SiteCode, '' AS FacilityID, - 'Kenya EMR' AS EMR, - 'Kenya HMIS II' AS Project, + 'KenyaEMR' AS EMR, + 'IRDO' AS Project, NOW() AS VisitDate, '' AS AdverseEventRegimen, '' AS AdverseEvent, @@ -3784,7 +3784,7 @@ ec3d7e30-bb10-11ea-b3de-0242ac130004|Hts Clients|HTS|a6221860-0e85-11e8-ba89-0ed SC.value_reference AS SiteCode, SN.name as FacilityName, 'KenyaEMR' as Emr, - 'Kenya HMIS II' AS Project, + 'IRDO' AS Project, id.identifier AS HtsNumber, d.DOB, case when d.Gender='M' then 'Male' else 'Female' end as Gender, @@ -3813,7 +3813,7 @@ ec3d7e31-bb10-11ea-b3de-0242ac130004|Hts Client Tests|HTS|a6221860-0e85-11e8-ba8 SC.value_reference AS SiteCode, SN.name as FacilityName, 'KenyaEMR' as Emr, - 'Kenya HMIS II' AS Project, + 'IRDO' AS Project, id.identifier AS HtsNumber, t.encounter_id as EncounterId, t.visit_date as TestDate, @@ -3849,7 +3849,7 @@ ec3d7e32-bb10-11ea-b3de-0242ac130004|Hts Client Linkage|HTS|a6221860-0e85-11e8-b SC.value_reference AS SiteCode, SN.name as FacilityName, 'KenyaEMR' as Emr, -'Kenya HMIS II' AS Project, +'IRDO' AS Project, id.identifier AS HtsNumber, ref.date_to_enrol as DatePrefferedToBeEnrolled, ref.facility_referred_to as FacilityReferredTo, @@ -3889,7 +3889,7 @@ ec3d7e33-bb10-11ea-b3de-0242ac130004|Hts Test Kits|HTS|a6221860-0e85-11e8-ba89-0 SC.value_reference AS SiteCode, SN.name as FacilityName, 'KenyaEMR' as Emr, - 'Kenya HMIS II' AS Project, + 'IRDO' AS Project, id.identifier AS HtsNumber, t.encounter_id AS EncounterId, t.test_1_kit_name AS TestKitName1, @@ -3919,7 +3919,7 @@ ec3d7e34-bb10-11ea-b3de-0242ac130004|Hts Client Tracing|HTS|a6221860-0e85-11e8-b htsrl.visit_date as TracingDate, SN.name as FacilityName, 'KenyaEMR' as Emr, - 'Kenya HMIS II' AS Project, + 'IRDO' AS Project, id.identifier AS HtsNumber, htsrl.tracing_status as TracingOutcome FROM @@ -3945,7 +3945,7 @@ contact_type as TraceType, encounter_date as TraceDate, SN.name as FacilityName, 'KenyaEMR' as Emr, -'Kenya HMIS II' AS Project, +'IRDO' AS Project, SC.value_reference AS SiteCode, status as TraceOutcome, tc.appointment_date as BookingDate @@ -3968,7 +3968,7 @@ DISTINCT SC.value_reference AS SiteCode, SN.name as FacilityName, 'KenyaEMR' as Emr, - 'Kenya HMIS II' AS Project, + 'IRDO' AS Project, id.identifier AS HtsNumber, ohpc.patient_id AS PartnerPatientPk, ohpc.id AS PartnerPersonId, diff --git a/test/Dwapi.UploadManagement.Core.Tests/Packager/Cbs/CbsPackagerTests.cs b/test/Dwapi.UploadManagement.Core.Tests/Packager/Cbs/CbsPackagerTests.cs index acf8d798..97193066 100644 --- a/test/Dwapi.UploadManagement.Core.Tests/Packager/Cbs/CbsPackagerTests.cs +++ b/test/Dwapi.UploadManagement.Core.Tests/Packager/Cbs/CbsPackagerTests.cs @@ -52,6 +52,19 @@ public void should_Generate_Multi_Manifest() } } + [Test] + public void should_Generate_Comm_Manifest() + { + var manifests = _packager.Generate(TestInitializer.KeEmrCommDto).ToList(); + Assert.True(manifests.Any()); + Assert.True(manifests.Count>1); + foreach (var m in manifests) + { + Assert.True(m.Cargoes.Any()); + Log.Debug($"{m}"); + } + } + [Test] public void should_Generate_Manifest_With_Metrics() { @@ -90,6 +103,27 @@ public void should_Generate_Multi_Manifest_With_Metrics() }); } } + [Test] + public void should_Generate_Comm_Manifest_With_Metrics() + { + var emrDto = TestInitializer.KeEmrCommDto; + var manfiests = _packager.GenerateWithMetrics(emrDto).ToList(); + Assert.True(manfiests.Any()); + Assert.True(manfiests.Count>1); + foreach (var m in manfiests) + { + Assert.True(m.Cargoes.Any(x => x.Type == CargoType.Patient)); + Assert.True(m.Cargoes.Any(x => x.Type == CargoType.Metrics)); + Assert.True(m.Cargoes.Any(x => x.Type == CargoType.AppMetrics)); + Log.Debug($"{m}"); + m.Cargoes.ForEach(c => + { + Log.Debug($"{c.Type}"); + Log.Debug($" {c.Items} "); + }); + } + } + [Test] public void should_Generate_MpiDtos() diff --git a/test/Dwapi.UploadManagement.Core.Tests/Packager/Dwh/DwhPackagerTests.cs b/test/Dwapi.UploadManagement.Core.Tests/Packager/Dwh/DwhPackagerTests.cs index 64bcb305..cb2d55b2 100644 --- a/test/Dwapi.UploadManagement.Core.Tests/Packager/Dwh/DwhPackagerTests.cs +++ b/test/Dwapi.UploadManagement.Core.Tests/Packager/Dwh/DwhPackagerTests.cs @@ -56,6 +56,20 @@ public void should_Generate_Multi_Manifest() } } + [Test] + public void should_Generate_Comm_Manifest() + { + var emrDto = TestInitializer.KeEmrCommDto; + var manifests = _packager.Generate(emrDto).ToList(); + Assert.True(manifests.Any()); + Assert.True(manifests.Count>1); + foreach (var m in manifests) + { + Assert.True(m.PatientPks.Any()); + Log.Debug($"{m}"); + } + } + [Test] public void should_Generate_Manifest_With_Metrics() { @@ -95,6 +109,27 @@ public void should_Generate_Multi_Manifest_With_Metrics() } } + [Test] + public void should_Generate_Comm_Manifest_With_Metrics() + { + var emrDto = TestInitializer.KeEmrCommDto; + var manifests = _packager.GenerateWithMetrics(emrDto).ToList(); + Assert.True(manifests.Any()); + Assert.True(manifests.Count > 1); + foreach (var m in manifests) + { + Assert.True(m.PatientPks.Any()); + Assert.True(m.FacMetrics.Any(x => x.CargoType == CargoType.Metrics)); + Assert.True(m.FacMetrics.Any(x => x.CargoType == CargoType.AppMetrics)); + Log.Debug($"{m}"); + m.FacMetrics.ForEach(c => + { + Log.Debug($"{c.CargoType}"); + Log.Debug($" {c.Metric} "); + }); + } + } + [Test] public void should_Generate_Art_Extracts() diff --git a/test/Dwapi.UploadManagement.Core.Tests/Packager/Hts/HtsPackagerTests.cs b/test/Dwapi.UploadManagement.Core.Tests/Packager/Hts/HtsPackagerTests.cs index f826ee87..94e1402d 100644 --- a/test/Dwapi.UploadManagement.Core.Tests/Packager/Hts/HtsPackagerTests.cs +++ b/test/Dwapi.UploadManagement.Core.Tests/Packager/Hts/HtsPackagerTests.cs @@ -44,6 +44,20 @@ public void should_Generate_Multi_Manifest() } } + [Test] + public void should_Generate_Comm_Manifest() + { + var emrDto = TestInitializer.KeEmrCommDto; + var manifests = _packager.Generate(emrDto).ToList(); + Assert.True(manifests.Any()); + Assert.True(manifests.Count>1); + foreach (var m in manifests) + { + Assert.True(m.Cargoes.Any()); + Log.Debug($"{m}"); + } + } + [Test] public void should_Generate_Manifest_With_Metrics() { @@ -83,6 +97,28 @@ public void should_Generate_Multi_Manifest_With_Metrics() } } + [Test] + public void should_Generate_Comm_Manifest_With_Metrics() + { + var emrDto = TestInitializer.KeEmrCommDto; + var manfiests = _packager.GenerateWithMetrics(emrDto).ToList(); + Assert.True(manfiests.Any()); + Assert.True(manfiests.Count>1); + foreach (var m in manfiests) + { + Assert.True(m.Cargoes.Any(x => x.Type == CargoType.Patient)); + Assert.True(m.Cargoes.Any(x => x.Type == CargoType.Metrics)); + Assert.True(m.Cargoes.Any(x => x.Type == CargoType.AppMetrics)); + Log.Debug($"{m}"); + m.Cargoes.ForEach(c => + { + Log.Debug($"{c.Type}"); + Log.Debug($" {c.Items} "); + }); + } + } + + [Test] public void should_Generate_Clients() { diff --git a/test/Dwapi.UploadManagement.Core.Tests/TestInitializer.cs b/test/Dwapi.UploadManagement.Core.Tests/TestInitializer.cs index ed24d1f4..7bbc4998 100644 --- a/test/Dwapi.UploadManagement.Core.Tests/TestInitializer.cs +++ b/test/Dwapi.UploadManagement.Core.Tests/TestInitializer.cs @@ -142,6 +142,7 @@ public class TestInitializer public static List Extracts; public static EmrDto IqEmrDto; public static EmrDto IqEmrMultiDto; + public static EmrDto KeEmrCommDto; public static EmrDto KeEmrDto; public static EmrDto KeEmrMultiDto; @@ -168,6 +169,7 @@ public void Setup() EmrSetup.MultiFacility); KeEmrDto=new EmrDto(new Guid("a6221856-0e85-11e8-ba89-0ed5f89f718b"),"KenyaEMR",EmrSetup.SingleFacility); KeEmrMultiDto=new EmrDto(new Guid("a6221856-0e85-11e8-ba89-0ed5f89f718b"),"KenyaEMR",EmrSetup.MultiFacility); + KeEmrCommDto=new EmrDto(new Guid( "a6221860-0e85-11e8-ba89-0ed5f89f718b"),"KenyaEMR",EmrSetup.Community); EmrConnectionString = GenerateConnection(config, "emrConnection", false); ConnectionString = GenerateCopyConnection(config, "dwapiConnection"); MsSqlConnectionString = config.GetConnectionString("mssqlConnection"); From 7d595050a68550193fdfd3d41815dbe8e6e808a6 Mon Sep 17 00:00:00 2001 From: Koske Kimutai Date: Thu, 9 Jul 2020 21:56:03 +0300 Subject: [PATCH 3/3] community support impl and hts fixes --- .../Cbs/MasterPatientIndexSourceExtractor.cs | 4 ++- .../Loader/Hts/HtsClientTestsLoader.cs | 24 +++++++------- .../Loader/Hts/HtsClientTracingLoader.cs | 11 ++----- .../Loader/Hts/HtsClientsLinkageLoader.cs | 19 ++--------- .../HtsPartnerNotificationServicesLoader.cs | 11 ++----- .../Loader/Hts/HtsPartnerTracingLoader.cs | 11 ++----- .../Loader/Hts/HtsTestKitsTracingLoader.cs | 12 ++----- .../Loader/Hts/QueryUtil.cs | 33 +++++++++++++++++++ .../Services/EmrMetricsService.cs | 9 +++-- ...20180621082810_MySqlFunctionPermissions.cs | 12 +++---- .../20180621092045_UpdateFunction.cs | 2 +- .../TempHtsClientTestsExtractRepository.cs | 13 +++++--- .../TempHtsClientTracingExtractRepository.cs | 13 +++++--- .../TempHtsClientsLinkageExtractRepository.cs | 13 +++++--- ...erNotificationServicesExtractRepository.cs | 13 +++++--- .../TempHtsPartnerTracingExtractRepository.cs | 13 +++++--- .../TempHtsTestKitsExtractRepository.cs | 13 +++++--- .../Seed/DatabaseProtocols.csv | 8 ++--- src/Dwapi/Dwapi.csproj | 2 +- test/Dwapi.IntegrationTests/appsettings.json | 4 +-- 20 files changed, 132 insertions(+), 108 deletions(-) create mode 100644 src/Dwapi.ExtractsManagement.Core/Loader/Hts/QueryUtil.cs diff --git a/src/Dwapi.ExtractsManagement.Core/Extractors/Cbs/MasterPatientIndexSourceExtractor.cs b/src/Dwapi.ExtractsManagement.Core/Extractors/Cbs/MasterPatientIndexSourceExtractor.cs index 6e853054..6b952b98 100644 --- a/src/Dwapi.ExtractsManagement.Core/Extractors/Cbs/MasterPatientIndexSourceExtractor.cs +++ b/src/Dwapi.ExtractsManagement.Core/Extractors/Cbs/MasterPatientIndexSourceExtractor.cs @@ -53,7 +53,9 @@ public async Task Extract(DbExtract extract, DbProtocol dbProtocol) // AutoMapper profiles var extractRecord = Mapper.Map(rdr); extractRecord.Id = LiveGuid.NewGuid(); - list.Add(extractRecord); + + if(!string.IsNullOrWhiteSpace(extractRecord.sxdmPKValueDoB)) + list.Add(extractRecord); if (count == batch) { diff --git a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientTestsLoader.cs b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientTestsLoader.cs index 61b28d9b..1f18b680 100644 --- a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientTestsLoader.cs +++ b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientTestsLoader.cs @@ -1,13 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using System.Threading.Tasks; using AutoMapper; using Dwapi.ExtractsManagement.Core.Interfaces.Loaders.Hts; using Dwapi.ExtractsManagement.Core.Interfaces.Repository.Hts; using Dwapi.ExtractsManagement.Core.Model.Destination.Hts.NewHts; +using Dwapi.ExtractsManagement.Core.Model.Source.Dwh; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; using Dwapi.ExtractsManagement.Core.Notifications; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.TempExtracts; using Dwapi.SharedKernel.Events; using Dwapi.SharedKernel.Model; using Dwapi.SharedKernel.Utility; @@ -34,24 +37,15 @@ public async Task Load() try { - /* - DomainEvents.Dispatch( - new ExtractActivityNotification(extractId, new DwhProgress( - nameof(PatientExtract), - nameof(ExtractStatus.Loading), - found, 0, 0, 0, 0))); - - */ - const int take = 1000; - var eCount = await _tempHtsClientTestsExtractRepository.GetCleanCount(); + var eCount = await _tempHtsClientTestsExtractRepository.GetCleanCount(); var pageCount = _tempHtsClientTestsExtractRepository.PageCount(take, eCount); int page = 1; while (page <= pageCount) { - var tempHtsClientTests =await - _tempHtsClientTestsExtractRepository.GetAll(a => a.ErrorType == 0, page, take); + var tempHtsClientTests = await + _tempHtsClientTestsExtractRepository.GetAll(QueryUtil.Tests, page, take); var batch = tempHtsClientTests.ToList(); count += batch.Count; @@ -61,6 +55,7 @@ public async Task Load() { record.Id = LiveGuid.NewGuid(); } + //Batch Insert var inserted = _htsClientTestsExtractRepository.BatchInsert(extractRecords); if (!inserted) @@ -68,6 +63,7 @@ public async Task Load() Log.Error($"Extract {nameof(HtsClientTests)} not Loaded"); return 0; } + Log.Debug("saved batch"); page++; /* @@ -78,7 +74,9 @@ public async Task Load() found, count, 0, 0, 0))); */ } - DomainEvents.Dispatch(new HtsNotification(new ExtractProgress(nameof(HtsClientTests), "Loading...", Found, 0, 0, 0, 0))); + + DomainEvents.Dispatch(new HtsNotification(new ExtractProgress(nameof(HtsClientTests), "Loading...", + Found, 0, 0, 0, 0))); return count; } catch (Exception e) diff --git a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientTracingLoader.cs b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientTracingLoader.cs index 18a3e2da..7316248f 100644 --- a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientTracingLoader.cs +++ b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientTracingLoader.cs @@ -8,6 +8,7 @@ using Dwapi.ExtractsManagement.Core.Model.Destination.Hts.NewHts; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; using Dwapi.ExtractsManagement.Core.Notifications; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.TempExtracts; using Dwapi.SharedKernel.Events; using Dwapi.SharedKernel.Model; using Dwapi.SharedKernel.Utility; @@ -33,14 +34,6 @@ public async Task Load() int count = 0; try { - /* - DomainEvents.Dispatch( - new ExtractActivityNotification(extractId, new DwhProgress( - nameof(PatientExtract), - nameof(ExtractStatus.Loading), - found, 0, 0, 0, 0))); - - */ const int take = 1000; var eCount = await _tempHtsClientTracingExtractRepository.GetCleanCount(); @@ -50,7 +43,7 @@ public async Task Load() while (page <= pageCount) { var tempHtsClientTracings =await - _tempHtsClientTracingExtractRepository.GetAll(a => a.ErrorType == 0, page, take); + _tempHtsClientTracingExtractRepository.GetAll(QueryUtil.Tracing, page, take); var batch = tempHtsClientTracings.ToList(); count += batch.Count; diff --git a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientsLinkageLoader.cs b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientsLinkageLoader.cs index db2f98d6..1eb55c45 100644 --- a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientsLinkageLoader.cs +++ b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsClientsLinkageLoader.cs @@ -8,6 +8,7 @@ using Dwapi.ExtractsManagement.Core.Model.Destination.Hts.NewHts; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; using Dwapi.ExtractsManagement.Core.Notifications; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.TempExtracts; using Dwapi.SharedKernel.Events; using Dwapi.SharedKernel.Model; using Dwapi.SharedKernel.Utility; @@ -34,15 +35,6 @@ public async Task Load() try { - /* - DomainEvents.Dispatch( - new ExtractActivityNotification(extractId, new DwhProgress( - nameof(PatientExtract), - nameof(ExtractStatus.Loading), - found, 0, 0, 0, 0))); - - */ - const int take = 1000; var eCount = await _tempHtsClientsLinkageExtractRepository.GetCleanCount(); var pageCount = _tempHtsClientsLinkageExtractRepository.PageCount(take, eCount); @@ -51,7 +43,7 @@ public async Task Load() while (page <= pageCount) { var tempHtsClientLinkages =await - _tempHtsClientsLinkageExtractRepository.GetAll(a => a.ErrorType == 0, page, take); + _tempHtsClientsLinkageExtractRepository.GetAll(QueryUtil.Linkage, page, take); var batch = tempHtsClientLinkages.ToList(); count += batch.Count; @@ -70,13 +62,6 @@ public async Task Load() } Log.Debug("saved batch"); page++; - /* - DomainEvents.Dispatch( - new ExtractActivityNotification(extractId, new DwhProgress( - nameof(PatientExtract), - nameof(ExtractStatus.Loading), - found, count, 0, 0, 0))); - */ } DomainEvents.Dispatch(new HtsNotification(new ExtractProgress(nameof(HtsClientLinkage), "Loading...", Found, 0, 0, 0, 0))); return count; diff --git a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsPartnerNotificationServicesLoader.cs b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsPartnerNotificationServicesLoader.cs index 15a896f0..21f1f161 100644 --- a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsPartnerNotificationServicesLoader.cs +++ b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsPartnerNotificationServicesLoader.cs @@ -8,6 +8,7 @@ using Dwapi.ExtractsManagement.Core.Model.Destination.Hts.NewHts; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; using Dwapi.ExtractsManagement.Core.Notifications; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.TempExtracts; using Dwapi.SharedKernel.Events; using Dwapi.SharedKernel.Model; using Dwapi.SharedKernel.Utility; @@ -34,14 +35,6 @@ public async Task Load() int count = 0; try { - /* - DomainEvents.Dispatch( - new ExtractActivityNotification(extractId, new DwhProgress( - nameof(PatientExtract), - nameof(ExtractStatus.Loading), - found, 0, 0, 0, 0))); - - */ const int take = 1000; var eCount = await _tempHtsPartnerNotificationServicesExtractRepository.GetCleanCount(); @@ -51,7 +44,7 @@ public async Task Load() while (page <= pageCount) { var tempHtsPartnerNotifications =await - _tempHtsPartnerNotificationServicesExtractRepository.GetAll(a => a.ErrorType == 0, page, take); + _tempHtsPartnerNotificationServicesExtractRepository.GetAll(QueryUtil.Pns, page, take); var batch = tempHtsPartnerNotifications.ToList(); count += batch.Count; diff --git a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsPartnerTracingLoader.cs b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsPartnerTracingLoader.cs index 461cd96f..96548cb1 100644 --- a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsPartnerTracingLoader.cs +++ b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsPartnerTracingLoader.cs @@ -8,6 +8,7 @@ using Dwapi.ExtractsManagement.Core.Model.Destination.Hts.NewHts; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; using Dwapi.ExtractsManagement.Core.Notifications; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.TempExtracts; using Dwapi.SharedKernel.Events; using Dwapi.SharedKernel.Model; using Dwapi.SharedKernel.Utility; @@ -33,14 +34,6 @@ public async Task Load() int count = 0; try { - /* - DomainEvents.Dispatch( - new ExtractActivityNotification(extractId, new DwhProgress( - nameof(PatientExtract), - nameof(ExtractStatus.Loading), - found, 0, 0, 0, 0))); - - */ const int take = 1000; var eCount = await _tempHtsPartnerTracingExtractRepository.GetCleanCount(); @@ -50,7 +43,7 @@ public async Task Load() while (page <= pageCount) { var tempHtsPartnerTracings =await - _tempHtsPartnerTracingExtractRepository.GetAll(a => a.ErrorType == 0, page, take); + _tempHtsPartnerTracingExtractRepository.GetAll(QueryUtil.PartnerTracing, page, take); var batch = tempHtsPartnerTracings.ToList(); count += batch.Count; diff --git a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsTestKitsTracingLoader.cs b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsTestKitsTracingLoader.cs index 73676e5d..123d089a 100644 --- a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsTestKitsTracingLoader.cs +++ b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/HtsTestKitsTracingLoader.cs @@ -8,6 +8,7 @@ using Dwapi.ExtractsManagement.Core.Model.Destination.Hts.NewHts; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; using Dwapi.ExtractsManagement.Core.Notifications; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.TempExtracts; using Dwapi.SharedKernel.Events; using Dwapi.SharedKernel.Model; using Dwapi.SharedKernel.Utility; @@ -33,15 +34,6 @@ public async Task Load() int count = 0; try { - /* - DomainEvents.Dispatch( - new ExtractActivityNotification(extractId, new DwhProgress( - nameof(PatientExtract), - nameof(ExtractStatus.Loading), - found, 0, 0, 0, 0))); - - */ - const int take = 1000; var eCount = await _tempHtsTestKitsExtractRepository.GetCleanCount(); var pageCount = _tempHtsTestKitsExtractRepository.PageCount(take, eCount); @@ -50,7 +42,7 @@ public async Task Load() while (page <= pageCount) { var tempHtsTestKits =await - _tempHtsTestKitsExtractRepository.GetAll(a => a.ErrorType == 0, page, take); + _tempHtsTestKitsExtractRepository.GetAll(QueryUtil.Kits, page, take); var batch = tempHtsTestKits.ToList(); count += batch.Count; diff --git a/src/Dwapi.ExtractsManagement.Core/Loader/Hts/QueryUtil.cs b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/QueryUtil.cs new file mode 100644 index 00000000..57ce7587 --- /dev/null +++ b/src/Dwapi.ExtractsManagement.Core/Loader/Hts/QueryUtil.cs @@ -0,0 +1,33 @@ +namespace Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.TempExtracts +{ + public class QueryUtil + { + public static string Linkage => QueryBuilder("TempHtsClientsLinkageExtracts"); + public static string Tests => QueryBuilder("TempHtsClientTestsExtracts"); + public static string Tracing => QueryBuilder("TempHtsClientTracingExtracts"); + public static string Pns => QueryBuilder("TempHtsPartnerNotificationServicesExtracts"); + public static string PartnerTracing => QueryBuilder("TempHtsPartnerTracingExtracts"); + public static string Kits => QueryBuilder("TempHtsTestKitsExtracts"); + + public static string LinkageCount => QueryBuilder("TempHtsClientsLinkageExtracts", true); + public static string TestsCount => QueryBuilder("TempHtsClientTestsExtracts", true); + public static string TracingCount => QueryBuilder("TempHtsClientTracingExtracts", true); + public static string PnsCount => QueryBuilder("TempHtsPartnerNotificationServicesExtracts", true); + public static string PartnerTracingCount => QueryBuilder("TempHtsPartnerTracingExtracts", true); + public static string KitsCount => QueryBuilder("TempHtsTestKitsExtracts", true); + + public static string QueryBuilder(string extract, bool count = false) + { + var select = count ? "SELECT Count(s.Id) " : "SELECT s.* "; + + var from = $@" + FROM {extract} s + INNER JOIN HtsClientsExtracts p ON s.PatientPK = p.PatientPK AND s.SiteCode = p.SiteCode + WHERE ErrorType = 0"; + + var query = $"{select} {from}"; + + return query; + } + } +} diff --git a/src/Dwapi.ExtractsManagement.Core/Services/EmrMetricsService.cs b/src/Dwapi.ExtractsManagement.Core/Services/EmrMetricsService.cs index b9cd51df..b1446c4a 100644 --- a/src/Dwapi.ExtractsManagement.Core/Services/EmrMetricsService.cs +++ b/src/Dwapi.ExtractsManagement.Core/Services/EmrMetricsService.cs @@ -34,6 +34,7 @@ public EmrMetricsService(IEmrMetricRepository emrMetricRepository) public async Task Read(AuthProtocol authProtocol, string url) { EmrMetricSource metricSoruce = null; + string metricsUrl=string.Empty; if (authProtocol.HasAuth) { @@ -48,7 +49,8 @@ public async Task Read(AuthProtocol authProtocol, string url) try { - var response = await _httpClient.GetAsync(GetUrl(authProtocol.Url, url)); + metricsUrl = GetUrl(authProtocol.Url, url); + var response = await _httpClient.GetAsync(metricsUrl); if (response.IsSuccessStatusCode) { metricSoruce = await response.Content.ReadAsJsonAsync(); @@ -60,7 +62,10 @@ public async Task Read(AuthProtocol authProtocol, string url) } catch (Exception e) { - Log.Error(e, "Error Reading metrics"); + Log.Error(new string('-',40)); + Log.Error($"Error Reading metrics on [{metricsUrl}]"); + Log.Error(e.Message,"Metrics Error"); + Log.Error(new string('-',40)); } if (null != metricSoruce) diff --git a/src/Dwapi.ExtractsManagement.Infrastructure/Migrations/20180621082810_MySqlFunctionPermissions.cs b/src/Dwapi.ExtractsManagement.Infrastructure/Migrations/20180621082810_MySqlFunctionPermissions.cs index 083fa3f2..0d2ae8a1 100644 --- a/src/Dwapi.ExtractsManagement.Infrastructure/Migrations/20180621082810_MySqlFunctionPermissions.cs +++ b/src/Dwapi.ExtractsManagement.Infrastructure/Migrations/20180621082810_MySqlFunctionPermissions.cs @@ -9,17 +9,17 @@ protected override void Up(MigrationBuilder migrationBuilder) if (migrationBuilder.ActiveProvider.ToLower().Contains("MySql".ToLower())) { migrationBuilder.Sql(@" - GRANT EXECUTE ON FUNCTION fn_calculateJaro TO '*'@'%'; - GRANT EXECUTE ON FUNCTION fn_calculateJaroWinkler TO '*'@'%'; - GRANT EXECUTE ON FUNCTION fn_calculateMatchWindow TO '*'@'%'; - GRANT EXECUTE ON FUNCTION fn_calculatePrefixLength TO '*'@'%'; - GRANT EXECUTE ON FUNCTION fn_GetCommonCharacters TO '*'@'%';"); + GRANT EXECUTE ON FUNCTION fn_calculateJaro TO 'dwapi'@'%'; + GRANT EXECUTE ON FUNCTION fn_calculateJaroWinkler TO 'dwapi'@'%'; + GRANT EXECUTE ON FUNCTION fn_calculateMatchWindow TO 'dwapi'@'%'; + GRANT EXECUTE ON FUNCTION fn_calculatePrefixLength TO 'dwapi'@'%'; + GRANT EXECUTE ON FUNCTION fn_GetCommonCharacters TO 'dwapi'@'%';"); } } protected override void Down(MigrationBuilder migrationBuilder) { - + } } } diff --git a/src/Dwapi.ExtractsManagement.Infrastructure/Migrations/20180621092045_UpdateFunction.cs b/src/Dwapi.ExtractsManagement.Infrastructure/Migrations/20180621092045_UpdateFunction.cs index 3569b4d5..1b7504da 100644 --- a/src/Dwapi.ExtractsManagement.Infrastructure/Migrations/20180621092045_UpdateFunction.cs +++ b/src/Dwapi.ExtractsManagement.Infrastructure/Migrations/20180621092045_UpdateFunction.cs @@ -34,7 +34,7 @@ IF SUBSTRING( str1, i+1, 1) <> SUBSTRING( str2, i+1, 1) THEN END;"); - migrationBuilder.Sql(@"GRANT EXECUTE ON FUNCTION fn_calculateTranspositions TO '*'@'%'; + migrationBuilder.Sql(@"GRANT EXECUTE ON FUNCTION fn_calculateTranspositions TO 'dwapi'@'%'; FLUSH PRIVILEGES;"); } diff --git a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientTestsExtractRepository.cs b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientTestsExtractRepository.cs index 6443dbe9..267de3e9 100644 --- a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientTestsExtractRepository.cs +++ b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientTestsExtractRepository.cs @@ -3,8 +3,10 @@ using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; +using Dapper; using Dwapi.ExtractsManagement.Core.Interfaces.Repository.Hts; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.Extracts; using Dwapi.SharedKernel.Infrastructure.Repository; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; @@ -68,10 +70,13 @@ public bool BatchInsert(IEnumerable extracts) public Task GetCleanCount() { - return DbSet.AsNoTracking() - .Where(a => a.ErrorType == 0) - .Select(x => x.Id) - .CountAsync(); + int count = 0; + using (var cn=GetNewConnection()) + { + var query = QueryUtil.TestsCount; + count = cn.ExecuteScalar(query); + } + return Task.FromResult(count); } } } diff --git a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientTracingExtractRepository.cs b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientTracingExtractRepository.cs index 31586609..ed2a8ec6 100644 --- a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientTracingExtractRepository.cs +++ b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientTracingExtractRepository.cs @@ -3,8 +3,10 @@ using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; +using Dapper; using Dwapi.ExtractsManagement.Core.Interfaces.Repository.Hts; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.Extracts; using Dwapi.SharedKernel.Infrastructure.Repository; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; @@ -68,10 +70,13 @@ public bool BatchInsert(IEnumerable extracts) public Task GetCleanCount() { - return DbSet.AsNoTracking() - .Where(a => a.ErrorType == 0) - .Select(x => x.Id) - .CountAsync(); + int count = 0; + using (var cn=GetNewConnection()) + { + var query = QueryUtil.TracingCount; + count = cn.ExecuteScalar(query); + } + return Task.FromResult(count); } } } diff --git a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientsLinkageExtractRepository.cs b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientsLinkageExtractRepository.cs index 081ceb1f..cdd850af 100644 --- a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientsLinkageExtractRepository.cs +++ b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsClientsLinkageExtractRepository.cs @@ -3,8 +3,10 @@ using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; +using Dapper; using Dwapi.ExtractsManagement.Core.Interfaces.Repository.Hts; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.Extracts; using Dwapi.SharedKernel.Infrastructure.Repository; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; @@ -68,10 +70,13 @@ public bool BatchInsert(IEnumerable extracts) public Task GetCleanCount() { - return DbSet.AsNoTracking() - .Where(a => a.ErrorType == 0) - .Select(x => x.Id) - .CountAsync(); + int count = 0; + using (var cn=GetNewConnection()) + { + var query = QueryUtil.LinkageCount; + count = cn.ExecuteScalar(query); + } + return Task.FromResult(count); } } } diff --git a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsPartnerNotificationServicesExtractRepository.cs b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsPartnerNotificationServicesExtractRepository.cs index 88d3527d..7a0c6843 100644 --- a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsPartnerNotificationServicesExtractRepository.cs +++ b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsPartnerNotificationServicesExtractRepository.cs @@ -3,8 +3,10 @@ using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; +using Dapper; using Dwapi.ExtractsManagement.Core.Interfaces.Repository.Hts; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.Extracts; using Dwapi.SharedKernel.Infrastructure.Repository; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; @@ -68,10 +70,13 @@ public bool BatchInsert(IEnumerable extracts public Task GetCleanCount() { - return DbSet.AsNoTracking() - .Where(a => a.ErrorType == 0) - .Select(x => x.Id) - .CountAsync(); + int count = 0; + using (var cn=GetNewConnection()) + { + var query = QueryUtil.PnsCount; + count = cn.ExecuteScalar(query); + } + return Task.FromResult(count); } } } diff --git a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsPartnerTracingExtractRepository.cs b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsPartnerTracingExtractRepository.cs index b9253a18..ae640be1 100644 --- a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsPartnerTracingExtractRepository.cs +++ b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsPartnerTracingExtractRepository.cs @@ -3,8 +3,10 @@ using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; +using Dapper; using Dwapi.ExtractsManagement.Core.Interfaces.Repository.Hts; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.Extracts; using Dwapi.SharedKernel.Infrastructure.Repository; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; @@ -68,10 +70,13 @@ public bool BatchInsert(IEnumerable extracts) public Task GetCleanCount() { - return DbSet.AsNoTracking() - .Where(a => a.ErrorType == 0) - .Select(x => x.Id) - .CountAsync(); + int count = 0; + using (var cn=GetNewConnection()) + { + var query = QueryUtil.PartnerTracingCount; + count = cn.ExecuteScalar(query); + } + return Task.FromResult(count); } } } diff --git a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsTestKitsExtractRepository.cs b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsTestKitsExtractRepository.cs index 2457fd04..646907e4 100644 --- a/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsTestKitsExtractRepository.cs +++ b/src/Dwapi.ExtractsManagement.Infrastructure/Repository/Hts/TempExtracts/TempHtsTestKitsExtractRepository.cs @@ -3,8 +3,10 @@ using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; +using Dapper; using Dwapi.ExtractsManagement.Core.Interfaces.Repository.Hts; using Dwapi.ExtractsManagement.Core.Model.Source.Hts.NewHts; +using Dwapi.ExtractsManagement.Infrastructure.Repository.Hts.Extracts; using Dwapi.SharedKernel.Infrastructure.Repository; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; @@ -67,10 +69,13 @@ public bool BatchInsert(IEnumerable extracts) public Task GetCleanCount() { - return DbSet.AsNoTracking() - .Where(a => a.ErrorType == 0) - .Select(x => x.Id) - .CountAsync(); + int count = 0; + using (var cn=GetNewConnection()) + { + var query = QueryUtil.KitsCount; + count = cn.ExecuteScalar(query); + } + return Task.FromResult(count); } } } diff --git a/src/Dwapi.SettingsManagement.Infrastructure/Seed/DatabaseProtocols.csv b/src/Dwapi.SettingsManagement.Infrastructure/Seed/DatabaseProtocols.csv index 73e2705e..3a580566 100644 --- a/src/Dwapi.SettingsManagement.Infrastructure/Seed/DatabaseProtocols.csv +++ b/src/Dwapi.SettingsManagement.Infrastructure/Seed/DatabaseProtocols.csv @@ -1,11 +1,11 @@ Id|DatabaseName|DatabaseType|EmrSystemId|Host|Password|Port|Username|AdvancedProperties A6221982-0E85-11E8-BA89-0ED5F89F718B|IQCare|1|a62216ee-0e85-11e8-ba89-0ed5f89f718b|.|M@un1983||sa| a6221983-0e85-11e8-ba89-0ed5f89f718b|IQTools_KeHMIS|1|a62216ee-0e85-11e8-ba89-0ed5f89f718b|.|M@un1983||sa| -a6221aa4-0e85-11e8-ba89-0ed5f89f718b|openmrs|2|a6221856-0e85-11e8-ba89-0ed5f89f718b|127.0.0.1|openmrs|3306|root|Allow User Variables=True +a6221aa4-0e85-11e8-ba89-0ed5f89f718b|openmrs|2|a6221856-0e85-11e8-ba89-0ed5f89f718b|127.0.0.1|dwapi|3306|dwapi|Allow User Variables=True a6221aa5-0e85-11e8-ba89-0ed5f89f718b|amrsndwr|2|a6221857-0e85-11e8-ba89-0ed5f89f718b|127.0.0.1|openmrs|3306|root|Allow User Variables=True a6221982-0e86-11e8-ba89-0ed5f89f718b|ECare|1|a6221858-0e85-11e8-ba89-0ed5f89f718b|.|P@ssw0rd||sa| -a6221989-0e85-11e8-ba89-0ed5f89f718b|openmrs|2|a6221859-0e85-11e8-ba89-0ed5f89f718b|127.0.0.1|openmrs|3306|root|Allow User Variables=True -bb254606-38f8-409f-8e36-ab6601139dea|other|2|a6221859-0e85-11e8-ba89-0ed5f89f718b|127.0.0.1|openmrs|3306|root|Allow User Variables=True +a6221989-0e85-11e8-ba89-0ed5f89f718b|openmrs|2|a6221859-0e85-11e8-ba89-0ed5f89f718b|127.0.0.1|dwapi|3306|dwapi|Allow User Variables=True +bb254606-38f8-409f-8e36-ab6601139dea|other|2|a6221859-0e85-11e8-ba89-0ed5f89f718b|127.0.0.1|dwapi|3306|dwapi|Allow User Variables=True A6221987-0E85-11E8-BA89-0ED5F89F718B|IQCare_CHAK|1|926f49b8-305d-11ea-978f-2e728ce88125|.|c0nstella||sa| a6221988-0e85-11e8-ba89-0ed5f89f718b|IQTools_CHAK|1|926f49b8-305d-11ea-978f-2e728ce88125|.|c0nstella||sa| -a6221aa6-0e85-11e8-ba89-0ed5f89f718b|openmrs|2|a6221860-0e85-11e8-ba89-0ed5f89f718b|127.0.0.1|openmrs|3306|root|Allow User Variables=True +a6221aa6-0e85-11e8-ba89-0ed5f89f718b|openmrs|2|a6221860-0e85-11e8-ba89-0ed5f89f718b|127.0.0.1|dwapi|3306|dwapi|Allow User Variables=True diff --git a/src/Dwapi/Dwapi.csproj b/src/Dwapi/Dwapi.csproj index 066d16cb..4e99a731 100644 --- a/src/Dwapi/Dwapi.csproj +++ b/src/Dwapi/Dwapi.csproj @@ -4,7 +4,7 @@ Latest true ..\docker-compose.dcproj - 2.4.8.2 + 2.4.8.3 Palladium Group Davidson Gikandi, Danson Koske, Mwenda Gitonga, Brian Mwasi, Teddy Brian https://github.com/palladiumkenya/DWAPI diff --git a/test/Dwapi.IntegrationTests/appsettings.json b/test/Dwapi.IntegrationTests/appsettings.json index 148d5d57..b5f6b830 100644 --- a/test/Dwapi.IntegrationTests/appsettings.json +++ b/test/Dwapi.IntegrationTests/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "mssqlConnection": "Data Source=.;Initial Catalog=dwapiTest;Persist Security Info=True;User ID=sa;Password=M@un1983;Pooling=True;MultipleActiveResultSets=True", - "mysqlConnection": "Server=127.0.0.1;User Id=dwapi;Password=dwapi;Database=dwapiTest;Pooling=True;Persist Security Info=True;Convert Zero Datetime=True;Port=3307" + "mssqlConnection": "Data Source=192.168.100.3\\SQLEXPRESS;Initial Catalog=dwapiTest;Persist Security Info=True;User ID=sa;Password=maun;Pooling=True;MultipleActiveResultSets=True", + "mysqlConnection": "Server=192.168.100.3;User Id=dwapi;Password=dwapi;Database=dwapiTest;Pooling=True;Persist Security Info=True;Convert Zero Datetime=True;Port=3306" } }