diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/FacilityDashboardUtil.java b/api/src/main/java/org/openmrs/module/kenyaemr/FacilityDashboardUtil.java index 3dd5db59d..7147da26e 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/FacilityDashboardUtil.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/FacilityDashboardUtil.java @@ -208,19 +208,163 @@ public static Long getPregnantPostpartumNotInPrep() { Context.removeProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS); } } + + /** + * Surveillance dashboards + * 3. Delayed viral load testing. Eligible without VL test taken + * @return long value + */ + public static Long getEligibleForVl() { + String eligibleForVlQuery = "select count(b.patient_id) as eligible_for_vl\n" + + "from (select fup.visit_date,\n" + + " fup.patient_id,\n" + + " min(e.visit_date) as enroll_date,\n" + + " max(fup.visit_date) as latest_vis_date,\n" + + " mid(max(concat(fup.visit_date, fup.next_appointment_date)), 11) as latest_tca,\n" + + " max(d.visit_date) as date_discontinued,\n" + + " d.patient_id as disc_patient,\n" + + " de.patient_id as started_on_drugs\n" + + " from kenyaemr_etl.etl_patient_hiv_followup fup\n" + + " join kenyaemr_etl.etl_patient_demographics p on p.patient_id = fup.patient_id\n" + + " join kenyaemr_etl.etl_hiv_enrollment e on fup.patient_id = e.patient_id\n" + + " left outer join kenyaemr_etl.etl_drug_event de\n" + + " on e.patient_id = de.patient_id and date(date_started) <= CURRENT_DATE\n" + + " left outer JOIN\n" + + " (select patient_id, visit_date\n" + + " from kenyaemr_etl.etl_patient_program_discontinuation\n" + + " where date(visit_date) <= CURRENT_DATE\n" + + " and program_name = 'HIV'\n" + + " group by patient_id) d on d.patient_id = fup.patient_id\n" + + " where fup.visit_date <= CURRENT_DATE\n" + + " group by patient_id\n" + + " having (started_on_drugs is not null and started_on_drugs <> \"\")\n" + + " and (\n" + + " (date(latest_tca) > CURRENT_DATE and\n" + + " (date(latest_tca) > date(date_discontinued) or disc_patient is null)) or\n" + + " (((date(latest_tca) between date_sub(CURRENT_DATE, interval 3 MONTH) and CURRENT_DATE) and\n" + + " (date(latest_vis_date) >= date(latest_tca)))) and\n" + + " (date(latest_tca) > date(date_discontinued) or disc_patient is null))) e\n" + + " INNER JOIN (select v.patient_id\n" + + " from kenyaemr_etl.etl_viral_load_validity_tracker v\n" + + " inner join kenyaemr_etl.etl_patient_demographics d on v.patient_id = d.patient_id\n" + + " where (TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" + + " v.base_viral_load_test_result is null) -- First VL new on ART\n" + + " OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" + + " (v.vl_result is not null and\n" + + " v.date_test_requested < v.latest_hiv_followup_visit)) -- immediate for PG & BF\n" + + " OR (v.vl_result >= 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" + + " 3) -- Unsuppressed VL\n" + + " OR (v.vl_result < 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 6 and\n" + + " TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) BETWEEN 0 AND 24) -- 0-24 with last suppressed vl\n" + + " OR (v.vl_result < 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" + + " 12 and\n" + + " TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) > 24) -- > 24 with last suppressed vl\n" + + " OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3\n" + + " and (v.order_reason in (159882, 1434) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" + + " 12) and\n" + + " v.vl_result < 200) -- PG & BF after PG/BF baseline < 200\n" + + ") b on e.patient_id = b.patient_id;\n" + + "\n" + + "-- Eligible for VL sample not taken\n" + + "select count(v.patient_id) as eligible_for_vl\n" + + "from kenyaemr_etl.etl_viral_load_validity_tracker v\n" + + " inner join kenyaemr_etl.etl_patient_demographics d on v.patient_id = d.patient_id\n" + + "where ((TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" + + " v.base_viral_load_test_result is null) -- First VL new on ART\n" + + " OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" + + " (v.vl_result is not null and v.date_test_requested < v.latest_hiv_followup_visit)) -- immediate for PG & BF\n" + + " OR (v.vl_result >= 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3) -- Unsuppressed VL\n" + + " OR (v.vl_result < 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 6 and\n" + + " TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) BETWEEN 0 AND 24) -- 0-24 with last suppressed vl\n" + + " OR (v.vl_result < 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 12 and\n" + + " TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) > 24) -- > 24 with last suppressed vl\n" + + " OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3\n" + + " and (v.order_reason in (159882, 1434) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 12) and\n" + + " v.vl_result < 200)) -- PG & BF after PG/BF baseline < 200\n" + + " and v.latest_hiv_followup_visit != v.date_test_requested;"; + + try { + Context.addProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS); + return (Long) Context.getAdministrationService().executeSQL(eligibleForVlQuery, true).get(0).get(0); + } + finally { + Context.removeProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS); + } + } /** * Surveillance dashboards * 3. Delayed viral load testing. Eligible without VL test taken * @return long value */ public static Long getEligibleForVlSampleNotTaken() { - String eligibleForVlSampleNotTakenQuery = "select count(t.patient_id) from kenyaemr_etl.etl_hts_test t left join\n" + - " (select l.patient_id, l.ccc_number from kenyaemr_etl.etl_hts_referral_and_linkage l \n" + - " where date(l.visit_date) <= date('2020-01-01') group by l.patient_id) l on t.patient_id = l.patient_id\n" + - " left join (select e.patient_id from kenyaemr_etl.etl_hiv_enrollment e \n" + - " where date(e.visit_date) <= date('2020-01-01'))e on e.patient_id = t.patient_id\n" + - " where t.final_test_result='Positive' and t.test_type = 2 \n" + - " and date(t.visit_date) between date('2020-01-01') and date('2025-01-01') and l.ccc_number is null and e.patient_id is null;"; + String eligibleForVlSampleNotTakenQuery = "select count(b.patient_id) as eligible_for_vl_sample_not_taken\n" + + "from (select fup.visit_date,\n" + + " fup.patient_id,\n" + + " min(e.visit_date) as enroll_date,\n" + + " max(fup.visit_date) as latest_vis_date,\n" + + " mid(max(concat(fup.visit_date, fup.next_appointment_date)), 11) as latest_tca,\n" + + " max(d.visit_date) as date_discontinued,\n" + + " d.patient_id as disc_patient,\n" + + " de.patient_id as started_on_drugs\n" + + " from kenyaemr_etl.etl_patient_hiv_followup fup\n" + + " join kenyaemr_etl.etl_patient_demographics p on p.patient_id = fup.patient_id\n" + + " join kenyaemr_etl.etl_hiv_enrollment e on fup.patient_id = e.patient_id\n" + + " left outer join kenyaemr_etl.etl_drug_event de\n" + + " on e.patient_id = de.patient_id and date(date_started) <= CURRENT_DATE\n" + + " left outer JOIN\n" + + " (select patient_id, visit_date\n" + + " from kenyaemr_etl.etl_patient_program_discontinuation\n" + + " where date(visit_date) <= CURRENT_DATE\n" + + " and program_name = 'HIV'\n" + + " group by patient_id) d on d.patient_id = fup.patient_id\n" + + " where fup.visit_date <= CURRENT_DATE\n" + + " group by patient_id\n" + + " having (started_on_drugs is not null and started_on_drugs <> \"\")\n" + + " and (\n" + + " (date(latest_tca) > CURRENT_DATE and\n" + + " (date(latest_tca) > date(date_discontinued) or disc_patient is null)) or\n" + + " (((date(latest_tca) between date_sub(CURRENT_DATE, interval 3 MONTH) and CURRENT_DATE) and\n" + + " (date(latest_vis_date) >= date(latest_tca)))) and\n" + + " (date(latest_tca) > date(date_discontinued) or disc_patient is null))) e\n" + + " INNER JOIN (select v.patient_id\n" + + " from kenyaemr_etl.etl_viral_load_validity_tracker v\n" + + " inner join kenyaemr_etl.etl_patient_demographics d on v.patient_id = d.patient_id\n" + + " where ((TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" + + " v.base_viral_load_test_result is null) -- First VL new on ART\n" + + " OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" + + " (v.vl_result is not null and\n" + + " v.date_test_requested < v.latest_hiv_followup_visit)) -- immediate for PG & BF\n" + + " OR (v.vl_result >= 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" + + " 3) -- Unsuppressed VL\n" + + " OR (v.vl_result < 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" + + " 6 and\n" + + " TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) BETWEEN 0 AND 24) -- 0-24 with last suppressed vl\n" + + " OR (v.vl_result < 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" + + " 12 and\n" + + " TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) > 24) -- > 24 with last suppressed vl\n" + + " OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3\n" + + " and (v.order_reason in (159882, 1434) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" + + " 12) and\n" + + " v.vl_result < 200)) -- PG & BF after PG/BF baseline < 200\n" + + " and v.latest_hiv_followup_visit > v.date_test_requested) b on e.patient_id = b.patient_id;"; try { Context.addProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS); diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/PublicHealthActionReportBuilder.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/PublicHealthActionReportBuilder.java index 66f0e13ef..37610c848 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/PublicHealthActionReportBuilder.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/builder/common/PublicHealthActionReportBuilder.java @@ -60,8 +60,8 @@ protected DataSetDefinition publicHealthAction() { cohortDsd.addColumn("Current on ART without valid VL", "", ReportUtils.map(publicHealthActionIndicatorLibrary.invalidVL(), "startDate=${startDate},endDate=${endDate}"), ""); cohortDsd.addColumn("Current on ART with Unsuppressed Valid VL", "", ReportUtils.map(publicHealthActionIndicatorLibrary.unsuppressedWithValidVL(), "endDate=${endDate}"), ""); cohortDsd.addColumn("Current on ART with Unsuppressed invalid VL", "", ReportUtils.map(publicHealthActionIndicatorLibrary.unsuppressedWithoutValidVL(), "startDate=${startDate},endDate=${endDate}"), ""); - cohortDsd.addColumn("Virally Unsuppressed without Enhanced Adherence Counselling", "", ReportUtils.map(publicHealthActionIndicatorLibrary.txCUrrUnsuppressedWithoutEAC(), "startDate=${startDate},endDate=${endDate}"), ""); - // cohortDsd.addColumn("Delayed viral load testing (Visited facility were eligible for vl but sample not taken)", "", ReportUtils.map(publicHealthActionIndicatorLibrary.delayedVLTesting(), "startDate=${startDate},endDate=${endDate}"), ""); + cohortDsd.addColumn("Virally Unsuppressed without Enhanced Adherence Counselling", "(No EAC past 2 weeks)", ReportUtils.map(publicHealthActionIndicatorLibrary.txCUrrUnsuppressedWithoutEAC(), "startDate=${startDate},endDate=${endDate}"), ""); + cohortDsd.addColumn("Delayed viral load testing (Visited facility were eligible for vl but sample not taken)", "(Eligible within past 7 days)", ReportUtils.map(publicHealthActionIndicatorLibrary.delayedVLTesting(), "startDate=${startDate},endDate=${endDate}"), ""); cohortDsd.addColumn("Current on ART Clients without NUPI", "", ReportUtils.map(publicHealthActionIndicatorLibrary.txCurrclientsWithoutNUPI(), "startDate=${startDate},endDate=${endDate}"), ""); cohortDsd.addColumn("Recent defaulters", " (Missed appointment within 30 days)", ReportUtils.map(publicHealthActionIndicatorLibrary.recentDefaulters(), "startDate=${startDate},endDate=${endDate}"), ""); cohortDsd.addColumn("Undocumented LTFU/IIT", "", ReportUtils.map(publicHealthActionIndicatorLibrary.undocumentedLTFU(), "startDate=${startDate},endDate=${endDate}"), ""); @@ -73,9 +73,9 @@ protected DataSetDefinition publicHealthAction() { cohortDsd.addColumn("HEI with undocumented HIV status", "", ReportUtils.map(publicHealthActionIndicatorLibrary.undocumentedHEIStatus(), "startDate=${startDate},endDate=${endDate}"), ""); cohortDsd.addColumn("HEI not Linked to Mothers", "", ReportUtils.map(publicHealthActionIndicatorLibrary.unlinkedHEI(), "startDate=${startDate},endDate=${endDate}"), ""); cohortDsd.addColumn("HEI with Missed HIV Tests", " (Please run HEI Missed HIV Tests linelist)", ReportUtils.map(publicHealthActionIndicatorLibrary.heiMissedHIVTests(), ""), ""); - cohortDsd.addColumn("HEI (6-8 weeks) without DNA PCR results", "", ReportUtils.map(publicHealthActionIndicatorLibrary.heiSixToEightWeeksMissingPCRTests(), ""), ""); - cohortDsd.addColumn("HEI (24 months) without a final documented outcome", "", ReportUtils.map(publicHealthActionIndicatorLibrary.hei24MonthsUndocumentedOutcome(), ""), ""); - cohortDsd.addColumn("Pregnant and postpartum women at high risk (ML-based) not linked to PrEP", "", ReportUtils.map(publicHealthActionIndicatorLibrary.pregnantPostPartumNotLinkedToPrep(), ""), ""); + cohortDsd.addColumn("HEI (6-8 weeks) without DNA PCR results", "(Turning 6-8 weeks within past 7 days", ReportUtils.map(publicHealthActionIndicatorLibrary.heiSixToEightWeeksMissingPCRTests(), ""), ""); + cohortDsd.addColumn("HEI (24 months) without a final documented outcome", "(Turning 24 months within past 7 days)", ReportUtils.map(publicHealthActionIndicatorLibrary.hei24MonthsUndocumentedOutcome(), ""), ""); + cohortDsd.addColumn("Pregnant and postpartum women at high risk (ML-based) not linked to PrEP", "(Tested within past 7 days)", ReportUtils.map(publicHealthActionIndicatorLibrary.pregnantPostPartumNotLinkedToPrep(), ""), ""); cohortDsd.addColumn("HIV+ and NOT Linked", "", ReportUtils.map(publicHealthActionIndicatorLibrary.notLinked(), "startDate=${startDate},endDate=${endDate}"), ""); cohortDsd.addColumn("Children of HIV infected adults with undocumented HIV status", " (Please run Children of HIV infected adults with undocumented HIV status for linelist)", ReportUtils.map(publicHealthActionIndicatorLibrary.childrenContactsUndocumentedHIVStatus(), "startDate=${startDate},endDate=${endDate}"), ""); cohortDsd.addColumn("PNS Contacts with undocumented HIV status", " (Please run PNS contacts with undocumented HIV status for linelist)", ReportUtils.map(publicHealthActionIndicatorLibrary.contactsUndocumentedHIVStatus(), "startDate=${startDate},endDate=${endDate}"), ""); diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/publicHealthActionReport/PublicHealthActionCohortLibrary.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/publicHealthActionReport/PublicHealthActionCohortLibrary.java index f66942673..c417b85e7 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/publicHealthActionReport/PublicHealthActionCohortLibrary.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/publicHealthActionReport/PublicHealthActionCohortLibrary.java @@ -883,6 +883,61 @@ public CohortDefinition txCUrrUnsuppressedWithoutEAC() { cd.setCompositionString("txcurr and unsuppressedWithoutEAC"); return cd; } + + /** + * Eligible for VL samlple not taken + * @return + */ + public CohortDefinition eligibleForVLSampleNotTaken() { + String sqlQuery = "select v.patient_id\n" + + "from kenyaemr_etl.etl_viral_load_validity_tracker v\n" + + " inner join kenyaemr_etl.etl_patient_demographics d on v.patient_id = d.patient_id\n" + + "where ((TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" + + " v.base_viral_load_test_result is null) -- First VL new on ART\n" + + " OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3 and\n" + + " (v.vl_result is not null and\n" + + " v.date_test_requested < v.latest_hiv_followup_visit)) -- immediate for PG & BF\n" + + " OR (v.vl_result >= 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" + + " 3) -- Unsuppressed VL\n" + + " OR (v.vl_result < 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" + + " 6 and\n" + + " TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) BETWEEN 0 AND 24) -- 0-24 with last suppressed vl\n" + + " OR (v.vl_result < 200 AND\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" + + " 12 and\n" + + " TIMESTAMPDIFF(YEAR, v.date_test_requested, d.DOB) > 24) -- > 24 with last suppressed vl\n" + + " OR ((v.pregnancy_status = 1065 or v.breastfeeding_status = 1065) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_started_art, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >= 3\n" + + " and (v.order_reason in (159882, 1434) and\n" + + " TIMESTAMPDIFF(MONTH, v.date_test_requested, DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY)) >=\n" + + " 12) and\n" + + " v.vl_result < 200)) -- PG & BF after PG/BF baseline < 200\n" + + " and v.latest_hiv_followup_visit > v.date_test_requested;\n"; + SqlCohortDefinition cd = new SqlCohortDefinition(); + cd.setName("allSuppressedWithoutEAC"); + cd.setQuery(sqlQuery); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.setDescription("Patients with unsuppressed without Enhanced Adherence Counseling"); + return cd; + } + + /** + * Current on ART eligible for VL, sample not taken during visit + * @return + */ + public CohortDefinition delayedVLTesting() { + CompositionCohortDefinition cd = new CompositionCohortDefinition(); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.addSearch("txcurr", ReportUtils.map(datimCohortLibrary.currentlyOnArt(), "startDate=${startDate},endDate=${endDate}")); + cd.addSearch("eligibleForVLSampleNotTaken", ReportUtils.map(eligibleForVLSampleNotTaken(), "startDate=${startDate},endDate=${endDate}")); + cd.setCompositionString("txcurr and eligibleForVLSampleNotTaken"); + return cd; + } /** * HEIs 6-8 weeks missing HIV DNA PCR * @return diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/publicHealthActionReport/PublicHealthActionIndicatorLibrary.java b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/publicHealthActionReport/PublicHealthActionIndicatorLibrary.java index aa44c0966..df7dac80a 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/publicHealthActionReport/PublicHealthActionIndicatorLibrary.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/reporting/library/ETLReports/publicHealthActionReport/PublicHealthActionIndicatorLibrary.java @@ -78,6 +78,10 @@ public CohortIndicator unsuppressedWithoutValidVL() { public CohortIndicator txCUrrUnsuppressedWithoutEAC() { return cohortIndicator("Tx Curr Unsuppressed VL without EAC", ReportUtils.map(cohortLibrary.txCUrrUnsuppressedWithoutEAC(), "startDate=${startDate},endDate=${endDate}")); } + + public CohortIndicator delayedVLTesting() { + return cohortIndicator("Tx Curr Unsuppressed VL without EAC", ReportUtils.map(cohortLibrary.delayedVLTesting(), "startDate=${startDate},endDate=${endDate}")); + } /** * Number of undocumented LTFU patients * @return the indicator diff --git a/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java b/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java index 81df90c7a..3fa9c30b0 100644 --- a/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java +++ b/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java @@ -182,8 +182,7 @@ import static org.openmrs.module.kenyaemr.util.EmrUtils.getGlobalPropertyValue; /** - * The rest controller for exposing resources through kenyacore and kenyaemr - * modules + * The rest controller for exposing resources through kenyacore and kenyaemr modules */ @Controller @RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/kenyaemr") @@ -232,7 +231,7 @@ public class KenyaemrCoreRestController extends BaseRestController { public static final String PWID_UUID = "105AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; - public static final String PWUD_UUID = "642945a8-045a-4010-b3f3-bc50aaaab386"; + public static final String PWUD_UUID = "642945a8-045a-4010-b3f3-bc50aaaab386" ; public static final String TRANSGENDER_UUID = "bd370cad-06fe-4950-a36f-ed991b280ce6"; @@ -244,15 +243,13 @@ public class KenyaemrCoreRestController extends BaseRestController { /** * Gets a list of available/completed forms for a patient - * * @param request * @param patientUuid * @return */ @RequestMapping(method = RequestMethod.GET, value = "/forms") // gets all visit forms for a patient @ResponseBody - public Object getAllAvailableFormsForVisit(HttpServletRequest request, - @RequestParam("patientUuid") String patientUuid) { + public Object getAllAvailableFormsForVisit(HttpServletRequest request, @RequestParam("patientUuid") String patientUuid) { if (StringUtils.isBlank(patientUuid)) { return new ResponseEntity("You must specify patientUuid in the request!", new HttpHeaders(), HttpStatus.BAD_REQUEST); @@ -278,16 +275,15 @@ public Object getAllAvailableFormsForVisit(HttpServletRequest request, if (!uncompletedFormDescriptors.isEmpty()) { for (FormDescriptor descriptor : uncompletedFormDescriptors) { - if (!descriptor.getTarget().getRetired()) { + if(!descriptor.getTarget().getRetired()) { ObjectNode formObj = generateFormDescriptorPayload(descriptor); formObj.put("formCategory", "available"); formList.add(formObj); } } PatientWrapper patientWrapper = new PatientWrapper(patient); - Encounter lastMchEnrollment = patientWrapper.lastEncounter( - MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_ENROLLMENT)); - if (lastMchEnrollment != null) { + Encounter lastMchEnrollment = patientWrapper.lastEncounter(MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_ENROLLMENT)); + if(lastMchEnrollment != null) { ObjectNode delivery = JsonNodeFactory.instance.objectNode(); delivery.put("uuid", MCH_DELIVERY_FORM_UUID); delivery.put("name", "Delivery"); @@ -297,9 +293,8 @@ public Object getAllAvailableFormsForVisit(HttpServletRequest request, delivery.put("retired", false); formList.add(delivery); } - CalculationResult eligibleForDischarge = EmrCalculationUtils - .evaluateForPatient(EligibleForMchmsDischargeCalculation.class, null, patient); - if ((Boolean) eligibleForDischarge.getValue() == true) { + CalculationResult eligibleForDischarge = EmrCalculationUtils.evaluateForPatient(EligibleForMchmsDischargeCalculation.class, null, patient); + if((Boolean) eligibleForDischarge.getValue() == true) { ObjectNode discharge = JsonNodeFactory.instance.objectNode(); discharge.put("uuid", MCH_DISCHARGE_FORM_UUID); discharge.put("name", "Discharge"); @@ -319,7 +314,6 @@ public Object getAllAvailableFormsForVisit(HttpServletRequest request, /** * Gets a list of flags for a patient - * * @param request * @param patientUuid * @return @@ -327,8 +321,7 @@ public Object getAllAvailableFormsForVisit(HttpServletRequest request, @RequestMapping(method = RequestMethod.GET, value = "/flags") // gets all flags for a patient @ResponseBody @Cacheable(value = "patientFlagCache", key = "#patientUuid") - public Object getAllPatientFlags(HttpServletRequest request, @RequestParam("patientUuid") String patientUuid, - @SpringBean CalculationManager calculationManager) { + public Object getAllPatientFlags(HttpServletRequest request, @RequestParam("patientUuid") String patientUuid, @SpringBean CalculationManager calculationManager) { if (StringUtils.isBlank(patientUuid)) { return new ResponseEntity("You must specify patientUuid in the request!", new HttpHeaders(), HttpStatus.BAD_REQUEST); @@ -336,15 +329,14 @@ public Object getAllPatientFlags(HttpServletRequest request, @RequestParam("pati Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); ProgramWorkflowService service = Context.getProgramWorkflowService(); - List programEnrolmentHistory = service.getPatientPrograms(patient, null, null, null, null, null, - false); + List programEnrolmentHistory = service.getPatientPrograms(patient, null, null, null, null, null, false); if (patient == null) { return new ResponseEntity("The provided patient was not found in the system!", new HttpHeaders(), HttpStatus.NOT_FOUND); } - Map patientFlagsMap = new HashMap<>(); + Map patientFlagsMap = new HashMap<>(); ObjectNode flagsObj = JsonNodeFactory.instance.objectNode(); // TODO: Consider flags categorization for a patient who is not in any program @@ -356,35 +348,32 @@ public Object getAllPatientFlags(HttpServletRequest request, @RequestParam("pati CacheManager cacheManager = Context.getRegisteredComponent("apiCacheManager", CacheManager.class); Cache patientFlagCache = cacheManager.getCache("patientFlagCache"); List patientFlagsToRefreshOnEveryRequest = Arrays.asList( - "EligibleForIDSRFlagsCalculation"); + "EligibleForIDSRFlagsCalculation" + ); calculationManager.refresh(); /** * The patientFlagCache is implemented using a map of property and value pair. - * For flags, the property (the key), is the simple name of the flags - * calculation - * We append a special property of lastUpdated to keep track of the last updated - * time. + * For flags, the property (the key), is the simple name of the flags calculation + * We append a special property of lastUpdated to keep track of the last updated time. * We can use the property to check if certain flags need refresh or not * We only want to refresh flags which can change in the course of a visit */ if (patientFlagCache != null && patientFlagCache.get(patientUuid) != null) { - patientFlagsMap = (HashMap) cacheManager.getCache("patientFlagCache").get(patientUuid) - .get(); + patientFlagsMap = (HashMap) cacheManager.getCache("patientFlagCache").get(patientUuid).get(); for (PatientFlagCalculation calc : calculationManager.getFlagCalculations()) { - if (!(calc instanceof PatientFlagCalculation) - || !patientFlagsToRefreshOnEveryRequest.contains(calc.getClass().getSimpleName())) { + if (!(calc instanceof PatientFlagCalculation) || !patientFlagsToRefreshOnEveryRequest.contains(calc.getClass().getSimpleName())) { continue; } try { - CalculationResult result = Context.getService(PatientCalculationService.class) - .evaluate(patient.getId(), calc); + CalculationResult result = Context.getService(PatientCalculationService.class).evaluate(patient.getId(), calc); if (result != null && (Boolean) result.getValue()) { patientFlagsMap.put(calc.getClass().getSimpleName(), calc.getFlagMessage()); } - } catch (Exception ex) { + } + catch (Exception ex) { System.out.println("Error evaluating " + ex.getMessage()); log.error("Error evaluating " + calc.getClass(), ex); } @@ -396,8 +385,7 @@ public Object getAllPatientFlags(HttpServletRequest request, @RequestParam("pati return flagsObj.toString(); } - // define a hashmap of flag name and value for ease of update in other parts of - // the code + // define a hashmap of flag name and value for ease of update in other parts of the code for (PatientFlagCalculation calc : calculationManager.getFlagCalculations()) { if (!(calc instanceof PatientFlagCalculation)) { // we are only interested in flags calculation @@ -405,12 +393,12 @@ public Object getAllPatientFlags(HttpServletRequest request, @RequestParam("pati } try { - CalculationResult result = Context.getService(PatientCalculationService.class).evaluate(patient.getId(), - calc); + CalculationResult result = Context.getService(PatientCalculationService.class).evaluate(patient.getId(), calc); if (result != null && (Boolean) result.getValue()) { patientFlagsMap.put(calc.getClass().getSimpleName(), calc.getFlagMessage()); } - } catch (Exception ex) { + } + catch (Exception ex) { System.out.println("Error evaluating " + ex.getMessage()); log.error("Error evaluating " + calc.getClass(), ex); } @@ -428,16 +416,15 @@ public Object getAllPatientFlags(HttpServletRequest request, @RequestParam("pati /** * Prepares an array of flags from Patient flags map - * * @param flagsMap * @return */ - private ArrayNode composePatientFlagsFromMap(Map flagsMap) { + private ArrayNode composePatientFlagsFromMap(Map flagsMap) { ArrayNode flags = JsonNodeFactory.instance.arrayNode(); if (flagsMap.isEmpty()) { return flags; } - for (Map.Entry entry : flagsMap.entrySet()) { + for (Map.Entry entry : flagsMap.entrySet()) { if (entry.getKey().equalsIgnoreCase("lastUpdated")) { continue; } @@ -445,10 +432,8 @@ private ArrayNode composePatientFlagsFromMap(Map flagsMap) { } return flags; } - /** * Returns custom patient object - * * @param patientUuid * @return */ @@ -480,15 +465,13 @@ public Object getPatientIdByPatientUuid(@RequestParam("patientUuid") String pati /** * Returns regimen history for a patient - * - * @param category // ARV or TB + * @param category // ARV or TB * @param patientUuid * @return */ @RequestMapping(method = RequestMethod.GET, value = "/regimenHistory") @ResponseBody - public Object getRegimenHistory(@RequestParam("patientUuid") String patientUuid, - @RequestParam("category") String category) { + public Object getRegimenHistory(@RequestParam("patientUuid") String patientUuid, @RequestParam("category") String category) { ObjectNode regimenObj = JsonNodeFactory.instance.objectNode(); if (StringUtils.isBlank(patientUuid)) { return new ResponseEntity("You must specify patientUuid in the request!", @@ -504,8 +487,7 @@ public Object getRegimenHistory(@RequestParam("patientUuid") String patientUuid, ArrayNode regimenNode = JsonNodeFactory.instance.arrayNode(); List obshistory = EncounterBasedRegimenUtils.getRegimenHistoryFromObservations(patient, category); for (SimpleObject obj : obshistory) { - ObjectNode node = JsonNodeFactory.instance.objectNode(); - ; + ObjectNode node = JsonNodeFactory.instance.objectNode();; node.put("startDate", obj.get("startDate").toString()); node.put("endDate", obj.get("endDate").toString()); node.put("regimenShortDisplay", obj.get("regimenShortDisplay").toString()); @@ -530,12 +512,10 @@ public Object getRegimenHistory(@RequestParam("patientUuid") String patientUuid, @RequestMapping(method = RequestMethod.GET, value = "/default-facility") @ResponseBody public Object getDefaultConfiguredFacility() { - GlobalProperty gp = Context.getAdministrationService() - .getGlobalPropertyObject(EmrConstants.GP_DEFAULT_LOCATION); + GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(EmrConstants.GP_DEFAULT_LOCATION); if (gp == null) { - return new ResponseEntity("Default facility not configured!", new HttpHeaders(), - HttpStatus.NOT_FOUND); + return new ResponseEntity("Default facility not configured!", new HttpHeaders(), HttpStatus.NOT_FOUND); } Location location = (Location) gp.getValue(); @@ -550,24 +530,20 @@ public Object getDefaultConfiguredFacility() { @RequestMapping(method = RequestMethod.GET, value = "/sha-facility-status") @ResponseBody - public ResponseEntity getShaFacilityStatus( - @RequestParam(value = "synchronize", defaultValue = "false") boolean isSynchronize) { + public ResponseEntity getShaFacilityStatus(@RequestParam(value = "synchronize", defaultValue = "false") boolean isSynchronize) { FacilityStatusHandler facilityStatusHandler = new FacilityStatusHandler(); return fetchData(facilityStatusHandler, isSynchronize); } - @RequestMapping(method = RequestMethod.GET, value = "/sha-benefits-package") @ResponseBody - public ResponseEntity getShaBenefitsPackage( - @RequestParam(value = "synchronize", defaultValue = "false") boolean isSynchronize) { + public ResponseEntity getShaBenefitsPackage(@RequestParam(value = "synchronize", defaultValue = "false") boolean isSynchronize) { SHABenefitsPackageHandler shaBenefitsPackageHandler = new SHABenefitsPackageHandler(); return fetchData(shaBenefitsPackageHandler, isSynchronize); } @RequestMapping(method = RequestMethod.GET, value = "/sha-interventions") @ResponseBody - public ResponseEntity getShaInterventions( - @RequestParam(value = "synchronize", defaultValue = "false") boolean isSynchronize) { + public ResponseEntity getShaInterventions(@RequestParam(value = "synchronize", defaultValue = "false") boolean isSynchronize) { SHAInterventionsHandler shaInterventionsHandler = new SHAInterventionsHandler(); return fetchData(shaInterventionsHandler, isSynchronize); } @@ -580,30 +556,30 @@ private ResponseEntity fetchData(DataHandler handler, boolean isSynchron // Wrap the array in an ObjectNode if (data.isArray()) { ObjectNode responseWrapper = handler.getObjectMapper().createObjectNode(); - responseWrapper.put("data", data); // Embed the array under the "data" field - responseWrapper.put("source", "HIE"); // or "HIE" if synchronized + responseWrapper.put("data", data); // Embed the array under the "data" field + responseWrapper.put("source", "HIE"); // or "HIE" if synchronized return ResponseEntity.ok(responseWrapper.toString()); } // If data is already an ObjectNode, add the source property directly if (data instanceof ObjectNode) { - ((ObjectNode) data).put("source", "HIE"); // or "HIE" + ((ObjectNode) data).put("source", "HIE"); // or "HIE" } } else { data = handler.readFromLocalFile(); // Wrap the array in an ObjectNode if (data.isArray()) { ObjectNode responseWrapper = handler.getObjectMapper().createObjectNode(); - responseWrapper.put("data", data); // Embed the array under the "data" field - responseWrapper.put("source", "Local"); // or "HIE" if synchronized + responseWrapper.put("data", data); // Embed the array under the "data" field + responseWrapper.put("source", "Local"); // or "HIE" if synchronized return ResponseEntity.ok(responseWrapper.toString()); } // If data is already an ObjectNode, add the source property directly if (data instanceof ObjectNode) { - ((ObjectNode) data).put("source", "Local"); // or "HIE" + ((ObjectNode) data).put("source", "Local"); // or "HIE" } } if (data == null) { @@ -612,7 +588,6 @@ private ResponseEntity fetchData(DataHandler handler, boolean isSynchron return ResponseEntity.ok(data.toString()); } - /** * ARV drugs * @@ -643,9 +618,10 @@ public Object getArvDrugs() { concService.getConcept(74258), concService.getConcept(164967), concService.getConcept(168612), - concService.getConcept(84797)); + concService.getConcept(84797) + ); - for (Concept con : arvDrugs) { + for (Concept con: arvDrugs) { ObjectNode node = JsonNodeFactory.instance.objectNode(); node.put("name", con.getName() != null ? con.getName().toString() : ""); node.put("uuid", con.getUuid() != null ? con.getUuid().toString() : ""); @@ -659,7 +635,6 @@ public Object getArvDrugs() { /** * Gets the facility name given the facility code - * * @return */ @RequestMapping(method = RequestMethod.GET, value = "/facilityName") @@ -670,28 +645,24 @@ public Object getFacilityName(@RequestParam("facilityCode") String facilityCode) locationResponseObj.put("name", facility.getName()); return locationResponseObj; } - /** * Gets last hei outcome encounter - * * @return */ @RequestMapping(method = RequestMethod.GET, value = "/heiOutcomeEncounter") @ResponseBody public Object getHeiOutcomeEncounter(@RequestParam("patientUuid") String patientUuid) { SimpleObject heiOutcomeResponseObj = new SimpleObject(); - PatientIdentifierType heiNumber = MetadataUtils.existing(PatientIdentifierType.class, - MchMetadata._PatientIdentifierType.HEI_ID_NUMBER); - Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); + PatientIdentifierType heiNumber = MetadataUtils.existing(PatientIdentifierType.class, MchMetadata._PatientIdentifierType.HEI_ID_NUMBER); + Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); PatientIdentifier pi = heiNumber != null && patient != null ? patient.getPatientIdentifier(heiNumber) : null; - EncounterType heiOutcomeEncType = MetadataUtils.existing(EncounterType.class, - MchMetadata._EncounterType.MCHCS_HEI_COMPLETION); + EncounterType heiOutcomeEncType = MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHCS_HEI_COMPLETION); Form heiOutcomeForm = MetadataUtils.existing(Form.class, MchMetadata._Form.MCHCS_HEI_COMPLETION); Encounter lastHeiOutcomeEnc = EmrUtils.lastEncounter(patient, heiOutcomeEncType, heiOutcomeForm); - if (pi != null && pi.getIdentifier() != null) { + if(pi != null && pi.getIdentifier() != null) { heiOutcomeResponseObj.put("heiNumber", pi.getIdentifier()); } - if (lastHeiOutcomeEnc != null) { + if(lastHeiOutcomeEnc != null) { heiOutcomeResponseObj.put("heiOutcomeEncounterUuid", lastHeiOutcomeEnc.getUuid()); } return heiOutcomeResponseObj; @@ -699,13 +670,11 @@ public Object getHeiOutcomeEncounter(@RequestParam("patientUuid") String patient /** * Get a list of programs a patient is eligible for - * * @param request * @param patientUuid * @return */ - @RequestMapping(method = RequestMethod.GET, value = "/eligiblePrograms") // gets all programs a patient is eligible - // for + @RequestMapping(method = RequestMethod.GET, value = "/eligiblePrograms") // gets all programs a patient is eligible for @ResponseBody public Object getEligiblePrograms(HttpServletRequest request, @RequestParam("patientUuid") String patientUuid) { if (StringUtils.isBlank(patientUuid)) { @@ -731,8 +700,7 @@ public Object getEligiblePrograms(HttpServletRequest request, @RequestParam("pat programObj.put("uuid", descriptor.getTargetUuid()); programObj.put("display", descriptor.getTarget().getName()); programObj.put("enrollmentFormUuid", descriptor.getDefaultEnrollmentForm().getTargetUuid()); - if (descriptor.getDefaultCompletionForm() != null - && descriptor.getDefaultCompletionForm().getTargetUuid() != null) { + if(descriptor.getDefaultCompletionForm() != null && descriptor.getDefaultCompletionForm().getTargetUuid() != null) { programObj.put("discontinuationFormUuid", descriptor.getDefaultCompletionForm().getTargetUuid()); } @@ -743,16 +711,13 @@ public Object getEligiblePrograms(HttpServletRequest request, @RequestParam("pat return programList.toString(); } - /** * Gets the last regimen encounter uuid by category - * * @return */ @RequestMapping(method = RequestMethod.GET, value = "/lastRegimenEncounter") @ResponseBody - public Object getLastRegimenEncounterUuid(@RequestParam("category") String category, - @RequestParam("patientUuid") String patientUuid) { + public Object getLastRegimenEncounterUuid(@RequestParam("category") String category, @RequestParam("patientUuid") String patientUuid) { ObjectNode encObj = JsonNodeFactory.instance.objectNode(); ObjectNode node = JsonNodeFactory.instance.objectNode(); Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); @@ -771,8 +736,7 @@ public Object getLastRegimenEncounterUuid(@RequestParam("category") String categ for (Obs obs : enc.getObs()) { // ARV Treatment Plan Event - if (ARV_TREATMENT_PLAN_EVENT.equals(obs.getConcept().getUuid()) - && obs.getObsDatetime().equals(latest)) { + if (ARV_TREATMENT_PLAN_EVENT.equals(obs.getConcept().getUuid()) && obs.getObsDatetime().equals(latest)) { event = obs.getValueCoded() != null ? obs.getValueCoded().getName().getName() : ""; } @@ -793,9 +757,9 @@ public Object getLastRegimenEncounterUuid(@RequestParam("category") String categ return encObj.toString(); } + /** * Get a list of standard regimen - * * @param * @return * @throws IOException @@ -830,6 +794,7 @@ public Object getStandardRegimen() throws SAXException, IOException, ParserConfi String categoryCode = categoryElement.getAttribute("code"); categoryObj.put("categoryCode", categoryCode); + NodeList groupNodes = categoryElement.getElementsByTagName("group"); ArrayNode standardRegimen = JsonNodeFactory.instance.arrayNode(); @@ -841,24 +806,27 @@ public Object getStandardRegimen() throws SAXException, IOException, ParserConfi if (groupName.equalsIgnoreCase("Adult (first line)")) { regimenLineValue = "AF"; - } else if (groupName.equalsIgnoreCase("Adult (second line)")) { + }else if (groupName.equalsIgnoreCase("Adult (second line)")) { regimenLineValue = "AS"; - } else if (groupName.equalsIgnoreCase("Adult (third line)")) { + }else if (groupName.equalsIgnoreCase("Adult (third line)")) { regimenLineValue = "AT"; - } else if (groupName.equalsIgnoreCase("Child (First Line)")) { + }else if (groupName.equalsIgnoreCase("Child (First Line)")) { regimenLineValue = "CF"; - } else if (groupName.equalsIgnoreCase("Child (Second Line)")) { + }else if (groupName.equalsIgnoreCase("Child (Second Line)")) { regimenLineValue = "CS"; - } else if (groupName.equalsIgnoreCase("Child (Third Line)")) { + }else if (groupName.equalsIgnoreCase("Child (Third Line)")) { regimenLineValue = "CT"; - } else if (groupName.equalsIgnoreCase("Intensive Phase (Adult)")) { + }else if (groupName.equalsIgnoreCase("Intensive Phase (Adult)")) { regimenLineValue = "Intensive Phase (Adult)"; - } else if (groupName.equalsIgnoreCase("Intensive Phase (Child)")) { + }else if (groupName.equalsIgnoreCase("Intensive Phase (Child)")) { regimenLineValue = "Intensive Phase (Child)"; - } else if (groupName.equalsIgnoreCase("Continuation Phase (Adult)")) { + }else if (groupName.equalsIgnoreCase("Continuation Phase (Adult)")) { regimenLineValue = "Continuation Phase (Adult)"; } + + + standardRegimenObj.put("regimenline", groupName); standardRegimenObj.put("regimenLineValue", regimenLineValue); @@ -883,8 +851,7 @@ public Object getStandardRegimen() throws SAXException, IOException, ParserConfi } catch (Exception e) { e.printStackTrace(); - throw new RuntimeException( - "Unable to load " + configuration.getModuleId() + ":" + configuration.getDefinitionsPath(), e); + throw new RuntimeException("Unable to load " + configuration.getModuleId() + ":" + configuration.getDefinitionsPath(), e); } finally { try { if (stream != null) { @@ -896,14 +863,15 @@ public Object getStandardRegimen() throws SAXException, IOException, ParserConfi } } + resultsObj.put("results", standardRegimenCategories); return resultsObj.toString(); } + /** * Returns regimen change/stop reasons - * * @return */ @RequestMapping(method = RequestMethod.GET, value = "/regimenReason") @@ -955,6 +923,7 @@ public Object getRegimenReason() { tbReasonOptionsMap.put("Drug formulation changed", "1258AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); tbReasonOptionsMap.put("Patient lacks finance", "819AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); + ArrayNode tbReasons = JsonNodeFactory.instance.arrayNode(); for (Map.Entry entry : tbReasonOptionsMap.entrySet()) { ObjectNode tbCategoryReasonObj = JsonNodeFactory.instance.objectNode(); @@ -972,7 +941,6 @@ public Object getRegimenReason() { /** * Calculate z-score based on a client's sex, weight, and height - * * @param sex * @param weight * @param height @@ -980,13 +948,11 @@ public Object getRegimenReason() { */ @RequestMapping(method = RequestMethod.GET, value = "/zscore") @ResponseBody - public Object calculateZScore(@RequestParam("sex") String sex, @RequestParam("weight") Double weight, - @RequestParam("height") Double height) { + public Object calculateZScore(@RequestParam("sex") String sex, @RequestParam("weight") Double weight, @RequestParam("height") Double height) { ObjectNode resultNode = JsonNodeFactory.instance.objectNode(); - Integer result = ZScoreUtil.calculateZScore(height, weight, sex); + Integer result = ZScoreUtil.calculateZScore(height, weight, sex); - if (result < -4) { // this is an indication of an error. We can break it down further for - // appropriate messages + if (result < -4) { // this is an indication of an error. We can break it down further for appropriate messages return new ResponseEntity("Could not compute the zscore for the patient!", new HttpHeaders(), HttpStatus.NOT_FOUND); } @@ -1012,28 +978,25 @@ public Object getPatientHivCarePanel(@RequestParam("patientUuid") String patient SimpleObject tbResponseObj = new SimpleObject(); CalculationResult enrolledInHiv = EmrCalculationUtils.evaluateForPatient(HIVEnrollment.class, null, patient); - if ((Boolean) enrolledInHiv.getValue() == false) { - CalculationResult lastWhoStage = EmrCalculationUtils.evaluateForPatient(LastWhoStageCalculation.class, null, - patient); - if (lastWhoStage != null && lastWhoStage.getValue() != null) { + if((Boolean) enrolledInHiv.getValue() == false) { + CalculationResult lastWhoStage = EmrCalculationUtils.evaluateForPatient(LastWhoStageCalculation.class, null, patient); + if(lastWhoStage != null && lastWhoStage.getValue() != null) { hivResponseObj.put("whoStage", EmrUtils.whoStage(((Obs) lastWhoStage.getValue()).getValueCoded())); hivResponseObj.put("whoStageDate", formatDate(((Obs) lastWhoStage.getValue()).getObsDatetime())); } else { hivResponseObj.put("whoStage", ""); hivResponseObj.put("whoStageDate", ""); } - CalculationResult lastCd4 = EmrCalculationUtils.evaluateForPatient(LastCd4CountDateCalculation.class, null, - patient); - if (lastCd4 != null && lastCd4.getValue() != null) { + CalculationResult lastCd4 = EmrCalculationUtils.evaluateForPatient(LastCd4CountDateCalculation.class, null, patient); + if(lastCd4 != null && lastCd4.getValue() != null) { hivResponseObj.put("cd4", ((Obs) lastCd4.getValue()).getValueNumeric().toString()); hivResponseObj.put("cd4Date", formatDate(((Obs) lastCd4.getValue()).getObsDatetime())); } else { hivResponseObj.put("cd4", "None"); hivResponseObj.put("cd4Date", ""); } - CalculationResult lastCd4Percent = EmrCalculationUtils - .evaluateForPatient(LastCd4PercentageCalculation.class, null, patient); - if (lastCd4Percent != null && lastCd4Percent.getValue() != null) { + CalculationResult lastCd4Percent = EmrCalculationUtils.evaluateForPatient(LastCd4PercentageCalculation.class, null, patient); + if(lastCd4Percent != null && lastCd4Percent.getValue() != null) { hivResponseObj.put("cd4Percent", ((Obs) lastCd4Percent.getValue()).getValueNumeric().toString()); hivResponseObj.put("cd4PercentDate", formatDate(((Obs) lastCd4Percent.getValue()).getObsDatetime())); } else { @@ -1041,19 +1004,18 @@ public Object getPatientHivCarePanel(@RequestParam("patientUuid") String patient hivResponseObj.put("cd4PercentDate", ""); } - CalculationResult lastViralLoad = EmrCalculationUtils.evaluateForPatient(ViralLoadAndLdlCalculation.class, - null, patient); + CalculationResult lastViralLoad = EmrCalculationUtils.evaluateForPatient(ViralLoadAndLdlCalculation.class, null, patient); String valuesRequired = "None"; Date datesRequired = null; - if (!lastViralLoad.isEmpty()) { + if(!lastViralLoad.isEmpty()){ String values = lastViralLoad.getValue().toString(); - // split by brace - String value = values.replaceAll("\\{", "").replaceAll("\\}", ""); - // split by equal sign - if (!value.isEmpty()) { + //split by brace + String value = values.replaceAll("\\{", "").replaceAll("\\}",""); + //split by equal sign + if(!value.isEmpty()) { String[] splitByEqualSign = value.split("="); valuesRequired = splitByEqualSign[0]; - // for a date from a string + //for a date from a string String dateSplitedBySpace = splitByEqualSign[1].split(" ")[0].trim(); String yearPart = dateSplitedBySpace.split("-")[0].trim(); String monthPart = dateSplitedBySpace.split("-")[1].trim(); @@ -1084,38 +1046,31 @@ public Object getPatientHivCarePanel(@RequestParam("patientUuid") String patient } // tb details - CalculationResult patientEnrolledInTbProgram = EmrCalculationUtils - .evaluateForPatient(PatientInTbProgramCalculation.class, null, patient); - if ((Boolean) patientEnrolledInTbProgram.getValue() == true) { - CalculationResult tbDiseaseClassification = EmrCalculationUtils - .evaluateForPatient(TbDiseaseClassificationCalculation.class, null, patient); - if (tbDiseaseClassification != null && tbDiseaseClassification.getValue() != null) { - tbResponseObj.put("tbDiseaseClassification", - ((Obs) tbDiseaseClassification.getValue()).getValueCoded().getName().getName()); - tbResponseObj.put("tbDiseaseClassificationDate", - formatDate(((Obs) tbDiseaseClassification.getValue()).getObsDatetime())); + CalculationResult patientEnrolledInTbProgram = EmrCalculationUtils.evaluateForPatient(PatientInTbProgramCalculation.class, null,patient); + if((Boolean) patientEnrolledInTbProgram.getValue() == true) { + CalculationResult tbDiseaseClassification = EmrCalculationUtils.evaluateForPatient(TbDiseaseClassificationCalculation.class, null, patient); + if(tbDiseaseClassification != null && tbDiseaseClassification.getValue() != null) { + tbResponseObj.put("tbDiseaseClassification", ((Obs) tbDiseaseClassification.getValue()).getValueCoded().getName().getName()); + tbResponseObj.put("tbDiseaseClassificationDate", formatDate(((Obs) tbDiseaseClassification.getValue()).getObsDatetime())); } else { tbResponseObj.put("tbDiseaseClassification", "None"); tbResponseObj.put("tbDiseaseClassificationDate", ""); } - CalculationResult tbPatientClassification = EmrCalculationUtils - .evaluateForPatient(TbPatientClassificationCalculation.class, null, patient); + CalculationResult tbPatientClassification = EmrCalculationUtils.evaluateForPatient(TbPatientClassificationCalculation.class, null, patient); if (tbPatientClassification != null) { Obs obs = (Obs) tbPatientClassification.getValue(); if (obs != null && obs.getValueCoded() != null) { Concept valueCoded = obs.getValueCoded(); - String classification = valueCoded - .equals(Dictionary.getConcept(Dictionary.SMEAR_POSITIVE_NEW_TUBERCULOSIS_PATIENT)) - ? "New tuberculosis patient" - : valueCoded.getName().getName(); + String classification = valueCoded.equals(Dictionary.getConcept(Dictionary.SMEAR_POSITIVE_NEW_TUBERCULOSIS_PATIENT)) + ? "New tuberculosis patient" + : valueCoded.getName().getName(); tbResponseObj.put("tbPatientClassification", classification); } } - CalculationResult tbTreatmentNo = EmrCalculationUtils.evaluateForPatient(TbTreatmentNumberCalculation.class, - null, patient); - if (tbTreatmentNo != null && tbTreatmentNo.getValue() != null) { + CalculationResult tbTreatmentNo = EmrCalculationUtils.evaluateForPatient(TbTreatmentNumberCalculation.class, null, patient); + if(tbTreatmentNo != null && tbTreatmentNo.getValue() != null) { tbResponseObj.put("tbTreatmentNumber", ((Obs) tbTreatmentNo.getValue())); } else { tbResponseObj.put("tbTreatmentNumber", "None"); @@ -1129,23 +1084,19 @@ public Object getPatientHivCarePanel(@RequestParam("patientUuid") String patient carePanelObj.put("TB", tbResponseObj); } - // mch mother details - PatientCalculationContext context = Context.getService(PatientCalculationService.class) - .createCalculationContext(); + //mch mother details + PatientCalculationContext context = Context.getService(PatientCalculationService.class).createCalculationContext(); Program hivProgram = MetadataUtils.existing(Program.class, HivMetadata._Program.HIV); PatientWrapper patientWrapper = new PatientWrapper(patient); - Encounter lastMchEnrollment = patientWrapper.lastEncounter( - MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_ENROLLMENT)); - Encounter lastMchFollowup = patientWrapper.lastEncounter( - MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_CONSULTATION)); + Encounter lastMchEnrollment = patientWrapper.lastEncounter(MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_ENROLLMENT)); + Encounter lastMchFollowup = patientWrapper.lastEncounter(MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHMS_CONSULTATION)); - if (lastMchEnrollment != null) { + if(lastMchEnrollment != null ) { EncounterWrapper lastMchEnrollmentWrapped = null; EncounterWrapper lastMchFollowUpWrapped = null; - // Check whether already in hiv program - CalculationResultMap enrolled = Calculations.firstEnrollments(hivProgram, - Arrays.asList(patient.getPatientId()), context); + //Check whether already in hiv program + CalculationResultMap enrolled = Calculations.firstEnrollments(hivProgram, Arrays.asList(patient.getPatientId()), context); PatientProgram program = EmrCalculationUtils.resultForPatient(enrolled, patient.getPatientId()); if (lastMchEnrollment != null) { @@ -1159,21 +1110,18 @@ public Object getPatientHivCarePanel(@RequestParam("patientUuid") String patient Obs hivFollowUpStatusObs = null; if (lastMchEnrollmentWrapped != null) { - hivEnrollmentStatusObs = lastMchEnrollmentWrapped - .firstObs(Dictionary.getConcept(Dictionary.HIV_STATUS)); + hivEnrollmentStatusObs = lastMchEnrollmentWrapped.firstObs(Dictionary.getConcept(Dictionary.HIV_STATUS)); } if (lastMchFollowUpWrapped != null) { hivFollowUpStatusObs = lastMchFollowUpWrapped.firstObs(Dictionary.getConcept(Dictionary.HIV_STATUS)); } - // Check if already enrolled in HIV, add regimen - if (program != null) { + //Check if already enrolled in HIV, add regimen + if(program != null) { String regimenName = null; String regimenStartDate = null; - Encounter lastDrugRegimenEditorEncounter = EncounterBasedRegimenUtils - .getLastEncounterForCategory(patient, "ARV"); // last DRUG_REGIMEN_EDITOR encounter + Encounter lastDrugRegimenEditorEncounter = EncounterBasedRegimenUtils.getLastEncounterForCategory(patient, "ARV"); //last DRUG_REGIMEN_EDITOR encounter if (lastDrugRegimenEditorEncounter != null) { - SimpleObject o = EncounterBasedRegimenUtils.buildRegimenChangeObject( - lastDrugRegimenEditorEncounter.getAllObs(), lastDrugRegimenEditorEncounter); + SimpleObject o = EncounterBasedRegimenUtils.buildRegimenChangeObject(lastDrugRegimenEditorEncounter.getAllObs(), lastDrugRegimenEditorEncounter); regimenName = o.get("regimenShortDisplay").toString(); regimenStartDate = o.get("startDate").toString(); if (regimenName != null) { @@ -1188,22 +1136,20 @@ public Object getPatientHivCarePanel(@RequestParam("patientUuid") String patient mchMotherResponseObj.put("onHaartDate", regimenStartDate); } } - // Check mch enrollment and followup forms - } else if (hivEnrollmentStatusObs != null || hivFollowUpStatusObs != null) { + //Check mch enrollment and followup forms + } else if(hivEnrollmentStatusObs != null || hivFollowUpStatusObs != null) { String regimenName = null; - if (hivFollowUpStatusObs != null && hivFollowUpStatusObs.getValueCoded() != null) { + if(hivFollowUpStatusObs != null && hivFollowUpStatusObs.getValueCoded() != null) { mchMotherResponseObj.put("hivStatus", hivFollowUpStatusObs.getValueCoded().getName().getName()); mchMotherResponseObj.put("hivStatusDate", hivFollowUpStatusObs.getValueDatetime()); - } else { + }else { mchMotherResponseObj.put("hivStatus", hivEnrollmentStatusObs.getValueCoded().getName().getName()); mchMotherResponseObj.put("hivStatusDate", hivEnrollmentStatusObs.getValueDatetime()); } - Encounter lastDrugRegimenEditorEncounter = EncounterBasedRegimenUtils - .getLastEncounterForCategory(patient, "ARV"); // last DRUG_REGIMEN_EDITOR encounter + Encounter lastDrugRegimenEditorEncounter = EncounterBasedRegimenUtils.getLastEncounterForCategory(patient, "ARV"); //last DRUG_REGIMEN_EDITOR encounter mchMotherResponseObj.put("onHaart", hivEnrollmentStatusObs.getValueDatetime()); if (lastDrugRegimenEditorEncounter != null) { - SimpleObject o = EncounterBasedRegimenUtils.buildRegimenChangeObject( - lastDrugRegimenEditorEncounter.getAllObs(), lastDrugRegimenEditorEncounter); + SimpleObject o = EncounterBasedRegimenUtils.buildRegimenChangeObject(lastDrugRegimenEditorEncounter.getAllObs(), lastDrugRegimenEditorEncounter); regimenName = o.get("regimenShortDisplay").toString(); if (regimenName != null) { if (hivEnrollmentStatusObs.getValueCoded().getName().getName().equalsIgnoreCase("positive")) { @@ -1231,11 +1177,10 @@ public Object getPatientHivCarePanel(@RequestParam("patientUuid") String patient } - // mch child details - Encounter lastHeiEnrollmentEncounter = Utils.lastEncounter(patient, - Context.getEncounterService().getEncounterTypeByUuid(MchMetadata._EncounterType.MCHCS_ENROLLMENT)); + //mch child details + Encounter lastHeiEnrollmentEncounter = Utils.lastEncounter(patient, Context.getEncounterService().getEncounterTypeByUuid(MchMetadata._EncounterType.MCHCS_ENROLLMENT)); - if (lastHeiEnrollmentEncounter != null) { + if(lastHeiEnrollmentEncounter != null) { List milestones = new ArrayList(); String prophylaxis; String feeding; @@ -1244,17 +1189,14 @@ public Object getPatientHivCarePanel(@RequestParam("patientUuid") String patient Integer feedingMethodQuestion = 1151; Integer heiOutcomesQuestion = 159427; - EncounterType mchcs_consultation_encounterType = MetadataUtils.existing(EncounterType.class, - MchMetadata._EncounterType.MCHCS_CONSULTATION); + EncounterType mchcs_consultation_encounterType = MetadataUtils.existing(EncounterType.class, MchMetadata._EncounterType.MCHCS_CONSULTATION); Encounter lastMchcsConsultation = patientWrapper.lastEncounter(mchcs_consultation_encounterType); - Encounter lastHeiCWCFollowupEncounter = Utils.lastEncounter(patient, Context.getEncounterService() - .getEncounterTypeByUuid(MchMetadata._EncounterType.MCHCS_CONSULTATION)); - Encounter lastHeiOutComeEncounter = Utils.lastEncounter(patient, Context.getEncounterService() - .getEncounterTypeByUuid(MchMetadata._EncounterType.MCHCS_HEI_COMPLETION)); + Encounter lastHeiCWCFollowupEncounter = Utils.lastEncounter(patient, Context.getEncounterService().getEncounterTypeByUuid(MchMetadata._EncounterType.MCHCS_CONSULTATION)); + Encounter lastHeiOutComeEncounter = Utils.lastEncounter(patient, Context.getEncounterService().getEncounterTypeByUuid(MchMetadata._EncounterType.MCHCS_HEI_COMPLETION)); - if (lastHeiOutComeEncounter != null) { - for (Obs obs : lastHeiOutComeEncounter.getAllObs()) { + if(lastHeiOutComeEncounter !=null){ + for (Obs obs : lastHeiOutComeEncounter.getAllObs() ){ if (obs.getConcept().getConceptId().equals(heiOutcomesQuestion)) { heiOutcomes = obs.getValueCoded().getName().toString(); mchChildResponseObj.put("heiOutcome", heiOutcomes); @@ -1272,19 +1214,19 @@ public Object getPatientHivCarePanel(@RequestParam("patientUuid") String patient mchChildResponseObj.put("currentProphylaxisUsed", prophylaxis); mchChildResponseObj.put("currentProphylaxisUsedDate", obs.getValueDatetime()); } else if (heiProphylaxisObsAnswer.equals(80586)) { - prophylaxis = obs.getValueCoded().getName().toString(); + prophylaxis = obs.getValueCoded().getName().toString(); mchChildResponseObj.put("currentProphylaxisUsed", prophylaxis); mchChildResponseObj.put("currentProphylaxisUsedDate", obs.getValueDatetime()); } else if (heiProphylaxisObsAnswer.equals(1652)) { - prophylaxis = obs.getValueCoded().getName().toString(); + prophylaxis = obs.getValueCoded().getName().toString(); mchChildResponseObj.put("currentProphylaxisUsed", prophylaxis); mchChildResponseObj.put("currentProphylaxisUsedDate", obs.getValueDatetime()); } else if (heiProphylaxisObsAnswer.equals(1149)) { - prophylaxis = obs.getValueCoded().getName().toString(); + prophylaxis = obs.getValueCoded().getName().toString(); mchChildResponseObj.put("currentProphylaxisUsed", prophylaxis); mchChildResponseObj.put("currentProphylaxisUsedDate", obs.getValueDatetime()); } else if (heiProphylaxisObsAnswer.equals(1107)) { - prophylaxis = obs.getValueCoded().getName().toString(); + prophylaxis = obs.getValueCoded().getName().toString(); mchChildResponseObj.put("currentProphylaxisUsed", prophylaxis); mchChildResponseObj.put("currentProphylaxisUsedDate", obs.getValueDatetime()); } else { @@ -1321,13 +1263,12 @@ public Object getPatientHivCarePanel(@RequestParam("patientUuid") String patient if (lastMchcsConsultation != null) { EncounterWrapper mchcsConsultationWrapper = new EncounterWrapper(lastMchcsConsultation); - milestones.addAll( - mchcsConsultationWrapper.allObs(Dictionary.getConcept(Dictionary.DEVELOPMENTAL_MILESTONES))); + milestones.addAll(mchcsConsultationWrapper.allObs(Dictionary.getConcept(Dictionary.DEVELOPMENTAL_MILESTONES))); String joined = ""; if (milestones.size() > 0) { StringBuilder sb = new StringBuilder(); for (Obs milestone : milestones) { - if (milestone.getValueCoded() != null) { + if(milestone.getValueCoded() != null) { sb.append(milestone.getValueCoded().getName().toString()); sb.append(", "); } @@ -1347,9 +1288,7 @@ public Object getPatientHivCarePanel(@RequestParam("patientUuid") String patient } /** - * Generate payload for a form descriptor. Required when serving forms to the - * frontend - * + * Generate payload for a form descriptor. Required when serving forms to the frontend * @param descriptor * @return */ @@ -1395,8 +1334,7 @@ public ArrayList getPatientHistoricalEnrollment(@RequestParam("pat // Display active programs on top programs.addAll(activePrograms); - // Don't add duplicates for programs for which patient is both active and - // eligible + // Don't add duplicates for programs for which patient is both active and eligible for (ProgramDescriptor descriptor : eligiblePrograms) { if (!programs.contains(descriptor)) { programs.add(descriptor); @@ -1404,11 +1342,11 @@ public ArrayList getPatientHistoricalEnrollment(@RequestParam("pat } } ArrayList enrollmentDetails = new ArrayList(); - for (ProgramDescriptor descriptor : programs) { + for(ProgramDescriptor descriptor: programs) { Program program = descriptor.getTarget(); - Form defaultCompletionForm = null; + Form defaultCompletionForm = null ; Form defaultEnrollmentForm = descriptor.getDefaultEnrollmentForm().getTarget(); - if (descriptor.getDefaultCompletionForm() != null) { + if(descriptor.getDefaultCompletionForm()!= null) { defaultCompletionForm = descriptor.getDefaultCompletionForm().getTarget(); } @@ -1486,111 +1424,104 @@ public ArrayList getPatientHistoricalEnrollment(@RequestParam("pat programDetails.put("enrollmentFormUuid", HivMetadata._Form.HIV_ENROLLMENT); programDetails.put("enrollmentFormName", "HIV Enrollment"); } else - // tpt program - if (patientProgramEnrollment.getProgram().getUuid().equals(TPT_PROGRAM_UUID)) { - Enrollment tptEnrollment = new Enrollment(patientProgramEnrollment); - Encounter tptEnrollmentEncounter = tptEnrollment - .lastEncounter(defaultEnrollmentForm.getEncounterType()); - Encounter tptDiscontinuationEncounter = tptEnrollment - .lastEncounter(defaultCompletionForm.getEncounterType()); - - if (tptEnrollmentEncounter != null) { - for (Obs obs : tptEnrollmentEncounter.getAllObs(true)) { - if (obs.getConcept() - .equals(Dictionary.getConcept(Dictionary.INDICATION_FOR_TB_PROPHYLAXIS))) { - programDetails.put("tptIndication", obs.getValueCoded().getName().getName()); - break; + // tpt program + if (patientProgramEnrollment.getProgram().getUuid().equals(TPT_PROGRAM_UUID)) { + Enrollment tptEnrollment = new Enrollment(patientProgramEnrollment); + Encounter tptEnrollmentEncounter = tptEnrollment + .lastEncounter(defaultEnrollmentForm.getEncounterType()); + Encounter tptDiscontinuationEncounter = tptEnrollment + .lastEncounter(defaultCompletionForm.getEncounterType()); + + if (tptEnrollmentEncounter != null) { + for (Obs obs : tptEnrollmentEncounter.getAllObs(true)) { + if (obs.getConcept() + .equals(Dictionary.getConcept(Dictionary.INDICATION_FOR_TB_PROPHYLAXIS))) { + programDetails.put("tptIndication", obs.getValueCoded().getName().getName()); + break; + } } + programDetails.put("enrollmentEncounterUuid", tptEnrollmentEncounter.getUuid()); } - programDetails.put("enrollmentEncounterUuid", tptEnrollmentEncounter.getUuid()); - } - if (tptDiscontinuationEncounter != null) { - programDetails.put("discontinuationEncounterUuid", tptDiscontinuationEncounter.getUuid()); - } - try { - // get medication patient is on - CareSetting outpatient = Context.getOrderService().getCareSettingByName("OUTPATIENT"); // TODO: - // include - // all - // relevant - // care - // settings - OrderType drugOrderType = Context.getOrderService() - .getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID); - List allDrugOrders = Context.getOrderService().getOrders(patient, outpatient, - drugOrderType, false); - List tptDrugOrders = new ArrayList(); - for (Order order : allDrugOrders) { - if (order != null && order.getConcept() != null) { - ConceptName cn = order.getConcept().getName(CoreConstants.LOCALE); - if (cn != null && (cn.getUuid().equals(ISONIAZID_DRUG_UUID) - || cn.getUuid().equals(RIFAMPIN_ISONIAZID_DRUG_UUID))) { - tptDrugOrders.add((DrugOrder) order); + if (tptDiscontinuationEncounter != null) { + programDetails.put("discontinuationEncounterUuid", tptDiscontinuationEncounter.getUuid()); + } + try { + // get medication patient is on + CareSetting outpatient = Context.getOrderService().getCareSettingByName("OUTPATIENT"); // TODO: include all relevant care settings + OrderType drugOrderType = Context.getOrderService().getOrderTypeByUuid(OrderType.DRUG_ORDER_TYPE_UUID); + List allDrugOrders = Context.getOrderService().getOrders(patient, outpatient, drugOrderType, false); + List tptDrugOrders = new ArrayList(); + for (Order order : allDrugOrders) { + if (order != null && order.getConcept() != null) { + ConceptName cn = order.getConcept().getName(CoreConstants.LOCALE); + if (cn != null && (cn.getUuid().equals(ISONIAZID_DRUG_UUID) + || cn.getUuid().equals(RIFAMPIN_ISONIAZID_DRUG_UUID))) { + tptDrugOrders.add((DrugOrder) order); + } } } - } - if (!tptDrugOrders.isEmpty()) { + if (!tptDrugOrders.isEmpty()) { + + Collections.sort(tptDrugOrders, new Comparator() { + @Override + public int compare(DrugOrder order1, DrugOrder order2) { + return order2.getDateCreated().compareTo(order1.getDateCreated()); + } + }); + DrugOrder drugOrder = (DrugOrder) tptDrugOrders.get(0).cloneForRevision(); + // Now you can use the latestDrugOrder as needed + programDetails.put("tptDrugName", + drugOrder.getDrug() != null ? drugOrder.getDrug().getFullName(LOCALE) : ""); + programDetails.put("tptDrugStartDate", formatDate(drugOrder.getEffectiveStartDate())); + } + } catch (NullPointerException e) { + // Handle null pointer exception + e.printStackTrace(); - Collections.sort(tptDrugOrders, new Comparator() { - @Override - public int compare(DrugOrder order1, DrugOrder order2) { - return order2.getDateCreated().compareTo(order1.getDateCreated()); - } - }); - DrugOrder drugOrder = (DrugOrder) tptDrugOrders.get(0).cloneForRevision(); - // Now you can use the latestDrugOrder as needed - programDetails.put("tptDrugName", - drugOrder.getDrug() != null ? drugOrder.getDrug().getFullName(LOCALE) : ""); - programDetails.put("tptDrugStartDate", formatDate(drugOrder.getEffectiveStartDate())); + } catch (Exception e) { + e.printStackTrace(); } - } catch (NullPointerException e) { - // Handle null pointer exception - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - - programDetails.put("enrollmentFormUuid", IPTMetadata._Form.IPT_INITIATION); - programDetails.put("enrollmentFormName", "IPT Initiation"); - programDetails.put("discontinuationFormUuid", IPTMetadata._Form.IPT_OUTCOME); - programDetails.put("discontinuationFormName", "IPT Outcome"); - } else - // tb program - if (patientProgramEnrollment.getProgram().getUuid().equals(TB_PROGRAM_UUID)) { - Enrollment tbEnrollment = new Enrollment(patientProgramEnrollment); - Encounter tbEnrollmentEncounter = tbEnrollment - .lastEncounter(defaultEnrollmentForm.getEncounterType()); - Encounter tbDiscontinuationEncounter = tbEnrollment - .lastEncounter(defaultCompletionForm.getEncounterType()); + programDetails.put("enrollmentFormUuid", IPTMetadata._Form.IPT_INITIATION); + programDetails.put("enrollmentFormName", "IPT Initiation"); + programDetails.put("discontinuationFormUuid", IPTMetadata._Form.IPT_OUTCOME); + programDetails.put("discontinuationFormName", "IPT Outcome"); + } else + // tb program + if (patientProgramEnrollment.getProgram().getUuid().equals(TB_PROGRAM_UUID)) { + Enrollment tbEnrollment = new Enrollment(patientProgramEnrollment); + Encounter tbEnrollmentEncounter = tbEnrollment + .lastEncounter(defaultEnrollmentForm.getEncounterType()); + Encounter tbDiscontinuationEncounter = tbEnrollment + .lastEncounter(defaultCompletionForm.getEncounterType()); + + if (tbEnrollmentEncounter != null) { + for (Obs obs : tbEnrollmentEncounter.getAllObs(true)) { + if (obs.getConcept() + .equals(Dictionary.getConcept(Dictionary.REFERRING_CLINIC_OR_HOSPITAL))) { + programDetails.put("referredFrom", obs.getValueCoded().getName().getName()); + break; + } + } - if (tbEnrollmentEncounter != null) { - for (Obs obs : tbEnrollmentEncounter.getAllObs(true)) { - if (obs.getConcept() - .equals(Dictionary.getConcept(Dictionary.REFERRING_CLINIC_OR_HOSPITAL))) { - programDetails.put("referredFrom", obs.getValueCoded().getName().getName()); - break; + programDetails.put("enrollmentEncounterUuid", tbEnrollmentEncounter.getUuid()); + Encounter firstEnc = EncounterBasedRegimenUtils.getFirstEncounterForCategory(patient, "TB"); + SimpleObject firstEncDetails = null; + if (firstEnc != null) { + firstEncDetails = EncounterBasedRegimenUtils.buildRegimenChangeObject(firstEnc.getObs(), + firstEnc); + } + programDetails.put("firstEncounter", firstEncDetails); } + if (tbDiscontinuationEncounter != null) { + programDetails.put("discontinuationEncounterUuid", tbDiscontinuationEncounter.getUuid()); + } + programDetails.put("enrollmentFormUuid", TbMetadata._Form.TB_ENROLLMENT); + programDetails.put("enrollmentFormName", "TB Enrollment"); + programDetails.put("discontinuationFormUuid", TbMetadata._Form.TB_COMPLETION); + programDetails.put("discontinuationFormName", "TB Discontinuation"); } - programDetails.put("enrollmentEncounterUuid", tbEnrollmentEncounter.getUuid()); - Encounter firstEnc = EncounterBasedRegimenUtils.getFirstEncounterForCategory(patient, "TB"); - SimpleObject firstEncDetails = null; - if (firstEnc != null) { - firstEncDetails = EncounterBasedRegimenUtils.buildRegimenChangeObject(firstEnc.getObs(), - firstEnc); - } - programDetails.put("firstEncounter", firstEncDetails); - } - if (tbDiscontinuationEncounter != null) { - programDetails.put("discontinuationEncounterUuid", tbDiscontinuationEncounter.getUuid()); - } - programDetails.put("enrollmentFormUuid", TbMetadata._Form.TB_ENROLLMENT); - programDetails.put("enrollmentFormName", "TB Enrollment"); - programDetails.put("discontinuationFormUuid", TbMetadata._Form.TB_COMPLETION); - programDetails.put("discontinuationFormName", "TB Discontinuation"); - } - // mch mother program if (patientProgramEnrollment.getProgram().getUuid().equals(MCH_MOTHER_PROGRAM_UUID)) { Enrollment mchmEnrollment = new Enrollment(patientProgramEnrollment); @@ -1622,8 +1553,7 @@ public int compare(DrugOrder order1, DrugOrder order2) { programDetails.put("lmp", "N/A"); programDetails.put("eddLmp", "N/A"); } - } else if (obs.getConcept() - .equals(Dictionary.getConcept(Dictionary.EXPECTED_DATE_OF_DELIVERY))) { + } else if (obs.getConcept().equals(Dictionary.getConcept(Dictionary.EXPECTED_DATE_OF_DELIVERY))) { if (deliveryEncounter == null) { programDetails.put("eddUltrasound", formatDate(obs.getValueDate())); } @@ -1650,126 +1580,126 @@ public int compare(DrugOrder order1, DrugOrder order2) { programDetails.put("discontinuationFormName", "MCH-MS Discontinuation"); } else - // mch child program - if (patientProgramEnrollment.getProgram().getUuid().equals(MCH_CHILD_PROGRAM_UUID)) { - Enrollment mchcEnrollment = new Enrollment(patientProgramEnrollment); - Encounter mchcEnrollmentEncounter = mchcEnrollment - .lastEncounter(defaultEnrollmentForm.getEncounterType()); - Encounter mchcDiscontinuationEncounter = mchcEnrollment - .lastEncounter(defaultCompletionForm.getEncounterType()); - - if (mchcEnrollmentEncounter != null) { - for (Obs obs : mchcEnrollmentEncounter.getAllObs(true)) { - if (obs.getConcept().equals(Dictionary.getConcept(Dictionary.METHOD_OF_ENROLLMENT))) { - programDetails.put("entryPoint", entryPointAbbriviations(obs.getValueCoded())); - break; + // mch child program + if (patientProgramEnrollment.getProgram().getUuid().equals(MCH_CHILD_PROGRAM_UUID)) { + Enrollment mchcEnrollment = new Enrollment(patientProgramEnrollment); + Encounter mchcEnrollmentEncounter = mchcEnrollment + .lastEncounter(defaultEnrollmentForm.getEncounterType()); + Encounter mchcDiscontinuationEncounter = mchcEnrollment + .lastEncounter(defaultCompletionForm.getEncounterType()); + + if (mchcEnrollmentEncounter != null) { + for (Obs obs : mchcEnrollmentEncounter.getAllObs(true)) { + if (obs.getConcept().equals(Dictionary.getConcept(Dictionary.METHOD_OF_ENROLLMENT))) { + programDetails.put("entryPoint", entryPointAbbriviations(obs.getValueCoded())); + break; + } } + programDetails.put("enrollmentEncounterUuid", mchcEnrollmentEncounter.getUuid()); } - programDetails.put("enrollmentEncounterUuid", mchcEnrollmentEncounter.getUuid()); - } - if (mchcDiscontinuationEncounter != null) { - programDetails.put("discontinuationEncounterUuid", mchcDiscontinuationEncounter.getUuid()); - } - programDetails.put("enrollmentFormUuid", MchMetadata._Form.MCHCS_ENROLLMENT); - programDetails.put("enrollmentFormName", "Mch Child Enrolment Form"); - programDetails.put("discontinuationFormUuid", MchMetadata._Form.MCHCS_DISCONTINUATION); - programDetails.put("discontinuationFormName", "Child Welfare Services Discontinuation"); - } else - // otz program - if (patientProgramEnrollment.getProgram().getUuid().equals(OTZ_PROGRAM_UUID)) { - Enrollment otzEnrollment = new Enrollment(patientProgramEnrollment); - Encounter otzEnrollmentEncounter = otzEnrollment - .lastEncounter(defaultEnrollmentForm.getEncounterType()); - Encounter otzDiscontinuationEncounter = otzEnrollment - .lastEncounter(defaultCompletionForm.getEncounterType()); - - if (otzEnrollmentEncounter != null) { - programDetails.put("enrollmentEncounterUuid", otzEnrollmentEncounter.getUuid()); - } - if (otzDiscontinuationEncounter != null) { - programDetails.put("discontinuationEncounterUuid", otzDiscontinuationEncounter.getUuid()); - } - programDetails.put("enrollmentFormUuid", OTZMetadata._Form.OTZ_ENROLLMENT_FORM); - programDetails.put("enrollmentFormName", "OTZ Enrollment Form"); - programDetails.put("discontinuationFormUuid", OTZMetadata._Form.OTZ_DISCONTINUATION_FORM); - programDetails.put("discontinuationFormName", "OTZ Discontinuation Form"); - } else - // ovc program - if (patientProgramEnrollment.getProgram().getUuid().equals(OVC_PROGRAM_UUID)) { - Enrollment ovcEnrollment = new Enrollment(patientProgramEnrollment); - Encounter ovcEnrollmentEncounter = ovcEnrollment - .lastEncounter(defaultEnrollmentForm.getEncounterType()); - Encounter ovcDiscontinuationEncounter = ovcEnrollment - .lastEncounter(defaultCompletionForm.getEncounterType()); - - if (ovcEnrollmentEncounter != null) { - programDetails.put("enrollmentEncounterUuid", ovcEnrollmentEncounter.getUuid()); - } - if (ovcDiscontinuationEncounter != null) { - programDetails.put("discontinuationEncounterUuid", ovcDiscontinuationEncounter.getUuid()); - } - programDetails.put("enrollmentFormUuid", OVCMetadata._Form.OVC_ENROLLMENT_FORM); - programDetails.put("enrollmentFormName", "OVC Enrollment Form"); - programDetails.put("discontinuationFormUuid", OVCMetadata._Form.OVC_DISCONTINUATION_FORM); - programDetails.put("discontinuationFormName", "OVC Discontinuation Form"); - } else - // vmmc program - if (patientProgramEnrollment.getProgram().getUuid().equals(VMMC_PROGRAM_UUID)) { - Enrollment vmmcEnrollment = new Enrollment(patientProgramEnrollment); - Encounter vmmcEnrollmentEncounter = vmmcEnrollment - .lastEncounter(defaultEnrollmentForm.getEncounterType()); - Encounter vmmcDiscontinuationEncounter = vmmcEnrollment - .lastEncounter(defaultCompletionForm.getEncounterType()); - - if (vmmcEnrollmentEncounter != null) { - programDetails.put("enrollmentEncounterUuid", vmmcEnrollmentEncounter.getUuid()); - } - if (vmmcDiscontinuationEncounter != null) { - programDetails.put("discontinuationEncounterUuid", vmmcDiscontinuationEncounter.getUuid()); - } - programDetails.put("enrollmentFormUuid", VMMCMetadata._Form.VMMC_ENROLLMENT_FORM); - programDetails.put("enrollmentFormName", "VMMC Enrollment Form"); - programDetails.put("discontinuationFormUuid", VMMCMetadata._Form.VMMC_DISCONTINUATION_FORM); - programDetails.put("discontinuationFormName", "VMMC Discontinuation Form"); - } else - // prep program - if (patientProgramEnrollment.getProgram().getUuid().equals(PREP_PROGRAM_UUID)) { - Enrollment prepEnrollment = new Enrollment(patientProgramEnrollment); - Encounter prepEnrollmentEncounter = prepEnrollment - .lastEncounter(defaultEnrollmentForm.getEncounterType()); - Encounter prepDiscontinuationEncounter = prepEnrollment - .lastEncounter(defaultCompletionForm.getEncounterType()); - - if (prepEnrollmentEncounter != null) { - programDetails.put("enrollmentEncounterUuid", prepEnrollmentEncounter.getUuid()); - } - if (prepDiscontinuationEncounter != null) { - programDetails.put("discontinuationEncounterUuid", prepDiscontinuationEncounter.getUuid()); - } - programDetails.put("enrollmentFormUuid", PREP_ENROLLMENT_FORM); - programDetails.put("enrollmentFormName", "PrEP Enrollment"); - programDetails.put("discontinuationFormUuid", PREP_DISCONTINUATION_FORM); - programDetails.put("discontinuationFormName", "PrEP Client Discontinuation"); - } else - // kp program - if (patientProgramEnrollment.getProgram().getUuid().equals(KP_PROGRAM_UUID)) { - Enrollment kpEnrollment = new Enrollment(patientProgramEnrollment); - Encounter kpEnrollmentEncounter = kpEnrollment - .lastEncounter(defaultEnrollmentForm.getEncounterType()); - Encounter kpDiscontinuationEncounter = kpEnrollment - .lastEncounter(defaultCompletionForm.getEncounterType()); - - if (kpEnrollmentEncounter != null) { - programDetails.put("enrollmentEncounterUuid", kpEnrollmentEncounter.getUuid()); - } - if (kpDiscontinuationEncounter != null) { - programDetails.put("discontinuationEncounterUuid", kpDiscontinuationEncounter.getUuid()); - } - programDetails.put("enrollmentFormUuid", KP_CLIENT_ENROLMENT); - programDetails.put("enrollmentFormName", "KP Enrollment"); - programDetails.put("discontinuationFormUuid", KP_CLIENT_DISCONTINUATION); - programDetails.put("discontinuationFormName", "KP Discontinuation"); - } + if (mchcDiscontinuationEncounter != null) { + programDetails.put("discontinuationEncounterUuid", mchcDiscontinuationEncounter.getUuid()); + } + programDetails.put("enrollmentFormUuid", MchMetadata._Form.MCHCS_ENROLLMENT); + programDetails.put("enrollmentFormName", "Mch Child Enrolment Form"); + programDetails.put("discontinuationFormUuid", MchMetadata._Form.MCHCS_DISCONTINUATION); + programDetails.put("discontinuationFormName", "Child Welfare Services Discontinuation"); + } else + // otz program + if (patientProgramEnrollment.getProgram().getUuid().equals(OTZ_PROGRAM_UUID)) { + Enrollment otzEnrollment = new Enrollment(patientProgramEnrollment); + Encounter otzEnrollmentEncounter = otzEnrollment + .lastEncounter(defaultEnrollmentForm.getEncounterType()); + Encounter otzDiscontinuationEncounter = otzEnrollment + .lastEncounter(defaultCompletionForm.getEncounterType()); + + if (otzEnrollmentEncounter != null) { + programDetails.put("enrollmentEncounterUuid", otzEnrollmentEncounter.getUuid()); + } + if (otzDiscontinuationEncounter != null) { + programDetails.put("discontinuationEncounterUuid", otzDiscontinuationEncounter.getUuid()); + } + programDetails.put("enrollmentFormUuid", OTZMetadata._Form.OTZ_ENROLLMENT_FORM); + programDetails.put("enrollmentFormName", "OTZ Enrollment Form"); + programDetails.put("discontinuationFormUuid", OTZMetadata._Form.OTZ_DISCONTINUATION_FORM); + programDetails.put("discontinuationFormName", "OTZ Discontinuation Form"); + } else + // ovc program + if (patientProgramEnrollment.getProgram().getUuid().equals(OVC_PROGRAM_UUID)) { + Enrollment ovcEnrollment = new Enrollment(patientProgramEnrollment); + Encounter ovcEnrollmentEncounter = ovcEnrollment + .lastEncounter(defaultEnrollmentForm.getEncounterType()); + Encounter ovcDiscontinuationEncounter = ovcEnrollment + .lastEncounter(defaultCompletionForm.getEncounterType()); + + if (ovcEnrollmentEncounter != null) { + programDetails.put("enrollmentEncounterUuid", ovcEnrollmentEncounter.getUuid()); + } + if (ovcDiscontinuationEncounter != null) { + programDetails.put("discontinuationEncounterUuid", ovcDiscontinuationEncounter.getUuid()); + } + programDetails.put("enrollmentFormUuid", OVCMetadata._Form.OVC_ENROLLMENT_FORM); + programDetails.put("enrollmentFormName", "OVC Enrollment Form"); + programDetails.put("discontinuationFormUuid", OVCMetadata._Form.OVC_DISCONTINUATION_FORM); + programDetails.put("discontinuationFormName", "OVC Discontinuation Form"); + } else + // vmmc program + if (patientProgramEnrollment.getProgram().getUuid().equals(VMMC_PROGRAM_UUID)) { + Enrollment vmmcEnrollment = new Enrollment(patientProgramEnrollment); + Encounter vmmcEnrollmentEncounter = vmmcEnrollment + .lastEncounter(defaultEnrollmentForm.getEncounterType()); + Encounter vmmcDiscontinuationEncounter = vmmcEnrollment + .lastEncounter(defaultCompletionForm.getEncounterType()); + + if (vmmcEnrollmentEncounter != null) { + programDetails.put("enrollmentEncounterUuid", vmmcEnrollmentEncounter.getUuid()); + } + if (vmmcDiscontinuationEncounter != null) { + programDetails.put("discontinuationEncounterUuid", vmmcDiscontinuationEncounter.getUuid()); + } + programDetails.put("enrollmentFormUuid", VMMCMetadata._Form.VMMC_ENROLLMENT_FORM); + programDetails.put("enrollmentFormName", "VMMC Enrollment Form"); + programDetails.put("discontinuationFormUuid", VMMCMetadata._Form.VMMC_DISCONTINUATION_FORM); + programDetails.put("discontinuationFormName", "VMMC Discontinuation Form"); + } else + // prep program + if (patientProgramEnrollment.getProgram().getUuid().equals(PREP_PROGRAM_UUID)) { + Enrollment prepEnrollment = new Enrollment(patientProgramEnrollment); + Encounter prepEnrollmentEncounter = prepEnrollment + .lastEncounter(defaultEnrollmentForm.getEncounterType()); + Encounter prepDiscontinuationEncounter = prepEnrollment + .lastEncounter(defaultCompletionForm.getEncounterType()); + + if (prepEnrollmentEncounter != null) { + programDetails.put("enrollmentEncounterUuid", prepEnrollmentEncounter.getUuid()); + } + if (prepDiscontinuationEncounter != null) { + programDetails.put("discontinuationEncounterUuid", prepDiscontinuationEncounter.getUuid()); + } + programDetails.put("enrollmentFormUuid", PREP_ENROLLMENT_FORM); + programDetails.put("enrollmentFormName", "PrEP Enrollment"); + programDetails.put("discontinuationFormUuid", PREP_DISCONTINUATION_FORM); + programDetails.put("discontinuationFormName", "PrEP Client Discontinuation"); + } else + // kp program + if (patientProgramEnrollment.getProgram().getUuid().equals(KP_PROGRAM_UUID)) { + Enrollment kpEnrollment = new Enrollment(patientProgramEnrollment); + Encounter kpEnrollmentEncounter = kpEnrollment + .lastEncounter(defaultEnrollmentForm.getEncounterType()); + Encounter kpDiscontinuationEncounter = kpEnrollment + .lastEncounter(defaultCompletionForm.getEncounterType()); + + if (kpEnrollmentEncounter != null) { + programDetails.put("enrollmentEncounterUuid", kpEnrollmentEncounter.getUuid()); + } + if (kpDiscontinuationEncounter != null) { + programDetails.put("discontinuationEncounterUuid", kpDiscontinuationEncounter.getUuid()); + } + programDetails.put("enrollmentFormUuid", KP_CLIENT_ENROLMENT); + programDetails.put("enrollmentFormName", "KP Enrollment"); + programDetails.put("discontinuationFormUuid", KP_CLIENT_DISCONTINUATION); + programDetails.put("discontinuationFormName", "KP Discontinuation"); + } programDetails.put("programName", patientProgramEnrollment.getProgram().getName()); programDetails.put("active", patientProgramEnrollment.getActive()); @@ -2049,26 +1979,12 @@ public Object getPatientSummary(@RequestParam("patientUuid") String patientUuid) } // facility transferred form - CalculationResultMap transferInFacility = Calculations.lastObs( - Dictionary.getConcept(Dictionary.TRANSFER_FROM_FACILITY), - Arrays.asList(patient.getPatientId()), + CalculationResultMap transferInFacilty = Calculations.lastObs( + Dictionary.getConcept(Dictionary.TRANSFER_FROM_FACILITY), Arrays.asList(patient.getPatientId()), context); - - if (transferInFacility != null) { - Obs facilityObs = EmrCalculationUtils.obsResultForPatient(transferInFacility, patient.getPatientId()); - - if (facilityObs != null) { - String facilityUuid = facilityObs.getValueText(); - if (facilityUuid != null && !facilityUuid.isEmpty()) { - Location location = locationService.getLocationByUuid(facilityUuid); - patientSummary.put("transferInFacility", - location != null ? location.getName() : facilityUuid); - } else { - patientSummary.put("transferInFacility", ""); - } - } else { - patientSummary.put("transferInFacility", "N/A"); - } + Obs faciltyObs = EmrCalculationUtils.obsResultForPatient(transferInFacilty, patient.getPatientId()); + if (faciltyObs != null) { + patientSummary.put("transferInFacility", faciltyObs.getValueText() != null ? locationService.getLocationByUuid(faciltyObs.getValueText()).getName() : ""); } else { patientSummary.put("transferInFacility", "N/A"); } @@ -2185,140 +2101,120 @@ public Object getPatientSummary(@RequestParam("patientUuid") String patientUuid) } else { for (Obs obs : listOfAllergies) { if (obs != null) { - allergies += obs.getValueCoded().getName().getName() + " "; + allergies += obs.getValueCoded().getName().getName()+" "; } } patientSummary.put("allergies", allergies); } - // previous art details - CalculationResultMap previousArt = Calculations.lastObs(Dictionary.getConcept(Dictionary.PREVIOUS_ON_ART), - Arrays.asList(patient.getPatientId()), context); - Obs previousArtObs = EmrCalculationUtils.obsResultForPatient(previousArt, patient.getPatientId()); - if (previousArtObs != null && previousArtObs.getValueCoded() != null - && previousArtObs.getValueCoded().getConceptId() == 1 && previousArtObs.getVoided().equals(false)) { - patientSummary.put("previousArtStatus", "Yes"); - } else if (previousArtObs != null && previousArtObs.getValueCoded() != null - && previousArtObs.getValueCoded().getConceptId() == 2 && previousArtObs.getVoided().equals(false)) { + //previous art details + CalculationResultMap previousArt = Calculations.lastObs(Dictionary.getConcept(Dictionary.PREVIOUS_ON_ART), Arrays.asList(patient.getPatientId()), context); + Obs previousArtObs = EmrCalculationUtils.obsResultForPatient(previousArt,patient.getPatientId()); + if (previousArtObs != null && previousArtObs.getValueCoded() != null && previousArtObs.getValueCoded().getConceptId() == 1 && previousArtObs.getVoided().equals(false)) { + patientSummary.put("previousArtStatus","Yes"); + } else if (previousArtObs != null && previousArtObs.getValueCoded() != null && previousArtObs.getValueCoded().getConceptId() == 2 && previousArtObs.getVoided().equals(false)) { patientSummary.put("previousArtStatus", "No"); } else { patientSummary.put("previousArtStatus", "None"); } - // set the purpose for previous art - CalculationResultMap previousArtPurposePmtct = Calculations.lastObs( - Dictionary.getConcept(Dictionary.PREVIOUS_ON_ART_PURPOSE_PMTCT), Arrays.asList(patient.getPatientId()), - context); - CalculationResultMap previousArtPurposePep = Calculations.lastObs( - Dictionary.getConcept(Dictionary.PREVIOUS_ON_ART_PURPOSE_PEP), Arrays.asList(patient.getPatientId()), - context); - CalculationResultMap previousArtPurposeHaart = Calculations.lastObs( - Dictionary.getConcept(Dictionary.PREVIOUS_ON_ART_PURPOSE_HAART), Arrays.asList(patient.getPatientId()), - context); - Obs previousArtPurposePmtctObs = EmrCalculationUtils.obsResultForPatient(previousArtPurposePmtct, - patient.getPatientId()); - Obs previousArtPurposePepObs = EmrCalculationUtils.obsResultForPatient(previousArtPurposePep, - patient.getPatientId()); - Obs previousArtPurposeHaartObs = EmrCalculationUtils.obsResultForPatient(previousArtPurposeHaart, - patient.getPatientId()); + //set the purpose for previous art + CalculationResultMap previousArtPurposePmtct = Calculations.lastObs(Dictionary.getConcept(Dictionary.PREVIOUS_ON_ART_PURPOSE_PMTCT), Arrays.asList(patient.getPatientId()), context); + CalculationResultMap previousArtPurposePep = Calculations.lastObs(Dictionary.getConcept(Dictionary.PREVIOUS_ON_ART_PURPOSE_PEP), Arrays.asList(patient.getPatientId()), context); + CalculationResultMap previousArtPurposeHaart = Calculations.lastObs(Dictionary.getConcept(Dictionary.PREVIOUS_ON_ART_PURPOSE_HAART), Arrays.asList(patient.getPatientId()), context); + Obs previousArtPurposePmtctObs = EmrCalculationUtils.obsResultForPatient(previousArtPurposePmtct, patient.getPatientId()); + Obs previousArtPurposePepObs = EmrCalculationUtils.obsResultForPatient(previousArtPurposePep, patient.getPatientId()); + Obs previousArtPurposeHaartObs = EmrCalculationUtils.obsResultForPatient(previousArtPurposeHaart, patient.getPatientId()); String purposeString = ""; - if (patientSummary.get("previousArtStatus").equals("None") - || patientSummary.get("previousArtStatus").equals("No")) { - purposeString = "None"; + if(patientSummary.get("previousArtStatus").equals("None") || patientSummary.get("previousArtStatus").equals("No")){ + purposeString ="None"; } - if (previousArtPurposePmtctObs != null && previousArtPurposePmtctObs.getValueCoded() != null) { - purposeString += previousArtReason(previousArtPurposePmtctObs.getConcept()); + if(previousArtPurposePmtctObs != null && previousArtPurposePmtctObs.getValueCoded() != null) { + purposeString +=previousArtReason(previousArtPurposePmtctObs.getConcept()); } - if (previousArtPurposePepObs != null && previousArtPurposePepObs.getValueCoded() != null) { - purposeString += " " + previousArtReason(previousArtPurposePepObs.getConcept()); + if(previousArtPurposePepObs != null && previousArtPurposePepObs.getValueCoded() != null){ + purposeString += " "+previousArtReason(previousArtPurposePepObs.getConcept()); } - if (previousArtPurposeHaartObs != null && previousArtPurposeHaartObs.getValueCoded() != null) { - purposeString += " " + previousArtReason(previousArtPurposeHaartObs.getConcept()); + if(previousArtPurposeHaartObs != null && previousArtPurposeHaartObs.getValueCoded() != null){ + purposeString +=" "+ previousArtReason(previousArtPurposeHaartObs.getConcept()); } patientSummary.put("artPurpose", purposeString); - // art start date - CalculationResult artStartDateResults = EmrCalculationUtils - .evaluateForPatient(InitialArtStartDateCalculation.class, null, patient); - if (artStartDateResults != null) { + //art start date + CalculationResult artStartDateResults = EmrCalculationUtils.evaluateForPatient(InitialArtStartDateCalculation.class, null, patient); + if(artStartDateResults != null) { patientSummary.put("dateStartedArt", formatDate((Date) artStartDateResults.getValue())); - } else { + } + else { patientSummary.put("dateStartedArt", ""); } - // Clinical stage at art start - CalculationResult whoStageAtArtStartResults = EmrCalculationUtils - .evaluateForPatient(WhoStageAtArtStartCalculation.class, null, patient); - if (whoStageAtArtStartResults != null) { + //Clinical stage at art start + CalculationResult whoStageAtArtStartResults = EmrCalculationUtils.evaluateForPatient(WhoStageAtArtStartCalculation.class, null,patient); + if(whoStageAtArtStartResults != null){ patientSummary.put("whoStageAtArtStart", intergerToRoman(whoStageAtArtStartResults.getValue().toString())); - } else { + } + else { patientSummary.put("whoStageAtArtStart", ""); } - // cd4 at art initiation - CalculationResult cd4AtArtStartResults = EmrCalculationUtils - .evaluateForPatient(CD4AtARTInitiationCalculation.class, null, patient); - if (cd4AtArtStartResults != null) { + //cd4 at art initiation + CalculationResult cd4AtArtStartResults = EmrCalculationUtils.evaluateForPatient(CD4AtARTInitiationCalculation.class, null,patient); + if(cd4AtArtStartResults != null){ patientSummary.put("cd4AtArtStart", cd4AtArtStartResults.getValue().toString()); - } else { + } + else { patientSummary.put("cd4AtArtStart", ""); } - // bmi - CalculationResult bmiResults = EmrCalculationUtils.evaluateForPatient(BMICalculation.class, null, patient); - if (bmiResults != null) { + //bmi + CalculationResult bmiResults = EmrCalculationUtils.evaluateForPatient(BMICalculation.class, null,patient); + if(bmiResults != null){ patientSummary.put("bmi", bmiResults.getValue().toString()); - } else { + } + else { patientSummary.put("bmi", ""); } - // first regimen for the patient + //first regimen for the patient Encounter firstEnc = EncounterBasedRegimenUtils.getFirstEncounterForCategory(patient, "ARV"); - if (firstEnc != null) { - patientSummary.put("firstRegimen", - EncounterBasedRegimenUtils.buildRegimenChangeObject(firstEnc.getObs(), firstEnc)); + if(firstEnc != null) { + patientSummary.put("firstRegimen", EncounterBasedRegimenUtils.buildRegimenChangeObject(firstEnc.getObs(), firstEnc)); } - // previous drugs/regimens and dates + //previous drugs/regimens and dates String regimens = ""; String regimenDates = ""; - CalculationResultMap pmtctRegimenHivEnroll = Calculations.lastObs( - Dictionary.getConcept(Dictionary.PMTCT_REGIMEN_HIV_ENROLL), Arrays.asList(patient.getPatientId()), - context); - CalculationResultMap pepAndHaartRegimenHivEnroll = Calculations.allObs( - Dictionary.getConcept(Dictionary.PEP_REGIMEN_HIV_ENROLL), Arrays.asList(patient.getPatientId()), - context); + CalculationResultMap pmtctRegimenHivEnroll = Calculations.lastObs(Dictionary.getConcept(Dictionary.PMTCT_REGIMEN_HIV_ENROLL), Arrays.asList(patient.getPatientId()), context); + CalculationResultMap pepAndHaartRegimenHivEnroll = Calculations.allObs(Dictionary.getConcept(Dictionary.PEP_REGIMEN_HIV_ENROLL), Arrays.asList(patient.getPatientId()), context); Obs obsPmtctHivEnroll = EmrCalculationUtils.obsResultForPatient(pmtctRegimenHivEnroll, patient.getPatientId()); ListResult listResults = (ListResult) pepAndHaartRegimenHivEnroll.get(patient.getPatientId()); List pepAndHaartRegimenObsList = CalculationUtils.extractResultValues(listResults); - if (patientSummary.get("previousArtStatus").equals("None") - || patientSummary.get("previousArtStatus").equals("No")) { + if(patientSummary.get("previousArtStatus").equals("None") || patientSummary.get("previousArtStatus").equals("No")){ regimens = "None"; regimenDates += "None"; } - if (obsPmtctHivEnroll != null) { + if(obsPmtctHivEnroll != null){ regimens = getCorrectDrugCode(obsPmtctHivEnroll.getValueCoded()); regimenDates = formatDate(obsPmtctHivEnroll.getObsDatetime()); } - if (pepAndHaartRegimenObsList != null && !pepAndHaartRegimenObsList.isEmpty() - && pepAndHaartRegimenObsList.size() == 1) { - regimens = getCorrectDrugCode(pepAndHaartRegimenObsList.get(0).getValueCoded()); - regimenDates = formatDate(pepAndHaartRegimenObsList.get(0).getObsDatetime()); - } else if (pepAndHaartRegimenObsList != null && !pepAndHaartRegimenObsList.isEmpty() - && pepAndHaartRegimenObsList.size() > 1) { - for (Obs obs : pepAndHaartRegimenObsList) { - regimens += getCorrectDrugCode(obs.getValueCoded()) + ","; - regimenDates = formatDate(obs.getObsDatetime()); + if(pepAndHaartRegimenObsList != null && !pepAndHaartRegimenObsList.isEmpty() && pepAndHaartRegimenObsList.size() == 1){ + regimens =getCorrectDrugCode(pepAndHaartRegimenObsList.get(0).getValueCoded()); + regimenDates =formatDate(pepAndHaartRegimenObsList.get(0).getObsDatetime()); + } + else if(pepAndHaartRegimenObsList != null && !pepAndHaartRegimenObsList.isEmpty() && pepAndHaartRegimenObsList.size() > 1){ + for(Obs obs:pepAndHaartRegimenObsList) { + regimens +=getCorrectDrugCode(obs.getValueCoded())+","; + regimenDates =formatDate(obs.getObsDatetime()); } } - // past or current oisg - CalculationResultMap problemsAdded = Calculations.allObs(Dictionary.getConcept(Dictionary.PROBLEM_ADDED), - Arrays.asList(patient.getPatientId()), context); + //past or current oisg + CalculationResultMap problemsAdded = Calculations.allObs(Dictionary.getConcept(Dictionary.PROBLEM_ADDED), Arrays.asList(patient.getPatientId()), context); ListResult problemsAddedList = (ListResult) problemsAdded.get(patient.getPatientId()); List problemsAddedListObs = CalculationUtils.extractResultValues(problemsAddedList); @@ -2340,205 +2236,176 @@ public Object getPatientSummary(@RequestParam("patientUuid") String patientUuid) } patientSummary.put("iosResults", iosResults); - // current art regimen + //current art regimen Encounter lastEnc = EncounterBasedRegimenUtils.getLastEncounterForCategory(patient, "ARV"); - if (lastEnc != null) { - patientSummary.put("currentArtRegimen", - EncounterBasedRegimenUtils.buildRegimenChangeObject(lastEnc.getObs(), lastEnc)); + if(lastEnc != null) { + patientSummary.put("currentArtRegimen", EncounterBasedRegimenUtils.buildRegimenChangeObject(lastEnc.getObs(), lastEnc)); } - // current who staging - CalculationResult currentWhoStaging = EmrCalculationUtils.evaluateForPatient(LastWhoStageCalculation.class, - null, patient); - if (currentWhoStaging != null) { + //current who staging + CalculationResult currentWhoStaging = EmrCalculationUtils.evaluateForPatient(LastWhoStageCalculation.class, null, patient); + if(currentWhoStaging != null){ patientSummary.put("currentWhoStaging", whoStaging(((Obs) currentWhoStaging.getValue()).getValueCoded())); - } else { + } + else { patientSummary.put("currentWhoStaging", ""); } - // find whether this patient has been in CTX - CalculationResultMap medOrdersMapCtx = Calculations.allObs(Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), - Arrays.asList(patient.getPatientId()), context); - CalculationResultMap medicationDispensedCtx = Calculations.lastObs( - Dictionary.getConcept(Dictionary.COTRIMOXAZOLE_DISPENSED), Arrays.asList(patient.getPatientId()), - context); + //find whether this patient has been in CTX + CalculationResultMap medOrdersMapCtx = Calculations.allObs(Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), Arrays.asList(patient.getPatientId()), context); + CalculationResultMap medicationDispensedCtx = Calculations.lastObs(Dictionary.getConcept(Dictionary.COTRIMOXAZOLE_DISPENSED), Arrays.asList(patient.getPatientId()), context); ListResult medOrdersMapListResults = (ListResult) medOrdersMapCtx.get(patient.getPatientId()); List listOfObsCtx = CalculationUtils.extractResultValues(medOrdersMapListResults); - Obs medicationDispensedCtxObs = EmrCalculationUtils.obsResultForPatient(medicationDispensedCtx, - patient.getPatientId()); + Obs medicationDispensedCtxObs = EmrCalculationUtils.obsResultForPatient(medicationDispensedCtx, patient.getPatientId()); String ctxValue = ""; - if (listOfObsCtx.size() > 0) { + if(listOfObsCtx.size() > 0){ Collections.reverse(listOfObsCtx); - for (Obs obs : listOfObsCtx) { - if (obs.getValueCoded().equals(Dictionary.getConcept(Dictionary.SULFAMETHOXAZOLE_TRIMETHOPRIM))) { + for(Obs obs:listOfObsCtx){ + if(obs.getValueCoded().equals(Dictionary.getConcept(Dictionary.SULFAMETHOXAZOLE_TRIMETHOPRIM))){ ctxValue = "Yes"; break; } } patientSummary.put("ctxValue", ctxValue); - } else if (medicationDispensedCtxObs != null - && medicationDispensedCtxObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.YES))) { + } + else if(medicationDispensedCtxObs != null && medicationDispensedCtxObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.YES))){ patientSummary.put("ctxValue", "Yes"); - } else if (medicationDispensedCtxObs != null - && medicationDispensedCtxObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.NO))) { + } + else if(medicationDispensedCtxObs != null && medicationDispensedCtxObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.NO))){ patientSummary.put("ctxValue", "No"); - } else if (medicationDispensedCtxObs != null - && medicationDispensedCtxObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE))) { + } + else if(medicationDispensedCtxObs != null && medicationDispensedCtxObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE))){ patientSummary.put("ctxValue", "N/A"); - } else { + } + else { patientSummary.put("ctxValue", "No"); } - // Find if a patient is on dapsone - CalculationResultMap medOrdersMapDapsone = Calculations.lastObs( - Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), Arrays.asList(patient.getPatientId()), context); - Obs medOrdersMapObsDapsone = EmrCalculationUtils.obsResultForPatient(medOrdersMapDapsone, - patient.getPatientId()); - if (medOrdersMapObsDapsone != null - && medOrdersMapObsDapsone.getValueCoded().equals(Dictionary.getConcept(Dictionary.DAPSONE))) { + //Find if a patient is on dapsone + CalculationResultMap medOrdersMapDapsone = Calculations.lastObs(Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), Arrays.asList(patient.getPatientId()), context); + Obs medOrdersMapObsDapsone = EmrCalculationUtils.obsResultForPatient(medOrdersMapDapsone, patient.getPatientId()); + if(medOrdersMapObsDapsone != null && medOrdersMapObsDapsone.getValueCoded().equals(Dictionary.getConcept(Dictionary.DAPSONE))){ patientSummary.put("dapsone", "Yes"); - } else if (medOrdersMapObsDapsone != null - && medOrdersMapObsDapsone.getValueCoded() - .equals(Dictionary.getConcept(Dictionary.SULFAMETHOXAZOLE_TRIMETHOPRIM)) - || medicationDispensedCtxObs != null - && medicationDispensedCtxObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.YES))) { + } + else if(medOrdersMapObsDapsone != null && medOrdersMapObsDapsone.getValueCoded().equals(Dictionary.getConcept(Dictionary.SULFAMETHOXAZOLE_TRIMETHOPRIM)) || medicationDispensedCtxObs != null && medicationDispensedCtxObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.YES))){ patientSummary.put("dapsone", "No"); - } else { + } + else { patientSummary.put("dapsone", "No"); } - // on IPT - CalculationResultMap medOrdersMapInh = Calculations.lastObs(Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), - Arrays.asList(patient.getPatientId()), context); + //on IPT + CalculationResultMap medOrdersMapInh = Calculations.lastObs(Dictionary.getConcept(Dictionary.MEDICATION_ORDERS), Arrays.asList(patient.getPatientId()), context); Obs medOrdersMapObsInh = EmrCalculationUtils.obsResultForPatient(medOrdersMapInh, patient.getPatientId()); - CalculationResultMap medicationDispensedIpt = Calculations.lastObs( - Dictionary.getConcept(Dictionary.ISONIAZID_DISPENSED), Arrays.asList(patient.getPatientId()), context); - Obs medicationDispensedIptObs = EmrCalculationUtils.obsResultForPatient(medicationDispensedIpt, - patient.getPatientId()); - if (medOrdersMapObsInh != null - && medOrdersMapObsInh.getValueCoded().equals(Dictionary.getConcept(Dictionary.ISONIAZID))) { + CalculationResultMap medicationDispensedIpt = Calculations.lastObs(Dictionary.getConcept(Dictionary.ISONIAZID_DISPENSED), Arrays.asList(patient.getPatientId()), context); + Obs medicationDispensedIptObs = EmrCalculationUtils.obsResultForPatient(medicationDispensedIpt, patient.getPatientId()); + if(medOrdersMapObsInh != null && medOrdersMapObsInh.getValueCoded().equals(Dictionary.getConcept(Dictionary.ISONIAZID))){ patientSummary.put("onIpt", "Yes"); - } else if (medicationDispensedIptObs != null - && medicationDispensedIptObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.YES))) { + } + else if(medicationDispensedIptObs != null && medicationDispensedIptObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.YES))){ patientSummary.put("onIpt", "Yes"); - } else if (medicationDispensedIptObs != null - && medicationDispensedIptObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.NO))) { + } + else if(medicationDispensedIptObs != null && medicationDispensedIptObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.NO))){ patientSummary.put("onIpt", "No"); - } else if (medicationDispensedIptObs != null - && medicationDispensedIptObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE))) { + } + else if(medicationDispensedIptObs != null && medicationDispensedIptObs.getValueCoded().equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE))){ patientSummary.put("onIpt", "N/A"); - } else { + } + else { patientSummary.put("onIpt", "No"); } - // find clinics enrolled - CalculationResult clinicsEnrolledResult = EmrCalculationUtils - .evaluateForPatient(PatientProgramEnrollmentCalculation.class, null, patient); - Set patientProgramList = new HashSet(); + //find clinics enrolled + CalculationResult clinicsEnrolledResult = EmrCalculationUtils.evaluateForPatient(PatientProgramEnrollmentCalculation.class, null, patient); + Set patientProgramList= new HashSet(); List setToList = new ArrayList(); - if (clinicsEnrolledResult != null) { + if(clinicsEnrolledResult != null){ List patientPrograms = (List) clinicsEnrolledResult.getValue(); - for (PatientProgram p : patientPrograms) { + for(PatientProgram p: patientPrograms) { patientProgramList.add(programs(p.getProgram().getConcept().getConceptId())); } } setToList.addAll(patientProgramList); String clinicValues = ""; - if (setToList.size() == 1) { + if(setToList.size() == 1){ clinicValues = setToList.get(0); - } else { - for (String val : setToList) { - clinicValues += val + ","; + } + else { + for(String val:setToList) { + clinicValues += val+","; } } patientSummary.put("clinicsEnrolled", clinicValues); - // most recent cd4 - CalculationResult cd4Results = EmrCalculationUtils.evaluateForPatient(LastCd4CountDateCalculation.class, null, - patient); - if (cd4Results != null && cd4Results.getValue() != null) { - patientSummary.put("mostRecentCd4", ((Obs) cd4Results.getValue()).getValueNumeric().toString()); + //most recent cd4 + CalculationResult cd4Results = EmrCalculationUtils.evaluateForPatient(LastCd4CountDateCalculation.class, null, patient); + if(cd4Results != null && cd4Results.getValue() != null){ + patientSummary.put("mostRecentCd4",((Obs) cd4Results.getValue()).getValueNumeric().toString()); patientSummary.put("mostRecentCd4Date", formatDate(((Obs) cd4Results.getValue()).getObsDatetime())); - } else { + } + else{ patientSummary.put("mostRecentCd4", ""); patientSummary.put("mostRecentCd4Date", ""); } + + // find deceased date - CalculationResult deadResults = EmrCalculationUtils.evaluateForPatient(DateOfDeathCalculation.class, null, - patient); - if (deadResults.isEmpty()) { + CalculationResult deadResults = EmrCalculationUtils.evaluateForPatient(DateOfDeathCalculation.class, null, patient); + if(deadResults.isEmpty()){ patientSummary.put("deathDate", "N/A"); - } else { + } + else { patientSummary.put("deathDate", formatDate((Date) deadResults.getValue())); } // next appointment date - CalculationResult returnVisitResults = EmrCalculationUtils - .evaluateForPatient(LastReturnVisitDateCalculation.class, null, patient); - if (returnVisitResults != null) { + CalculationResult returnVisitResults = EmrCalculationUtils.evaluateForPatient(LastReturnVisitDateCalculation.class, null, patient); + if(returnVisitResults != null){ patientSummary.put("nextAppointmentDate", formatDate((Date) returnVisitResults.getValue())); - } else { + } + else { patientSummary.put("nextAppointmentDate", ""); } // transfer out date - CalculationResult totResults = EmrCalculationUtils.evaluateForPatient(TransferOutDateCalculation.class, null, - patient); - if (totResults.isEmpty()) { + CalculationResult totResults = EmrCalculationUtils.evaluateForPatient(TransferOutDateCalculation.class, null, patient); + if(totResults.isEmpty()){ patientSummary.put("transferOutDate", "N/A"); - } else { + } + else { patientSummary.put("transferOutDate", formatDate((Date) totResults.getValue())); } - // transfer out to facility - CalculationResultMap transferOutFacilityMap = Calculations.lastObs( - Dictionary.getConcept(Dictionary.TRANSFER_OUT_FACILITY), - Arrays.asList(patient.getPatientId()), - context); - - String transferOutFacilityName = "N/A"; // Default value - - if (transferOutFacilityMap != null) { - Obs transferOutFacilityObs = EmrCalculationUtils.obsResultForPatient(transferOutFacilityMap, - patient.getPatientId()); - - if (transferOutFacilityObs != null) { - String facilityUuid = transferOutFacilityObs.getValueText(); - - if (facilityUuid != null && !facilityUuid.isEmpty()) { - Location location = locationService.getLocationByUuid(facilityUuid); - transferOutFacilityName = (location != null) ? location.getName() : facilityUuid; - } else { - transferOutFacilityName = ""; - } - } - } else { - patientSummary.put("transferOutFacility", transferOutFacilityName); - + //transfer out to facility + CalculationResultMap transferOutFacilty = Calculations.lastObs(Dictionary.getConcept(Dictionary.TRANSFER_OUT_FACILITY), Arrays.asList(patient.getPatientId()), context); + Obs transferOutFacilityObs = EmrCalculationUtils.obsResultForPatient(transferOutFacilty, patient.getPatientId()); + if(transferOutFacilityObs != null){ + patientSummary.put("transferOutFacility", transferOutFacilityObs.getValueText() != null ? locationService.getLocationByUuid(transferOutFacilityObs.getValueText()).getName() : ""); + } + else { + patientSummary.put("transferOutFacility", "N/A"); } - // All Vl - CalculationResult allVlResults = EmrCalculationUtils.evaluateForPatient(AllVlCountCalculation.class, null, - patient); + //All Vl + CalculationResult allVlResults = EmrCalculationUtils.evaluateForPatient(AllVlCountCalculation.class, null, patient); patientSummary.put("allVlResults", allVlResults); - // most recent viral load - CalculationResult vlResults = EmrCalculationUtils.evaluateForPatient(ViralLoadAndLdlCalculation.class, null, - patient); + //most recent viral load + CalculationResult vlResults = EmrCalculationUtils.evaluateForPatient(ViralLoadAndLdlCalculation.class, null, patient); String viralLoadValue = "None"; String viralLoadDate = "None"; - if (!vlResults.isEmpty()) { + if(!vlResults.isEmpty()) { String values = vlResults.getValue().toString(); - // split by brace - String value = values.replaceAll("\\{", "").replaceAll("\\}", ""); - if (!value.isEmpty()) { + //split by brace + String value = values.replaceAll("\\{", "").replaceAll("\\}",""); + if(!value.isEmpty()) { String[] splitByEqualSign = value.split("="); patientSummary.put("viralLoadValue", splitByEqualSign[0]); - // for a date from a string + //for a date from a string String dateSplitedBySpace = splitByEqualSign[1].split(" ")[0].trim(); String yearPart = dateSplitedBySpace.split("-")[0].trim(); String monthPart = dateSplitedBySpace.split("-")[1].trim(); @@ -2553,15 +2420,9 @@ public Object getPatientSummary(@RequestParam("patientUuid") String patientUuid) } } - // All CD4 Count - CalculationResult allCd4CountResults = EmrCalculationUtils.evaluateForPatient(AllCd4CountCalculation.class, - null, patient); - System.out.println( - "allCd4CountResults============================================================================================================" - + allCd4CountResults); - patientSummary.put("allCd4CountResults", - !allCd4CountResults.isEmpty() && allCd4CountResults.getValue() != null ? allCd4CountResults.getValue() - : ""); + //All CD4 Count + CalculationResult allCd4CountResults = EmrCalculationUtils.evaluateForPatient(AllCd4CountCalculation.class, null, patient); + patientSummary.put("allCd4CountResults", allCd4CountResults.getValue()); return patientSummary; @@ -2569,8 +2430,7 @@ public Object getPatientSummary(@RequestParam("patientUuid") String patientUuid) @RequestMapping(method = RequestMethod.GET, value = "/relationship") @ResponseBody - public String getRelationship(@RequestParam("patientUuid") String patientUuid, - @RequestParam("relationshipType") String relationshipType) { + public String getRelationship(@RequestParam("patientUuid") String patientUuid, @RequestParam("relationshipType") String relationshipType) { String personRelationshipName = ""; Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); List people = new ArrayList(); @@ -2589,17 +2449,16 @@ public String getRelationship(@RequestParam("patientUuid") String patientUuid, } } - if (people.size() > 0) { + if(people.size() > 0) { personRelationshipName = people.get(0).getPersonName().getFullName(); } - return personRelationshipName; + return personRelationshipName; } @RequestMapping(method = RequestMethod.GET, value = "/kpIdentifier") @ResponseBody - public Object getGeneratedKPIdentifier(@RequestParam("patientUuid") String patientUuid, - @RequestParam("kpType") String kpTypeVal, @RequestParam("subCounty") String subCounty, - @RequestParam("ward") String ward, @RequestParam("hotspotCode") String hotSpotCodeVal) { + public Object getGeneratedKPIdentifier(@RequestParam("patientUuid") String patientUuid, @RequestParam("kpType") String kpTypeVal, @RequestParam("subCounty") String subCounty, + @RequestParam("ward") String ward, @RequestParam("hotspotCode") String hotSpotCodeVal) { PersonService personService = Context.getPersonService(); Patient patient = Context.getPatientService().getPatientByUuid(patientUuid); Context.addProxyPrivilege(PrivilegeConstants.SQL_LEVEL_ACCESS); @@ -2618,8 +2477,7 @@ public Object getGeneratedKPIdentifier(@RequestParam("patientUuid") String patie String implementingPartnerCode = null; StringBuilder identifier = new StringBuilder(); GlobalProperty globalCountyCode = Context.getAdministrationService().getGlobalPropertyObject(GP_COUNTY); - GlobalProperty globalImplementingPartnerCode = Context.getAdministrationService() - .getGlobalPropertyObject(GP_KP_IMPLEMENTING_PARTNER); + GlobalProperty globalImplementingPartnerCode = Context.getAdministrationService().getGlobalPropertyObject(GP_KP_IMPLEMENTING_PARTNER); String strCountyCode = globalCountyCode.getPropertyValue(); String strImplementingPartner = globalImplementingPartnerCode.getPropertyValue(); SimpleObject kpIdentifier = new SimpleObject(); @@ -2665,13 +2523,11 @@ public Object getGeneratedKPIdentifier(@RequestParam("patientUuid") String patie identifier.append(serialNumber); ProgramWorkflowService service = Context.getProgramWorkflowService(); - List programs = service.getPatientPrograms( - Context.getPatientService().getPatient(patient.getId()), + List programs = service.getPatientPrograms(Context.getPatientService().getPatient(patient.getId()), kpProgram, null, null, null, null, true); if (programs.size() > 0) { - PatientIdentifierType pit = MetadataUtils.existing(PatientIdentifierType.class, - KP_UNIQUE_PATIENT_NUMBER_UUID); + PatientIdentifierType pit = MetadataUtils.existing(PatientIdentifierType.class, KP_UNIQUE_PATIENT_NUMBER_UUID); PatientIdentifier pObject = patient.getPatientIdentifier(pit); sb.append(pObject.getIdentifier()); } else { @@ -2684,7 +2540,7 @@ public Object getGeneratedKPIdentifier(@RequestParam("patientUuid") String patie String entryPointAbbriviations(Concept concept) { String value = "Other"; - if (concept != null) { + if(concept != null) { if (concept.equals(Dictionary.getConcept(Dictionary.VCT_PROGRAM))) { value = "VCT"; } else if (concept.equals(Dictionary.getConcept(Dictionary.PMTCT_PROGRAM))) { @@ -2729,20 +2585,26 @@ String entryPointAbbriviations(Concept concept) { String cacxScreeningOutcome(Concept concept) { String value = ""; - if (concept != null) { + if(concept != null) { if (concept.equals(Dictionary.getConcept(Dictionary.POSITIVE))) { value = "Positive"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.NEGATIVE))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.NEGATIVE))) { value = "Negative"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.YES))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.YES))) { value = "Yes"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.NO))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.NO))) { value = "No"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.UNKNOWN))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.UNKNOWN))) { value = "Unknown"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.NOT_DONE))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.NOT_DONE))) { value = "Not Done"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE))) { value = "N/A"; } } @@ -2751,7 +2613,7 @@ String cacxScreeningOutcome(Concept concept) { String familyPlanningMethods(Concept concept) { String value = "Other"; - if (concept != null) { + if(concept != null) { if (concept.equals(Dictionary.getConcept(Dictionary.INJECTABLE_HORMONES))) { value = "INJECTABLE HORMONES"; } else if (concept.equals(Dictionary.getConcept(Dictionary.CERVICAL_CAP))) { @@ -2783,23 +2645,32 @@ String familyPlanningMethods(Concept concept) { } else if (concept.equals(Dictionary.getConcept(Dictionary.NONE))) { value = "None"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.IUD_CONTRACEPTION))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.IUD_CONTRACEPTION))) { value = "IUD Contraception"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.HYSTERECTOMY))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.HYSTERECTOMY))) { value = "Hysterectomy"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.EMERGENCY_CONTRACEPTIVE_PILLS))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.EMERGENCY_CONTRACEPTIVE_PILLS))) { value = "Emergency contraceptive pills"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.LACTATIONAL_AMENORRHEA))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.LACTATIONAL_AMENORRHEA))) { value = "Lactational amenorrhea"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.UNKNOWN))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.UNKNOWN))) { value = "Unknown"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.CONTRACEPTION_METHOD_UNDECIDED))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.CONTRACEPTION_METHOD_UNDECIDED))) { value = "Contraception method undecided"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.FEMALE_CONDOM))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.FEMALE_CONDOM))) { value = "Female condom"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.MALE_CONDOM))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.MALE_CONDOM))) { value = "Male condom"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.IMPLANTABLE_CONTRACEPTIVE))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.IMPLANTABLE_CONTRACEPTIVE))) { value = "Implantable contraceptive (unspecified type)"; } @@ -2810,47 +2681,62 @@ String familyPlanningMethods(Concept concept) { String stiScreeningOutcome(Concept concept) { String value = ""; - if (concept != null) { + if(concept != null) { if (concept.equals(Dictionary.getConcept(Dictionary.POSITIVE))) { value = "Positive"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.NEGATIVE))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.NEGATIVE))) { value = "Negative"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.NOT_DONE))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.NOT_DONE))) { value = "Not Done"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE))) { + } + else if (concept.equals(Dictionary.getConcept(Dictionary.NOT_APPLICABLE))) { value = "N/A"; } } return value; } - String getCorrectDrugCode(Concept concept) { + String getCorrectDrugCode(Concept concept){ String defaultString = ""; - if (concept.equals(Dictionary.getConcept("794AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + if(concept.equals(Dictionary.getConcept("794AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "LPV/r"; - } else if (concept.equals(Dictionary.getConcept("84309AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + } + else if(concept.equals(Dictionary.getConcept("84309AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "d4T"; - } else if (concept.equals(Dictionary.getConcept("74807AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + } + else if(concept.equals(Dictionary.getConcept("74807AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "DDI"; - } else if (concept.equals(Dictionary.getConcept("70056AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + } + else if(concept.equals(Dictionary.getConcept("70056AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "ABC"; - } else if (concept.equals(Dictionary.getConcept("80487AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + } + else if(concept.equals(Dictionary.getConcept("80487AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "NFV"; - } else if (concept.equals(Dictionary.getConcept("80586AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + } + else if(concept.equals(Dictionary.getConcept("80586AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "NVP"; - } else if (concept.equals(Dictionary.getConcept("75523AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + } + else if(concept.equals(Dictionary.getConcept("75523AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "EFV"; - } else if (concept.equals(Dictionary.getConcept("78643AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + } + else if(concept.equals(Dictionary.getConcept("78643AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "3TC"; - } else if (concept.equals(Dictionary.getConcept("84795AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + } + else if(concept.equals(Dictionary.getConcept("84795AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "TDF"; - } else if (concept.equals(Dictionary.getConcept("86663AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + } + else if(concept.equals(Dictionary.getConcept("86663AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "AZT"; - } else if (concept.equals(Dictionary.getConcept("83412AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + } + else if(concept.equals(Dictionary.getConcept("83412AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "RTV"; - } else if (concept.equals(Dictionary.getConcept("71647AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + } + else if(concept.equals(Dictionary.getConcept("71647AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ defaultString = "ATV"; - } else { + } + else { defaultString = concept.getName().getName(); } @@ -2858,48 +2744,66 @@ String getCorrectDrugCode(Concept concept) { } String ios(Integer concept) { - String value; - if (concept.equals(123358)) { + String value ; + if(concept.equals(123358)){ value = "Zoster"; - } else if (concept.equals(5334)) { + } + else if(concept.equals(5334)){ value = "Thrush - oral"; - } else if (concept.equals(298)) { + } + else if(concept.equals(298)){ value = "Thrush - vaginal"; - } else if (concept.equals(143264)) { + } + else if(concept.equals(143264)){ value = "Cough"; - } else if (concept.equals(122496)) { + } + else if(concept.equals(122496)){ value = "Difficult breathing"; - } else if (concept.equals(140238)) { + } + else if(concept.equals(140238)){ value = "Fever"; - } else if (concept.equals(487)) { + } + else if(concept.equals(487)){ value = "Dementia/Enceph"; - } else if (concept.equals(150796)) { + } + else if(concept.equals(150796)){ value = "Weight loss"; - } else if (concept.equals(114100)) { + } + else if(concept.equals(114100)){ value = "Pneumonia"; - } else if (concept.equals(123529)) { + } + else if(concept.equals(123529)){ value = "Urethral discharge"; - } else if (concept.equals(902)) { + } + else if(concept.equals(902)){ value = "Pelvic inflammatory disease"; - } else if (concept.equals(111721)) { + } + else if(concept.equals(111721)){ value = "Ulcers - mouth"; - } else if (concept.equals(120939)) { + } + else if(concept.equals(120939)){ value = "Ulcers - other"; - } else if (concept.equals(145762)) { + } + else if(concept.equals(145762)){ value = "Genital ulcer disease"; - } else if (concept.equals(140707)) { + } + else if(concept.equals(140707)){ value = "Poor weight gain"; - } else if (concept.equals(112141)) { + } + else if(concept.equals(112141)){ value = "Tuberculosis"; - } else if (concept.equals(160028)) { + } + else if(concept.equals(160028)){ value = "Immune reconstitution inflammatory syndrome"; - } else if (concept.equals(162330)) { + } + else if(concept.equals(162330)){ value = "Severe uncomplicated malnutrition"; - } else if (concept.equals(162331)) { + } + else if(concept.equals(162331)){ value = "Severe complicated malnutrition"; } - else if (concept.equals(1107)) { + else if(concept.equals(1107)){ value = "None"; } @@ -2909,74 +2813,77 @@ else if (concept.equals(1107)) { return value; } - String whoStaging(Concept concept) { + String whoStaging(Concept concept){ String stage = ""; - if (concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_1_ADULT)) - || concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_1_PEDS))) { + if(concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_1_ADULT)) || concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_1_PEDS))){ stage = "I"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_2_ADULT)) - || concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_2_PEDS))) { + } + else if(concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_2_ADULT)) || concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_2_PEDS))){ stage = "II"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_3_ADULT)) - || concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_3_PEDS))) { + } + else if(concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_3_ADULT)) || concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_3_PEDS))){ stage = "III"; - } else if (concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_4_ADULT)) - || concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_4_PEDS))) { + } + else if(concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_4_ADULT)) || concept.equals(Dictionary.getConcept(Dictionary.WHO_STAGE_4_PEDS))){ stage = "IV"; } return stage; } - String intergerToRoman(String integer) { + String intergerToRoman(String integer){ String value = ""; - if (integer.equals("1")) { + if(integer.equals("1")){ value = "I"; - } else if (integer.equals("2")) { + } + else if(integer.equals("2")){ value = "II"; - } else if (integer.equals("3")) { + } + else if(integer.equals("3")){ value = "III"; - } else if (integer.equals("4")) { + } + else if(integer.equals("4")){ value = "IV"; } return value; } - String programs(int value) { - String prog = ""; - if (value == 160541) { - prog = "TB"; + String programs(int value){ + String prog=""; + if(value == 160541){ + prog ="TB"; } - if (value == 160631) { - prog = "HIV"; + if(value == 160631){ + prog ="HIV"; } - if (value == 159937) { - prog = "MCH"; + if(value == 159937){ + prog ="MCH"; } return prog; } - String previousArtReason(Concept concept) { + String previousArtReason(Concept concept){ String value = ""; - if (concept.equals(Dictionary.getConcept("1148AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { - value = "PMTCT"; - } else if (concept.equals(Dictionary.getConcept("1691AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + if(concept.equals(Dictionary.getConcept("1148AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ + value ="PMTCT"; + } + else if(concept.equals(Dictionary.getConcept("1691AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ value = "PEP"; } - else if (concept.equals(Dictionary.getConcept("1181AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))) { + else if(concept.equals(Dictionary.getConcept("1181AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))){ value = "HAART"; } - return value; + return value; } - private int age(Date d1, Date d2) { + private int age(Date d1, Date d2){ DateTime birthDate = new DateTime(d1.getTime()); DateTime today = new DateTime(d2.getTime()); @@ -3038,15 +2945,13 @@ private String mapConceptNamesToShortNames(String conceptUuid) { */ @RequestMapping(method = RequestMethod.GET, value = "/sql") @ResponseBody - public List search(@RequestParam("q") String query, - HttpServletRequest request) throws Exception { + public List search(@RequestParam("q") String query, HttpServletRequest request) throws Exception { return Context.getService(KenyaEmrService.class).search(query, request.getParameterMap()); } /** * Generates KenyaEMR related metrics - * * @param request * @return */ @@ -3057,35 +2962,32 @@ public Object getKenyaEMRDetails(HttpServletRequest request) { "EmrName", "KenyaEMR", "EmrVersion", DwapiMetricsUtil.getKenyaemrVersion(), "LastLoginDate", DwapiMetricsUtil.getLastLogin(), - "LastMoH731RunDate", DwapiMetricsUtil.getDateofLastMOH731()); + "LastMoH731RunDate", DwapiMetricsUtil.getDateofLastMOH731() + ); } /** * Verify NUPI exists (EndPoint) - * * @return */ - @CrossOrigin(origins = "*", methods = { RequestMethod.GET, RequestMethod.OPTIONS }) + @CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @RequestMapping(method = RequestMethod.GET, value = "/verifynupi/{country}/{identifierType}/{identifier}") @ResponseBody - public Object verifyNUPI(@PathVariable String country, @PathVariable String identifierType, - @PathVariable String identifier) { + public Object verifyNUPI(@PathVariable String country, @PathVariable String identifierType, @PathVariable String identifier) { String ret = "{\"status\": \"Error\"}"; try { - GlobalProperty globalGetUrl = Context.getAdministrationService() - .getGlobalPropertyObject(CommonMetadata.GP_CLIENT_VERIFICATION_GET_END_POINT); + GlobalProperty globalGetUrl = Context.getAdministrationService().getGlobalPropertyObject(CommonMetadata.GP_CLIENT_VERIFICATION_GET_END_POINT); String baseURL = globalGetUrl.getPropertyValue(); - if (baseURL == null || baseURL.trim().isEmpty()) { - baseURL = "https://afyakenyaapi.health.go.ke/partners/registry/search";// TODO: we need to remove this - // ASAP + if(baseURL == null || baseURL.trim().isEmpty()) { + baseURL = "https://afyakenyaapi.health.go.ke/partners/registry/search";//TODO: we need to remove this ASAP } - String completeURL = baseURL + "/" + country + "/" + identifierType + "/" + identifier; + String completeURL = baseURL + "/" + country + "/" + identifierType + "/" + identifier; URL url = new URL(completeURL); UpiUtilsDataExchange upiUtilsDataExchange = new UpiUtilsDataExchange(); String authToken = upiUtilsDataExchange.getToken(); - HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); + HttpsURLConnection con =(HttpsURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("Authorization", "Bearer " + authToken); @@ -3095,7 +2997,7 @@ public Object verifyNUPI(@PathVariable String country, @PathVariable String iden int responseCode = con.getResponseCode(); - if (responseCode == HttpURLConnection.HTTP_OK) { // success + if (responseCode == HttpURLConnection.HTTP_OK) { //success // Read the response BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); @@ -3136,7 +3038,7 @@ public Object verifyNUPI(@PathVariable String country, @PathVariable String iden HttpHeaders headers = new HttpHeaders(); String contentType = con.getHeaderField("Content-Type"); - if (contentType != null && contentType.toLowerCase().contains("json")) { + if(contentType != null && contentType.toLowerCase().contains("json")) { headers.setContentType(MediaType.APPLICATION_JSON); } else { headers.setContentType(MediaType.TEXT_PLAIN); @@ -3144,7 +3046,7 @@ public Object verifyNUPI(@PathVariable String country, @PathVariable String iden return ResponseEntity.status(responseCode).headers(headers).body(errorBody); } - } catch (Exception ex) { + } catch(Exception ex) { System.err.println("NUPI verification: ERROR: " + ex.getMessage()); ex.printStackTrace(); } @@ -3154,10 +3056,9 @@ public Object verifyNUPI(@PathVariable String country, @PathVariable String iden /** * Search for NUPI (EndPoint) - * * @return */ - @CrossOrigin(origins = "*", methods = { RequestMethod.GET, RequestMethod.OPTIONS }) + @CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @RequestMapping(method = RequestMethod.GET, value = "/searchnupi/{searchkey}/{searchvalue}") @ResponseBody public Object searchNUPI(@PathVariable String searchkey, @PathVariable String searchvalue) { @@ -3166,22 +3067,20 @@ public Object searchNUPI(@PathVariable String searchkey, @PathVariable String se System.out.println("NUPI search: SearchKey: " + searchkey + " SearchValue: " + searchvalue); // Create URL - // String baseURL = - // "https://afyakenyaapi.health.go.ke/partners/registry/search"; - GlobalProperty globalGetUrl = Context.getAdministrationService() - .getGlobalPropertyObject(CommonMetadata.GP_CLIENT_VERIFICATION_GET_END_POINT); + // String baseURL = "https://afyakenyaapi.health.go.ke/partners/registry/search"; + GlobalProperty globalGetUrl = Context.getAdministrationService().getGlobalPropertyObject(CommonMetadata.GP_CLIENT_VERIFICATION_GET_END_POINT); String baseURL = globalGetUrl.getPropertyValue(); - if (baseURL == null || baseURL.trim().isEmpty()) { + if(baseURL == null || baseURL.trim().isEmpty()) { baseURL = "https://afyakenyaapi.health.go.ke/partners/registry/search"; } - String completeURL = baseURL + "/" + searchkey + "/" + searchvalue; + String completeURL = baseURL + "/" + searchkey + "/" + searchvalue; System.out.println("NUPI search: Using NUPI GET URL: " + completeURL); URL url = new URL(completeURL); UpiUtilsDataExchange upiUtilsDataExchange = new UpiUtilsDataExchange(); String authToken = upiUtilsDataExchange.getToken(); - HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); + HttpsURLConnection con =(HttpsURLConnection) url.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("Authorization", "Bearer " + authToken); @@ -3191,7 +3090,7 @@ public Object searchNUPI(@PathVariable String searchkey, @PathVariable String se int responseCode = con.getResponseCode(); - if (responseCode == HttpURLConnection.HTTP_OK) { // success + if (responseCode == HttpURLConnection.HTTP_OK) { //success // Read the response BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); @@ -3231,7 +3130,7 @@ public Object searchNUPI(@PathVariable String searchkey, @PathVariable String se HttpHeaders headers = new HttpHeaders(); String contentType = con.getHeaderField("Content-Type"); - if (contentType != null && contentType.toLowerCase().contains("json")) { + if(contentType != null && contentType.toLowerCase().contains("json")) { headers.setContentType(MediaType.APPLICATION_JSON); } else { headers.setContentType(MediaType.TEXT_PLAIN); @@ -3239,7 +3138,7 @@ public Object searchNUPI(@PathVariable String searchkey, @PathVariable String se return ResponseEntity.status(responseCode).headers(headers).body(errorBody); } - } catch (Exception ex) { + } catch(Exception ex) { System.err.println("NUPI search: ERROR: " + ex.getMessage()); ex.printStackTrace(); } @@ -3249,11 +3148,10 @@ public Object searchNUPI(@PathVariable String searchkey, @PathVariable String se /** * Get a new NUPI (EndPoint) - * * @param request * @return */ - @CrossOrigin(origins = "*", methods = { RequestMethod.POST, RequestMethod.OPTIONS }) + @CrossOrigin(origins = "*", methods = {RequestMethod.POST, RequestMethod.OPTIONS}) @RequestMapping(method = RequestMethod.POST, value = "/newnupi") @ResponseBody public Object newNUPI(HttpServletRequest request) { @@ -3266,10 +3164,9 @@ public Object newNUPI(HttpServletRequest request) { // Create URL // String baseURL = "https://afyakenyaapi.health.go.ke/partners/registry"; - GlobalProperty globalPostUrl = Context.getAdministrationService() - .getGlobalPropertyObject(CommonMetadata.GP_CLIENT_VERIFICATION_POST_END_POINT); + GlobalProperty globalPostUrl = Context.getAdministrationService().getGlobalPropertyObject(CommonMetadata.GP_CLIENT_VERIFICATION_POST_END_POINT); String baseURL = globalPostUrl.getPropertyValue(); - if (baseURL == null || baseURL.trim().isEmpty()) { + if(baseURL == null || baseURL.trim().isEmpty()) { baseURL = "https://afyakenyaapi.health.go.ke/partners/registry"; } String completeURL = baseURL; @@ -3280,7 +3177,7 @@ public Object newNUPI(HttpServletRequest request) { String authToken = upiUtilsDataExchange.getToken(); // Make the Connection - con = (HttpsURLConnection) url.openConnection(); + con =(HttpsURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setDoOutput(true); con.setRequestProperty("Authorization", "Bearer " + authToken); @@ -3292,8 +3189,7 @@ public Object newNUPI(HttpServletRequest request) { String requestBody = ""; BufferedReader requestReader = request.getReader(); - for (String output = ""; (output = requestReader.readLine()) != null; requestBody = requestBody + output) { - } + for(String output = ""; (output = requestReader.readLine()) != null; requestBody = requestBody + output) {} System.out.println("New NUPI: Sending to remote: " + requestBody); PrintStream os = new PrintStream(con.getOutputStream()); os.print(requestBody); @@ -3301,7 +3197,7 @@ public Object newNUPI(HttpServletRequest request) { int responseCode = con.getResponseCode(); - if (responseCode == HttpURLConnection.HTTP_OK) { // success + if (responseCode == HttpURLConnection.HTTP_OK) { //success // Read the response BufferedReader in = null; @@ -3318,6 +3214,7 @@ public Object newNUPI(HttpServletRequest request) { String returnResponse = response.toString(); System.out.println("New NUPI: Got the Response as: " + returnResponse); + HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return ResponseEntity.ok().headers(headers).body(returnResponse); @@ -3343,7 +3240,7 @@ public Object newNUPI(HttpServletRequest request) { HttpHeaders headers = new HttpHeaders(); String contentType = con.getHeaderField("Content-Type"); - if (contentType != null && contentType.toLowerCase().contains("json")) { + if(contentType != null && contentType.toLowerCase().contains("json")) { headers.setContentType(MediaType.APPLICATION_JSON); } else { headers.setContentType(MediaType.TEXT_PLAIN); @@ -3351,7 +3248,7 @@ public Object newNUPI(HttpServletRequest request) { return ResponseEntity.status(responseCode).headers(headers).body(errorBody); } - } catch (Exception ex) { + } catch(Exception ex) { System.err.println("New NUPI: ERROR: " + ex.getMessage()); ex.printStackTrace(); } @@ -3361,15 +3258,13 @@ public Object newNUPI(HttpServletRequest request) { /** * Modify NUPI patient data e.g CCC Number (EndPoint) - * * @param request * @return */ - @CrossOrigin(origins = "*", methods = { RequestMethod.PUT, RequestMethod.OPTIONS }) + @CrossOrigin(origins = "*", methods = {RequestMethod.PUT, RequestMethod.OPTIONS}) @RequestMapping(method = RequestMethod.PUT, value = "/modifynupi/{nupinumber}/{searchtype}") @ResponseBody - public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinumber, - @PathVariable String searchtype) { + public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinumber, @PathVariable String searchtype) { String ret = "{\"status\": \"Error\"}"; // InputStream errorStream = null; @@ -3380,10 +3275,9 @@ public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinu // Create URL // String baseURL = "https://afyakenyaapi.health.go.ke/partners/registry"; - GlobalProperty globalPostUrl = Context.getAdministrationService() - .getGlobalPropertyObject(CommonMetadata.GP_CLIENT_VERIFICATION_UPDATE_END_POINT); + GlobalProperty globalPostUrl = Context.getAdministrationService().getGlobalPropertyObject(CommonMetadata.GP_CLIENT_VERIFICATION_UPDATE_END_POINT); String baseURL = globalPostUrl.getPropertyValue(); - if (baseURL == null || baseURL.trim().isEmpty()) { + if(baseURL == null || baseURL.trim().isEmpty()) { baseURL = "https://afyakenyaapi.health.go.ke/partners/registry"; } String completeURL = baseURL + "/" + nupinumber + "/" + searchtype; @@ -3394,7 +3288,7 @@ public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinu String authToken = upiUtilsDataExchange.getToken(); // Make the Connection - con = (HttpsURLConnection) url.openConnection(); + con =(HttpsURLConnection) url.openConnection(); con.setRequestMethod("PUT"); con.setDoOutput(true); con.setRequestProperty("Authorization", "Bearer " + authToken); @@ -3406,8 +3300,7 @@ public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinu String requestBody = ""; BufferedReader requestReader = request.getReader(); - for (String output = ""; (output = requestReader.readLine()) != null; requestBody = requestBody + output) { - } + for(String output = ""; (output = requestReader.readLine()) != null; requestBody = requestBody + output) {} System.out.println("Modify NUPI: Sending to remote: " + requestBody); PrintStream os = new PrintStream(con.getOutputStream()); os.print(requestBody); @@ -3415,7 +3308,7 @@ public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinu int responseCode = con.getResponseCode(); - if (responseCode == HttpURLConnection.HTTP_OK) { // success + if (responseCode == HttpURLConnection.HTTP_OK) { //success // Read the response BufferedReader in = null; @@ -3432,6 +3325,7 @@ public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinu String returnResponse = response.toString(); System.out.println("Modify NUPI: Got the Response as: " + returnResponse); + HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return ResponseEntity.ok().headers(headers).body(returnResponse); @@ -3457,7 +3351,7 @@ public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinu HttpHeaders headers = new HttpHeaders(); String contentType = con.getHeaderField("Content-Type"); - if (contentType != null && contentType.toLowerCase().contains("json")) { + if(contentType != null && contentType.toLowerCase().contains("json")) { headers.setContentType(MediaType.APPLICATION_JSON); } else { headers.setContentType(MediaType.TEXT_PLAIN); @@ -3465,7 +3359,7 @@ public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinu return ResponseEntity.status(responseCode).headers(headers).body(errorBody); } - } catch (Exception ex) { + } catch(Exception ex) { System.err.println("Modify NUPI: ERROR: " + ex.getMessage()); ex.printStackTrace(); } @@ -3474,17 +3368,14 @@ public Object modifyNUPI(HttpServletRequest request, @PathVariable String nupinu } /** - * Returns the latest patient Obs value coded concept ID and UUID given the - * patient UUID and Concept UUID - * + * Returns the latest patient Obs value coded concept ID and UUID given the patient UUID and Concept UUID * @param patientUuid * @return value coded concept id and uuid */ - @CrossOrigin(origins = "*", methods = { RequestMethod.GET, RequestMethod.OPTIONS }) + @CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @RequestMapping(method = RequestMethod.GET, value = "/latestobs") @ResponseBody - public Object getLatestObs(@RequestParam("patientUuid") String patientUuid, - @RequestParam("concept") String conceptIdentifier) { + public Object getLatestObs(@RequestParam("patientUuid") String patientUuid, @RequestParam("concept") String conceptIdentifier) { SimpleObject ret = SimpleObject.create("conceptId", 0, "conceptUuid", ""); if (StringUtils.isBlank(patientUuid)) { return new ResponseEntity("You must specify a patientUuid in the request!", @@ -3510,7 +3401,6 @@ public Object getLatestObs(@RequestParam("patientUuid") String patientUuid, return ret; } - @RequestMapping(method = RequestMethod.POST, value = "/send-kenyaemr-sms") public Object sendKenyaEmrSms(@RequestParam("message") String message, @RequestParam("phone") String phone) { return Context.getService(KenyaEmrService.class).sendKenyaEmrSms(phone, message); @@ -3518,15 +3408,13 @@ public Object sendKenyaEmrSms(@RequestParam("message") String message, @RequestP /** * End Point for getting Patient resource from SHA client registry - * * @param identifier * @param identifierType * @return */ - @CrossOrigin(origins = "*", methods = { RequestMethod.GET, RequestMethod.OPTIONS }) + @CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @RequestMapping(method = RequestMethod.GET, value = "/getSHAPatient/{identifier}/{identifierType}") - public ResponseEntity getSHAPatient(@PathVariable String identifier, @PathVariable String identifierType) - throws IOException { + public ResponseEntity getSHAPatient(@PathVariable String identifier, @PathVariable String identifierType) throws IOException { String toReturn = getCrStatus(identifier, identifierType); return ResponseEntity.ok() @@ -3536,11 +3424,10 @@ public ResponseEntity getSHAPatient(@PathVariable String identifier, @Pa /** * End Point for getting Practitioner resource from SHA client registry - * * @param allParams to capture the query parameters * @return */ - @CrossOrigin(origins = "*", methods = { RequestMethod.GET, RequestMethod.OPTIONS }) + @CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.OPTIONS}) @RequestMapping(method = RequestMethod.GET, value = "/practitionersearch") public ResponseEntity getSHAPractitioner(@RequestParam Map allParams) throws IOException { @@ -3550,8 +3437,7 @@ public ResponseEntity getSHAPractitioner(@RequestParam Map getSHAPractitioner(@RequestParam Map it = mappingEntries.iterator(); it.hasNext();) { + for (Iterator it = mappingEntries.iterator(); it.hasNext(); ) { ObjectNode node = (ObjectNode) it.next(); Integer conceptId = node.get("ConceptId").asInt(); @@ -3700,15 +3579,11 @@ public Object processICD11ConceptMapping() throws IOException { if (concept == null) { continue; // just skip } - ConceptReferenceTerm referenceTerm = conceptService.getConceptReferenceTermByCode(icd11Code, - icd11Who) != null ? conceptService.getConceptReferenceTermByCode(icd11Code, icd11Who) - : new ConceptReferenceTerm(icd11Who, icd11Code, icd11Name); + ConceptReferenceTerm referenceTerm = conceptService.getConceptReferenceTermByCode(icd11Code, icd11Who) != null ? conceptService.getConceptReferenceTermByCode(icd11Code, icd11Who) : new ConceptReferenceTerm(icd11Who, icd11Code, icd11Name); ConceptMap conceptMap = new ConceptMap(); conceptMap.setConceptMapType(sameAs); conceptMap.setConceptReferenceTerm(referenceTerm); - if (concept.getConceptMappings().stream() - .anyMatch(cMap -> cMap.getConceptReferenceTerm().getCode().equals(icd11Code) - && cMap.getConceptReferenceTerm().getConceptSource().equals(icd11Who))) { + if (concept.getConceptMappings().stream().anyMatch(cMap -> cMap.getConceptReferenceTerm().getCode().equals(icd11Code) && cMap.getConceptReferenceTerm().getConceptSource().equals(icd11Who))) { continue; // skip existing mappings } concept.addConceptMapping(conceptMap); @@ -3733,21 +3608,17 @@ public Object processICD11ConceptMapping() throws IOException { return responseObject.toString(); } - - /** - * Generates Facility Dashboard - * - * @param request - * @return - */ - @RequestMapping(method = RequestMethod.GET, value = "/facility-dashboard") - @ResponseBody - public Object getFacilityDashboard(HttpServletRequest request) { + /** + * Generates Facility Dashboard + * @param request + * @return + */ + @RequestMapping(method = RequestMethod.GET, value = "/facility-dashboard") + @ResponseBody + public Object getFacilityDashboard(HttpServletRequest request) { double PERCENT_DIVISOR = 100.0; - final String clinicalActionPercentageThreshold = getGlobalPropertyValue( - CommonMetadata.GP_CLINICAL_ACTION_PERCENTAGE_THRESHOLD); - final String clinicalActionHEIAbsoluteThreshold = getGlobalPropertyValue( - CommonMetadata.GP_CLINICAL_ACTION_HEI_ABSOLUTE_THRESHOLD); + final String clinicalActionPercentageThreshold = getGlobalPropertyValue(CommonMetadata.GP_CLINICAL_ACTION_PERCENTAGE_THRESHOLD); + final String clinicalActionHEIAbsoluteThreshold = getGlobalPropertyValue(CommonMetadata.GP_CLINICAL_ACTION_HEI_ABSOLUTE_THRESHOLD); double clinicalActionThreshold = 0.0; double heiClinicalActionThreshold; @@ -3764,22 +3635,21 @@ public Object getFacilityDashboard(HttpServletRequest request) { throw new IllegalArgumentException("Clinical action hei absolute threshold is not configured correctly."); } - return SimpleObject.create( - "getHivPositiveNotLinked", FacilityDashboardUtil.getHivPositiveNotLinked(), - "getHivTestedPositive", FacilityDashboardUtil.getPatientsTestedHivPositive(), - "getPregnantOrPostpartumClients", FacilityDashboardUtil.getPregnantOrPostpartumClients(), - "getPregnantPostpartumNotInPrep", FacilityDashboardUtil.getPregnantPostpartumNotInPrep(), - "getEligibleForVl", 0, - "getEligibleForVlSampleNotTaken", 0, - "getVirallyUnsuppressed", FacilityDashboardUtil.getVirallyUnsuppressed(), - "getVirallyUnsuppressedWithoutEAC", FacilityDashboardUtil.getVirallyUnsuppressedWithoutEAC(), - "getHeiSixToEightWeeksOld", FacilityDashboardUtil.getHeiSixToEightWeeksOld(), - "getHeiSixToEightWeeksWithoutPCRResults", - FacilityDashboardUtil.getHeiSixToEightWeeksWithoutPCRResults(), - "getHei24MonthsOld", FacilityDashboardUtil.getHei24MonthsOld(), - "getHei24MonthsWithoutDocumentedOutcome", - FacilityDashboardUtil.getHei24MonthsWithoutDocumentedOutcome(), - "clinicalActionThreshold", clinicalActionThreshold, - "heiClinicalActionThreshold", heiClinicalActionThreshold); - } + return SimpleObject.create( + "getHivPositiveNotLinked", FacilityDashboardUtil.getHivPositiveNotLinked(), + "getHivTestedPositive", FacilityDashboardUtil.getPatientsTestedHivPositive(), + "getPregnantOrPostpartumClients", FacilityDashboardUtil.getPregnantOrPostpartumClients(), + "getPregnantPostpartumNotInPrep", FacilityDashboardUtil.getPregnantPostpartumNotInPrep(), + "getEligibleForVl", FacilityDashboardUtil.getEligibleForVl(), + "getEligibleForVlSampleNotTaken", FacilityDashboardUtil.getEligibleForVlSampleNotTaken(), + "getVirallyUnsuppressed", FacilityDashboardUtil.getVirallyUnsuppressed(), + "getVirallyUnsuppressedWithoutEAC", FacilityDashboardUtil.getVirallyUnsuppressedWithoutEAC(), + "getHeiSixToEightWeeksOld", FacilityDashboardUtil.getHeiSixToEightWeeksOld(), + "getHeiSixToEightWeeksWithoutPCRResults", FacilityDashboardUtil.getHeiSixToEightWeeksWithoutPCRResults(), + "getHei24MonthsOld", FacilityDashboardUtil.getHei24MonthsOld(), + "getHei24MonthsWithoutDocumentedOutcome", FacilityDashboardUtil.getHei24MonthsWithoutDocumentedOutcome(), + "clinicalActionThreshold",clinicalActionThreshold, + "heiClinicalActionThreshold",heiClinicalActionThreshold + ); + } }