From db9d81e4ed147497eab1d93788f9032f2fa6d79c Mon Sep 17 00:00:00 2001 From: Joao machiana Date: Thu, 20 Feb 2020 15:29:12 +0200 Subject: [PATCH 1/9] another approach to hide apss data on clinical consultation --- .../reports/sql/List_of_Patients_Summary.sql | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql index 5f82ab683..39787a90c 100644 --- a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql +++ b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql @@ -1598,7 +1598,60 @@ LEFT JOIN (SELECT AND ob.concept_id = cn.concept_id AND cn.concept_name_type = 'FULLY_SPECIFIED' AND cn.locale = 'en' - AND cn.name = 'PP_If_Key_population_yes') key_population ON key_population.encounter_id = obs.encounter_id + AND cn.name = 'PP_If_Key_population_yes') key_population2 ON key_population2.encounter_id = obs.encounter_id +LEFT JOIN ( + SELECT + kp.encounter_id, + kp.person_id, + kp.obs_group_id, + kp_fields.concept_id, + kp_fields.value_coded, + kp.pop_chave + FROM + (SELECT + e.encounter_id, + ob.person_id, + ob.value_coded, + ob.obs_group_id, + ob.concept_id, + (SELECT + name + FROM + concept_name + WHERE + concept_id = ob.value_coded + AND locale = 'pt' + AND concept_name_type = 'SHORT') AS pop_chave + FROM + obs ob, encounter e, concept_name cn + WHERE + e.encounter_id = ob.encounter_id + AND e.patient_id = ob.person_id + AND ob.concept_id = cn.concept_id + AND cn.concept_name_type = 'FULLY_SPECIFIED' + AND cn.locale = 'en' + AND cn.name = 'PP_If_Key_population_yes') AS kp + INNER JOIN ( + SELECT + ob_kp.encounter_id, + ob_kp.person_id, + ob_kp.value_coded, + ob_kp.concept_id, + ob_kp.obs_group_id, + ob_kp.obs_id + FROM + obs ob_kp + WHERE + -- ob_kp.encounter_id = 247197 + -- AND ob_kp.obs_group_id = 5017686 + ob_kp.concept_id IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'User_type_pop' OR name = 'User_type')) + AND ob_kp.value_coded IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'Clinical_user' OR name = 'APSS_an_Clinical_user' OR name = 'Clinical_user_pop' OR name = 'APSS_an_Clinical_user_pop')) + AND ob_kp.voided = 0 + ) kp_fields + -- ON kp_fields.encounter_id = kp.encounter_id + -- AND kp_fields.obs_group_id = kp.obs_group_id + ON kp_fields.obs_group_id = kp.obs_group_id +) key_population ON key_population.encounter_id = obs.encounter_id LEFT JOIN (SELECT e.encounter_id, ob.person_id, From 2600afff8f80ec884f05e0a8ff239ffe7ebdc937 Mon Sep 17 00:00:00 2001 From: Joao machiana Date: Fri, 21 Feb 2020 16:26:51 +0200 Subject: [PATCH 2/9] removed old code for key_population --- .../reports/sql/List_of_Patients_Summary.sql | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql index 39787a90c..c14ec7ed8 100644 --- a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql +++ b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql @@ -1578,27 +1578,6 @@ LEFT JOIN (SELECT WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en') cn_f_planning_other ON cn_f_planning_other.concept_id = f_planning_other.value_coded) fp_other ON fp_other.encounter_id = obs.encounter_id -LEFT JOIN (SELECT - e.encounter_id, - ob.person_id, - ob.value_coded, - (SELECT - name - FROM - concept_name - WHERE - concept_id = ob.value_coded - AND locale = 'pt' - AND concept_name_type = 'SHORT') AS pop_chave - FROM - obs ob, encounter e, concept_name cn - WHERE - ob.person_id = e.patient_id - AND ob.encounter_id = e.encounter_id - AND ob.concept_id = cn.concept_id - AND cn.concept_name_type = 'FULLY_SPECIFIED' - AND cn.locale = 'en' - AND cn.name = 'PP_If_Key_population_yes') key_population2 ON key_population2.encounter_id = obs.encounter_id LEFT JOIN ( SELECT kp.encounter_id, @@ -1642,14 +1621,10 @@ LEFT JOIN ( FROM obs ob_kp WHERE - -- ob_kp.encounter_id = 247197 - -- AND ob_kp.obs_group_id = 5017686 ob_kp.concept_id IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'User_type_pop' OR name = 'User_type')) AND ob_kp.value_coded IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'Clinical_user' OR name = 'APSS_an_Clinical_user' OR name = 'Clinical_user_pop' OR name = 'APSS_an_Clinical_user_pop')) AND ob_kp.voided = 0 ) kp_fields - -- ON kp_fields.encounter_id = kp.encounter_id - -- AND kp_fields.obs_group_id = kp.obs_group_id ON kp_fields.obs_group_id = kp.obs_group_id ) key_population ON key_population.encounter_id = obs.encounter_id LEFT JOIN (SELECT From c0f1d74aacd622a5b0dc410b0881755fa00a9827 Mon Sep 17 00:00:00 2001 From: Joao machiana Date: Fri, 21 Feb 2020 17:37:20 +0200 Subject: [PATCH 3/9] fixed column for reference_to_other_services --- .../reports/sql/List_of_Patients_Summary.sql | 82 ++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql index c14ec7ed8..455f93a5b 100644 --- a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql +++ b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql @@ -1241,7 +1241,85 @@ LEFT JOIN (SELECT WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en') cn_serviceslist ON cn_serviceslist.concept_id = serviceslist.value_coded) list_of_services - GROUP BY encounter_id) services_list ON services_list.encounter_id = obs.encounter_id + GROUP BY encounter_id) services_list2 ON services_list2.encounter_id = obs.encounter_id +LEFT JOIN ( + SELECT + list_services.encounter_id, + list_services.services AS services + FROM + (SELECT + encounter_id, + GROUP_CONCAT(other_services) AS services + FROM + (SELECT + serviceslist.obs_id, + serviceslist.encounter_id, + CASE + WHEN cn_serviceslist.name = 'Reference_TB' THEN 'TB' + WHEN cn_serviceslist.name = 'Reference_PTV' THEN 'PTV' + WHEN cn_serviceslist.name = 'Reference_PF' THEN 'PF' + WHEN cn_serviceslist.name = 'Reference_APSS&PP' THEN 'APSS&PP' + WHEN cn_serviceslist.name = 'Reference_In patient' THEN 'Internamento' + WHEN cn_serviceslist.name = 'Reference_Other' THEN 'Outro' + END AS other_services + FROM + (SELECT + value_text, + value_numeric, + value_coded, + concept_name_type, + name, + locale, + encounter_id, + obs_id + FROM + obs + JOIN concept_name c ON c.concept_id = obs.concept_id + WHERE + concept_name_type = 'FULLY_SPECIFIED' + AND locale = 'en' + AND name = 'Reference_Other_Services' + ) serviceslist + JOIN ( + SELECT + name, + concept_id + FROM + concept_name + WHERE + concept_name_type = 'FULLY_SPECIFIED' + AND locale = 'en' + ) cn_serviceslist ON cn_serviceslist.concept_id = serviceslist.value_coded + ) list_of_services + GROUP BY encounter_id) AS list_services + INNER JOIN ( + SELECT + ob_service_form.encounter_id, + ob_service_form.obs_group_id + FROM + encounter e_service_form, obs ob_service_form, concept_name cn_service_form + WHERE + e_service_form.encounter_id = ob_service_form.encounter_id + AND cn_service_form.concept_id = ob_service_form.concept_id + AND cn_service_form.concept_name_type = 'FULLY_SPECIFIED' + AND cn_service_form.locale = 'en' + AND cn_service_form.name = 'Reference_Other_Services' + ) AS service_form + ON service_form.encounter_id = list_services.encounter_id + INNER JOIN ( + SELECT + ob_service_user.encounter_id, + ob_service_user.concept_id, + ob_service_user.obs_group_id + FROM + obs ob_service_user + WHERE + ob_service_user.concept_id = (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND name = 'User_type') + AND ob_service_user.value_coded IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'Clinical_user' OR name = 'APSS_an_Clinical_user' OR name = 'Clinical_user_pop' OR name = 'APSS_an_Clinical_user_pop')) + AND ob_service_user.voided = 0 + ) AS service_form_fields + ON service_form_fields.obs_group_id = service_form.obs_group_id +) services_list ON services_list.encounter_id = obs.encounter_id LEFT JOIN (SELECT g_apoio.encounter_id, GROUP_CONCAT(g_apoio.sg_list_with_states) AS g_apoio_list @@ -1621,7 +1699,7 @@ LEFT JOIN ( FROM obs ob_kp WHERE - ob_kp.concept_id IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'User_type_pop' OR name = 'User_type')) + ob_kp.concept_id = (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND name = 'User_type_pop') AND ob_kp.value_coded IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'Clinical_user' OR name = 'APSS_an_Clinical_user' OR name = 'Clinical_user_pop' OR name = 'APSS_an_Clinical_user_pop')) AND ob_kp.voided = 0 ) kp_fields From c00322b4d956ea97a9da04fecd75fdaf98bba1a6 Mon Sep 17 00:00:00 2001 From: Joao machiana Date: Fri, 21 Feb 2020 17:39:13 +0200 Subject: [PATCH 4/9] removed old code --- .../reports/sql/List_of_Patients_Summary.sql | 39 ------------------- 1 file changed, 39 deletions(-) diff --git a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql index 455f93a5b..c449a0536 100644 --- a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql +++ b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql @@ -1203,45 +1203,6 @@ LEFT JOIN (SELECT WHERE date(patient_status_state.date_created) <= date('#endDate#') ORDER BY patient_status_state.id) patient_state ON patient_state.patient_id = obs.patient_id AND date(patient_state.date_created) <=date(encounter_datetime) -LEFT JOIN (SELECT - encounter_id, GROUP_CONCAT(other_services) AS services - FROM - (SELECT - serviceslist.obs_id, - serviceslist.encounter_id, - CASE - WHEN cn_serviceslist.name = 'Reference_TB' THEN 'TB' - WHEN cn_serviceslist.name = 'Reference_PTV' THEN 'PTV' - WHEN cn_serviceslist.name = 'Reference_PF' THEN 'PF' - WHEN cn_serviceslist.name = 'Reference_APSS&PP' THEN 'APSS&PP' - WHEN cn_serviceslist.name = 'Reference_In patient' THEN 'Internamento' - WHEN cn_serviceslist.name = 'Reference_Other' THEN 'Outro' - END AS other_services - FROM - (SELECT - value_text, - value_numeric, - value_coded, - concept_name_type, - name, - locale, - encounter_id, - obs_id - FROM - obs - JOIN concept_name c ON c.concept_id = obs.concept_id - WHERE - concept_name_type = 'FULLY_SPECIFIED' - AND locale = 'en' - AND name = 'Reference_Other_Services') serviceslist - JOIN (SELECT - name, concept_id - FROM - concept_name - WHERE - concept_name_type = 'FULLY_SPECIFIED' - AND locale = 'en') cn_serviceslist ON cn_serviceslist.concept_id = serviceslist.value_coded) list_of_services - GROUP BY encounter_id) services_list2 ON services_list2.encounter_id = obs.encounter_id LEFT JOIN ( SELECT list_services.encounter_id, From 724fc605ed66965a8ff451defde7480235d68c1c Mon Sep 17 00:00:00 2001 From: Joao machiana Date: Fri, 21 Feb 2020 18:30:04 +0200 Subject: [PATCH 5/9] fixed code for grupos de apoio --- .../reports/sql/List_of_Patients_Summary.sql | 95 +++++++++++++------ 1 file changed, 64 insertions(+), 31 deletions(-) diff --git a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql index c449a0536..dbe48afea 100644 --- a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql +++ b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql @@ -1281,39 +1281,44 @@ LEFT JOIN ( ) AS service_form_fields ON service_form_fields.obs_group_id = service_form.obs_group_id ) services_list ON services_list.encounter_id = obs.encounter_id -LEFT JOIN (SELECT - g_apoio.encounter_id, - GROUP_CONCAT(g_apoio.sg_list_with_states) AS g_apoio_list - FROM - (SELECT - sg_obs.obs_id, - sg_obs.encounter_id, - CONCAT_WS(' - ', sg_shortname.name, sg_status.name) AS sg_list_with_states +LEFT JOIN ( + SELECT + grupo_de_apoio.encounter_id, + grupo_de_apoio.g_apoio_list FROM (SELECT - sg_obs.obs_id, - sg_obs.encounter_id, - sg_obs.concept_id, - sg_obs.person_id, - sg_obs.value_coded - FROM - obs AS sg_obs) AS sg_obs - JOIN (SELECT - c_name_pt.concept_id, c_name_pt.name - FROM - concept_name AS c_name_pt - WHERE - c_name_pt.concept_id IN (SELECT - concept_id + g_apoio.encounter_id, + GROUP_CONCAT(g_apoio.sg_list_with_states) AS g_apoio_list + FROM + (SELECT + sg_obs.obs_id, + sg_obs.encounter_id, + CONCAT_WS(' - ', sg_shortname.name, sg_status.name) AS sg_list_with_states FROM - concept_name - WHERE - name IN ('Reference_CR' , 'Reference_PC', 'Reference_AR', 'Reference_MPS') - AND concept_name_type = 'FULLY_SPECIFIED' - AND locale = 'en' - ORDER BY concept_id ASC) - AND c_name_pt.concept_name_type = 'SHORT' - AND c_name_pt.locale = 'pt') sg_shortname ON sg_obs.concept_id = sg_shortname.concept_id + (SELECT + sg_obs.obs_id, + sg_obs.encounter_id, + sg_obs.concept_id, + sg_obs.person_id, + sg_obs.value_coded + FROM + obs AS sg_obs) AS sg_obs + JOIN (SELECT + c_name_pt.concept_id, c_name_pt.name + FROM + concept_name AS c_name_pt + WHERE + c_name_pt.concept_id IN (SELECT + concept_id + FROM + concept_name + WHERE + name IN ('Reference_CR' , 'Reference_PC', 'Reference_AR', 'Reference_MPS') + AND concept_name_type = 'FULLY_SPECIFIED' + AND locale = 'en' + ORDER BY concept_id ASC) + AND c_name_pt.concept_name_type = 'SHORT' + AND c_name_pt.locale = 'pt') sg_shortname ON sg_obs.concept_id = sg_shortname.concept_id JOIN (SELECT c_name_status.concept_id, c_name_status.name FROM @@ -1329,7 +1334,35 @@ LEFT JOIN (SELECT AND locale = 'en') AND c_name_status.concept_name_type = 'SHORT' AND c_name_status.locale = 'pt') sg_status ON sg_status.concept_id = sg_obs.value_coded) g_apoio - GROUP BY encounter_id) gr_apoio ON gr_apoio.encounter_id = obs.encounter_id + GROUP BY encounter_id) AS grupo_de_apoio + INNER JOIN ( + SELECT + ob_g_apoio_form.encounter_id, + ob_g_apoio_form.obs_group_id + FROM + encounter e_g_apoio_form, obs ob_g_apoio_form, concept_name cn_g_apoio_form + WHERE + e_g_apoio_form.encounter_id = ob_g_apoio_form.encounter_id + AND cn_g_apoio_form.concept_id = ob_g_apoio_form.concept_id + AND cn_g_apoio_form.concept_name_type = 'FULLY_SPECIFIED' + AND cn_g_apoio_form.locale = 'en' + AND cn_g_apoio_form.name = 'Reference_Other_Services' + ) AS g_apoio_form + ON g_apoio_form.encounter_id = grupo_de_apoio.encounter_id + INNER JOIN ( + SELECT + ob_g_apoio_user.encounter_id, + ob_g_apoio_user.concept_id, + ob_g_apoio_user.obs_group_id + FROM + obs ob_g_apoio_user + WHERE + ob_g_apoio_user.concept_id = (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND name = 'User_type') + AND ob_g_apoio_user.value_coded IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'Clinical_user' OR name = 'APSS_an_Clinical_user' OR name = 'Clinical_user_pop' OR name = 'APSS_an_Clinical_user_pop')) + AND ob_g_apoio_user.voided = 0 + ) AS g_apoio_form_fields + ON g_apoio_form_fields.obs_group_id = g_apoio_form.obs_group_id +) gr_apoio ON gr_apoio.encounter_id = obs.encounter_id LEFT JOIN (SELECT GROUP_CONCAT(mdc_table.mdc_list_with_states) AS states, mdc_table.encounter_id, From e74e7fdbc954946268a43a4cbd5fd5212f8238fa Mon Sep 17 00:00:00 2001 From: Joao machiana Date: Mon, 24 Feb 2020 13:48:09 +0200 Subject: [PATCH 6/9] Added lista de grupo de apoio filter --- .../reports/sql/List_of_Patients_Summary.sql | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql index dbe48afea..3ec38ccf1 100644 --- a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql +++ b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql @@ -1281,6 +1281,7 @@ LEFT JOIN ( ) AS service_form_fields ON service_form_fields.obs_group_id = service_form.obs_group_id ) services_list ON services_list.encounter_id = obs.encounter_id +-- //TODO adicionar modelos diferenciados de cuidado LEFT JOIN ( SELECT grupo_de_apoio.encounter_id, @@ -1441,7 +1442,70 @@ LEFT JOIN (SELECT ORDER BY concept_id ASC) AND c_name_pt.concept_name_type = 'SHORT' AND c_name_pt.locale = 'pt') sg_shortname ON sg_obs.concept_id = sg_shortname.concept_id) support_group - GROUP BY encounter_id) sg_list ON sg_list.encounter_id = obs.encounter_id + GROUP BY encounter_id ) sg_list2 ON sg_list2.encounter_id = obs.encounter_id +LEFT JOIN ( + SELECT + sg_list_names.list_sg AS list_sg, + sg_list_names.encounter_id + FROM + (SELECT + GROUP_CONCAT(name) AS list_sg, encounter_id + FROM + (SELECT + sg_obs.obs_id, + sg_shortname.name, + sg_obs.encounter_id, + sg_obs.concept_id, + sg_obs.person_id, + sg_obs.value_coded + FROM + obs AS sg_obs + JOIN (SELECT + c_name_pt.concept_id, c_name_pt.name + FROM + concept_name AS c_name_pt + WHERE + c_name_pt.concept_id IN (SELECT + concept_id + FROM + concept_name + WHERE + name IN ('Reference_CR' , 'Reference_PC', 'Reference_AR', 'Reference_MPS') + AND concept_name_type = 'FULLY_SPECIFIED' + AND locale = 'en' + ORDER BY concept_id ASC) + AND c_name_pt.concept_name_type = 'SHORT' + AND c_name_pt.locale = 'pt') sg_shortname ON sg_obs.concept_id = sg_shortname.concept_id) support_group + GROUP BY encounter_id ) AS sg_list_names + INNER JOIN ( + SELECT + ob_g_apoio_form.encounter_id, + ob_g_apoio_form.obs_group_id + FROM + encounter e_g_apoio_form, obs ob_g_apoio_form, concept_name cn_g_apoio_form + WHERE + e_g_apoio_form.encounter_id = ob_g_apoio_form.encounter_id + AND cn_g_apoio_form.concept_id = ob_g_apoio_form.concept_id + AND cn_g_apoio_form.concept_name_type = 'FULLY_SPECIFIED' + AND cn_g_apoio_form.locale = 'en' + AND cn_g_apoio_form.name = 'Reference_Other_Services' + ) AS g_apoio_form + ON g_apoio_form.encounter_id = sg_list_names.encounter_id + INNER JOIN ( + SELECT + ob_g_apoio_user.encounter_id, + ob_g_apoio_user.concept_id, + ob_g_apoio_user.obs_group_id + FROM + obs ob_g_apoio_user + WHERE + ob_g_apoio_user.concept_id = (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND name = 'User_type') + AND ob_g_apoio_user.value_coded IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'Clinical_user' OR name = 'APSS_an_Clinical_user' OR name = 'Clinical_user_pop' OR name = 'APSS_an_Clinical_user_pop')) + AND ob_g_apoio_user.voided = 0 + ) AS g_apoio_form_fields + ON g_apoio_form_fields.obs_group_id = g_apoio_form.obs_group_id + +) sg_list ON sg_list.encounter_id = obs.encounter_id LEFT JOIN (SELECT mdc_obs.encounter_id, CASE From 976ccd62cb822136fe76ba51c6939dbddac25b0d Mon Sep 17 00:00:00 2001 From: Joao machiana Date: Mon, 24 Feb 2020 14:45:56 +0200 Subject: [PATCH 7/9] added mdc filter --- .../reports/sql/List_of_Patients_Summary.sql | 87 +++++++++++++------ 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql index 3ec38ccf1..a034431aa 100644 --- a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql +++ b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql @@ -1347,7 +1347,7 @@ LEFT JOIN ( AND cn_g_apoio_form.concept_id = ob_g_apoio_form.concept_id AND cn_g_apoio_form.concept_name_type = 'FULLY_SPECIFIED' AND cn_g_apoio_form.locale = 'en' - AND cn_g_apoio_form.name = 'Reference_Other_Services' + AND cn_g_apoio_form.name = 'Reference_Section_Support_Group' ) AS g_apoio_form ON g_apoio_form.encounter_id = grupo_de_apoio.encounter_id INNER JOIN ( @@ -1488,7 +1488,7 @@ LEFT JOIN ( AND cn_g_apoio_form.concept_id = ob_g_apoio_form.concept_id AND cn_g_apoio_form.concept_name_type = 'FULLY_SPECIFIED' AND cn_g_apoio_form.locale = 'en' - AND cn_g_apoio_form.name = 'Reference_Other_Services' + AND cn_g_apoio_form.name = 'Reference_Section_Support_Group' ) AS g_apoio_form ON g_apoio_form.encounter_id = sg_list_names.encounter_id INNER JOIN ( @@ -1531,36 +1531,69 @@ LEFT JOIN (SELECT AND mdc_concept.concept_name_type = 'FULLY_SPECIFIED' AND mdc_concept.locale = 'en' ORDER BY mdc_concept.concept_id ASC)) AS mdc_obs) mdc_eligibility ON mdc_eligibility.encounter_id = obs.encounter_id -LEFT JOIN (SELECT +LEFT JOIN ( + SELECT + mdc_data.encounter_id, + mdc_data.modelos_diferenciados AS modelos_diferenciados + FROM + (SELECT mdc_obs.encounter_id, GROUP_CONCAT(name SEPARATOR ', ') AS modelos_diferenciados -FROM -((SELECT - obs_mdc.obs_id, - obs_mdc.encounter_id, - obs_mdc.concept_id, - obs_mdc.person_id, - obs_mdc.value_coded - FROM - obs AS obs_mdc) mdc_obs - JOIN (SELECT - c_name_pt.concept_id, c_name_pt.name FROM - concept_name AS c_name_pt + ((SELECT + obs_mdc.obs_id, + obs_mdc.encounter_id, + obs_mdc.concept_id, + obs_mdc.person_id, + obs_mdc.value_coded + FROM + obs AS obs_mdc) mdc_obs + JOIN (SELECT + c_name_pt.concept_id, c_name_pt.name + FROM + concept_name AS c_name_pt + WHERE + c_name_pt.concept_id IN (SELECT + concept_id + FROM + concept_name + WHERE + name IN ('Reference_GA' , 'Reference_AF', 'Reference_CA', 'Reference_PU', 'Reference_FR', 'Reference_DT', 'Reference_DC', 'Reference_MDC_Other') + AND concept_name_type = 'FULLY_SPECIFIED' + AND locale = 'en' + ORDER BY concept_id ASC) + AND c_name_pt.concept_name_type = 'SHORT' + AND c_name_pt.locale = 'pt') mdc_shortname ON mdc_obs.concept_id = mdc_shortname.concept_id) + GROUP BY encounter_id) AS mdc_data + INNER JOIN ( + SELECT + ob_g_apoio_form.encounter_id, + ob_g_apoio_form.obs_group_id + FROM + encounter e_g_apoio_form, obs ob_g_apoio_form, concept_name cn_g_apoio_form WHERE - c_name_pt.concept_id IN (SELECT - concept_id - FROM - concept_name - WHERE - name IN ('Reference_GA' , 'Reference_AF', 'Reference_CA', 'Reference_PU', 'Reference_FR', 'Reference_DT', 'Reference_DC', 'Reference_MDC_Other') - AND concept_name_type = 'FULLY_SPECIFIED' - AND locale = 'en' - ORDER BY concept_id ASC) - AND c_name_pt.concept_name_type = 'SHORT' - AND c_name_pt.locale = 'pt') mdc_shortname ON mdc_obs.concept_id = mdc_shortname.concept_id) -GROUP BY encounter_id) mdc_table1 ON mdc_table1.encounter_id = obs.encounter_id + e_g_apoio_form.encounter_id = ob_g_apoio_form.encounter_id + AND cn_g_apoio_form.concept_id = ob_g_apoio_form.concept_id + AND cn_g_apoio_form.concept_name_type = 'FULLY_SPECIFIED' + AND cn_g_apoio_form.locale = 'en' + AND cn_g_apoio_form.name = 'Reference_MDC_Section' + ) AS g_apoio_form + ON g_apoio_form.encounter_id = mdc_data.encounter_id + INNER JOIN ( + SELECT + ob_g_apoio_user.encounter_id, + ob_g_apoio_user.concept_id, + ob_g_apoio_user.obs_group_id + FROM + obs ob_g_apoio_user + WHERE + ob_g_apoio_user.concept_id = (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND name = 'User_type') + AND ob_g_apoio_user.value_coded IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'Clinical_user' OR name = 'APSS_an_Clinical_user' OR name = 'Clinical_user_pop' OR name = 'APSS_an_Clinical_user_pop')) + AND ob_g_apoio_user.voided = 0 + ) AS g_apoio_form_fields + ON g_apoio_form_fields.obs_group_id = g_apoio_form.obs_group_id +) mdc_table1 ON mdc_table1.encounter_id = obs.encounter_id LEFT JOIN (SELECT GROUP_CONCAT(name) AS family_planning, encounter_id FROM From 886cc9a6d6574a5f67b2c1015a6a60af42c102ab Mon Sep 17 00:00:00 2001 From: Joao machiana Date: Tue, 25 Feb 2020 12:40:09 +0200 Subject: [PATCH 8/9] =?UTF-8?q?added=20Popula=C3=A7=C3=A3o=20Vulner=C3=A1v?= =?UTF-8?q?el?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reports/sql/List_of_Patients_Summary.sql | 54 ++++++++++++++----- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql index a034431aa..0d55c8cd6 100644 --- a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql +++ b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql @@ -1796,27 +1796,53 @@ LEFT JOIN ( ) kp_fields ON kp_fields.obs_group_id = kp.obs_group_id ) key_population ON key_population.encounter_id = obs.encounter_id -LEFT JOIN (SELECT - e.encounter_id, +LEFT JOIN ( + SELECT + populucao_vulneravel.encounter_id, + populucao_vulneravel.pop_vul AS pop_vul, + populucao_vulneravel.obs_group_id, + vp_fields.concept_id, + vp_fields.value_coded, + FROM + (SELECT + e.encounter_id, ob.person_id, ob.value_coded, + ob.obs_group_id, (SELECT - name - FROM - concept_name - WHERE - concept_id = ob.value_coded - AND locale = 'pt' - AND concept_name_type = 'SHORT') AS pop_vul + name + FROM + concept_name + WHERE + concept_id = ob.value_coded + AND locale = 'pt' + AND concept_name_type = 'SHORT') AS pop_vul FROM obs ob, encounter e, concept_name cn WHERE ob.person_id = e.patient_id - AND ob.encounter_id = e.encounter_id - AND ob.concept_id = cn.concept_id - AND cn.concept_name_type = 'FULLY_SPECIFIED' - AND cn.locale = 'en' - AND cn.name = 'PP_IF_Vulnerable_Population_Yes') vp ON vp.encounter_id = obs.encounter_id + AND ob.encounter_id = e.encounter_id + AND ob.concept_id = cn.concept_id + AND cn.concept_name_type = 'FULLY_SPECIFIED' + AND cn.locale = 'en' + AND cn.name = 'PP_IF_Vulnerable_Population_Yes') AS populucao_vulneravel + INNER JOIN ( + SELECT + ob_kp.encounter_id, + ob_kp.person_id, + ob_kp.value_coded, + ob_kp.concept_id, + ob_kp.obs_group_id, + ob_kp.obs_id + FROM + obs ob_kp + WHERE + ob_kp.concept_id = (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND name = 'User_type_pop') + AND ob_kp.value_coded IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'Clinical_user' OR name = 'APSS_an_Clinical_user' OR name = 'Clinical_user_pop' OR name = 'APSS_an_Clinical_user_pop')) + AND ob_kp.voided = 0 + ) vp_fields + ON vp_fields.obs_group_id = populucao_vulneravel.obs_group_id +) vp ON vp.encounter_id = obs.encounter_id LEFT JOIN (SELECT concept_name_type, GROUP_CONCAT(name) AS lab_tests, From 76599fea24ad31787f51caecebea3257c6cb6171 Mon Sep 17 00:00:00 2001 From: Joao machiana Date: Tue, 25 Feb 2020 15:24:31 +0200 Subject: [PATCH 9/9] fixed filters --- .../reports/sql/List_of_Patients_Summary.sql | 247 +++++++++++------- 1 file changed, 152 insertions(+), 95 deletions(-) diff --git a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql index 0d55c8cd6..09f67a05f 100644 --- a/openmrs/apps/reports/sql/List_of_Patients_Summary.sql +++ b/openmrs/apps/reports/sql/List_of_Patients_Summary.sql @@ -1206,15 +1206,18 @@ LEFT JOIN (SELECT LEFT JOIN ( SELECT list_services.encounter_id, - list_services.services AS services + list_services.services AS services, + list_services.obs_group_id FROM (SELECT encounter_id, + MAX(obs_group_id) AS obs_group_id, GROUP_CONCAT(other_services) AS services FROM (SELECT serviceslist.obs_id, serviceslist.encounter_id, + serviceslist.obs_group_id, CASE WHEN cn_serviceslist.name = 'Reference_TB' THEN 'TB' WHEN cn_serviceslist.name = 'Reference_PTV' THEN 'PTV' @@ -1232,6 +1235,7 @@ LEFT JOIN ( name, locale, encounter_id, + obs_group_id, obs_id FROM obs @@ -1253,20 +1257,6 @@ LEFT JOIN ( ) cn_serviceslist ON cn_serviceslist.concept_id = serviceslist.value_coded ) list_of_services GROUP BY encounter_id) AS list_services - INNER JOIN ( - SELECT - ob_service_form.encounter_id, - ob_service_form.obs_group_id - FROM - encounter e_service_form, obs ob_service_form, concept_name cn_service_form - WHERE - e_service_form.encounter_id = ob_service_form.encounter_id - AND cn_service_form.concept_id = ob_service_form.concept_id - AND cn_service_form.concept_name_type = 'FULLY_SPECIFIED' - AND cn_service_form.locale = 'en' - AND cn_service_form.name = 'Reference_Other_Services' - ) AS service_form - ON service_form.encounter_id = list_services.encounter_id INNER JOIN ( SELECT ob_service_user.encounter_id, @@ -1279,31 +1269,35 @@ LEFT JOIN ( AND ob_service_user.value_coded IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'Clinical_user' OR name = 'APSS_an_Clinical_user' OR name = 'Clinical_user_pop' OR name = 'APSS_an_Clinical_user_pop')) AND ob_service_user.voided = 0 ) AS service_form_fields - ON service_form_fields.obs_group_id = service_form.obs_group_id -) services_list ON services_list.encounter_id = obs.encounter_id --- //TODO adicionar modelos diferenciados de cuidado + ON service_form_fields.obs_group_id = list_services.obs_group_id +) services_list + ON services_list.encounter_id = obs.encounter_id LEFT JOIN ( SELECT grupo_de_apoio.encounter_id, - grupo_de_apoio.g_apoio_list + grupo_de_apoio.g_apoio_list, + grupo_de_apoio.obs_group_id FROM (SELECT g_apoio.encounter_id, - GROUP_CONCAT(g_apoio.sg_list_with_states) AS g_apoio_list + GROUP_CONCAT(g_apoio.sg_list_with_states) AS g_apoio_list, + MAX(g_apoio.obs_group_id) AS obs_group_id FROM (SELECT sg_obs.obs_id, sg_obs.encounter_id, + sg_obs.obs_group_id, CONCAT_WS(' - ', sg_shortname.name, sg_status.name) AS sg_list_with_states FROM (SELECT - sg_obs.obs_id, - sg_obs.encounter_id, - sg_obs.concept_id, - sg_obs.person_id, - sg_obs.value_coded + sg_obs_in.obs_id, + sg_obs_in.obs_group_id, + sg_obs_in.encounter_id, + sg_obs_in.concept_id, + sg_obs_in.person_id, + sg_obs_in.value_coded FROM - obs AS sg_obs) AS sg_obs + obs AS sg_obs_in) AS sg_obs JOIN (SELECT c_name_pt.concept_id, c_name_pt.name FROM @@ -1349,7 +1343,7 @@ LEFT JOIN ( AND cn_g_apoio_form.locale = 'en' AND cn_g_apoio_form.name = 'Reference_Section_Support_Group' ) AS g_apoio_form - ON g_apoio_form.encounter_id = grupo_de_apoio.encounter_id + ON g_apoio_form.encounter_id = grupo_de_apoio.obs_group_id INNER JOIN ( SELECT ob_g_apoio_user.encounter_id, @@ -1364,56 +1358,94 @@ LEFT JOIN ( ) AS g_apoio_form_fields ON g_apoio_form_fields.obs_group_id = g_apoio_form.obs_group_id ) gr_apoio ON gr_apoio.encounter_id = obs.encounter_id -LEFT JOIN (SELECT - GROUP_CONCAT(mdc_table.mdc_list_with_states) AS states, - mdc_table.encounter_id, - mdc_table.obs_id - FROM - (SELECT - CONCAT_WS(' - ', mdc_shortname.name, mdc_status.name) AS mdc_list_with_states, - mdc_obs.obs_id, - mdc_obs.encounter_id +LEFT JOIN ( + SELECT + mdc_table_data.encounter_id, + mdc_table_data.obs_group_id, + mdc_table_data.states AS states FROM (SELECT - obs_mdc.obs_id, - obs_mdc.concept_id, - obs_mdc.person_id, - obs_mdc.value_coded, - obs_mdc.encounter_id - FROM - obs AS obs_mdc) mdc_obs - JOIN (SELECT - c_name_pt.concept_id, c_name_pt.name - FROM - concept_name AS c_name_pt - WHERE - c_name_pt.concept_id IN (SELECT - concept_id + GROUP_CONCAT(mdc_table.mdc_list_with_states) AS states, + mdc_table.encounter_id, + mdc_table.obs_id, + mdc_table.obs_group_id FROM - concept_name + (SELECT + CONCAT_WS(' - ', mdc_shortname.name, mdc_status.name) AS mdc_list_with_states, + mdc_obs.obs_id, + mdc_obs.encounter_id, + mdc_obs.obs_group_id + FROM + (SELECT + obs_mdc.obs_id, + obs_mdc.concept_id, + obs_mdc.person_id, + obs_mdc.value_coded, + obs_mdc.encounter_id, + obs_mdc.obs_group_id + FROM + obs AS obs_mdc) mdc_obs + JOIN (SELECT + c_name_pt.concept_id, c_name_pt.name + FROM + concept_name AS c_name_pt WHERE - name IN ('Reference_GA' , 'Reference_AF', 'Reference_CA', 'Reference_PU', 'Reference_FR', 'Reference_DT', 'Reference_DC', 'Reference_MDC_Other') - AND concept_name_type = 'FULLY_SPECIFIED' - AND locale = 'en' - ORDER BY concept_id ASC) - AND c_name_pt.concept_name_type = 'SHORT' - AND c_name_pt.locale = 'pt') mdc_shortname ON mdc_obs.concept_id = mdc_shortname.concept_id - JOIN (SELECT - c_name_status.concept_id, c_name_status.name - FROM - concept_name AS c_name_status - WHERE - c_name_status.concept_id IN (SELECT - concept_id + c_name_pt.concept_id IN (SELECT + concept_id + FROM + concept_name + WHERE + name IN ('Reference_GA' , 'Reference_AF', 'Reference_CA', 'Reference_PU', 'Reference_FR', 'Reference_DT', 'Reference_DC', 'Reference_MDC_Other') + AND concept_name_type = 'FULLY_SPECIFIED' + AND locale = 'en' + ORDER BY concept_id ASC) + AND c_name_pt.concept_name_type = 'SHORT' + AND c_name_pt.locale = 'pt') mdc_shortname ON mdc_obs.concept_id = mdc_shortname.concept_id + JOIN (SELECT + c_name_status.concept_id, c_name_status.name FROM - concept_name + concept_name AS c_name_status WHERE - name IN ('Reference_Start' , 'Reference_In_Progress', 'Reference_End') - AND concept_name_type = 'FULLY_SPECIFIED' - AND locale = 'en') - AND c_name_status.concept_name_type = 'SHORT' - AND c_name_status.locale = 'pt') mdc_status ON mdc_status.concept_id = mdc_obs.value_coded) mdc_table - GROUP BY encounter_id) table_mdc ON table_mdc.encounter_id = obs.encounter_id + c_name_status.concept_id IN (SELECT + concept_id + FROM + concept_name + WHERE + name IN ('Reference_Start' , 'Reference_In_Progress', 'Reference_End') + AND concept_name_type = 'FULLY_SPECIFIED' + AND locale = 'en') + AND c_name_status.concept_name_type = 'SHORT' + AND c_name_status.locale = 'pt') mdc_status ON mdc_status.concept_id = mdc_obs.value_coded) mdc_table + GROUP BY encounter_id) AS mdc_table_data + INNER JOIN ( + SELECT + ob_g_apoio_form.encounter_id, + ob_g_apoio_form.obs_group_id + FROM + encounter e_g_apoio_form, obs ob_g_apoio_form, concept_name cn_g_apoio_form + WHERE + e_g_apoio_form.encounter_id = ob_g_apoio_form.encounter_id + AND cn_g_apoio_form.concept_id = ob_g_apoio_form.concept_id + AND cn_g_apoio_form.concept_name_type = 'FULLY_SPECIFIED' + AND cn_g_apoio_form.locale = 'en' + AND cn_g_apoio_form.name = 'Reference_Section_Support_Group' + ) AS g_apoio_form + ON g_apoio_form.obs_group_id = mdc_table_data.obs_group_id + INNER JOIN ( + SELECT + ob_g_apoio_user.encounter_id, + ob_g_apoio_user.concept_id, + ob_g_apoio_user.obs_group_id + FROM + obs ob_g_apoio_user + WHERE + ob_g_apoio_user.concept_id = (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND name = 'User_type') + AND ob_g_apoio_user.value_coded IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'Clinical_user' OR name = 'APSS_an_Clinical_user' OR name = 'Clinical_user_pop' OR name = 'APSS_an_Clinical_user_pop')) + AND ob_g_apoio_user.voided = 0 + ) AS g_apoio_form_fields + ON g_apoio_form_fields.obs_group_id = g_apoio_form.obs_group_id +) table_mdc + ON table_mdc.encounter_id = obs.encounter_id LEFT JOIN (SELECT GROUP_CONCAT(name) AS list_sg, encounter_id FROM @@ -1506,43 +1538,68 @@ LEFT JOIN ( ON g_apoio_form_fields.obs_group_id = g_apoio_form.obs_group_id ) sg_list ON sg_list.encounter_id = obs.encounter_id -LEFT JOIN (SELECT - mdc_obs.encounter_id, - CASE - WHEN mdc_obs.value_coded = 1 THEN 'Sim' - WHEN mdc_obs.value_coded = 2 THEN 'Não' - END AS mdc_yes_no +LEFT JOIN ( + SELECT + mdc_eligibility_data.encounter_id, + mdc_eligibility_data.obs_group_id, + mdc_eligibility_data.mdc_yes_no FROM (SELECT - obs_mdc.obs_id, - obs_mdc.encounter_id, - obs_mdc.concept_id, - obs_mdc.person_id, - obs_mdc.value_coded - FROM - obs AS obs_mdc - WHERE - obs_mdc.concept_id IN (SELECT - mdc_concept.concept_id + mdc_obs.encounter_id, + MAX(mdc_obs.obs_group_id) AS obs_group_id, + CASE + WHEN mdc_obs.value_coded = 1 THEN 'Sim' + WHEN mdc_obs.value_coded = 2 THEN 'Não' + END AS mdc_yes_no + FROM + (SELECT + obs_mdc.obs_id, + obs_mdc.obs_group_id, + obs_mdc.encounter_id, + obs_mdc.concept_id, + obs_mdc.person_id, + obs_mdc.value_coded + FROM + obs AS obs_mdc + WHERE + obs_mdc.concept_id IN (SELECT + mdc_concept.concept_id + FROM + concept_name AS mdc_concept + WHERE + name IN ('Reference_Eligible') + AND mdc_concept.concept_name_type = 'FULLY_SPECIFIED' + AND mdc_concept.locale = 'en' + ORDER BY mdc_concept.concept_id ASC)) AS mdc_obs) AS mdc_eligibility_data + INNER JOIN ( + SELECT + ob_g_apoio_user.encounter_id, + ob_g_apoio_user.concept_id, + ob_g_apoio_user.obs_group_id FROM - concept_name AS mdc_concept + obs ob_g_apoio_user WHERE - name IN ('Reference_Eligible') - AND mdc_concept.concept_name_type = 'FULLY_SPECIFIED' - AND mdc_concept.locale = 'en' - ORDER BY mdc_concept.concept_id ASC)) AS mdc_obs) mdc_eligibility ON mdc_eligibility.encounter_id = obs.encounter_id + ob_g_apoio_user.concept_id = (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND name = 'User_type') + AND ob_g_apoio_user.value_coded IN (SELECT concept_id FROM concept_name WHERE concept_name_type = 'FULLY_SPECIFIED' AND locale = 'en' AND (name = 'Clinical_user' OR name = 'APSS_an_Clinical_user' OR name = 'Clinical_user_pop' OR name = 'APSS_an_Clinical_user_pop')) + AND ob_g_apoio_user.voided = 0 + ) g_apoio_form_fields ON g_apoio_form_fields.obs_group_id = mdc_eligibility_data.obs_group_id +) mdc_eligibility + ON mdc_eligibility.encounter_id = obs.encounter_id LEFT JOIN ( SELECT mdc_data.encounter_id, + mdc_data.obs_group_id, mdc_data.modelos_diferenciados AS modelos_diferenciados FROM (SELECT - mdc_obs.encounter_id, + mdc_obs.encounter_id, + MAX(mdc_obs.obs_group_id) as obs_group_id, GROUP_CONCAT(name SEPARATOR ', ') AS modelos_diferenciados FROM ((SELECT obs_mdc.obs_id, + obs_mdc.obs_group_id, obs_mdc.encounter_id, obs_mdc.concept_id, obs_mdc.person_id, @@ -1579,7 +1636,7 @@ LEFT JOIN ( AND cn_g_apoio_form.locale = 'en' AND cn_g_apoio_form.name = 'Reference_MDC_Section' ) AS g_apoio_form - ON g_apoio_form.encounter_id = mdc_data.encounter_id + ON g_apoio_form.obs_group_id = mdc_data.obs_group_id INNER JOIN ( SELECT ob_g_apoio_user.encounter_id, @@ -1802,7 +1859,7 @@ LEFT JOIN ( populucao_vulneravel.pop_vul AS pop_vul, populucao_vulneravel.obs_group_id, vp_fields.concept_id, - vp_fields.value_coded, + vp_fields.value_coded FROM (SELECT e.encounter_id,