diff --git a/Serialized_Object.sql b/Serialized_Object.sql index 10f1662..a0b5ad6 100644 --- a/Serialized_Object.sql +++ b/Serialized_Object.sql @@ -1,8 +1,8 @@ --- MySQL dump 10.13 Distrib 5.6.40, for Linux (x86_64) +-- MySQL dump 10.13 Distrib 5.6.41, for Linux (x86_64) -- -- Host: localhost Database: openmrs -- ------------------------------------------------------ --- Server version 5.6.40 +-- Server version 5.6.41 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -58,7 +58,7 @@ LOCK TABLES `serialized_object` WRITE; /*!40000 ALTER TABLE `serialized_object` DISABLE KEYS */; INSERT INTO `serialized_object` VALUES (1,'ART Monthly Period Indicator Report','Period indicator report to be used to report to DHIS2 Lesotho Monthly ART Aggregate Report','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART Monthly Period Indicator Report\n Period indicator report to be used to report to DHIS2 Lesotho Monthly ART Aggregate Report\n \n 2018-02-21 08:48:22 UTC\n \n 2018-03-01 07:14:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2018-02-21 08:48:22',4,'2018-03-01 07:14:19',4,0,NULL,NULL,NULL,'c097de3d-fba8-40f1-ba07-580002f61d2b'),(2,'ART_test Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART_test Data Set\n \n 2018-02-21 08:48:23 UTC\n \n 2018-07-11 11:24:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 2\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n \n \n 001\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n 002\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n 003\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n 004\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n 005\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 05to09yrs\n \n \n \n \n \n 006\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 05to09yrs\n \n \n \n \n \n 007\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n 008\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n 009\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n 010\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n 011\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n 012\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n 013\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 25to49yrs\n \n \n \n \n \n 014\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 25to49yrs\n \n \n \n \n \n 015\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 50+yrs\n \n \n \n \n \n 016\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 50+yrs\n \n \n \n \n \n 017\n \n \n \n \n \n \n \n \n 018\n \n \n \n \n \n \n 019\n \n \n \n \n \n \n 020\n \n \n \n \n \n \n 021\n \n \n \n \n \n \n 022\n \n \n \n \n \n \n 023\n \n \n \n \n \n \n 024\n \n \n \n \n \n \n 025\n \n \n \n \n \n \n 026\n \n \n \n \n \n \n 027\n \n \n \n \n \n \n 028\n \n \n \n \n \n \n 029\n \n \n \n \n \n \n 030\n \n \n \n \n \n \n 031\n \n \n \n \n \n \n 032\n \n \n \n \n \n \n 033\n \n \n \n \n \n \n \n \n \n 034\n \n \n \n \n \n \n 035\n \n \n \n \n \n \n 036\n \n \n \n \n \n \n 037\n \n \n \n \n \n \n 038\n \n \n \n \n \n \n 039\n \n \n \n \n \n \n 040\n \n \n \n \n \n \n 041\n \n \n \n \n \n \n 042\n \n \n \n \n \n \n 043\n \n \n \n \n \n \n 044\n \n \n \n \n \n \n 045\n \n \n \n \n \n \n 046\n \n \n \n \n \n \n 047\n \n \n \n \n \n \n 048\n \n \n \n \n \n \n 049\n \n \n \n \n \n \n \n \n \n 050\n \n \n \n \n \n \n \n \n \n 051\n \n \n \n \n \n \n \n \n \n 052\n \n \n \n \n \n \n \n \n \n 053\n \n \n \n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 054\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 055\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Adults\n \n \n \n \n \n 056\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n 057\n \n \n \n \n \n \n \n \n \n 058\n \n \n \n \n \n \n 059\n \n \n \n \n \n \n 060\n \n \n \n \n \n \n 192\n \n \n \n \n \n \n \n \n \n 193\n \n \n \n \n \n \n 194\n \n \n \n \n \n \n 195\n \n \n \n \n \n \n 196\n \n \n \n \n \n \n 197\n \n \n \n \n \n \n 198\n \n \n \n \n \n \n 199\n \n \n \n \n \n \n 200\n \n \n \n \n \n \n 201\n \n \n \n \n \n \n 202\n \n \n \n \n \n \n 203\n \n \n \n \n \n \n 204\n \n \n \n \n \n \n 205\n \n \n \n \n \n \n 206\n \n \n \n \n \n \n 207\n \n \n \n \n \n \n 208\n \n \n \n \n \n \n \n \n \n 209\n \n \n \n \n \n \n 210\n \n \n \n \n \n \n 211\n \n \n \n \n \n \n 212\n \n \n \n \n \n \n 213\n \n \n \n \n \n \n 214\n \n \n \n \n \n \n 215\n \n \n \n \n \n \n 216\n \n \n \n \n \n \n 217\n \n \n \n \n \n \n 218\n \n \n \n \n \n \n 219\n \n \n \n \n \n \n 220\n \n \n \n \n \n \n 221\n \n \n \n \n \n \n 222\n \n \n \n \n \n \n 223\n \n \n \n \n \n \n','2018-02-21 14:18:23',4,'2018-07-11 16:54:16',4,0,NULL,NULL,NULL,'0e2ab4bb-abdb-4097-916c-794d14bd9664'),(3,'Sex_Cohort_Query','Patients sex','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.GenderCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Sex_Cohort_Query\n Patients sex\n \n 2018-02-21 08:55:41 UTC\n \n 2018-02-27 09:19:19 UTC\n \n \n maleIncluded\n \n java.lang.Boolean\n true\n \n \n femaleIncluded\n \n java.lang.Boolean\n true\n \n \n 3\n false\n','2018-02-21 08:55:41',4,'2018-02-27 09:19:19',4,0,NULL,NULL,NULL,'a1ddc580-da2c-4297-8c69-866de9252263'),(4,'Age_cohort_Query','patients ages','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.AgeCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Age_cohort_Query\n patients ages\n \n 2018-02-21 09:00:07 UTC\n \n 2019-03-26 13:41:51 UTC\n \n \n minAge\n \n java.lang.Integer\n true\n \n \n maxAge\n \n java.lang.Integer\n true\n \n \n effectiveDate\n \n java.util.Date\n true\n \n \n 4\n YEARS\n YEARS\n false\n','2018-02-21 09:00:07',4,'2019-03-26 13:41:51',4,0,NULL,NULL,NULL,'f8d3dd08-0b1f-4780-b77f-97d021b803af'),(5,'ART start date','ART clients newly started on ART','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.DateObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART start date\n ART clients newly started on ART\n \n 2018-02-21 09:08:47 UTC\n \n 2018-03-01 07:22:25 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n value1\n \n java.util.Date\n true\n \n \n value2\n \n java.util.Date\n true\n \n \n 5\n ANY\n \n \n \n \n GREATER_EQUAL\n LESS_EQUAL\n','2018-02-21 09:08:47',4,'2018-03-01 07:22:25',4,0,NULL,NULL,NULL,'3cfb3f8e-ceff-4201-8fcb-25e2d61a77c5'),(6,'CI_01: Clients newly started on ART','Cohort Indicator for clients newly started on ART','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI_01: Clients newly started on ART\n Cohort Indicator for clients newly started on ART\n \n 2018-02-21 09:55:13 UTC\n \n 2019-01-31 18:03:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 6\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-02-21 09:55:13',4,'2019-01-31 18:03:42',4,0,NULL,NULL,NULL,'e815a8e7-ba99-4a34-9e3b-038a0fbaa34d'),(9,'DM_Age','age dimensions','org.openmrs.module.reporting.indicator.dimension.Dimension','org.openmrs.module.reporting.indicator.dimension.CohortDefinitionDimension','org.openmrs.module.reporting.serializer.ReportingSerializer','\n DM_Age\n age dimensions\n \n 2018-02-27 09:21:44 UTC\n \n 2020-04-26 11:02:40 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n 9\n \n \n 01to04yrs\n \n \n \n \n maxAge\n 4\n \n \n minAge\n 1\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 05to09yrs\n \n \n \n \n maxAge\n 9\n \n \n minAge\n 5\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 05yrsto14yrs\n \n \n \n \n maxAge\n 14\n \n \n minAge\n 5\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 06Mnths-5yrs\n \n \n \n \n maxAge\n 5\n \n \n minAge\n 6\n \n \n \n \n \n 06yrs-14yrs\n \n \n \n \n maxAge\n 14\n \n \n minAge\n 6\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 0Mnths-4yrs\n \n \n \n \n maxAge\n 4\n \n \n minAge\n 0\n \n \n \n \n \n 100to150yrs\n \n \n \n \n maxAge\n 150\n \n \n minAge\n 120\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 10to14yrs\n \n \n \n \n maxAge\n 14\n \n \n minAge\n 10\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 15+yrs\n \n \n \n \n maxAge\n 120\n \n \n minAge\n 15\n \n \n \n \n \n 15to19yrs\n \n \n \n \n maxAge\n 19\n \n \n minAge\n 15\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 20to24yrs\n \n \n \n \n maxAge\n 24\n \n \n minAge\n 20\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 25to29yrs\n \n \n \n \n maxAge\n 29\n \n \n minAge\n 25\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 25to49yrs\n \n \n \n \n maxAge\n 49\n \n \n minAge\n 25\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 30to34yrs\n \n \n \n \n maxAge\n 34\n \n \n minAge\n 30\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 35to39yrs\n \n \n \n \n maxAge\n 39\n \n \n minAge\n 35\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 40to44yrs\n \n \n \n \n maxAge\n 44\n \n \n minAge\n 40\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 45to49yrs\n \n \n \n \n maxAge\n 49\n \n \n minAge\n 45\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 50+yrs\n \n \n \n \n maxAge\n 110\n \n \n minAge\n 50\n \n \n \n \n \n 50to100yrs\n \n \n \n \n maxAge\n 119\n \n \n minAge\n 50\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n <6Months\n \n \n \n \n maxAge\n 5\n \n \n minAge\n 0\n \n \n \n \n \n Adults\n \n \n \n Age_cohort_Query\n \n \n \n \n maxAge\n 100\n \n \n minAge\n 50\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n Children 0to14\n \n \n \n \n maxAge\n 14\n \n \n minAge\n 0\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n Under 1yr\n \n \n \n \n maxAge\n 0\n \n \n minAge\n 0\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n','2018-02-27 09:21:44',4,'2020-04-26 11:02:40',4,0,NULL,NULL,NULL,'93da8e26-c1ea-44e3-a0f3-f325c7797d9a'),(10,'DM_Sex','Sex dimession','org.openmrs.module.reporting.indicator.dimension.Dimension','org.openmrs.module.reporting.indicator.dimension.CohortDefinitionDimension','org.openmrs.module.reporting.serializer.ReportingSerializer','\n DM_Sex\n Sex dimession\n \n 2018-02-27 09:39:18 UTC\n \n 2018-02-27 09:42:20 UTC\n \n 10\n \n \n Females\n \n \n \n \n femaleIncluded\n true\n \n \n maleIncluded\n false\n \n \n \n \n \n Males\n \n \n \n \n femaleIncluded\n false\n \n \n maleIncluded\n true\n \n \n \n \n \n','2018-02-27 09:39:18',4,'2018-02-27 09:42:20',4,0,NULL,NULL,NULL,'dec74189-72cc-4981-b956-557f37b82a87'),(11,'Weight_Cohort_Query','for weight bands','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.NumericObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Weight_Cohort_Query\n for weight bands\n \n 2018-02-27 10:06:14 UTC\n \n 2020-06-16 09:53:20 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n value1\n \n java.lang.Double\n true\n \n \n value2\n \n java.lang.Double\n true\n \n \n 11\n LAST\n \n \n \n \n GREATER_EQUAL\n LESS_EQUAL\n','2018-02-27 10:06:14',4,'2020-06-16 09:53:20',4,0,NULL,NULL,NULL,'33a425d0-d6f9-42b8-8afe-08df159de8b7'),(12,'DM_Weight','patient weight','org.openmrs.module.reporting.indicator.dimension.Dimension','org.openmrs.module.reporting.indicator.dimension.CohortDefinitionDimension','org.openmrs.module.reporting.serializer.ReportingSerializer','\n DM_Weight\n patient weight\n \n 2018-02-27 10:11:05 UTC\n \n 2020-06-05 16:01:23 UTC\n \n 12\n \n \n 03to3.9kg\n \n \n \n \n value2\n 3.9\n \n \n value1\n 0.0\n \n \n \n \n \n 04to5.9kg\n \n \n \n \n locationList\n \n \n \n value2\n 5.9\n \n \n value1\n 4.0\n \n \n \n \n \n 06to9.9kg\n \n \n \n \n locationList\n \n \n \n value2\n 9.9\n \n \n value1\n 6.0\n \n \n \n \n \n 10to13.9kg\n \n \n \n \n locationList\n \n \n \n value2\n 13.9\n \n \n value1\n 10.0\n \n \n \n \n \n 14to19.9kg\n \n \n \n \n locationList\n \n \n \n value2\n 19.9\n \n \n value1\n 14.0\n \n \n \n \n \n 20to24.9kg\n \n \n \n \n locationList\n \n \n \n value2\n 24.9\n \n \n value1\n 20.0\n \n \n \n \n \n 25+kg\n \n \n \n \n locationList\n \n \n \n value2\n 200.0\n \n \n value1\n 25.0\n \n \n \n \n \n 25to34.9kg\n \n \n \n \n value2\n 34.9\n \n \n value1\n 25.0\n \n \n \n \n \n 34.9kg+\n \n \n \n \n value2\n 50.0\n \n \n value1\n 34.9\n \n \n \n \n \n','2018-02-27 12:11:05',4,'2020-06-05 18:01:23',4,0,NULL,NULL,NULL,'776ab68c-5afb-4054-8ee1-e9d6667c53cf'),(13,'Clients seen','','org.openmrs.module.reporting.query.encounter.definition.EncounterQuery','org.openmrs.module.reporting.query.encounter.definition.SqlEncounterQuery','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen\n \n \n 2018-02-27 13:17:12 UTC\n \n 2018-02-27 15:09:07 UTC\n \n \n client_type_seen\n \n org.openmrs.Concept\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 13\n select count(*) as numEncounters \nfrom encounter enc inner join obs on enc.encounter_id = obs.encounter_id \nwhere \nencounter_type = 1 and enc.location_id = 7 and \n(DATE(encounter_datetime) >= '2018-02-01' and DATE(encounter_datetime) <= '2018-02-28') and \nconcept_id = 3843 and value_coded = 3842 \nGROUP BY enc.encounter_id;\n','2018-02-27 13:17:12',4,'2018-02-27 15:09:07',4,0,NULL,NULL,NULL,'23eb8d9f-180f-4522-a23b-8298c7cedb8f'),(15,'Clients seen for consultation','Any client seen at the location specified and period (ENCOUNTER QUERY)','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.EncounterCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen for consultation\n Any client seen at the location specified and period (ENCOUNTER QUERY)\n \n 2018-02-28 11:01:22 UTC\n \n 2019-01-22 09:51:11 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n 15\n ANY\n \n \n \n 1\n','2018-02-28 13:01:22',4,'2019-01-22 11:51:11',4,0,NULL,NULL,NULL,'0b52550f-d47c-46ba-81f1-ca8aa8eeb4b3'),(16,'type of client','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n type of client\n \n \n 2018-02-28 11:06:40 UTC\n \n 2018-10-30 14:11:35 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n 16\n ANY\n \n \n \n \n IN\n \n \n \n \n','2018-02-28 13:06:40',4,'2018-10-30 16:11:35',4,0,NULL,NULL,NULL,'14d6cb12-1b59-4023-b7d7-f67a5138423a'),(17,'ART clients_seen','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART clients_seen\n \n \n 2018-02-28 11:08:24 UTC\n \n 2018-03-28 08:56:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 17\n type-of-client AND Clients-seen\n \n \n type-of-client\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n Clients-seen\n \n \n \n \n \n \n','2018-02-28 13:08:24',4,'2018-03-28 10:56:10',4,0,NULL,NULL,NULL,'a01c89db-b405-4c76-9f33-14e918211569'),(19,'CI03: Tx Curr Previous Months','Clients seen for ART services in the reporting period males (under 1) (excludes) new initiations','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI03: Tx Curr Previous Months\n Clients seen for ART services in the reporting period males (under 1) (excludes) new initiations\n \n 2018-03-01 07:23:08 UTC\n \n 2019-02-27 14:28:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 19\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-01 07:23:08',4,'2019-02-27 14:28:13',4,0,NULL,NULL,NULL,'ba6124a3-7406-4cd9-9f5b-32cc0c56286c'),(20,'Current on ART clients who made visits in previous 2 months','Current on ART clients who made visits in previous 2 months (2 months ARV drug supply)','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Current on ART clients who made visits in previous 2 months\n Current on ART clients who made visits in previous 2 months (2 months ARV drug supply)\n \n 2018-03-01 08:15:35 UTC\n \n 2018-03-01 08:42:34 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 20\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand (o.concept_id = 3843 and o.value_coded = 3842) \nand MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH))\n','2018-03-01 08:15:35',4,'2018-03-01 08:42:34',4,0,NULL,NULL,NULL,'6fc68835-cd3f-4241-8d81-346182b4f552'),(21,'Current on ART clients who made visits in previous 3 months','ART Clients who made visits in previous 3 Months (3 months drug supply)','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Current on ART clients who made visits in previous 3 months\n ART Clients who made visits in previous 3 Months (3 months drug supply)\n \n 2018-03-01 08:16:01 UTC\n \n 2018-10-30 09:18:30 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n 21\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand (o.concept_id = 3843 and o.value_coded = 3842) \nand MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH))\n','2018-03-01 10:16:01',4,'2018-10-30 11:18:30',4,0,NULL,NULL,NULL,'96bee18b-f015-4f51-9684-58a0be770afc'),(22,'Current on ART clients who made visits in the previous month','Current on ART clients who made visits in the previous month (1 month ARV Drug Supply)','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Current on ART clients who made visits in the previous month\n Current on ART clients who made visits in the previous month (1 month ARV Drug Supply)\n \n 2018-03-01 08:20:17 UTC\n \n 2018-03-01 08:45:22 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 22\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand (o.concept_id = 3843 and o.value_coded = 3842) \nand MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -0 MONTH))\n','2018-03-01 08:20:17',4,'2018-03-01 08:45:22',4,0,NULL,NULL,NULL,'18b8f912-a433-4fe7-9181-44b5f752db66'),(23,'ARV Drug Supply for 2 Months','Current on ART clients who made visits in previous months (2 months ARV drug supply)','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.NumericObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV Drug Supply for 2 Months\n Current on ART clients who made visits in previous months (2 months ARV drug supply)\n \n 2018-03-01 08:59:39 UTC\n \n 2018-03-01 18:11:21 UTC\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n 23\n ANY\n \n \n \n \n GREATER_THAN\n 30.0\n','2018-03-01 08:59:39',4,'2018-03-01 18:11:21',4,0,NULL,NULL,NULL,'fd31f026-4f55-484b-bed1-8d3a9d1a1b70'),(24,'ARV Drug Supply for 3 Months','Current on ART clients who made visits in previous months (3 months ARV drug supply)','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.NumericObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV Drug Supply for 3 Months\n Current on ART clients who made visits in previous months (3 months ARV drug supply)\n \n 2018-03-01 09:03:05 UTC\n \n 2018-03-01 18:15:05 UTC\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n 24\n ANY\n \n \n \n \n GREATER_EQUAL\n 90.0\n','2018-03-01 09:03:05',4,'2018-03-01 18:15:05',4,0,NULL,NULL,NULL,'96c4ce6b-436f-499e-9c07-9dedadc0f60e'),(25,'Tx. Curr. with visits in prev. 2 months and 2 months ARV Drug Supply','Current on ART clients who made visits in previous 2 months and ARV Drug Supply for 2 Months','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Tx. Curr. with visits in prev. 2 months and 2 months ARV Drug Supply\n Current on ART clients who made visits in previous 2 months and ARV Drug Supply for 2 Months\n \n 2018-03-01 09:09:51 UTC\n \n 2018-03-01 18:16:50 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 25\n Current-on-ART-clients-who-made-visits-in-previous-2-months AND ARV-Drug-Supply-for-2-Months\n \n \n Current-on-ART-clients-who-made-visits-in-previous-2-months\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n \n \n ARV-Drug-Supply-for-2-Months\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n \n \n \n','2018-03-01 09:09:51',4,'2018-03-01 18:16:50',4,0,NULL,NULL,NULL,'796bd0e5-9af3-4536-9d6c-c80410cbede3'),(26,'Tx. Curr. with visits in prev. 3 months and 3 months ARV Drug Supply','Current on ART clients with visits in prev. 3 months and 3 months ARV Drug Supply','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Tx. Curr. with visits in prev. 3 months and 3 months ARV Drug Supply\n Current on ART clients with visits in prev. 3 months and 3 months ARV Drug Supply\n \n 2018-03-01 09:13:01 UTC\n \n 2018-03-01 18:17:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 26\n Current-on-ART-clients-who-made-visits-in-previous-3-months AND ARV-Drug-Supply-for-3-Months\n \n \n Current-on-ART-clients-who-made-visits-in-previous-3-months\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n \n \n ARV-Drug-Supply-for-3-Months\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n \n \n \n','2018-03-01 09:13:01',4,'2018-03-01 18:17:30',4,0,NULL,NULL,NULL,'963f27e9-75ea-42d0-8611-a66a3de9d6ab'),(27,'Tx. Curr. with visits in prev. 2 or 3 months and 2 or 3 months ARV Drug Supply','Current on ART clients with visits in prev. 2 or 3 months and 2 or 3 months ARV Drug Supply','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Tx. Curr. with visits in prev. 2 or 3 months and 2 or 3 months ARV Drug Supply\n Current on ART clients with visits in prev. 2 or 3 months and 2 or 3 months ARV Drug Supply\n \n 2018-03-01 09:17:02 UTC\n \n 2018-03-01 09:19:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 27\n Tx.-Curr.-with-visits-in-prev.-3-months-and-3-months-ARV-Drug-Supply OR Tx.-Curr.-with-visits-in-prev.-2-months-and-2-months-ARV-Drug-Supply\n \n \n Tx.-Curr.-with-visits-in-prev.-3-months-and-3-months-ARV-Drug-Supply\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Tx.-Curr.-with-visits-in-prev.-2-months-and-2-months-ARV-Drug-Supply\n \n \n \n \n \n \n','2018-03-01 09:17:02',4,'2018-03-01 09:19:22',4,0,NULL,NULL,NULL,'7aaa2b3f-5eb7-45bc-93f7-8e22534e6f2d'),(28,'ART Summary (DSD)',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.LogicDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART Summary (DSD)\n \n 2018-03-01 09:42:19 UTC\n \n \n','2018-03-01 09:42:19',4,NULL,NULL,0,NULL,NULL,NULL,'3245fc9e-d4b6-46fb-9f14-b9f5db7ca56a'),(31,'ART patients transferred Into site','Transfer In for ART clients','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART patients transferred Into site\n Transfer In for ART clients\n \n 2018-03-15 07:44:35 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 09:44:35',4,NULL,NULL,0,NULL,NULL,NULL,'5a9986bc-e592-4fbe-9c2d-67a68975be60'),(32,'ART patients transferred to other sites','Transfer out for ART patients','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART patients transferred to other sites\n Transfer out for ART patients\n \n 2018-03-15 08:08:19 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 10:08:19',4,NULL,NULL,0,NULL,NULL,NULL,'0fe1183e-5cfd-4a12-bb33-915bd3212d52'),(33,'Date Restarted ART','Date ART was restarted after being stopped','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.DateObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Date Restarted ART\n Date ART was restarted after being stopped\n \n 2018-03-15 08:14:46 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n value1\n \n java.util.Date\n true\n \n \n value2\n \n java.util.Date\n true\n \n \n ANY\n \n \n \n \n GREATER_EQUAL\n LESS_EQUAL\n','2018-03-15 10:14:46',4,NULL,NULL,0,NULL,NULL,NULL,'19676fac-ac6b-4f91-a407-e179e74e9d27'),(34,'Children CD4 percent','Count the number of baseline CD4 percentages','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.NumericObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children CD4 percent\n Count the number of baseline CD4 percentages\n \n 2018-03-15 08:21:54 UTC\n \n 2018-03-15 08:35:26 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n 34\n ANY\n \n \n \n \n','2018-03-15 10:21:54',4,'2018-03-15 10:35:26',4,0,NULL,NULL,NULL,'c82c286a-90c2-44f4-8ce1-671df77529cd'),(35,'Adult CD4 Count','Return patient with a baseline CD4 counts','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.NumericObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Adult CD4 Count\n Return patient with a baseline CD4 counts\n \n 2018-03-15 08:26:07 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n','2018-03-15 10:26:07',4,NULL,NULL,0,NULL,NULL,NULL,'954ae31e-21d8-4ed6-8a4f-c9be726a5cf0'),(36,'New ART clients with baseline CD4 counts','New ART clients with baseline CD4 counts','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n New ART clients with baseline CD4 counts\n New ART clients with baseline CD4 counts\n \n 2018-03-15 08:28:17 UTC\n \n 2018-03-15 08:40:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 36\n (Adult-CD4-Count OR Children-CD4-percent) AND ART-start-date\n \n \n Adult-CD4-Count\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n Children-CD4-percent\n \n \n \n \n \n \n ART-start-date\n \n \n \n \n locationList\n ${location}\n \n \n value2\n ${endDate}\n \n \n value1\n ${startDate}\n \n \n \n \n \n','2018-03-15 10:28:17',4,'2018-03-15 10:40:18',4,0,NULL,NULL,NULL,'b23434a0-ea24-4c1e-82e4-86fd50568241'),(37,'HIV care clients screened for TB','HIV care clients screened for TB','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HIV care clients screened for TB\n HIV care clients screened for TB\n \n 2018-03-15 13:41:45 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n \n \n','2018-03-15 15:41:45',4,NULL,NULL,0,NULL,NULL,NULL,'e74b63f9-655b-46fe-9397-29b07625ce61'),(38,'Presumptive TB case','Presumptive TB case- these are clients suspected for TB','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Presumptive TB case\n Presumptive TB case- these are clients suspected for TB\n \n 2018-03-15 13:47:06 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 15:47:06',4,NULL,NULL,0,NULL,NULL,NULL,'aa138e08-67c8-48bb-a54e-ce7ed7891547'),(41,'ARV regimen 1e TDF-3TC-NVP','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 1e TDF-3TC-NVP\n \n \n 2018-03-15 14:43:00 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 16:43:00',4,NULL,NULL,0,NULL,NULL,NULL,'f62bc2e5-0c7f-462a-bb28-ae0a6925c088'),(42,'ARV regimen 1f TDF-3TC-EFV','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 1f TDF-3TC-EFV\n \n \n 2018-03-15 14:44:30 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 16:44:30',4,NULL,NULL,0,NULL,NULL,NULL,'06693a67-bb3d-45d7-b9ba-a145d08bb974'),(43,'ARV regimen 1g ABC-3TC-NVP','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 1g ABC-3TC-NVP\n \n \n 2018-03-15 14:46:39 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 16:46:39',4,NULL,NULL,0,NULL,NULL,NULL,'4a1b3589-2ffd-493d-be4f-53a009ec903b'),(44,'ARV regimen 4b AZT-3TC-NVP','ARV regimen 4b AZT-3TC-NVP','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 4b AZT-3TC-NVP\n ARV regimen 4b AZT-3TC-NVP\n \n 2018-03-15 14:55:56 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 16:55:56',4,NULL,NULL,0,NULL,NULL,NULL,'f7ea0f19-995c-4563-b17a-5e0028fafb7b'),(45,'ARV regimen 1h ABC-3TC-EFV','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 1h ABC-3TC-EFV\n \n \n 2018-03-15 14:57:38 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 16:57:38',4,NULL,NULL,0,NULL,NULL,NULL,'99a80476-a4fa-4df3-be47-4dd669a8f34e'),(47,'ARV regimen 2d AZT-3TC-LPV/r','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 2d AZT-3TC-LPV/r\n \n \n 2018-03-15 15:02:27 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:02:27',4,NULL,NULL,0,NULL,NULL,NULL,'d03c0f54-dd1d-4fdd-9b52-d9b4ae023df6'),(48,'ARV regimen 2c TDF-3TC-LPV/r','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 2c TDF-3TC-LPV/r\n \n \n 2018-03-15 15:04:34 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:04:34',4,NULL,NULL,0,NULL,NULL,NULL,'46d6acb9-6e78-4194-bd7c-31b8894461cd'),(49,'ARV regimen 4d ABC-3TC-NVP','ARV regimen 4d ABC-3TC-NVP','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 4d ABC-3TC-NVP\n ARV regimen 4d ABC-3TC-NVP\n \n 2018-03-15 15:05:00 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:05:00',4,NULL,NULL,0,NULL,NULL,NULL,'84c300d3-4f0c-4861-b59f-7bd95b6250c1'),(50,'ARV regimen 2e TDF-3TC-ATV/r','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 2e TDF-3TC-ATV/r\n \n \n 2018-03-15 15:07:00 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:07:00',4,NULL,NULL,0,NULL,NULL,NULL,'3487cef8-a434-4bf5-93e3-d7b1d35de3b7'),(51,'ARV regimen 4c ABC-3TC-EFV','ARV regimen 4c ABC-3TC-EFV','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 4c ABC-3TC-EFV\n ARV regimen 4c ABC-3TC-EFV\n \n 2018-03-15 15:07:42 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:07:42',4,NULL,NULL,0,NULL,NULL,NULL,'44e9041e-b27a-4d4f-9dcb-61a4e6013818'),(52,'ARV regimen 2f AZT-3TC-ATV/r','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 2f AZT-3TC-ATV/r\n \n \n 2018-03-15 15:09:16 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:09:16',4,NULL,NULL,0,NULL,NULL,NULL,'03d90077-1768-4abb-a91e-4f2e80d5bab1'),(53,'ARV regimen 2g AZT-3TC-TDF-LPV/r','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 2g AZT-3TC-TDF-LPV/r\n \n \n 2018-03-15 15:12:02 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:12:02',4,NULL,NULL,0,NULL,NULL,NULL,'cbbbe740-93a5-4c78-81b4-998dc76bc27f'),(54,'ARV regimen 4a AZT-3TC-EFV','ARV regimen 4a AZT-3TC-EFV','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 4a AZT-3TC-EFV\n ARV regimen 4a AZT-3TC-EFV\n \n 2018-03-15 15:13:49 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:13:49',4,NULL,NULL,0,NULL,NULL,NULL,'29d5515c-bd24-40ac-8dad-048138385125'),(55,'ARV regimen 2g ABC-3TC-LPV/r','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 2g ABC-3TC-LPV/r\n \n \n 2018-03-15 15:16:19 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:16:19',4,NULL,NULL,0,NULL,NULL,NULL,'cf84777c-279b-4830-bfd3-c5ec1b424850'),(57,'ARV regimen 2h ABC-3TC-ATV/r','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 2h ABC-3TC-ATV/r\n \n \n 2018-03-15 15:17:46 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:17:46',4,NULL,NULL,0,NULL,NULL,NULL,'7f02425f-cf7d-469a-9655-d637938673ae'),(59,'ARV regimen 5b AZT-3TC-LPV/r','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 5b AZT-3TC-LPV/r\n \n \n 2018-03-15 15:20:34 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:20:34',4,NULL,NULL,0,NULL,NULL,NULL,'20b53122-3fa7-462d-82e3-f27f0ed30aa0'),(60,'ARV regimen 5a ABC-3TC-LPV/r','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 5a ABC-3TC-LPV/r\n \n \n 2018-03-15 15:22:30 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:22:30',4,NULL,NULL,0,NULL,NULL,NULL,'ffad5bd5-cc99-4a0c-9e2a-6fd312687894'),(61,'ARV Regimen 6a Ral-3TC-LPV/r','ARV Regimen 6a Ral-3TC-LPV/r','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV Regimen 6a Ral-3TC-LPV/r\n ARV Regimen 6a Ral-3TC-LPV/r\n \n 2018-03-15 15:22:41 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:22:41',4,NULL,NULL,0,NULL,NULL,NULL,'a4dfb5bf-0027-4631-b4f4-c08b481af363'),(62,'ARV regimen 3a Ral-3TC-LPV/r','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV regimen 3a Ral-3TC-LPV/r\n \n \n 2018-03-15 15:29:30 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:29:30',4,NULL,NULL,0,NULL,NULL,NULL,'52db4eec-2908-498f-a2fd-065b6eab6b50'),(63,'ARV Regimen 3b TDF-3TC-Ral-DRV/r','ARV Regimen 3b TDF-3TC-Ral-DRV/r','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV Regimen 3b TDF-3TC-Ral-DRV/r\n ARV Regimen 3b TDF-3TC-Ral-DRV/r\n \n 2018-03-15 15:30:20 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-03-15 17:30:20',4,NULL,NULL,0,NULL,NULL,NULL,'d0de30d5-9680-415c-a00d-ad9cc587616a'),(64,'CI04: Adults 1st Line ARV Regimen 1(c)AZT-3TC-NVP','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI04: Adults 1st Line ARV Regimen 1(c)AZT-3TC-NVP\n \n \n 2018-03-19 02:13:36 UTC\n \n 2019-01-10 19:00:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 64\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:13:36',4,'2019-01-10 19:00:35',4,0,NULL,NULL,NULL,'5891f5b4-bfe3-48cb-b782-6339f9d46ad6'),(65,'CI05: Adults 1st Line ARV Regimen 1(d)AZT-3TC-EFV','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI05: Adults 1st Line ARV Regimen 1(d)AZT-3TC-EFV\n \n \n 2018-03-19 02:17:34 UTC\n \n 2019-01-10 19:02:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 65\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:17:34',4,'2019-01-10 19:02:01',4,0,NULL,NULL,NULL,'19e9cc1b-0ffc-4415-84b6-a5b56edf5a23'),(66,'CI06: Adults 1st Line ARV Regimen 1(e)TDF-3TC-NVP','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI06: Adults 1st Line ARV Regimen 1(e)TDF-3TC-NVP\n \n \n 2018-03-19 02:19:37 UTC\n \n 2019-01-10 19:03:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 66\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:19:37',4,'2019-01-10 19:03:17',4,0,NULL,NULL,NULL,'302479e6-10a0-47c8-9931-21133317a576'),(67,'CI07: Adults 1st Line ARV Regimen 1(f)TDF-3TC-EFV','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI07: Adults 1st Line ARV Regimen 1(f)TDF-3TC-EFV\n \n \n 2018-03-19 02:21:35 UTC\n \n 2019-01-10 19:04:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 67\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:21:35',4,'2019-01-10 19:04:01',4,0,NULL,NULL,NULL,'1f6b7448-9557-4335-8d9c-3d1310626aa0'),(68,'CI08: Adults 1st Line ARV Regimen 1(g)ABC-3TC-NVP','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI08: Adults 1st Line ARV Regimen 1(g)ABC-3TC-NVP\n \n \n 2018-03-19 02:22:50 UTC\n \n 2019-01-10 19:05:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 68\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:22:50',4,'2019-01-10 19:05:20',4,0,NULL,NULL,NULL,'4a4a1d6a-5c08-451e-b63e-e590890bc6fc'),(69,'CI09: Adults 1st Line ARV Regimen 1(h)ABC-3TC-EFV','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI09: Adults 1st Line ARV Regimen 1(h)ABC-3TC-EFV\n \n \n 2018-03-19 02:24:03 UTC\n \n 2019-01-10 19:06:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 69\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:24:03',4,'2019-01-10 19:06:22',4,0,NULL,NULL,NULL,'e1a6903f-5c76-4d1f-85cb-561bc2a1ea1e'),(70,'CI09: Children 1st Line ARV Regimen 4(c)AZT-3TC-NVP','4(c)AZT-3TC-NVP','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI09: Children 1st Line ARV Regimen 4(c)AZT-3TC-NVP\n 4(c)AZT-3TC-NVP\n \n 2018-03-19 02:26:02 UTC\n \n 2019-02-08 07:20:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 70\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:26:02',4,'2019-02-08 07:20:57',4,0,NULL,NULL,NULL,'b92c628d-b93e-40aa-a5d0-c8f354ab12c9'),(71,'CI10: Children 1st Line ARV Regimen 4(d)AZT-3TC-EFV','4(d)AZT-3TC-EFV','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI10: Children 1st Line ARV Regimen 4(d)AZT-3TC-EFV\n 4(d)AZT-3TC-EFV\n \n 2018-03-19 02:27:41 UTC\n \n 2019-02-08 07:29:58 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 71\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:27:41',4,'2019-02-08 07:29:58',4,0,NULL,NULL,NULL,'5401502e-24d3-4a01-85c9-f8389c59b566'),(72,'CI11: Children 1st Line ARV Regimen 4(e)ABC-3TC-NVP','4(e)ABC-3TC-NVP','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI11: Children 1st Line ARV Regimen 4(e)ABC-3TC-NVP\n 4(e)ABC-3TC-NVP\n \n 2018-03-19 02:29:03 UTC\n \n 2019-02-08 07:32:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 72\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:29:03',4,'2019-02-08 07:32:26',4,0,NULL,NULL,NULL,'183a5f26-6f97-427c-9409-d6263e015aab'),(73,'CI12: Children 1st Line ARV Regimen 4(f)ABC-3TC-EFV','4(f)ABC-3TC-EFV','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI12: Children 1st Line ARV Regimen 4(f)ABC-3TC-EFV\n 4(f)ABC-3TC-EFV\n \n 2018-03-19 02:30:25 UTC\n \n 2019-02-08 07:34:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 73\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:30:25',4,'2019-02-08 07:34:32',4,0,NULL,NULL,NULL,'d84fd2f9-951d-4bbc-b6fc-f59b71dbba6b'),(74,'CI13: Adult 2nd Line ARV Regimen 2(d)TDF-3TC-LPV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI13: Adult 2nd Line ARV Regimen 2(d)TDF-3TC-LPV/r\n \n \n 2018-03-19 02:32:22 UTC\n \n 2019-04-04 06:51:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 74\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:32:22',4,'2019-04-04 06:51:57',4,0,NULL,NULL,NULL,'20bdcee4-fe92-4457-a041-6db72def1895'),(75,'CI14: Adult 2nd Line ARV Regimen 2(c)AZT-3TC-LPV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI14: Adult 2nd Line ARV Regimen 2(c)AZT-3TC-LPV/r\n \n \n 2018-03-19 02:33:44 UTC\n \n 2019-04-04 06:50:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 75\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:33:44',4,'2019-04-04 06:50:57',4,0,NULL,NULL,NULL,'998aa33c-d34b-438a-b4c4-c2dbe25aa481'),(76,'CI15: Adult 2nd Line ARV Regimen 2(e)AZT-3TC-ATV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI15: Adult 2nd Line ARV Regimen 2(e)AZT-3TC-ATV/r\n \n \n 2018-03-19 02:35:46 UTC\n \n 2019-04-04 06:53:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 76\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:35:46',4,'2019-04-04 06:53:03',4,0,NULL,NULL,NULL,'78ffec82-cb3a-49ad-aaa2-1f50bfe12e80'),(77,'CI16: Adult 2nd Line ARV Regimen 2(f)TDF-3TC-ATV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI16: Adult 2nd Line ARV Regimen 2(f)TDF-3TC-ATV/r\n \n \n 2018-03-19 02:36:59 UTC\n \n 2019-04-04 06:53:58 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 77\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:36:59',4,'2019-04-04 06:53:58',4,0,NULL,NULL,NULL,'f5c9b6ce-13e2-4305-b991-045536fd153e'),(78,'CI17: Adult 2nd Line ARV Regimen 2(g)AZT-3TC-TDF-LPV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI17: Adult 2nd Line ARV Regimen 2(g)AZT-3TC-TDF-LPV/r\n \n \n 2018-03-19 02:38:02 UTC\n \n 2018-03-19 02:42:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 78\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n','2018-03-19 04:38:02',4,'2018-03-19 04:42:22',4,0,NULL,NULL,NULL,'00a49e20-9f14-437e-a4cd-857ae281e238'),(79,'CI18: Adults 2nd Line ARV Regimen 2(g) ABC-3TC-LPV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI18: Adults 2nd Line ARV Regimen 2(g) ABC-3TC-LPV/r\n \n \n 2018-03-19 02:40:22 UTC\n \n 2019-01-10 19:18:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 79\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:40:22',4,'2019-01-10 19:18:05',4,0,NULL,NULL,NULL,'8b70c3a8-a114-4ace-a458-9677150c48e2'),(80,'CI19: Adults 2nd Line ARV Regimen 2(h) ABC-3TC-ATV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI19: Adults 2nd Line ARV Regimen 2(h) ABC-3TC-ATV/r\n \n \n 2018-03-19 02:43:15 UTC\n \n 2019-01-10 19:19:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 80\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:43:15',4,'2019-01-10 19:19:12',4,0,NULL,NULL,NULL,'11e7ab47-8ee4-4bbb-8199-32619d304e32'),(81,'CI20: Adults 3rd Line ARV Regimen 3(a) Ral-3TC-LPV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI20: Adults 3rd Line ARV Regimen 3(a) Ral-3TC-LPV/r\n \n \n 2018-03-19 02:45:12 UTC\n \n 2019-01-10 19:20:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 81\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:45:12',4,'2019-01-10 19:20:10',4,0,NULL,NULL,NULL,'e22a68da-5893-42c3-b261-1b0e0a5a98aa'),(82,'CI21: Adults 3rd Line ARV Regimen 3(b) TDF/3TC/Ral/DRV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI21: Adults 3rd Line ARV Regimen 3(b) TDF/3TC/Ral/DRV/r\n \n \n 2018-03-19 02:46:35 UTC\n \n 2019-01-10 19:21:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 82\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:46:35',4,'2019-01-10 19:21:13',4,0,NULL,NULL,NULL,'5b189710-2a56-477b-b2d4-569b7a16a30f'),(83,'CI22: Adults and Children 3rd Line ARV Regimen 3(c)EFV-DRV/r-Ral','replaced 6(a) ETV DRV/r/ral must ahve been a typo error','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI22: Adults and Children 3rd Line ARV Regimen 3(c)EFV-DRV/r-Ral\n replaced 6(a) ETV DRV/r/ral must ahve been a typo error\n \n 2018-03-19 02:48:05 UTC\n \n 2019-02-21 09:31:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 83\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:48:05',4,'2019-02-21 09:31:19',4,0,NULL,NULL,NULL,'51510b74-2bad-4e95-8a68-7211097e16b2'),(84,'CI23: Children 2nd Line ARV Regimen 5(a)AZT-3TC-LPV/r','5(a)AZT-3TC-LPV/r','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI23: Children 2nd Line ARV Regimen 5(a)AZT-3TC-LPV/r\n 5(a)AZT-3TC-LPV/r\n \n 2018-03-19 02:49:37 UTC\n \n 2019-04-04 09:44:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 84\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:49:37',4,'2019-04-04 09:44:35',4,0,NULL,NULL,NULL,'cd5977ea-be20-4b8c-af53-2dd17d4b771b'),(85,'CI24: Children 2nd Line ARV Regimen 5(b)ABC-3TC-LPV/r','5(b)ABC-3TC-LPV/r','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI24: Children 2nd Line ARV Regimen 5(b)ABC-3TC-LPV/r\n 5(b)ABC-3TC-LPV/r\n \n 2018-03-19 02:50:49 UTC\n \n 2019-04-04 09:45:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 85\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:50:49',4,'2019-04-04 09:45:40',4,0,NULL,NULL,NULL,'c9fca87c-8069-49ef-b8fd-aae5f6ab4de8'),(86,'CI25: Children 3rd Line ARV Regimen 6(a) Ral-3TC-LPV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI25: Children 3rd Line ARV Regimen 6(a) Ral-3TC-LPV/r\n \n \n 2018-03-19 02:52:07 UTC\n \n 2019-02-08 08:05:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 86\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:52:07',4,'2019-02-08 08:05:17',4,0,NULL,NULL,NULL,'b7afeb4d-f5f6-49fc-bf16-b65fa53f485a'),(87,'CI26: ART Transfer Ins','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI26: ART Transfer Ins\n \n \n 2018-03-19 02:53:56 UTC\n \n 2019-01-31 18:12:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 87\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:53:56',4,'2019-01-31 18:12:52',4,0,NULL,NULL,NULL,'d31412f8-9a7a-46d8-9f2e-7c51ed7f2057'),(88,'CI27: ART Transfer Outs','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI27: ART Transfer Outs\n \n \n 2018-03-19 02:55:42 UTC\n \n 2019-01-31 18:11:39 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 88\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:55:42',4,'2019-01-31 18:11:39',4,0,NULL,NULL,NULL,'939c91e7-c164-456f-a4dc-4da80bacc4b3'),(89,'CI28: Client who Restarted ART','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI28: Client who Restarted ART\n \n \n 2018-03-19 02:57:34 UTC\n \n 2019-01-31 18:08:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 89\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 02:57:34',4,'2019-01-31 18:08:06',4,0,NULL,NULL,NULL,'65cd06c4-31ed-4a82-a6a4-02e217b1e0ba'),(90,'CI29: New ART clients with baseline CD4+ counts','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI29: New ART clients with baseline CD4+ counts\n \n \n 2018-03-19 03:00:05 UTC\n \n 2018-03-19 03:01:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 90\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 05:00:05',4,'2018-03-19 05:01:21',4,0,NULL,NULL,NULL,'bf36f124-d930-431e-b22a-fd0d7f7353c4'),(91,'CI30: HIV Care clients screened for TB','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI30: HIV Care clients screened for TB\n \n \n 2018-03-19 03:03:31 UTC\n \n 2019-02-03 09:56:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 91\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 03:03:31',4,'2019-02-03 09:56:53',4,0,NULL,NULL,NULL,'47456755-c716-4eab-b686-c9d372ea7468'),(92,'CI31: Presumptive TB HIV Care cases','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI31: Presumptive TB HIV Care cases\n \n \n 2018-03-19 03:06:01 UTC\n \n 2019-02-03 09:58:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 92\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-19 03:06:01',4,'2019-02-03 09:58:15',4,0,NULL,NULL,NULL,'cd4971f7-81a7-45f8-b49b-9de683d0c8d3'),(94,'Date confirmed HIV Positive test','Date confirmed HIV+ test','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.DateObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Date confirmed HIV Positive test\n Date confirmed HIV+ test\n \n 2018-03-20 14:23:54 UTC\n \n 2018-03-20 14:33:43 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n 94\n ANY\n \n \n \n \n','2018-03-20 16:23:54',4,'2018-03-20 16:33:43',4,0,NULL,NULL,NULL,'c62c2f3b-3f3e-442b-beab-c25809316b25'),(95,'Date enrolled in Pre-ART','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.DateObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Date enrolled in Pre-ART\n \n \n 2018-03-20 14:25:52 UTC\n \n 2019-01-23 08:27:20 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n value1\n \n java.util.Date\n true\n \n \n value2\n \n java.util.Date\n true\n \n \n 95\n ANY\n \n \n \n \n GREATER_EQUAL\n LESS_EQUAL\n','2018-03-20 16:25:52',4,'2019-01-23 10:27:20',4,0,NULL,NULL,NULL,'d785b586-bd07-4359-b733-54968416b764'),(97,'Clients newly diagnosed and enrolled into HIV Care/Pre-ART','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly diagnosed and enrolled into HIV Care/Pre-ART\n \n \n 2018-03-20 14:36:25 UTC\n \n 2019-01-31 20:12:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 97\n PreART-Clients-not-initiated-on-ART AND Date-Confirmed-HIV-positive-SQL\n \n \n PreART-Clients-not-initiated-on-ART\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n \n \n Date-Confirmed-HIV-positive-SQL\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2018-03-20 14:36:25',4,'2019-01-31 20:12:16',4,0,NULL,NULL,NULL,'77c109da-808a-4a26-8e7f-41839ab40574'),(98,'CI32: Clients newly diagnosed and started on Pre-ART','Clients newly diagnosed and started on HIV Care','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI32: Clients newly diagnosed and started on Pre-ART\n Clients newly diagnosed and started on HIV Care\n \n 2018-03-22 08:48:54 UTC\n \n 2019-02-04 08:17:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 98\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-22 08:48:54',4,'2019-02-04 08:17:38',4,0,NULL,NULL,NULL,'05e583fe-4a8b-4359-8ac8-8df7f02f8e96'),(99,'CI33: Clients Started on Pre-ART','Clients Started on HIV Care','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI33: Clients Started on Pre-ART\n Clients Started on HIV Care\n \n 2018-03-22 08:48:55 UTC\n \n 2019-02-04 08:21:41 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 99\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-22 08:48:55',4,'2019-02-04 08:21:41',4,0,NULL,NULL,NULL,'6ba04297-1210-4d0e-8728-0ac24c4b0a3a'),(100,'PIR02: Pre-ART Report','Reports all Pre-ART or Current in HIV Care indicators into DHIS2 i.e. Newly enrolled, Current in HIV Care etc. ','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR02: Pre-ART Report\n Reports all Pre-ART or Current in HIV Care indicators into DHIS2 i.e. Newly enrolled, Current in HIV Care etc. \n \n 2018-03-27 08:30:37 UTC\n \n 2018-03-27 08:31:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 100\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2018-03-27 10:30:37',4,'2018-03-27 10:31:03',4,0,NULL,NULL,NULL,'5b3a4b6f-1584-43c0-a3cb-7973270912f2'),(101,'PIR02: Pre-ART Report Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR02: Pre-ART Report Data Set\n \n 2018-03-27 08:30:38 UTC\n \n 2019-03-11 12:08:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 101\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age_DATE\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n \n \n CnPrF10-14\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 10to14yrs\n \n \n \n \n \n CnPrF15-19\n \n \n \n \n \n \n CnPrF20-24\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 20to24yrs\n \n \n \n \n \n CnPrF25-49\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 25to49yrs\n \n \n \n \n \n CnPrM10-14\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 10to14yrs\n \n \n \n \n \n CnPrM15-19\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 15to19yrs\n \n \n \n \n \n CnPrM20-24\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 20to24yrs\n \n \n \n \n \n CnPrM25-49\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 25to49yrs\n \n \n \n \n \n CnPreF1-4\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 01to04yrs\n \n \n \n \n \n CnPreF5-9\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 05to09yrs\n \n \n \n \n \n CnPreF50+\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 50+yrs\n \n \n \n \n \n CnPreFU1\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n Under 1yr\n \n \n \n \n \n CnPreM1-4\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 01to04yrs\n \n \n \n \n \n CnPreM5-9\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 05to09yrs\n \n \n \n \n \n CnPreM50+\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 50+yrs\n \n \n \n \n \n CnPreMU1\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n Under 1yr\n \n \n \n \n \n NuPrF10-14\n \n \n \n \n \n \n \n \n \n NuPrF15-19\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 15to19yrs\n \n \n \n \n \n NuPrF20-24\n \n \n \n \n \n \n NuPrF25-49\n \n \n \n \n \n \n NuPrM10-14\n \n \n \n \n \n \n NuPrM15-19\n \n \n \n \n \n \n NuPrM20-24\n \n \n \n \n \n \n NuPrM25-49\n \n \n \n \n \n \n NuPreF1-4\n \n \n \n \n \n \n NuPreF5-9\n \n \n \n \n \n \n NuPreF50+\n \n \n \n \n \n \n NuPreFU1\n \n \n \n \n \n \n NuPreM1-4\n \n \n \n \n \n \n NuPreM5-9\n \n \n \n \n \n \n NuPreM50+\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 50+yrs\n \n \n \n \n \n NuPreMU1\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n PreMF1-4\n \n \n \n \n \n \n \n \n \n PreMF10-14\n \n \n \n \n \n \n PreMF15-19\n \n \n \n \n \n \n PreMF20-24\n \n \n \n \n \n \n PreMF25-49\n \n \n \n \n \n \n PreMF5-9\n \n \n \n \n \n \n PreMF50+\n \n \n \n \n \n \n PreMFU1\n \n \n \n \n \n \n PreMM1-4\n \n \n \n \n \n \n PreMM10-14\n \n \n \n \n \n \n PreMM15-19\n \n \n \n \n \n \n PreMM20-24\n \n \n \n \n \n \n PreMM25-49\n \n \n \n \n \n \n PreMM5-9\n \n \n \n \n \n \n PreMM50+\n \n \n \n \n \n \n PreMMU1\n \n \n \n \n \n \n StaPF10-14\n \n \n \n \n \n \n \n \n \n StaPF15-19\n \n \n \n \n \n \n StaPF20-24\n \n \n \n \n \n \n StaPF25-49\n \n \n \n \n \n \n StaPM10-14\n \n \n \n \n \n \n StaPM15-19\n \n \n \n \n \n \n StaPM20-24\n \n \n \n \n \n \n StaPM25-49\n \n \n \n \n \n \n StaPreF1-4\n \n \n \n \n \n \n StaPreF5-9\n \n \n \n \n \n \n StaPreFU1\n \n \n \n \n \n \n StaPreM1-4\n \n \n \n \n \n \n StaPreM5-9\n \n \n \n \n \n \n StaPreM50+\n \n \n \n \n \n \n StaPreMU1\n \n \n \n \n \n \n','2018-03-27 08:30:38',4,'2019-03-11 12:08:33',4,0,NULL,NULL,NULL,'4cc67faa-d329-4188-95ac-8a6b0e61cbee'),(104,'PIR03: 5. ARV Regimen at end of every month Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR03: 5. ARV Regimen at end of every month Data Set\n \n 2018-03-27 13:44:01 UTC\n \n 2019-04-26 08:21:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 104\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n DM_Weight_Updated\n \n \n \n \n \n \n \n \n 1cAdultF\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n \n \n \n 1cAdultM\n \n \n \n \n DM_Sex\n Males\n \n \n \n \n \n 1dAdultF\n \n \n \n \n \n \n \n \n \n 1dAdultM\n \n \n \n \n \n \n 1eAdultF\n \n \n \n \n \n \n \n \n \n 1eAdultM\n \n \n \n \n \n \n 1fAdultF\n \n \n \n \n \n \n \n \n \n 1fAdultM\n \n \n \n \n \n \n 1gAdultF\n \n \n \n \n \n \n \n \n \n 1gAdultM\n \n \n \n \n \n \n 1hAdultF\n \n \n \n \n \n \n \n \n \n 1hAdultM\n \n \n \n \n \n \n 1st4c13.9F\n \n \n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Weight_Updated\n 10to13.9kg\n \n \n \n \n \n 1st4c13.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Weight_Updated\n 10to13.9kg\n \n \n \n \n \n 1st4c19.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Weight_Updated\n 14to19.9kg\n \n \n \n \n \n 1st4c19.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Weight_Updated\n 14to19.9kg\n \n \n \n \n \n 1st4c24.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Weight_Updated\n 20to24.9kg\n \n \n \n \n \n 1st4c24.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Weight_Updated\n 20to24.9kg\n \n \n \n \n \n 1st4c25F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Weight_Updated\n 25+kg\n \n \n \n \n \n 1st4c25M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Weight_Updated\n 25+kg\n \n \n \n \n \n 1st4c3.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Weight_Updated\n 03to3.9kg\n \n \n \n \n \n 1st4c3.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Weight_Updated\n 03to3.9kg\n \n \n \n \n \n 1st4c5.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Weight_Updated\n 04to5.9kg\n \n \n \n \n \n 1st4c5.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Weight_Updated\n 04to5.9kg\n \n \n \n \n \n 1st4c9.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Weight_Updated\n 06to9.9kg\n \n \n \n \n \n 1st4c9.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Weight_Updated\n 06to9.9kg\n \n \n \n \n \n 1st4d13.9F\n \n \n \n \n \n \n \n \n \n 1st4d13.9M\n \n \n \n \n \n \n 1st4d19.9F\n \n \n \n \n \n \n 1st4d19.9M\n \n \n \n \n \n \n 1st4d24.9F\n \n \n \n \n \n \n 1st4d24.9M\n \n \n \n \n \n \n 1st4d25F\n \n \n \n \n \n \n 1st4d25M\n \n \n \n \n \n \n 1st4d3.9F\n \n \n \n \n \n \n 1st4d3.9M\n \n \n \n \n \n \n 1st4d5.9F\n \n \n \n \n \n \n 1st4d5.9M\n \n \n \n \n \n \n 1st4d9.9F\n \n \n \n \n \n \n 1st4d9.9M\n \n \n \n \n \n \n 4e10-13.9F\n \n \n \n \n \n \n \n \n \n 4e10-13.9M\n \n \n \n \n \n \n 4e14-19.9F\n \n \n \n \n \n \n 4e14-19.9M\n \n \n \n \n \n \n 4e20-24.9F\n \n \n \n \n \n \n 4e20-24.9M\n \n \n \n \n \n \n 4e25+F\n \n \n \n \n \n \n 4e25+M\n \n \n \n \n \n \n 4e3-3.9F\n \n \n \n \n \n \n 4e3-3.9M\n \n \n \n \n \n \n 4e4-5.9F\n \n \n \n \n \n \n 4e4-5.9M\n \n \n \n \n \n \n 4e6-9.9F\n \n \n \n \n \n \n 4e6-9.9M\n \n \n \n \n \n \n 4f10-13.9F\n \n \n \n \n \n \n \n \n \n 4f10-13.9M\n \n \n \n \n \n \n 4f14-19.9F\n \n \n \n \n \n \n 4f14-19.9M\n \n \n \n \n \n \n 4f20-24.9F\n \n \n \n \n \n \n 4f20-24.9M\n \n \n \n \n \n \n 4f25+F\n \n \n \n \n \n \n 4f25+M\n \n \n \n \n \n \n 4f3-3.9F\n \n \n \n \n \n \n 4f3-3.9M\n \n \n \n \n \n \n 4f4-5.9F\n \n \n \n \n \n \n 4f4-5.9M\n \n \n \n \n \n \n 4f6-9.9F\n \n \n \n \n \n \n 4f6-9.9M\n \n \n \n \n \n \n','2018-03-27 13:44:01',4,'2019-04-26 08:21:29',4,0,NULL,NULL,NULL,'3b30ec64-f372-4307-9988-e169bd149057'),(106,'PIR04: 4. ARV Regimen at end of month (2nd Line Adults and Children) Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR04: 4. ARV Regimen at end of month (2nd Line Adults and Children) Data Set\n \n 2018-03-27 13:48:07 UTC\n \n 2019-04-29 14:42:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 106\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n DM_Weight_Updated\n \n \n \n \n \n \n \n \n 2cAdultF\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n \n \n \n 2cAdultM\n \n \n \n \n DM_Sex\n Males\n \n \n \n \n \n 2dAdultF\n \n \n \n \n \n \n \n \n \n 2dAdultM\n \n \n \n \n \n \n 2eAdultF\n \n \n \n \n \n \n \n \n \n 2eAdultM\n \n \n \n \n \n \n 2fAdultF\n \n \n \n \n \n \n \n \n \n 2fAdultM\n \n \n \n \n \n \n 2gBCAdultF\n \n \n \n \n \n \n \n \n \n 2gBCAdultM\n \n \n \n \n \n \n 2hAdultF\n \n \n \n \n \n \n \n \n \n 2hAdultM\n \n \n \n \n \n \n 5a10-13.9F\n \n \n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 10to13.9kg\n \n \n \n \n \n 5a10-13.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 10to13.9kg\n \n \n \n \n \n 5a14-19.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 14to19.9kg\n \n \n \n \n \n 5a14-19.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 14to19.9kg\n \n \n \n \n \n 5a20-24.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 20to24.9kg\n \n \n \n \n \n 5a20-24.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 20to24.9kg\n \n \n \n \n \n 5a25+F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 25+kg\n \n \n \n \n \n 5a25+M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 25+kg\n \n \n \n \n \n 5a3-3.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 03to3.9kg\n \n \n \n \n \n 5a3-3.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 03to3.9kg\n \n \n \n \n \n 5a4-5.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 04to5.9kg\n \n \n \n \n \n 5a4-5.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 04to5.9kg\n \n \n \n \n \n 5a6-9.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 06to9.9kg\n \n \n \n \n \n 5a6-9.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 06to9.9kg\n \n \n \n \n \n 5b10-13.9F\n \n \n \n \n \n \n \n \n \n 5b10-13.9M\n \n \n \n \n \n \n 5b14-19.9F\n \n \n \n \n \n \n 5b14-19.9M\n \n \n \n \n \n \n 5b20-24.9F\n \n \n \n \n \n \n 5b20-24.9M\n \n \n \n \n \n \n 5b25+F\n \n \n \n \n \n \n 5b25+M\n \n \n \n \n \n \n 5b3-3.9F\n \n \n \n \n \n \n 5b3-3.9M\n \n \n \n \n \n \n 5b4-5.9F\n \n \n \n \n \n \n 5b4-5.9M\n \n \n \n \n \n \n 5b6-9.9F\n \n \n \n \n \n \n 5b6-9.9M\n \n \n \n \n \n \n','2018-03-27 13:48:07',4,'2019-04-29 14:42:44',4,0,NULL,NULL,NULL,'8d27c88e-c64d-41d1-93ac-09194a43b8c6'),(107,'All clients ever enrolled in Pre-ART','Uses the Date Enrolled in HIV Care concept to check if there are any observation of this concept before today\'s date','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.DateObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n All clients ever enrolled in Pre-ART\n Uses the Date Enrolled in HIV Care concept to check if there are any observation of this concept before today's date\n \n 2018-03-28 07:47:30 UTC\n \n 2018-03-28 07:49:38 UTC\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n 107\n ANY\n \n \n \n \n','2018-03-28 09:47:30',4,'2018-03-28 09:49:38',4,0,NULL,NULL,NULL,'b29f40a8-f100-43d2-a841-753081556358'),(108,'Clients not initiated on ART','This cohort query is used in conjunction with the Clients ever enrolled on Pre-ART query to select only those who are not initiated on ART','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.DateObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients not initiated on ART\n This cohort query is used in conjunction with the Clients ever enrolled on Pre-ART query to select only those who are not initiated on ART\n \n 2018-03-28 08:00:39 UTC\n \n 2019-01-22 14:26:10 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n 108\n NO\n \n \n \n \n','2018-03-28 10:00:39',4,'2019-01-22 16:26:10',4,0,NULL,NULL,NULL,'e9fa623d-a779-4533-a4b2-26b701863195'),(109,'Clients currently enrolled on Pre-ART','Client currently on Pre-ART and not Started on ART','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients currently enrolled on Pre-ART\n Client currently on Pre-ART and not Started on ART\n \n 2018-03-28 08:04:27 UTC\n \n 2019-01-31 19:53:17 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 109\n All-clients-ever-enrolled-in-Pre-ART AND Clients-not-initiated-on-ART-SQL-Query-Version\n \n \n All-clients-ever-enrolled-in-Pre-ART\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n \n \n \n Clients-not-initiated-on-ART-SQL-Query-Version\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n \n \n','2018-03-28 08:04:27',4,'2019-01-31 19:53:17',4,0,NULL,NULL,NULL,'74a0a573-ec85-4624-80e7-f4b4fb69155b'),(110,'Current in Pre-ART clients Seen for Revisits','Current in HIV Care clients SEEN for revisits this month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Current in Pre-ART clients Seen for Revisits\n Current in HIV Care clients SEEN for revisits this month\n \n 2018-03-28 08:43:12 UTC\n \n 2019-01-24 13:44:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 110\n PreART-Clients-not-initiated-on-ART AND Clients-seen\n \n \n PreART-Clients-not-initiated-on-ART\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n \n \n Clients-seen\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n','2018-03-28 08:43:12',4,'2019-01-24 13:44:00',4,0,NULL,NULL,NULL,'12070eb5-96e0-4684-b71f-c0e1f7b88bcd'),(111,'PIR05: ART Report','Reports all Current in ART indicators into DHIS2 i.e. Newly Initiated, Current in ART etc.','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR05: ART Report\n Reports all Current in ART indicators into DHIS2 i.e. Newly Initiated, Current in ART etc.\n \n 2018-03-28 09:05:07 UTC\n \n 2018-03-28 09:08:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 111\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2018-03-28 11:05:07',4,'2018-03-28 11:08:08',4,0,NULL,NULL,NULL,'5e05f218-9849-4e55-8c1c-e3d02422227c'),(112,'ART Report Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART Report Data Set\n \n 2018-03-28 09:05:08 UTC\n \n 2019-03-26 13:07:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 112\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age_DATE\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n Discordant\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n NuStF10-14\n \n \n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 10to14yrs\n \n \n \n \n \n NuStF15-19\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 15to19yrs\n \n \n \n \n \n NuStF20-24\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 20to24yrs\n \n \n \n \n \n NuStF25-49\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 25to49yrs\n \n \n \n \n \n NuStM10-14\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 10to14yrs\n \n \n \n \n \n NuStM15-19\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 15to19yrs\n \n \n \n \n \n NuStM20-24\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 20to24yrs\n \n \n \n \n \n NuStM25-49\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 25to49yrs\n \n \n \n \n \n NuStatF1-4\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 01to04yrs\n \n \n \n \n \n NuStatF5-9\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 05to09yrs\n \n \n \n \n \n NuStatF50\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 50+yrs\n \n \n \n \n \n NuStatFU1\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n Under 1yr\n \n \n \n \n \n NuStatM1-4\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 01to04yrs\n \n \n \n \n \n NuStatM5-9\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 05to09yrs\n \n \n \n \n \n NuStatM50\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 50+yrs\n \n \n \n \n \n NustatMU1\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n Under 1yr\n \n \n \n \n \n RestartAll\n \n \n \n \n \n \n \n \n \n SeenF1-4\n \n \n \n \n \n \n \n \n \n SeenF10-14\n \n \n \n \n \n \n SeenF15-19\n \n \n \n \n \n \n SeenF20-24\n \n \n \n \n \n \n SeenF25-49\n \n \n \n \n \n \n SeenF5-9\n \n \n \n \n \n \n SeenF50\n \n \n \n \n \n \n SeenFU1\n \n \n \n \n \n \n SeenM1-4\n \n \n \n \n \n \n SeenM10-14\n \n \n \n \n \n \n SeenM15-19\n \n \n \n \n \n \n SeenM20-24\n \n \n \n \n \n \n SeenM25-49\n \n \n \n \n \n \n SeenM5-9\n \n \n \n \n \n \n SeenM50\n \n \n \n \n \n \n SeenMU1\n \n \n \n \n \n \n TranOutAll\n \n \n \n \n \n \n \n \n \n TransInAll\n \n \n \n \n \n \n \n \n \n TxPrF15-19\n \n \n \n \n \n \n \n \n \n TxPrF20-24\n \n \n \n \n \n \n TxPrF25-49\n \n \n \n \n \n \n TxPrM10-14\n \n \n \n \n \n \n TxPrM15-19\n \n \n \n \n \n \n TxPrM20-24\n \n \n \n \n \n \n TxPrM25-49\n \n \n \n \n \n \n TxPreF1-4\n \n \n \n \n \n \n TxPreF5-9\n \n \n \n \n \n \n TxPreF50\n \n \n \n \n \n \n TxPreFU1\n \n \n \n \n \n \n TxPreM1-4\n \n \n \n \n \n \n TxPreM5-9\n \n \n \n \n \n \n TxPreM50\n \n \n \n \n \n \n TxPreMU1\n \n \n \n \n \n \n TxprF10-14\n \n \n \n \n \n \n baseCD4All\n \n \n \n \n \n \n \n \n \n','2018-03-28 09:05:08',4,'2019-03-26 13:07:32',4,0,NULL,NULL,NULL,'6618a6b4-5678-4525-9785-0ae3abf0eb41'),(113,'Clients ever enrolled in Pre-ART and seen in previous 1 or 2 months','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients ever enrolled in Pre-ART and seen in previous 1 or 2 months\n \n \n 2018-03-28 10:13:44 UTC\n \n 2019-01-24 13:19:29 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n 113\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand o.concept_id = 2223 \nand (MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) OR \nMONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH))) \nand person_id not in ( \n select distinct person_id \n from obs os \n where os.location_id =:location \n and (os.concept_id = 3843 and os.value_coded = 3842) \n and MONTH(os.obs_datetime) = MONTH(DATE(:endDate)) \n and YEAR(os.obs_datetime) = YEAR(DATE(:endDate)) \n )\n','2018-03-28 10:13:44',4,'2019-01-24 13:19:29',4,0,NULL,NULL,NULL,'0d2bc33a-007b-4c9b-a6be-439f126f3c27'),(115,'ARV Regimen at end of month (3rd Line Adults and Children) Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV Regimen at end of month (3rd Line Adults and Children) Data Set\n \n 2018-03-28 10:34:02 UTC\n \n 2019-03-20 14:13:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 115\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n DM_Weight_Updated\n \n \n \n \n \n \n \n \n 3aAdultF\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n 3aAdultM\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Adults\n \n \n \n \n \n 3bAdultF\n \n \n \n \n \n \n \n \n \n 3bAdultM\n \n \n \n \n \n \n 3cAdultF\n \n \n \n \n \n \n \n \n \n 3cAdultM\n \n \n \n \n \n \n 6a10-13.9F\n \n \n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 10to13.9kg\n \n \n \n \n \n 6a10-13.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 10to13.9kg\n \n \n \n \n \n 6a14-19.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 14to19.9kg\n \n \n \n \n \n 6a14-19.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 14to19.9kg\n \n \n \n \n \n 6a20-24.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 20to24.9kg\n \n \n \n \n \n 6a20-24.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 20to24.9kg\n \n \n \n \n \n 6a25+F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 25+kg\n \n \n \n \n \n 6a25+M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 25+kg\n \n \n \n \n \n 6a3-3.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 03to3.9kg\n \n \n \n \n \n 6a3-3.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 03to3.9kg\n \n \n \n \n \n 6a4-5.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 04to5.9kg\n \n \n \n \n \n 6a4-5.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 04to5.9kg\n \n \n \n \n \n 6a6-9.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 06to9.9kg\n \n \n \n \n \n 6a6-9.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 06to9.9kg\n \n \n \n \n \n','2018-03-28 10:34:02',4,'2019-03-20 14:13:11',4,0,NULL,NULL,NULL,'f623aaa7-e30a-4eac-9853-704b715fd1c5'),(116,'Current in Pre-ART clients seen in previous months','Current in Pre-ART clients seen in previous months, but not seen this current month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Current in Pre-ART clients seen in previous months\n Current in Pre-ART clients seen in previous months, but not seen this current month\n \n 2018-03-28 10:39:06 UTC\n \n 2019-01-24 13:49:58 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 116\n PreART-Clients-not-initiated-on-ART AND Clients-enrolled-in-Pre-ART-and-seen-in-previous-1-or-2-months\n \n \n PreART-Clients-not-initiated-on-ART\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n \n \n Clients-enrolled-in-Pre-ART-and-seen-in-previous-1-or-2-months\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2018-03-28 10:39:06',4,'2019-01-24 13:49:58',4,0,NULL,NULL,NULL,'32d35d67-0663-4adf-bfc7-2e9af3ce7faf'),(117,'Clients not initiated on ART SQL Query Version','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients not initiated on ART SQL Query Version\n \n \n 2018-03-29 00:51:58 UTC\n \n 2019-01-31 19:54:24 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 117\n select distinct person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 2223 \nand person_id not in \n (select person_id \n from obs \n where concept_id = 2249 AND \n location_id =:location \n );\n','2018-03-29 00:51:58',4,'2019-01-31 19:54:24',4,0,NULL,NULL,NULL,'ada14623-f50b-4cee-9e9b-7744165da486'),(118,'CI34: Current in Pre-ART clients seen for revisits','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI34: Current in Pre-ART clients seen for revisits\n \n \n 2018-03-29 02:41:52 UTC\n \n 2018-03-29 02:43:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 118\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-29 04:41:52',4,'2018-03-29 04:43:20',4,0,NULL,NULL,NULL,'c6c76e05-1ee3-43cd-b5e1-a6cf8532f154'),(119,'CI35: Current in Pre-ART clients seen for revisits in previous months','Not seen this month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI35: Current in Pre-ART clients seen for revisits in previous months\n Not seen this month\n \n 2018-03-29 02:45:09 UTC\n \n 2018-03-29 02:49:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 119\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-03-29 04:45:09',4,'2018-03-29 04:49:51',4,0,NULL,NULL,NULL,'6eda74b4-c3d1-4a03-ab99-f274069f3f20'),(120,'Patient Death Query','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.BirthAndDeathCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Patient Death Query\n \n \n 2018-04-17 10:29:46 UTC\n \n \n diedOnOrAfter\n \n java.util.Date\n true\n \n \n diedOnOrBefore\n \n java.util.Date\n true\n \n \n','2018-04-17 12:29:46',4,NULL,NULL,0,NULL,NULL,NULL,'058a4ed9-14ec-46dc-bd83-b99c93da0558'),(123,'Clients ever enrolled on ART','Clients with any date observation of ART Start before the current date','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.DateObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients ever enrolled on ART\n Clients with any date observation of ART Start before the current date\n \n 2018-04-17 12:53:04 UTC\n \n 2019-01-23 08:21:35 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n value1\n \n java.util.Date\n true\n \n \n 123\n ANY\n \n \n \n \n LESS_EQUAL\n','2018-04-17 14:53:04',4,'2019-01-23 10:21:35',4,0,NULL,NULL,NULL,'761a1a86-745d-4fe7-a656-0eba474bb2d6'),(124,'Clients ever enrolled on ART who died','All clients who died whilst on ART','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients ever enrolled on ART who died\n All clients who died whilst on ART\n \n 2018-04-17 12:57:20 UTC\n \n 2018-04-17 13:00:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 124\n Patient-Death-Query AND Clients-ever-enrolled-on-ART\n \n \n Patient-Death-Query\n \n \n \n \n diedOnOrBefore\n ${endDate}\n \n \n diedOnOrAfter\n ${startDate}\n \n \n \n \n \n Clients-ever-enrolled-on-ART\n \n \n \n \n locationList\n ${location}\n \n \n value1\n ${endDate}\n \n \n \n \n \n','2018-04-17 14:57:20',4,'2018-04-17 15:00:34',4,0,NULL,NULL,NULL,'b51679db-9c8f-4574-b742-8b609a5bd653'),(125,'ART clients Lost','Defined as ART clients who missed their appointment date by 90 or more days','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART clients Lost\n Defined as ART clients who missed their appointment date by 90 or more days\n \n 2018-04-17 13:32:13 UTC\n \n 2022-04-27 13:52:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 125\n \n select distinct o.person_id \n from obs o \n -- CLIENTS WHO MISSED APPOINTMENTS > 89 DAYS during the month \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l ON o.location_id = l.location_id \n AND o.person_id in ( \n -- begin \n select active_clients.person_id \n from \n ( \n select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up,DATEDIFF(CAST(:endDate AS DATE), B.value_datetime) as num_day, \n case \n -- Added interval of 28,29,30,31 days to 89 days to calculate the number of days in a month(including 89 days that determine LTFU) \n -- determine the max days a client will have if LTFU during period \n when MONTH(CAST(:endDate AS DATE)) = 01 then '120' \n when MONTH(CAST(:endDate AS DATE)) = 02 then '117' \n when MONTH(CAST(:endDate AS DATE)) = 03 then '120' \n when MONTH(CAST(:endDate AS DATE)) = 04 then '119' \n when MONTH(CAST(:endDate AS DATE)) = 05 then '120' \n when MONTH(CAST(:endDate AS DATE)) = 06 then '119' \n when MONTH(CAST(:endDate AS DATE)) = 07 then '120' \n when MONTH(CAST(:endDate AS DATE)) = 08 then '120' \n when MONTH(CAST(:endDate AS DATE)) = 09 then '119' \n when MONTH(CAST(:endDate AS DATE)) = 10 then '120' \n when MONTH(CAST(:endDate AS DATE)) = 11 then '119' \n when MONTH(CAST(:endDate AS DATE)) = 12 then '119' \n else '29' end as days_in_month \n from obs B \n inner join \n \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n and voided = 0 \n having DATEDIFF(CAST(:endDate AS DATE), latest_follow_up) > 89 \n and DATEDIFF(CAST(:endDate AS DATE), latest_follow_up) < days_in_month \n \n ) as active_clients \n where active_clients.latest_follow_up < cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.obs_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2398 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n \n ) \n \n -- DEAD \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n','2018-04-17 13:32:13',4,'2022-04-27 13:52:05',4,0,NULL,NULL,NULL,'e2671095-bdf2-44cf-a857-065e2e2ad518'),(126,'ART clients with Missed Appointments','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART clients with Missed Appointments\n \n \n 2018-04-17 17:56:59 UTC\n \n 2019-05-02 09:04:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 126\n select distinct o.person_id \nFROM obs o \nINNER JOIN patient ON o.person_id = patient.patient_id \nand o.concept_id = 3752 \nand o.value_datetime in \n ( \n select latestFU from \n ( \n select distinct os.person_id, max(os.value_datetime) AS latestFU, datediff(CAST(:endDate AS DATE), max(value_datetime)) AS \n Num_Days \n from obs os \n inner join person_name pn on os.person_id = pn.person_id \n inner join patient p on pn.person_id = p.patient_id and pn.voided = 0 \n inner join person ps on ps.person_id = p.patient_id and ps.voided = 0 \n where os.concept_id = 3752 \n and obs_datetime <= :endDate \n group by os.person_id \n having Num_Days > 7 \n and Num_Days < 30 \n ) as lost \n ) \nand o.person_id in \n ( \n select person_id from \n ( \n select distinct os.person_id, max(os.value_datetime) AS latestFU, datediff(CAST(:endDate AS DATE), \n max(value_datetime)) AS Num_Days \n from obs os \n inner join person_name pn on os.person_id = pn.person_id \n inner join patient p on pn.person_id = p.patient_id and pn.voided = 0 \n inner join person ps on ps.person_id = p.patient_id and ps.voided = 0 \n where os.concept_id = 3752 \n and obs_datetime <= :endDate \n group by os.person_id \n having Num_Days > 7 \n and Num_Days < 30 \n ) as lost \n ) \n \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 ) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND o.person_id not in ( \n select person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n;\n','2018-04-17 17:56:59',4,'2019-05-02 09:04:29',4,0,NULL,NULL,NULL,'99784926-bc17-4308-9947-078e59b006ff'),(127,'ART clients who Defaulted','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART clients who Defaulted\n \n \n 2018-04-17 18:01:09 UTC\n \n 2019-05-02 08:58:41 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 127\n select distinct o.person_id \nFROM obs o \nINNER JOIN patient ON o.person_id = patient.patient_id \nand o.concept_id = 3752 \nand o.value_datetime in \n ( \n select latestFU from \n ( \n select distinct os.person_id, max(os.value_datetime) AS latestFU, datediff(CAST(:endDate AS DATE), max(value_datetime)) AS \n Num_Days \n from obs os \n inner join person_name pn on os.person_id = pn.person_id \n inner join patient p on pn.person_id = p.patient_id and pn.voided = 0 \n inner join person ps on ps.person_id = p.patient_id and ps.voided = 0 \n where os.concept_id = 3752 \n and obs_datetime <= :endDate \n group by os.person_id \n having Num_Days > 30 \n and Num_Days < 90 \n ) as defaulter \n ) \nand o.person_id in \n ( \n select person_id from \n ( \n select distinct os.person_id, max(os.value_datetime) AS latestFU, datediff(CAST(:endDate AS DATE), \n max(value_datetime)) AS Num_Days \n from obs os \n inner join person_name pn on os.person_id = pn.person_id \n inner join patient p on pn.person_id = p.patient_id and pn.voided = 0 \n inner join person ps on ps.person_id = p.patient_id and ps.voided = 0 \n where os.concept_id = 3752 \n and obs_datetime <= :endDate \n group by os.person_id \n having Num_Days > 30 \n and Num_Days < 90 \n ) as defaulter \n ) \n \n \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime <= :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND o.person_id not in ( \n select person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n;\n','2018-04-17 18:01:09',4,'2019-05-02 08:58:41',4,0,NULL,NULL,NULL,'32051001-863f-4e02-9165-599c2a3a9137'),(128,'ART clients stopped Query','ART patients who stopped ART','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART clients stopped Query\n ART patients who stopped ART\n \n 2018-04-18 07:35:57 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-04-18 09:35:57',4,NULL,NULL,0,NULL,NULL,NULL,'141ce68c-09b5-40ee-9c51-bff2aa09a54d'),(129,'Scheduled appointment','scheduled appointment. this are clients who came on the set date','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Scheduled appointment\n scheduled appointment. this are clients who came on the set date\n \n 2018-04-18 08:30:00 UTC\n \n 2018-04-18 08:31:09 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n 129\n ANY\n \n \n \n \n IN\n \n \n \n','2018-04-18 10:30:00',4,'2018-04-18 10:31:09',4,0,NULL,NULL,NULL,'44383c6e-b552-4703-9f88-faf374ff3b8e'),(130,'All ART drug refill visits','all clients who made a drug pick up visit','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n All ART drug refill visits\n all clients who made a drug pick up visit\n \n 2018-04-18 09:45:26 UTC\n \n 2019-01-31 04:58:43 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 130\n select distinct person_id \nfrom obs o, encounter e, visit v \nwhere o.encounter_id = e.encounter_id \nand e.visit_id = v.visit_id and \nv.visit_type_id = 10 \nand o.location_id =:location \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate;\n','2018-04-18 09:45:26',4,'2019-01-31 04:58:43',4,0,NULL,NULL,NULL,'da54992a-b327-4dff-a9d7-d9cc53f6697d'),(131,'On time Drug pick-up','Clients who picked their drug refill on the scheduled date','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n On time Drug pick-up\n Clients who picked their drug refill on the scheduled date\n \n 2018-04-18 10:34:10 UTC\n \n 2018-04-18 10:39:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 131\n All-ART-drug-refill-visits AND Scheduled-appointment\n \n \n All-ART-drug-refill-visits\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Scheduled-appointment\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n','2018-04-18 12:34:10',4,'2018-04-18 12:39:15',4,0,NULL,NULL,NULL,'23622729-be20-496f-ac0f-f6647093eb90'),(132,'ART clients provided nutrition supplements','ART clients provided nutrition suppements','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART clients provided nutrition supplements\n ART clients provided nutrition suppements\n \n 2018-04-19 10:11:22 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n','2018-04-19 12:11:22',4,NULL,NULL,0,NULL,NULL,NULL,'92e1c320-c133-4f98-9833-ad680b8f5bd5'),(133,'Plumpy Nut','ART clients who received plumpy nut','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Plumpy Nut\n ART clients who received plumpy nut\n \n 2018-04-19 10:22:41 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-04-19 12:22:41',4,NULL,NULL,0,NULL,NULL,NULL,'a1f707c2-4bb8-4d48-8c62-680746e324b2'),(134,'Given F75','Client who were given nutritional support F75','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Given F75\n Client who were given nutritional support F75\n \n 2018-04-19 10:25:36 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-04-19 12:25:36',4,NULL,NULL,0,NULL,NULL,NULL,'20aa6768-f594-4e25-87fb-032f27a018c2'),(135,'Given F100','clients who picked F100','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Given F100\n clients who picked F100\n \n 2018-04-19 10:26:53 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-04-19 12:26:53',4,NULL,NULL,0,NULL,NULL,NULL,'75622551-c46c-4797-a9cf-62ebc4871b86'),(136,'Other nutritional products','Client who were given nutritional support Other nutritional products','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Other nutritional products\n Client who were given nutritional support Other nutritional products\n \n 2018-04-19 10:27:43 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-04-19 12:27:43',4,NULL,NULL,0,NULL,NULL,NULL,'9852762a-1c2e-4bc4-b85f-f90b07245cbd'),(137,'ART clients given cotrimoxazole','ART clients given cotrimoxazole','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.NumericObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART clients given cotrimoxazole\n ART clients given cotrimoxazole\n \n 2018-04-19 10:43:03 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n GREATER_THAN\n 0.0\n','2018-04-19 12:43:03',4,NULL,NULL,0,NULL,NULL,NULL,'bd653d50-7c8b-4eef-b4df-f43b6895e687'),(138,'HIV positive clients Started IPT','HIV positive clients, in HIV care (preART or ART) Started IPT','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HIV positive clients Started IPT\n HIV positive clients, in HIV care (preART or ART) Started IPT\n \n 2018-04-19 13:45:43 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n IN\n \n \n \n','2018-04-19 15:45:43',4,NULL,NULL,0,NULL,NULL,NULL,'861f8278-7e7b-45b0-b3e4-62fbfbc1658a'),(139,'New pre-ART clients started IPT','New pre-ART clients started IPT','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n New pre-ART clients started IPT\n New pre-ART clients started IPT\n \n 2018-04-19 13:57:23 UTC\n \n 2018-04-19 14:09:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 139\n Date-enrolled-in-Pre-ART AND HIV-positive-clients-Started-IPT\n \n \n Date-enrolled-in-Pre-ART\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n HIV-positive-clients-Started-IPT\n \n \n \n \n \n \n','2018-04-19 15:57:23',4,'2018-04-19 16:09:54',4,0,NULL,NULL,NULL,'862c77cd-5bcb-4858-9cd3-d0b60704d05b'),(140,'New ART clients started IPT','New ART clients started IPT','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n New ART clients started IPT\n New ART clients started IPT\n \n 2018-04-19 14:10:35 UTC\n \n 2018-04-19 14:16:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 140\n ART-start-date AND HIV-positive-clients-Started-IPT\n \n \n ART-start-date\n \n \n \n \n locationList\n ${location}\n \n \n value2\n ${endDate}\n \n \n value1\n ${startDate}\n \n \n \n \n \n HIV-positive-clients-Started-IPT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n','2018-04-19 16:10:35',4,'2018-04-19 16:16:14',4,0,NULL,NULL,NULL,'02a211e3-0e79-4f07-b131-84b2c28a7f93'),(141,'No. of persons in original cohort 6 months','No. of persons in original cohort 6 months','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n No. of persons in original cohort 6 months\n No. of persons in original cohort 6 months\n \n 2018-04-20 07:40:13 UTC\n \n 2018-10-16 14:41:18 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n 141\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand o.concept_id = 2249 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH));\n','2018-04-20 09:40:13',4,'2018-10-16 16:41:18',4,0,NULL,NULL,NULL,'d768b001-7c65-49d1-b8db-d3bc04ccbf6c'),(142,'No. of persons in original cohort 12 months','No. of persons in original cohort 12 months','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n No. of persons in original cohort 12 months\n No. of persons in original cohort 12 months\n \n 2018-04-20 07:41:37 UTC\n \n 2018-10-16 14:39:12 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n 142\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand o.concept_id = 2249 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH));\n','2018-04-20 09:41:37',4,'2018-10-16 16:39:12',4,0,NULL,NULL,NULL,'d153ef33-2ae2-43c7-8c1a-ed070d4e0022'),(143,'Number of persons transfer in- 6 months','Number of persons transfer in- 6 months','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Number of persons transfer in- 6 months\n Number of persons transfer in- 6 months\n \n 2018-04-20 08:19:32 UTC\n \n 2018-04-20 08:27:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 143\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand o.concept_id = 4168 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH))\n','2018-04-20 10:19:32',4,'2018-04-20 10:27:22',4,0,NULL,NULL,NULL,'c9387748-c920-4665-886b-aaae0c5609f9'),(144,'Number of persons transfer in- 12 months','Number of persons transfer in- 12 months','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Number of persons transfer in- 12 months\n Number of persons transfer in- 12 months\n \n 2018-04-20 08:22:18 UTC\n \n 2018-04-20 08:26:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 144\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand o.concept_id = 4168 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH))\n','2018-04-20 10:22:18',4,'2018-04-20 10:26:32',4,0,NULL,NULL,NULL,'3528e2a5-002d-4a15-8565-e80d7e4a56e1'),(145,'Date transferred out','Date transferred out','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.DateObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Date transferred out\n Date transferred out\n \n 2018-04-20 08:47:48 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n value1\n \n java.util.Date\n true\n \n \n ANY\n \n \n \n \n LESS_EQUAL\n','2018-04-20 10:47:48',4,NULL,NULL,0,NULL,NULL,NULL,'e085074b-37f3-453c-a51e-7c11b6421d5d'),(146,'Number of persons in cohort transferred out 6 months','Number of persons cohort transferred out 6 months','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Number of persons in cohort transferred out 6 months\n Number of persons cohort transferred out 6 months\n \n 2018-04-20 08:53:19 UTC\n \n 2018-04-20 09:16:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 146\n Date-transferred-out AND No.-of-persons-in-original-cohort-6-months\n \n \n Date-transferred-out\n \n \n \n \n locationList\n ${location}\n \n \n value1\n ${endDate}\n \n \n \n \n \n No.-of-persons-in-original-cohort-6-months\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n \n \n','2018-04-20 10:53:19',4,'2018-04-20 11:16:16',4,0,NULL,NULL,NULL,'2172c378-b654-491b-8342-a2aec11d99eb'),(148,'Number of persons in cohort transferred out 12 months','Number of persons in cohort transferred out 12 months','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Number of persons in cohort transferred out 12 months\n Number of persons in cohort transferred out 12 months\n \n 2018-04-20 09:08:34 UTC\n \n 2018-04-20 09:13:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 148\n Date-transferred-out AND No.-of-persons-in-original-cohort-12-months\n \n \n Date-transferred-out\n \n \n \n \n locationList\n ${location}\n \n \n value1\n ${endDate}\n \n \n \n \n \n No.-of-persons-in-original-cohort-12-months\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n \n \n','2018-04-20 11:08:34',4,'2018-04-20 11:13:16',4,0,NULL,NULL,NULL,'e50bdec3-0982-4a13-a94d-c1c860b767b6'),(149,'No. of baseline CD4+ counts 6 months','No. of baseline CD4+ counts 6 months','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n No. of baseline CD4+ counts 6 months\n No. of baseline CD4+ counts 6 months\n \n 2018-04-20 09:27:44 UTC\n \n 2019-02-05 08:55:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 149\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand ((o.concept_id = 1187 and o.value_numeric > 0) OR (o.concept_id = 3661 and o.value_numeric > 0)) \nand MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \nand obs_datetime in \n (select min(os.obs_datetime) from obs os \n where ((o.concept_id = 1187 and o.value_numeric > 0) OR (o.concept_id = 3661 and o.value_numeric > 0)) \n group by os.person_id) \nand person_id in \n (select distinct person_id from obs os \n where ((o.concept_id = 1187 and o.value_numeric > 0) OR (o.concept_id = 3661 and o.value_numeric > 0)));\n','2018-04-20 11:27:44',4,'2019-02-05 10:55:59',4,0,NULL,NULL,NULL,'0a267111-8e29-46c3-8299-cb199c6b74aa'),(150,'No. of baseline CD4+ counts 12 months','No. of baseline CD4+ counts 12 months','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n No. of baseline CD4+ counts 12 months\n No. of baseline CD4+ counts 12 months\n \n 2018-04-20 09:40:28 UTC\n \n 2018-10-16 13:38:46 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n 150\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand ((o.concept_id = 1187 and o.value_numeric > 0) OR (o.concept_id = 3661 and o.value_numeric > 0)) \nand MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \nand obs_datetime in \n (select min(os.obs_datetime) from obs os \n where ((o.concept_id = 1187 and o.value_numeric > 0) OR (o.concept_id = 3661 and o.value_numeric > 0)) \n group by os.person_id) \nand person_id in \n (select distinct person_id from obs os \n where ((o.concept_id = 1187 and o.value_numeric > 0) OR (o.concept_id = 3661 and o.value_numeric > 0)));\n','2018-04-20 11:40:28',4,'2018-10-16 15:38:46',4,0,NULL,NULL,NULL,'3dc23527-d716-4e4b-bb05-7a504e0db44d'),(153,'TestMedian','TestMedian','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.SqlIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n TestMedian\n TestMedian\n \n 2018-04-20 11:34:00 UTC\n \n 2018-04-20 11:37:22 UTC\n \n 153\n SELECT \n AVG(sorted_obs.cd4) \nFROM \n (SELECT @rowindex:=@rowindex + 1 AS rowindex, \n o.value_numeric AS cd4 \n FROM obs o \n where location_id = 16 \n and o.concept_id = 1187 \n and MONTH(o.obs_datetime) = MONTH(DATE_ADD(now(), INTERVAL -2 MONTH)) \n ORDER BY o.value_numeric) AS sorted_obs \nWHERE \nsorted_obs.rowindex IN (FLOOR(@rowindex / 2) , CEIL(@rowindex / 2));\n','2018-04-20 13:34:00',4,'2018-04-20 13:37:22',4,0,NULL,NULL,NULL,'a5979205-f1fa-4ebe-ad68-8e3f5d4d311a'),(154,'DM_Weight_Updated','patient weight','org.openmrs.module.reporting.indicator.dimension.Dimension','org.openmrs.module.reporting.indicator.dimension.CohortDefinitionDimension','org.openmrs.module.reporting.serializer.ReportingSerializer','\n DM_Weight_Updated\n patient weight\n \n 2018-06-05 07:42:11 UTC\n \n 2018-06-05 07:45:30 UTC\n \n 154\n \n \n 03to3.9kg\n \n \n \n \n value2\n 3.9\n \n \n value1\n 0.0\n \n \n \n \n \n 04to5.9kg\n \n \n \n \n value2\n 5.9\n \n \n value1\n 4.0\n \n \n \n \n \n 06to9.9kg\n \n \n \n \n value2\n 9.9\n \n \n value1\n 6.0\n \n \n \n \n \n 10to13.9kg\n \n \n \n \n value2\n 13.9\n \n \n value1\n 10.0\n \n \n \n \n \n 14to19.9kg\n \n \n \n \n value2\n 19.9\n \n \n value1\n 14.0\n \n \n \n \n \n 20to24.9kg\n \n \n \n \n value2\n 24.9\n \n \n value1\n 20.0\n \n \n \n \n \n 25+kg\n \n \n \n \n value2\n 34.9\n \n \n value1\n 25.0\n \n \n \n \n \n','2018-06-05 09:42:11',4,'2018-06-05 09:45:30',4,0,NULL,NULL,NULL,'3cf562e6-0290-45c0-a999-6133791b0652'),(155,'Clients registered during period','Clients registered during period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.EncounterCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients registered during period\n Clients registered during period\n \n 2018-06-05 08:36:35 UTC\n \n 2018-06-08 06:51:40 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n 155\n ANY\n \n \n \n','2018-06-05 10:36:35',4,'2018-06-08 08:51:40',4,0,NULL,NULL,NULL,'1f5202c9-90ed-4203-ab0c-969c40bd5ec7'),(159,'PIR05: Patient consultation completeness report (Registration vs. Consultation) Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR05: Patient consultation completeness report (Registration vs. Consultation) Data Set\n \n 2018-06-07 10:43:04 UTC\n \n 2018-06-07 14:46:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 159\n \n \n \n 900\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n 901\n \n \n \n \n \n \n \n \n \n 902\n \n \n \n \n \n \n \n \n \n','2018-06-07 12:43:04',4,'2018-06-07 16:46:17',4,0,NULL,NULL,NULL,'040a8664-4033-4958-bcad-064f51e6889a'),(169,'Clients not registered during period','Clients not registered during period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.EncounterCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients not registered during period\n Clients not registered during period\n \n 2018-06-08 06:53:29 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n ANY\n \n \n \n true\n','2018-06-08 08:53:29',4,NULL,NULL,0,NULL,NULL,NULL,'56bc4ef4-3f60-47bd-b6c4-89f203ee199d'),(170,'Clients not seen for consultation during period','Clients not seen for consultation during period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.EncounterCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients not seen for consultation during period\n Clients not seen for consultation during period\n \n 2018-06-08 06:54:57 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n ANY\n \n \n \n true\n','2018-06-08 08:54:57',4,NULL,NULL,0,NULL,NULL,NULL,'1791b273-ab2c-4d1b-9029-77203be5ea4d'),(171,'Clients not registered but seen for consultation during the period','Clients not registered but seen for consultation during the period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients not registered but seen for consultation during the period\n Clients not registered but seen for consultation during the period\n \n 2018-06-08 06:57:10 UTC\n \n 2018-06-08 07:05:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 171\n Clients-seen-for-consultation AND Clients-not-registered-during-period\n \n \n Clients-seen-for-consultation\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n Clients-not-registered-during-period\n \n \n \n \n \n \n','2018-06-08 08:57:10',4,'2018-06-08 09:05:55',4,0,NULL,NULL,NULL,'331400b1-dd20-4e48-b06c-28356df8e88b'),(172,'Clients registered and not seen for consultation','Clients registered and not seen for consultation','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients registered and not seen for consultation\n Clients registered and not seen for consultation\n \n 2018-06-08 07:06:23 UTC\n \n 2018-06-08 07:41:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 172\n Clients-registered-during-period AND Clients-not-seen-for-consultation-during-period\n \n \n Clients-registered-during-period\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n Clients-not-seen-for-consultation-during-period\n \n \n \n \n \n \n','2018-06-08 09:06:23',4,'2018-06-08 09:41:52',4,0,NULL,NULL,NULL,'6ed321bb-a8b7-4c95-aed0-9f126b9225c0'),(173,'Clients registered and seen for consultation during period','Clients registered and seen for consultation during period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients registered and seen for consultation during period\n Clients registered and seen for consultation during period\n \n 2018-06-08 07:11:35 UTC\n \n 2018-06-08 07:13:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 173\n Clients-seen-for-consultation AND Clients-registered-during-period\n \n \n Clients-seen-for-consultation\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n Clients-registered-during-period\n \n \n \n \n \n \n','2018-06-08 09:11:35',4,'2018-06-08 09:13:37',4,0,NULL,NULL,NULL,'c2ff0485-8637-4415-893d-70b6b18c1c71'),(174,'Clients not registered but seen for consultation during the period','Clients not registered but seen for consultation during the period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients not registered but seen for consultation during the period\n Clients not registered but seen for consultation during the period\n \n 2018-06-08 07:14:53 UTC\n \n 2018-06-08 07:15:36 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 174\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-06-08 09:14:53',4,'2018-06-08 09:15:36',4,0,NULL,NULL,NULL,'7874aba7-94c7-43be-9601-0aeee2fafe41'),(175,'Clients not seen for consultation during period','Clients not seen for consultation during period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients not seen for consultation during period\n Clients not seen for consultation during period\n \n 2018-06-08 07:16:43 UTC\n \n 2018-06-08 07:17:27 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 175\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n','2018-06-08 09:16:43',4,'2018-06-08 09:17:27',4,0,NULL,NULL,NULL,'5697c599-0bc4-45e2-b2d7-23b6643742db'),(176,'Clients registered and not seen for consultation','Clients registered and not seen for consultation','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients registered and not seen for consultation\n Clients registered and not seen for consultation\n \n 2018-06-08 07:18:15 UTC\n \n 2018-06-08 07:18:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 176\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-06-08 09:18:15',4,'2018-06-08 09:18:48',4,0,NULL,NULL,NULL,'786a69e3-f9a4-4aad-903c-b511c7bca134'),(177,'Clients with visits and documented vitals encounter with documented consultation during period','Clients with visits and documented vitals encounter with documented consultation during period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with visits and documented vitals encounter with documented consultation during period\n Clients with visits and documented vitals encounter with documented consultation during period\n \n 2018-06-08 07:19:27 UTC\n \n 2018-06-17 05:17:09 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 177\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-06-08 07:19:27',4,'2018-06-17 05:17:09',4,0,NULL,NULL,NULL,'2b76b4a6-12ab-43f1-b4fd-f0baf1f31e35'),(178,'Clients with visits and documented vitals encounter at registration during period','Clients registered during period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with visits and documented vitals encounter at registration during period\n Clients registered during period\n \n 2018-06-08 07:20:29 UTC\n \n 2018-06-17 05:17:58 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 178\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n','2018-06-08 07:20:29',4,'2018-06-17 05:17:58',4,0,NULL,NULL,NULL,'b6c39f5c-2e9b-4250-9216-5a6eb1cabfca'),(179,'Clients seen for consultation during period','Clients seen for consultation during period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen for consultation during period\n Clients seen for consultation during period\n \n 2018-06-08 07:21:56 UTC\n \n 2018-06-08 07:24:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 179\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n','2018-06-08 09:21:56',4,'2018-06-08 09:24:22',4,0,NULL,NULL,NULL,'3323b353-6f81-44b5-80d8-41b31c1071f0'),(180,'Percentage of clients with visits started but not seen for consultation during period','Percentage of clients with visits started but not seen for consultation during period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Percentage of clients with visits started but not seen for consultation during period\n Percentage of clients with visits started but not seen for consultation during period\n \n 2018-06-08 07:24:56 UTC\n \n 2018-10-29 15:30:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 180\n FRACTION\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n \n \n locationList\n ${location}\n \n \n stoppedOnOrBefore\n ${endDate}\n \n \n startedOnOrAfter\n ${startDate}\n \n \n \n','2018-06-08 09:24:56',4,'2018-10-29 17:30:13',4,0,NULL,NULL,NULL,'e4155685-6661-42d0-9c74-be6a136eef5b'),(181,'Percentage of clients with visits started and also seen for consultation during period','Percentage of clients with visits started and also seen for consultation during period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Percentage of clients with visits started and also seen for consultation during period\n Percentage of clients with visits started and also seen for consultation during period\n \n 2018-06-08 07:26:26 UTC\n \n 2018-10-29 15:28:47 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 181\n FRACTION\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n \n \n locationList\n ${location}\n \n \n stoppedOnOrBefore\n ${endDate}\n \n \n startedOnOrAfter\n ${startDate}\n \n \n \n','2018-06-08 09:26:26',4,'2018-10-29 17:28:47',4,0,NULL,NULL,NULL,'e7f1eed7-f423-42e0-a37e-74e41ddfe4da'),(182,'PIR99: Registration vs Consultation (Completeness)','Registration vs Consultation (Completeness)','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR99: Registration vs Consultation (Completeness)\n Registration vs Consultation (Completeness)\n \n 2018-06-08 07:28:55 UTC\n \n 2018-06-08 07:28:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 182\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2018-06-08 09:28:55',4,'2018-06-08 09:28:56',4,0,NULL,NULL,NULL,'685dbc9b-752a-4b5b-a948-8bd8830f80fb'),(183,'PIR99: Registration vs Consultation (Completeness) Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR99: Registration vs Consultation (Completeness) Data Set\n \n 2018-06-08 07:28:56 UTC\n \n 2018-10-15 13:22:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 183\n \n \n \n 900\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n 901\n \n \n \n \n \n \n \n \n \n 903\n \n \n \n \n \n \n \n \n \n 904\n \n \n \n \n \n \n \n \n \n 905\n \n \n \n \n \n \n \n \n \n 906\n \n \n \n \n \n \n \n \n \n 907\n \n \n \n \n \n \n \n \n \n 908\n \n \n \n \n \n \n \n \n \n 909\n \n \n \n \n \n \n \n \n \n 910\n \n \n \n \n \n \n \n \n \n','2018-06-08 09:28:56',4,'2018-10-15 15:22:12',4,0,NULL,NULL,NULL,'6a4ca4b9-1fce-4ab1-b1dd-7d3d68c7e40a'),(184,'CI_Clients_seen','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI_Clients_seen\n \n \n 2018-06-08 10:21:40 UTC\n \n 2019-01-31 18:09:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 184\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-06-08 10:21:40',4,'2019-01-31 18:09:56',4,0,NULL,NULL,NULL,'ec42c51f-70c7-437f-8d1b-00d531626486'),(185,'Clients with visits started during period','Clients with visits started during period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.VisitCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with visits started during period\n Clients with visits started during period\n \n 2018-06-17 05:01:34 UTC\n \n 2018-10-29 15:24:40 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n startedOnOrAfter\n \n java.util.Date\n true\n \n \n stoppedOnOrBefore\n \n java.util.Date\n true\n \n \n 185\n false\n','2018-06-17 07:01:34',4,'2018-10-29 17:24:40',4,0,NULL,NULL,NULL,'2e034999-51ce-4694-8cfa-3892c11c9d83'),(186,'Clients with an active visit during period','Clients with an active visit during period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.VisitCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with an active visit during period\n Clients with an active visit during period\n \n 2018-06-17 05:03:41 UTC\n \n 2018-06-17 05:05:02 UTC\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n activeOnOrAfter\n \n java.util.Date\n true\n \n \n activeOnOrBefore\n \n java.util.Date\n true\n \n \n 186\n true\n false\n','2018-06-17 05:03:41',4,'2018-06-17 05:05:02',4,0,NULL,NULL,NULL,'18a150f9-baa1-47a1-a81f-8cdbf0e11bb7'),(187,'Clients with visits started during period','Clients with active visits which were started during period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with visits started during period\n Clients with active visits which were started during period\n \n 2018-06-17 05:06:57 UTC\n \n 2018-10-29 15:26:02 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 187\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n stoppedOnOrBefore\n ${endDate}\n \n \n startedOnOrAfter\n ${startDate}\n \n \n \n','2018-06-17 07:06:57',4,'2018-10-29 17:26:02',4,0,NULL,NULL,NULL,'94e360fc-bc15-4848-8af4-c49a1fc30cc9'),(188,'Clients with an active visit during period','Clients with an active visit during period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with an active visit during period\n Clients with an active visit during period\n \n 2018-06-17 05:09:21 UTC\n \n 2018-06-17 05:10:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 188\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n activeOnOrAfter\n ${startDate}\n \n \n activeOnOrBefore\n ${endDate}\n \n \n \n','2018-06-17 05:09:21',4,'2018-06-17 05:10:06',4,0,NULL,NULL,NULL,'0093fd77-6601-466d-abf7-bc38c91291ff'),(189,'All patients','All patients','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.AllPatientsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n All patients\n All patients\n \n 2018-06-19 11:07:07 UTC\n \n','2018-06-19 11:07:07',4,NULL,NULL,0,NULL,NULL,NULL,'2ba82672-5807-417c-bd4f-85216bee2b75'),(190,'Ratio of patient registered to those who are current of ART','Ratio of patient registered to those who are current of ART','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Ratio of patient registered to those who are current of ART\n Ratio of patient registered to those who are current of ART\n \n 2018-06-19 11:08:40 UTC\n \n 2018-06-19 11:09:15 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 190\n FRACTION\n \n \n \n \n','2018-06-19 11:08:40',4,'2018-06-19 11:09:15',4,0,NULL,NULL,NULL,'5d1d8893-ea50-4e58-900f-21bbd217d9a5'),(192,'New on ART_test','sql script here','org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.SqlDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n New on ART_test\n sql script here\n \n 2018-06-29 12:04:50 UTC\n \n 2018-06-29 12:14:22 UTC\n \n 192\n select * from visit where date_started >= '20-jun-2018'\n','2018-06-29 17:34:50',4,'2018-06-29 17:44:22',4,0,NULL,NULL,NULL,'d1b7fbd9-eabb-4a41-b40a-a0000bc9bb7d'),(194,'PIR06: Presumptive TB Cases Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR06: Presumptive TB Cases Data Set\n \n 2018-07-11 13:00:39 UTC\n \n 2018-07-11 15:17:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 194\n \n \n Gender\n \n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n \n \n ScrinAdulF\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Gender\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n ScrinAdulM\n \n \n \n \n Gender\n Males\n \n \n DM_Age\n Adults\n \n \n \n \n \n ScrinKidsF\n \n \n \n \n Gender\n Females\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n ScrinKidsM\n \n \n \n \n Gender\n Males\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n TBCaseAdF\n \n \n \n \n \n \n \n \n \n TBCaseAdM\n \n \n \n \n \n \n TBCaseChF\n \n \n \n \n \n \n TBCaseChM\n \n \n \n \n \n \n TBTreatAdF\n \n \n \n \n \n \n \n \n \n TBTreatAdM\n \n \n \n \n \n \n TBTreatChF\n \n \n \n \n \n \n TBTreatChM\n \n \n \n \n \n \n','2018-07-11 18:30:39',4,'2018-07-11 20:47:59',4,0,NULL,NULL,NULL,'0f8411d8-3f05-4bdf-aec2-8e98424dc083'),(195,'Male','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.GenderCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Male\n \n \n 2018-07-11 13:13:49 UTC\n \n true\n false\n false\n','2018-07-11 18:43:49',4,NULL,NULL,0,NULL,NULL,NULL,'8d691fae-5ceb-43dc-b4d6-5bac71678c96'),(196,'Presumptive TB Cases','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.InProgramCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Presumptive TB Cases\n \n \n 2018-07-11 13:26:30 UTC\n \n \n onDate\n \n java.util.Date\n true\n \n \n \n \n \n','2018-07-11 18:56:30',4,NULL,NULL,0,NULL,NULL,NULL,'b8632f66-eaff-4483-ace7-77ad437ae84f'),(198,'PIR06: Presumptive TB Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR06: Presumptive TB Data Set\n \n 2018-07-11 13:54:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n \n \n','2018-07-11 19:24:59',4,NULL,NULL,0,NULL,NULL,NULL,'b7cbdb76-1601-4381-a659-c08f500a0692'),(199,'Diagnosed with TB and started on treatment','No of people diagnosed with TB and started on TB treatment this month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Diagnosed with TB and started on treatment\n No of people diagnosed with TB and started on TB treatment this month\n \n 2018-07-11 14:46:45 UTC\n \n 2020-08-04 17:07:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 199\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-07-11 14:46:45',4,'2020-08-04 17:07:57',4,0,NULL,NULL,NULL,'026262eb-a4f9-4efa-95c1-08c7e3379bcb'),(200,'Lost Clients Indicator','counts clients we have not seen in over 90 days','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Lost Clients Indicator\n counts clients we have not seen in over 90 days\n \n 2018-08-01 10:27:04 UTC\n \n 2018-08-01 14:02:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 200\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-08-01 15:57:04',4,'2018-08-01 19:32:54',4,0,NULL,NULL,NULL,'7a98264d-45da-4d7f-a6f8-2d26af7c761f'),(202,'Lost CLients Report Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Lost CLients Report Data Set\n \n 2018-08-01 12:22:39 UTC\n \n 2018-08-01 14:38:09 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 202\n \n \n DM_Sex\n \n \n \n \n \n \n \n \n LostClient\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n','2018-08-01 17:52:39',4,'2018-08-01 20:08:09',4,0,NULL,NULL,NULL,'f3477198-4d0c-417f-8bae-8a537e014a99'),(203,'Missed Appointments Indicator','These are clients whose appointments are over 7 days due','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Missed Appointments Indicator\n These are clients whose appointments are over 7 days due\n \n 2018-08-01 14:09:12 UTC\n \n 2018-08-01 14:12:27 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 203\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-08-01 19:39:12',4,'2018-08-01 19:42:27',4,0,NULL,NULL,NULL,'e03fafd4-1495-4a09-b01f-f899be47cb38'),(205,'Missed Appointments Report Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Missed Appointments Report Data Set\n \n 2018-08-01 14:41:28 UTC\n \n 2018-08-01 14:52:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 205\n \n \n DM_Sex\n \n \n \n \n \n \n \n \n MissedAP-F\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n \n \n \n MissedAP-M\n \n \n \n \n DM_Sex\n Males\n \n \n \n \n \n','2018-08-01 20:11:28',4,'2018-08-01 20:22:07',4,0,NULL,NULL,NULL,'22300a2c-9096-4518-bb47-cae4c283bd72'),(206,'Defaulters Indicator','clients who havent come for appointments for over 7 days but less than 90','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Defaulters Indicator\n clients who havent come for appointments for over 7 days but less than 90\n \n 2018-08-01 15:10:40 UTC\n \n 2018-08-01 15:24:58 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 206\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-08-01 20:40:40',4,'2018-08-01 20:54:58',4,0,NULL,NULL,NULL,'0ec8e212-181e-41a3-9726-ff31fcf99c21'),(208,'Defaulted Report Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Defaulted Report Data Set\n \n 2018-08-01 15:28:51 UTC\n \n 2018-08-01 15:30:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 208\n \n \n \n Defaulters\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n','2018-08-01 20:58:51',4,'2018-08-01 21:00:11',4,0,NULL,NULL,NULL,'c41a9e0d-ac74-443f-98cf-52b341ecc1b2'),(209,'Clients who did not pick up ARV lost','Persons who did not pick upp their ARV regimen','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients who did not pick up ARV lost\n Persons who did not pick upp their ARV regimen\n \n 2018-08-02 13:47:29 UTC\n \n 2018-08-03 07:09:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 209\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-08-02 19:17:29',4,'2018-08-03 12:39:42',4,0,NULL,NULL,NULL,'ddcbd8c5-7e15-4006-be8b-0428db54bc51'),(211,'PIR_07_Persons_who_did_not_pick_up_their_ARV_regimen Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR_07_Persons_who_did_not_pick_up_their_ARV_regimen Data Set\n \n 2018-08-02 13:57:46 UTC\n \n 2018-08-02 14:05:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 211\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n \n \n LostAdultF\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n','2018-08-02 19:27:46',4,'2018-08-02 19:35:08',4,0,NULL,NULL,NULL,'6dbb2065-f8d0-4740-ba44-0e8f5cb5ced0'),(212,'Clients who died','Didnt pick up ARV due to death','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients who died\n Didnt pick up ARV due to death\n \n 2018-08-02 14:22:00 UTC\n \n 2019-03-29 06:58:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 212\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-08-02 14:22:00',4,'2019-03-29 06:58:08',4,0,NULL,NULL,NULL,'54fccccb-8c30-4235-a6a2-b40a3a6cc2ab'),(213,'Reason not yet known','didnt pick up ARV for unknown reasons','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Reason not yet known\n didnt pick up ARV for unknown reasons\n \n 2018-08-02 14:34:48 UTC\n \n 2018-08-02 14:56:02 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 213\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n','2018-08-02 20:04:48',4,'2018-08-02 20:26:02',4,0,NULL,NULL,NULL,'a15498e0-c11d-4691-aec6-be8cda80543d'),(214,'Clients not seen for unknown reasons','clients who didnt pick up their ARVs for unknown reasons','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients not seen for unknown reasons\n clients who didnt pick up their ARVs for unknown reasons\n \n 2018-08-02 15:04:22 UTC\n \n 2019-01-23 13:55:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 214\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-08-02 17:04:22',4,'2019-01-23 15:55:44',4,0,NULL,NULL,NULL,'e30a1ade-3819-40c5-b6f6-bc031d22e3ce'),(216,'PIR_NO_PICKUP_TEST Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR_NO_PICKUP_TEST Data Set\n \n 2018-08-02 15:17:09 UTC\n \n 2018-08-02 15:20:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 216\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n \n \n LostAdultF\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n','2018-08-02 20:47:09',4,'2018-08-02 20:50:06',4,0,NULL,NULL,NULL,'16735ee0-0160-43f8-8eb4-beee79866db9'),(217,'Clients who picked up their ARVs','Number of persons who picked up their ARV regimens on time','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients who picked up their ARVs\n Number of persons who picked up their ARV regimens on time\n \n 2018-08-03 07:01:40 UTC\n \n 2019-02-03 11:21:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 217\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-08-03 07:01:40',4,'2019-02-03 11:21:37',4,0,NULL,NULL,NULL,'6fa66b18-d626-4ffa-bc4d-99aacb661f68'),(219,'TEst Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n TEst Data Set\n \n 2018-08-03 07:05:32 UTC\n \n 2018-08-03 07:06:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 219\n \n \n \n ddfgh\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n gthhgh\n \n \n \n \n \n \n \n \n \n','2018-08-03 12:35:32',4,'2018-08-03 12:36:53',4,0,NULL,NULL,NULL,'9c60044d-a35f-45fb-81d7-2ec6fff3c769'),(220,'PIR07_Clients_who_did_not_pick_up_ARV','Persons who did not pick up their ARV regimens for different reasons, lost,died,unknown reason and those who stopped ART','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR07_Clients_who_did_not_pick_up_ARV\n Persons who did not pick up their ARV regimens for different reasons, lost,died,unknown reason and those who stopped ART\n \n 2018-08-03 07:10:51 UTC\n \n 2018-08-03 10:43:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 220\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2018-08-03 12:40:51',4,'2018-08-03 16:13:16',4,0,NULL,NULL,NULL,'a4d5077a-b21c-473b-9636-8dc0237a9bb7'),(221,'Clients_who_did Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients_who_did Data Set\n \n 2018-08-03 07:10:52 UTC\n \n 2019-02-03 10:45:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 221\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n \n \n DiedAdultF\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n DiedAdultM\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Adults\n \n \n \n \n \n DiedChild\n \n \n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n LostAdultF\n \n \n \n \n \n \n \n \n \n LostAdultM\n \n \n \n \n \n \n LostChild\n \n \n \n \n \n \n StoppedAdF\n \n \n \n \n \n \n \n \n \n StoppedAdM\n \n \n \n \n \n \n StoppedChi\n \n \n \n \n \n \n UnknownADF\n \n \n \n \n \n \n \n \n \n UnknownADM\n \n \n \n \n \n \n UnknownChi\n \n \n \n \n \n \n','2018-08-03 07:10:52',4,'2019-02-03 10:45:21',4,0,NULL,NULL,NULL,'41f52fdf-9b2f-4f40-9420-19f8470f76fa'),(222,'Stopped ART','Clients who did not pick up ARVs because they stopped ART','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Stopped ART\n Clients who did not pick up ARVs because they stopped ART\n \n 2018-08-03 08:50:56 UTC\n \n 2022-04-28 08:56:27 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 222\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-08-03 08:50:56',4,'2022-04-28 08:56:27',4,0,NULL,NULL,NULL,'7303b17a-e4ab-4b5e-b3ce-7880cf36bade'),(223,'On_time_pick_up','Number of persons who picked up their ARV regimens on time','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n On_time_pick_up\n Number of persons who picked up their ARV regimens on time\n \n 2018-08-03 09:11:49 UTC\n \n 2018-08-03 09:11:50 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 223\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2018-08-03 14:41:49',4,'2018-08-03 14:41:50',4,0,NULL,NULL,NULL,'fcb6a10d-d364-4aa3-a8fc-f4fbb961cbe4'),(224,'On_time_pick_up Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n On_time_pick_up Data Set\n \n 2018-08-03 09:11:50 UTC\n \n 2018-08-03 09:12:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 224\n \n \n \n TimePickUp\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n','2018-08-03 14:41:50',4,'2018-08-03 14:42:57',4,0,NULL,NULL,NULL,'75ff5ab7-0178-40ad-9960-d641a8895a7c'),(225,'NutritionalSupp1','Number of clients who received nutritional supplements RUFT- Plumpy nut','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n NutritionalSupp1\n Number of clients who received nutritional supplements RUFT- Plumpy nut\n \n 2018-08-03 09:21:57 UTC\n \n 2018-08-03 09:23:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 225\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n','2018-08-03 14:51:57',4,'2018-08-03 14:53:18',4,0,NULL,NULL,NULL,'e871b95a-9ea4-4dfe-8b2a-dd2c569bc2f7'),(226,'NutritionalSupp2','No of clients who received nutritional supplement F100','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n NutritionalSupp2\n No of clients who received nutritional supplement F100\n \n 2018-08-03 09:24:35 UTC\n \n 2018-08-03 09:25:39 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 226\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n','2018-08-03 14:54:35',4,'2018-08-03 14:55:39',4,0,NULL,NULL,NULL,'c63d9c45-d226-4110-8f54-e8a50ddcec95'),(227,'NutriotionalSupp3','NO of clients who received nutritional supplement F75','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n NutriotionalSupp3\n NO of clients who received nutritional supplement F75\n \n 2018-08-03 09:26:57 UTC\n \n 2018-08-03 09:27:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 227\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n','2018-08-03 14:56:57',4,'2018-08-03 14:57:56',4,0,NULL,NULL,NULL,'0a8b4609-1638-40a5-9b34-03a8de87a6a6'),(228,'NutritionalSupp4','No of clients who received nutritional supplement Other1','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n NutritionalSupp4\n No of clients who received nutritional supplement Other1\n \n 2018-08-03 09:29:48 UTC\n \n 2018-08-03 09:32:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 228\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n','2018-08-03 14:59:48',4,'2018-08-03 15:02:07',4,0,NULL,NULL,NULL,'83de7902-07a8-4ad8-a28d-efda8a8c302b'),(229,'Clients who received Cotrimox','Clients who received Cotrimox','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients who received Cotrimox\n Clients who received Cotrimox\n \n 2018-08-03 09:34:41 UTC\n \n 2019-02-03 11:53:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 229\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-08-03 09:34:41',4,'2019-02-03 11:53:59',4,0,NULL,NULL,NULL,'fe5bdf32-e7d2-4239-943e-38eb65e4b4ac'),(230,'Newly Enrolled in HIV care Started IPT','Newly Enrolled in HIV/ care Started IPT','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Newly Enrolled in HIV care Started IPT\n Newly Enrolled in HIV/ care Started IPT\n \n 2018-08-03 09:36:54 UTC\n \n 2019-02-03 20:20:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 230\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-08-03 09:36:54',4,'2019-02-03 20:20:25',4,0,NULL,NULL,NULL,'0dfe1170-9501-446f-8c7d-515881db67e4'),(231,'newly started on ART and IPT','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n newly started on ART and IPT\n \n \n 2018-08-03 10:23:17 UTC\n \n 2019-02-03 20:21:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 231\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-08-03 10:23:17',4,'2019-02-03 20:21:44',4,0,NULL,NULL,NULL,'b0be49b4-1ac5-4165-a934-05823c8faa5e'),(233,'PIR08: Nutritional_Supplement Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR08: Nutritional_Supplement Data Set\n \n 2018-08-03 10:45:54 UTC\n \n 2018-08-06 07:13:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 233\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n \n \n Nutri2AduF\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n Nutri2AduM\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Adults\n \n \n \n \n \n Nutri2ChiF\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n Nutri2ChiM\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n Nutri3AduF\n \n \n \n \n \n \n \n \n \n Nutri3AduM\n \n \n \n \n \n \n Nutri3ChiF\n \n \n \n \n \n \n Nutri3ChiM\n \n \n \n \n \n \n Nutri4AduF\n \n \n \n \n \n \n \n \n \n Nutri4AduM\n \n \n \n \n \n \n Nutri4ChiF\n \n \n \n \n \n \n Nutri4ChiM\n \n \n \n \n \n \n NutriAduF\n \n \n \n \n \n \n \n \n \n NutriAduM\n \n \n \n \n \n \n NutriChiF\n \n \n \n \n \n \n NutriChiM\n \n \n \n \n \n \n','2018-08-03 16:15:54',4,'2018-08-06 12:43:45',4,0,NULL,NULL,NULL,'6293f829-6d59-4aff-a121-5af73e522c28'),(235,'PIR10: Cotrimox Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR10: Cotrimox Data Set\n \n 2018-08-06 07:44:19 UTC\n \n 2019-03-11 17:35:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 235\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age_DATE\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n \n \n Cotr6to14F\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 06yrs-14yrs\n \n \n \n \n \n Cotr6to14M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 06yrs-14yrs\n \n \n \n \n \n Cotri5mtsF\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n <6Months\n \n \n \n \n \n Cotri5mtsM\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n <6Months\n \n \n \n \n \n Cotri6to5F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age_DATE\n 06Mnths-5yrs\n \n \n \n \n \n Cotri6to5M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age_DATE\n 06Mnths-5yrs\n \n \n \n \n \n CotriAduF\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n CotriAduM\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Adults\n \n \n \n \n \n','2018-08-06 07:44:19',4,'2019-03-11 17:35:13',4,0,NULL,NULL,NULL,'ce6e1b61-d77d-430c-85ea-5f2c8499cb69'),(237,'Month_to_month_age_cohort','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.AgeCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Month_to_month_age_cohort\n \n \n 2018-08-06 09:02:48 UTC\n \n 2018-08-06 09:15:44 UTC\n \n \n minAge\n \n java.lang.Integer\n true\n \n \n maxAge\n \n java.lang.Integer\n true\n \n \n 237\n MONTHS\n MONTHS\n false\n','2018-08-06 14:32:48',4,'2018-08-06 14:45:44',4,0,NULL,NULL,NULL,'b0fc9529-1c40-4ad0-b458-ef1d530c11ec'),(238,'Month_to_year_age_cohort','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.AgeCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Month_to_year_age_cohort\n \n \n 2018-08-06 09:05:50 UTC\n \n 2018-08-06 09:19:22 UTC\n \n \n minAge\n \n java.lang.Integer\n true\n \n \n maxAge\n \n java.lang.Integer\n true\n \n \n 238\n MONTHS\n YEARS\n false\n','2018-08-06 14:35:50',4,'2018-08-06 14:49:22',4,0,NULL,NULL,NULL,'88e4af2a-3f98-405c-b041-af814a86668c'),(240,'Isoniazid Preventive Therapy Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Isoniazid Preventive Therapy Data Set\n \n 2018-08-06 10:08:29 UTC\n \n 2019-03-11 17:42:02 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 240\n \n \n DM_Age_DATE\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n \n \n IPTart0to4\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Age_DATE\n 0Mnths-4yrs\n \n \n \n \n \n IPTart15\n \n \n \n \n DM_Age_DATE\n 15+yrs\n \n \n \n \n \n IPTat5to14\n \n \n \n \n DM_Age_DATE\n 05yrsto14yrs\n \n \n \n \n \n IPTpr5to14\n \n \n \n \n \n \n \n \n \n IPTpre0to4\n \n \n \n \n \n \n IPTpre15\n \n \n \n \n \n \n','2018-08-06 10:08:29',4,'2019-03-11 17:42:02',4,0,NULL,NULL,NULL,'f3cc2da8-ca50-481d-9010-d0614a43606e'),(242,'Change_in_CD4_Count Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Change_in_CD4_Count Data Set\n \n 2018-10-16 12:45:37 UTC\n \n 2019-02-05 09:54:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 242\n \n \n \n Dead12mts\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n Dead6mts\n \n \n \n \n \n \n \n \n \n TransOut12\n \n \n \n \n \n \n \n \n \n TransOut6m\n \n \n \n \n \n \n \n \n \n alt1st12m\n \n \n \n \n \n \n \n \n \n alt1st6m\n \n \n \n \n \n \n \n \n \n basecd412m\n \n \n \n \n \n \n \n \n \n basecd46m\n \n \n \n \n \n \n \n \n \n follow12mt\n \n \n \n \n \n \n \n \n \n follow6mt\n \n \n \n \n \n \n \n \n \n lost12mts\n \n \n \n \n \n \n \n \n \n lost6mts\n \n \n \n \n \n \n \n \n \n origin12mn\n \n \n \n \n \n \n \n \n \n origin6mnt\n \n \n \n \n \n \n \n \n \n stil1st12m\n \n \n \n \n \n \n \n \n \n stil1st6m\n \n \n \n \n \n \n \n \n \n stopped12m\n \n \n \n \n \n \n \n \n \n stopped6mt\n \n \n \n \n \n \n \n \n \n swich2nd12\n \n \n \n \n \n \n \n \n \n switch2nd6\n \n \n \n \n \n \n \n \n \n transIn12m\n \n \n \n \n \n \n \n \n \n transIn6mn\n \n \n \n \n \n \n \n \n \n viral12mts\n \n \n \n \n \n \n \n \n \n viral6mts\n \n \n \n \n \n \n \n \n \n','2018-10-16 14:45:37',4,'2019-02-05 11:54:13',4,0,NULL,NULL,NULL,'e396adf4-cca6-4add-9638-46750e10468b'),(243,'Number of persons in original cohort 6 mnths','Number of persons in original cohort 6 mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Number of persons in original cohort 6 mnths\n Number of persons in original cohort 6 mnths\n \n 2018-10-16 12:54:53 UTC\n \n 2018-10-16 13:15:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 243\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n','2018-10-16 14:54:53',4,'2018-10-16 15:15:13',4,0,NULL,NULL,NULL,'9bfc4aae-1960-41e9-b763-c6ed0af8416e'),(244,'Number of persons in original cohort 12 mnths','Number of persons in original cohort 12 mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Number of persons in original cohort 12 mnths\n Number of persons in original cohort 12 mnths\n \n 2018-10-16 12:57:51 UTC\n \n 2018-10-16 13:12:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 244\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n','2018-10-16 14:57:51',4,'2018-10-16 15:12:54',4,0,NULL,NULL,NULL,'4db88cd3-7834-419e-9078-cf8c676c317e'),(245,'Persons transfer in 6 months','number of persons transfer in 6 months','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Persons transfer in 6 months\n number of persons transfer in 6 months\n \n 2018-10-16 13:04:30 UTC\n \n 2018-10-16 13:06:52 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 245\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-10-16 15:04:30',4,'2018-10-16 15:06:52',4,0,NULL,NULL,NULL,'087ec921-1bc9-4801-8a08-b42c30c0e182'),(246,'Persons transfer in 12 months','Number of persons transferred in 12 months','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Persons transfer in 12 months\n Number of persons transferred in 12 months\n \n 2018-10-16 13:08:13 UTC\n \n 2018-10-16 13:09:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 246\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-10-16 15:08:13',4,'2018-10-16 15:09:51',4,0,NULL,NULL,NULL,'4a013856-0a85-49fb-8b38-b56ad12f91e8'),(247,'Persons transfer out 6 months','number of persons transferred out 6 months','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Persons transfer out 6 months\n number of persons transferred out 6 months\n \n 2018-10-16 13:27:14 UTC\n \n 2018-10-16 13:34:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 247\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand o.concept_id = 2398 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH))\n','2018-10-16 15:27:14',4,'2018-10-16 15:34:20',4,0,NULL,NULL,NULL,'a5e955fe-3d68-426e-be12-bfdd8ae80f0e'),(248,'Persons transfer out 12 months','Number of persons transferred out 12 months','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Persons transfer out 12 months\n Number of persons transferred out 12 months\n \n 2018-10-16 13:36:21 UTC\n \n 2018-10-16 13:37:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 248\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand o.concept_id = 2398 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH))\n','2018-10-16 15:36:21',4,'2018-10-16 15:37:17',4,0,NULL,NULL,NULL,'d1cb0ee5-2dba-4ee8-8661-fdf9e2b67d47'),(249,'Persons transfer out 12 months','number of persons transferred out 12 months','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Persons transfer out 12 months\n number of persons transferred out 12 months\n \n 2018-10-16 14:15:41 UTC\n \n 2018-10-16 14:17:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 249\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-10-16 16:15:41',4,'2018-10-16 16:17:54',4,0,NULL,NULL,NULL,'0695ac41-71c8-44b9-bba7-18b6601a2eb3'),(250,'Persons transfer out 6 months','number f persons transferred out 6 months','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Persons transfer out 6 months\n number f persons transferred out 6 months\n \n 2018-10-16 14:19:33 UTC\n \n 2018-10-16 14:27:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 250\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-10-16 16:19:33',4,'2018-10-16 16:27:52',4,0,NULL,NULL,NULL,'ffbeae3c-4bc4-4321-a654-14378436f973'),(251,'Number with follow up CD4 6mnths','Number with follow up CD4 subset of net cohort 6mnths','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Number with follow up CD4 6mnths\n Number with follow up CD4 subset of net cohort 6mnths\n \n 2018-10-17 06:57:53 UTC\n \n 2018-10-18 14:41:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 251\n select distinct person_id \nfrom obs o \nwhere person_id in \n (select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n and person_id not in \n \n ( select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n and location_id =:location \n and o.concept_id = 2256 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n \n;\n','2018-10-17 08:57:53',4,'2018-10-18 16:41:53',4,0,NULL,NULL,NULL,'efc3aa8f-0827-4d20-b258-6f8e819e3068'),(252,' New discordant couples who started ART',' New discordant couples who started ART','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n New discordant couples who started ART\n New discordant couples who started ART\n \n 2018-10-17 16:17:34 UTC\n \n 2019-01-31 17:58:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 252\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2018-10-17 16:17:34',4,'2019-01-31 17:58:53',4,0,NULL,NULL,NULL,'830d6157-f04e-4f1e-bfa8-39f471518945'),(253,'Discordant couple','HIV+ person in discordant couple','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.NumericObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Discordant couple\n HIV+ person in discordant couple\n \n 2018-10-17 19:30:31 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n','2018-10-17 21:30:31',4,NULL,NULL,0,NULL,NULL,NULL,'85395524-996e-48a4-b8ec-148549099e39'),(254,'Number with follow up CD4 12mnths','Number with follow up CD4 12mnths','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Number with follow up CD4 12mnths\n Number with follow up CD4 12mnths\n \n 2018-10-18 13:53:50 UTC\n \n 2018-10-18 14:41:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 254\n select distinct person_id \nfrom obs o \nwhere person_id in \n (select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \n and person_id not in \n \n ( select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \n and location_id =:location \n and o.concept_id = 2256 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n \n;\n','2018-10-18 15:53:50',4,'2018-10-18 16:41:08',4,0,NULL,NULL,NULL,'cbb4ec5e-947f-4c02-a46d-1d4d9cc1f28a'),(255,'Patients with follow up viral load 6 months','Patients with follow up viral load','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Patients with follow up viral load 6 months\n Patients with follow up viral load\n \n 2018-10-18 13:58:41 UTC\n \n 2018-10-18 14:10:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 255\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand location_id =:location \nand o.concept_id = 4186 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-18 15:58:41',4,'2018-10-18 16:10:22',4,0,NULL,NULL,NULL,'a886ed5e-0e11-4590-9dd0-456e26e6669f'),(256,'Patients with follow up viral load 12 months','Patients with follow up viral load','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Patients with follow up viral load 12 months\n Patients with follow up viral load\n \n 2018-10-18 14:42:51 UTC\n \n 2019-02-05 09:24:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 256\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand location_id =:location \nand o.concept_id = 4186 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-18 16:42:51',4,'2019-02-05 11:24:45',4,0,NULL,NULL,NULL,'77652a52-5c8c-46de-bf39-36b34fb3f0a7'),(257,'Clients lost to follow up 6months','Clients lost to follow up','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients lost to follow up 6months\n Clients lost to follow up\n \n 2018-10-18 14:45:16 UTC\n \n 2018-10-18 14:45:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 257\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand location_id =:location \nand o.concept_id = 2302 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-18 16:45:16',4,'2018-10-18 16:45:57',4,0,NULL,NULL,NULL,'cc22e6d5-7614-4234-9241-861eac14b7e5'),(258,'Clients Dead 6 months','Clients Dead','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients Dead 6 months\n Clients Dead\n \n 2018-10-18 14:47:21 UTC\n \n 2018-10-18 14:49:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 258\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand location_id =:location \nand o.concept_id = 3164 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-18 16:47:21',4,'2018-10-18 16:49:03',4,0,NULL,NULL,NULL,'3b2f4c98-1621-4a1b-b352-95367ce251ca'),(259,'Clients Stopped 6 months','Clients Stopped ','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients Stopped 6 months\n Clients Stopped \n \n 2018-10-18 14:50:25 UTC\n \n 2018-10-18 14:51:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 259\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand location_id =:location \nand o.concept_id = 2300 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-18 16:50:25',4,'2018-10-18 16:51:22',4,0,NULL,NULL,NULL,'5791856e-2f04-4eeb-980b-b151a820da7b'),(260,'Clients lost to follow up 12 months','Clients lost to follow up','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients lost to follow up 12 months\n Clients lost to follow up\n \n 2018-10-18 14:52:40 UTC\n \n 2018-10-18 14:54:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 260\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand location_id =:location \nand o.concept_id = 2302 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-18 16:52:40',4,'2018-10-18 16:54:05',4,0,NULL,NULL,NULL,'6cd2d49e-36d2-40ed-857e-5b2e65e1fc16'),(261,'Clients Dead 12 months','Clients Dead','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients Dead 12 months\n Clients Dead\n \n 2018-10-18 14:55:18 UTC\n \n 2018-10-18 14:57:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 261\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand location_id =:location \nand o.concept_id = 3164 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-18 16:55:18',4,'2018-10-18 16:57:01',4,0,NULL,NULL,NULL,'ff4f67ac-f450-4d32-b964-d2a978bd9249'),(262,'Clients Stopped 12 months','Clients Stopped','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients Stopped 12 months\n Clients Stopped\n \n 2018-10-18 14:57:50 UTC\n \n 2018-10-18 14:59:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 262\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand location_id =:location \nand o.concept_id = 2300 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-18 16:57:50',4,'2018-10-18 16:59:34',4,0,NULL,NULL,NULL,'f24fd74d-6a99-4a66-81d7-c29f7bce2392'),(263,'Number still on original first line 6months','Number still on original first line','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Number still on original first line 6months\n Number still on original first line\n \n 2018-10-19 07:48:00 UTC\n \n 2018-10-19 07:56:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 263\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand location_id =:location \nand o.concept_id in (3689,3691) \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-19 09:48:00',4,'2018-10-19 09:56:34',4,0,NULL,NULL,NULL,'de663b24-02ce-4d61-b039-dc505ede607d'),(264,'Clients still on original first line 12 months','clients of original 1st line regimen','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients still on original first line 12 months\n clients of original 1st line regimen\n \n 2018-10-19 08:09:03 UTC\n \n 2018-10-19 08:12:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 264\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand location_id =:location \nand o.concept_id in (3689,3691) \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-19 10:09:03',4,'2018-10-19 10:12:11',4,0,NULL,NULL,NULL,'490b6050-d002-47db-8214-0e48246f925d'),(265,'Clients on alternative 1st line ART 6months','Clients on alternative 1st line ART (switched)','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients on alternative 1st line ART 6months\n Clients on alternative 1st line ART (switched)\n \n 2018-10-19 08:14:11 UTC\n \n 2018-10-19 08:16:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 265\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand location_id =:location \nand o.concept_id in (3689,3691) AND o.concept_id = 2399 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-19 10:14:11',4,'2018-10-19 10:16:57',4,0,NULL,NULL,NULL,'2e3d9aae-ab50-47e2-9c28-92726668cc78'),(266,'Clients on alternative 1st line ART 12 months','clients on alternative 1st line switched','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients on alternative 1st line ART 12 months\n clients on alternative 1st line switched\n \n 2018-10-19 08:21:27 UTC\n \n 2018-10-19 08:29:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 266\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand location_id =:location \nand o.concept_id in (3689,3691) AND o.concept_id = 2399 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-19 10:21:27',4,'2018-10-19 10:29:03',4,0,NULL,NULL,NULL,'dfb1ed02-163a-4814-b5d0-0c630fc969a5'),(267,'Clients switched to 2nd line 6months','swicthed second line','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients switched to 2nd line 6months\n swicthed second line\n \n 2018-10-19 08:34:22 UTC\n \n 2018-10-19 08:36:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 267\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \nand location_id =:location \nand o.concept_id in (3692,3690) AND o.concept_id = 2399 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-19 10:34:22',4,'2018-10-19 10:36:21',4,0,NULL,NULL,NULL,'a3ccbabd-a7c3-4bf6-af4a-a25ad0d0b8ec'),(268,'Clients switched to 2nd line 12 months','switched 2nd line','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients switched to 2nd line 12 months\n switched 2nd line\n \n 2018-10-19 08:37:24 UTC\n \n 2018-10-19 08:38:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 268\n select distinct person_id \nfrom obs o \nwhere person_id in \n ( \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 2249 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n union \n select person_id \n from obs o \n where location_id =:location \n and o.concept_id = 4168 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand person_id not in \n ( \n select person_id \n from obs o \n where o.concept_id = 2398 \n and MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -12 MONTH)) \n ) \nand location_id =:location \nand o.concept_id in (3692,3690) AND o.concept_id = 2399 \nand MONTH(o.value_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n;\n','2018-10-19 10:37:24',4,'2018-10-19 10:38:19',4,0,NULL,NULL,NULL,'800b7890-ee58-47d4-9133-66bffe5400ba'),(269,'SQL ARV Regimen 2 or 3 months drug prescription in prev. 1 month','ARV Regimen 2 or 3 months drug prescription in previous 1 month SQL Cohort Query Version','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n SQL ARV Regimen 2 or 3 months drug prescription in prev. 1 month\n ARV Regimen 2 or 3 months drug prescription in previous 1 month SQL Cohort Query Version\n \n 2018-10-29 14:12:49 UTC\n \n 2018-10-30 10:06:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 269\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand (o.concept_id = 4174 and (o.value_coded = 4176 or o.value_coded = 4177)) \nand MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) and YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \nand o.voided = 0 \n \nand \n \nperson_id not in ( \nselect distinct person_id \nfrom obs os \nwhere os.location_id =:location \nand (os.concept_id = 3843 and os.value_coded = 3842) \nand MONTH(os.obs_datetime) = MONTH(DATE(:endDate)) and YEAR(os.obs_datetime) = YEAR(DATE(:endDate)) \n)\n','2018-10-29 16:12:49',4,'2018-10-30 12:06:37',4,0,NULL,NULL,NULL,'d987055f-14bb-4a9e-be79-050bba503637'),(270,'SQL ARV Regimen 3 months drug prescription in prev. 2 months','ARV Regimen 3 months drug prescription in previous 2 months SQL Cohort Query version','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n SQL ARV Regimen 3 months drug prescription in prev. 2 months\n ARV Regimen 3 months drug prescription in previous 2 months SQL Cohort Query version\n \n 2018-10-29 14:17:36 UTC\n \n 2018-10-30 10:07:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 270\n select distinct person_id \nfrom obs o \nwhere location_id =:location \nand o.concept_id = 4174 and o.value_coded = 4177 \nand MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) and YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \nand o.voided = 0 \n \nand \n \nperson_id not in ( \nselect distinct person_id \nfrom obs os \nwhere os.location_id =:location \nand (os.concept_id = 3843 and os.value_coded = 3842) \nand MONTH(os.obs_datetime) = MONTH(DATE(:endDate)) and YEAR(os.obs_datetime) = YEAR(DATE(:endDate)) \n)\n','2018-10-29 16:17:36',4,'2018-10-30 12:07:31',4,0,NULL,NULL,NULL,'98a1122a-d39d-4a67-bed0-7489dd29608d'),(271,'Tx. Curr. SQL Version with visits in previous 1 or 2 months and were given 2 or 3 months drug prescription','Tx. Curr. SQL Version with visits in previous 1 or 2 months and were given 2 or 3 months drug prescription','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Tx. Curr. SQL Version with visits in previous 1 or 2 months and were given 2 or 3 months drug prescription\n Tx. Curr. SQL Version with visits in previous 1 or 2 months and were given 2 or 3 months drug prescription\n \n 2018-10-29 14:18:41 UTC\n \n 2018-10-29 14:22:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 271\n SQL-ARV-Regimen-2-or-3-months-drug-prescription-in-prev.-1-month OR SQL-ARV-Regimen-3-months-drug-prescription-in-prev.-2-months\n \n \n SQL-ARV-Regimen-2-or-3-months-drug-prescription-in-prev.-1-month\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n SQL-ARV-Regimen-3-months-drug-prescription-in-prev.-2-months\n \n \n \n \n \n \n','2018-10-29 16:18:41',4,'2018-10-29 16:22:28',4,0,NULL,NULL,NULL,'f2af4f7d-643e-4ee6-93eb-74488cf98704'),(272,'Clients seen 1f','1f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 1f\n 1f\n \n 2018-10-30 08:31:02 UTC\n \n 2020-07-19 02:41:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 272\n select distinct o.person_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n and o.concept_id = 3843 and o.value_coded in (3841, 3842) \n and month(obs_datetime) = month(cast(:endDate as date)) \n and year(obs_datetime) = year(cast(:endDate as date)) \n inner join person on person.person_id = o.person_id and person.voided = 0 and o.voided = 0 \n \nwhere (o.location_id = :location or parent_location = :location) \n and o.person_id in ( \n-- CLIENTS GIVEN 1F \n select distinct os.person_id \n from obs os \n where os.obs_datetime BETWEEN :startDate AND :endDate \n and os.concept_id = 2250 and os.value_coded = 2207 \n ) \n and o.person_id not in ( \n select distinct os.person_id AS Id \n from obs os \n where os.concept_id = 2249 \n and os.value_datetime between :startDate and :endDate \n and os.voided = 0 \n ) \n and o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n and date(os.obs_datetime) between :startDate and :endDate) \n and o.person_id not in \n -- EXCLUDE DECEASED \n (select distinct person_id \n from person \n where death_date < cast(:endDate as date) \n and dead = 1)\n','2018-10-30 08:31:02',4,'2020-07-19 02:41:07',4,0,NULL,NULL,NULL,'55df743e-4818-40e3-9df4-f76db645b660'),(273,'Clients multi month 1f','1f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 1f\n 1f\n \n 2018-10-30 08:55:29 UTC\n \n 2019-05-09 09:02:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 273\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2207 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2207 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2207 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2207 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2207 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2207 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2207 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2207 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2207 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2207 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2207 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2018-10-30 08:55:29',4,'2019-05-09 09:02:12',4,0,NULL,NULL,NULL,'a018ec2e-bf15-49cb-96e2-cbfe9201211e'),(274,'CMP_ART Regimen 1month supply 6e','6e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 6e\n 6e\n \n 2018-10-30 09:01:24 UTC\n \n 2021-01-28 01:43:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 274\n Clients-seen-given-1-month-supply-6e OR Clients-newly-initiated-6e\n \n \n Clients-seen-given-1-month-supply-6e\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-6e\n \n \n \n \n \n \n','2018-10-30 09:01:24',4,'2021-01-28 01:43:24',4,0,NULL,NULL,NULL,'af784bca-5138-4cb1-9f88-83a571d00101'),(275,'Clients seen 1c ','1c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 1c \n 1c\n \n 2019-01-09 23:00:14 UTC\n \n 2019-05-08 07:50:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 275\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date < :endDate \n and dead = 1 \n ) \n \n \n','2019-01-09 23:00:14',4,'2019-05-08 07:50:10',4,0,NULL,NULL,NULL,'cc807875-4872-45bc-9b92-f1d98ed9c1c9'),(276,'Clients seen 1d','1d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 1d\n 1d\n \n 2019-01-09 23:06:41 UTC\n \n 2019-05-08 08:07:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 276\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-09 23:06:41',4,'2019-05-08 08:07:00',4,0,NULL,NULL,NULL,'9d433224-b4de-4540-b350-c3ef93507f1e'),(277,'Clients seen 1e','1e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 1e\n 1e\n \n 2019-01-09 23:10:05 UTC\n \n 2019-05-08 08:08:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 277\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-09 23:10:05',4,'2019-05-08 08:08:46',4,0,NULL,NULL,NULL,'c08132fe-9f08-4c82-a42c-3228fa855d5c'),(278,'Clients seen 1g','1g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 1g\n 1g\n \n 2019-01-09 23:11:31 UTC\n \n 2019-05-08 08:12:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 278\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-09 23:11:31',4,'2019-05-08 08:12:38',4,0,NULL,NULL,NULL,'5e7ddc90-35bd-44be-b561-9b0887891e67'),(279,'Clients seen 1h','1h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 1h\n 1h\n \n 2019-01-09 23:12:35 UTC\n \n 2019-05-08 08:13:49 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 279\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-09 23:12:35',4,'2019-05-08 08:13:49',4,0,NULL,NULL,NULL,'3db0f8da-5cfd-460e-a6b3-c0990a276802'),(280,'Clients seen 2c','2c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 2c\n 2c\n \n 2019-01-09 23:17:52 UTC\n \n 2019-05-08 09:58:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 280\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-09 23:17:52',4,'2019-05-08 09:58:10',4,0,NULL,NULL,NULL,'5b37bb40-282b-4d97-9981-a3d8198b8627'),(281,'Clients seen 2d','2d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 2d\n 2d\n \n 2019-01-09 23:18:59 UTC\n \n 2019-05-08 10:03:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 281\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-09 23:18:59',4,'2019-05-08 10:03:25',4,0,NULL,NULL,NULL,'649d5831-2887-4080-bcff-6a71897413a2'),(282,'Clients seen 2e','2e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 2e\n 2e\n \n 2019-01-09 23:20:18 UTC\n \n 2019-05-08 10:04:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 282\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-09 23:20:18',4,'2019-05-08 10:04:34',4,0,NULL,NULL,NULL,'60e76070-aea0-4257-ae5a-a954455d9e99'),(283,'Clients seen 2f','2f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 2f\n 2f\n \n 2019-01-09 23:22:24 UTC\n \n 2019-05-08 10:05:36 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 283\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-09 23:22:24',4,'2019-05-08 10:05:36',4,0,NULL,NULL,NULL,'8c729f10-ec54-45b3-aea2-aeb95a4c3694'),(284,'Clients seen 2g','2g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 2g\n 2g\n \n 2019-01-09 23:30:40 UTC\n \n 2019-05-08 10:10:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 284\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-09 23:30:40',4,'2019-05-08 10:10:12',4,0,NULL,NULL,NULL,'5f942d03-1351-4fc6-8617-f64ab62eba7a'),(285,'Clients seen 2h','2h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 2h\n 2h\n \n 2019-01-09 23:32:06 UTC\n \n 2019-05-08 10:13:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 285\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-09 23:32:06',4,'2019-05-08 10:13:08',4,0,NULL,NULL,NULL,'a7416bdd-ffb1-4658-afb2-1e646a52ebf4'),(286,'Clients multi month 1c','1c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 1c\n 1c\n \n 2019-01-09 23:49:58 UTC\n \n 2019-05-09 09:09:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 286\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2201 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-09 23:49:58',4,'2019-05-09 09:09:54',4,0,NULL,NULL,NULL,'128fe28c-9f9b-494c-a220-314433181501'),(287,'Clients multi month 1d','1d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 1d\n 1d\n \n 2019-01-09 23:54:38 UTC\n \n 2019-05-09 09:11:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 287\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2203 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-09 23:54:38',4,'2019-05-09 09:11:37',4,0,NULL,NULL,NULL,'6591b115-2cd0-42ef-ab14-d4c229ed05e8'),(288,'Clients multi month 1e','1e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 1e\n 1e\n \n 2019-01-09 23:56:11 UTC\n \n 2019-05-09 09:12:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 288\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2205 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-09 23:56:11',4,'2019-05-09 09:12:55',4,0,NULL,NULL,NULL,'2bee1266-3b05-4cd1-9eaa-3a9dce01ed06'),(289,'Clients multi month 1g','1g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 1g\n 1g\n \n 2019-01-09 23:57:13 UTC\n \n 2019-05-09 09:17:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 289\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3672 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-09 23:57:13',4,'2019-05-09 09:17:19',4,0,NULL,NULL,NULL,'894b729d-bded-4fa0-b54e-30a379dc4927'),(290,'Clients multi month 1h','1h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 1h\n 1h\n \n 2019-01-09 23:58:17 UTC\n \n 2019-05-09 09:43:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 290\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3673 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-09 23:58:17',4,'2019-05-09 09:43:44',4,0,NULL,NULL,NULL,'2e5a0852-2047-4c6e-be30-d19665f1f838'),(291,'Clients multi month 2c','2c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 2c\n 2c\n \n 2019-01-10 00:00:16 UTC\n \n 2019-05-09 09:27:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 291\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2210 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-10 00:00:16',4,'2019-05-09 09:27:52',4,0,NULL,NULL,NULL,'dc0406d3-2c3c-4157-ae83-537ae4e65e59'); INSERT INTO `serialized_object` VALUES (292,'Clients multi month 2d','2d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 2d\n 2d\n \n 2019-01-10 00:01:21 UTC\n \n 2019-05-09 09:29:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 292\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2209 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-10 00:01:21',4,'2019-05-09 09:29:04',4,0,NULL,NULL,NULL,'4452e974-8c6e-442e-bb45-d6e09d26765a'),(293,'Clients multi month 2e','2e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 2e\n 2e\n \n 2019-01-10 00:02:30 UTC\n \n 2019-05-09 09:30:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 293\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3674 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-10 00:02:30',4,'2019-05-09 09:30:24',4,0,NULL,NULL,NULL,'b70551ca-7dda-4d71-be21-852530c01b27'),(294,'Clients multi month 2f','2f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 2f\n 2f\n \n 2019-01-10 00:04:54 UTC\n \n 2019-05-09 09:31:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 294\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3675 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-10 00:04:54',4,'2019-05-09 09:31:55',4,0,NULL,NULL,NULL,'7b572190-3a8e-41fd-9f13-b857c5a2d5a6'),(295,'Clients multi month 2g','2g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 2g\n 2g\n \n 2019-01-10 00:05:54 UTC\n \n 2019-05-09 09:32:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 295\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3676 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-10 00:05:54',4,'2019-05-09 09:32:54',4,0,NULL,NULL,NULL,'5aa75e1d-5ae4-47d7-9b0b-e099ecdfbde9'),(296,'Clients multi month 2h','2h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 2h\n 2h\n \n 2019-01-10 00:06:48 UTC\n \n 2019-05-09 09:34:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 296\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3677 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-10 00:06:48',4,'2019-05-09 09:34:00',4,0,NULL,NULL,NULL,'e008404a-b1f1-442a-b667-5590a15ed2e9'),(297,'Clients multi month 3a','3a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 3a\n 3a\n \n 2019-01-10 00:08:01 UTC\n \n 2019-05-09 09:38:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 297\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-10 00:08:01',4,'2019-05-09 09:38:07',4,0,NULL,NULL,NULL,'88b2c868-7a1f-49e1-9277-e8dc122cafdd'),(298,'Clients multi month 3b','3b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 3b\n 3b\n \n 2019-01-10 00:09:34 UTC\n \n 2019-05-09 09:39:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 298\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-01-10 00:09:34',4,'2019-05-09 09:39:22',4,0,NULL,NULL,NULL,'c3243091-3cc9-4c2d-94d8-0b3c1b7c226a'),(299,'Clients seen 3a','3a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 3a\n 3a\n \n 2019-01-10 00:11:14 UTC\n \n 2019-05-08 10:25:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 299\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3683 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-10 00:11:14',4,'2019-05-08 10:25:34',4,0,NULL,NULL,NULL,'f635e506-399a-49f2-8016-c9b3410fb65d'),(300,'Clients seen 3b','3b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 3b\n 3b\n \n 2019-01-10 00:12:05 UTC\n \n 2019-05-08 10:37:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 300\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3684 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-01-10 00:12:05',4,'2019-05-08 10:37:48',4,0,NULL,NULL,NULL,'56b9db93-8aab-4bb7-9296-06b385249737'),(309,'CMP_ART Regimen 1month supply 6b','6b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 6b\n 6b\n \n 2019-01-10 16:41:42 UTC\n \n 2021-01-28 01:22:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 309\n Clients-seen-given-1-month-supply-6b OR Clients-newly-initiated-6b\n \n \n Clients-seen-given-1-month-supply-6b\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-6b\n \n \n \n \n \n \n','2019-01-10 16:41:42',4,'2021-01-28 01:22:44',4,0,NULL,NULL,NULL,'36e870b9-ea69-42f4-af1c-ab0dc12652d1'),(310,'CMP_ART Regimen 1month supply 6c','6c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 6c\n 6c\n \n 2019-01-10 16:51:23 UTC\n \n 2021-01-28 01:29:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 310\n Clients-seen-given-1-month-supply-6c OR Clients-newly-initiated-6c\n \n \n Clients-seen-given-1-month-supply-6c\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-6c\n \n \n \n \n \n \n','2019-01-10 16:51:23',4,'2021-01-28 01:29:53',4,0,NULL,NULL,NULL,'ab5ee2c6-b62a-4730-ab20-93402f758aba'),(311,'CMP_ART Regimen 1month supply 6d','6d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 6d\n 6d\n \n 2019-01-10 17:18:53 UTC\n \n 2021-01-28 01:36:27 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 311\n Clients-seen-given-1-month-supply-6d OR Clients-newly-initiated-6d\n \n \n Clients-seen-given-1-month-supply-6d\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-6d\n \n \n \n \n \n \n','2019-01-10 17:18:53',4,'2021-01-28 01:36:27',4,0,NULL,NULL,NULL,'6fab4ceb-75e5-4687-ab3d-96d87493c83c'),(312,'CMP_ART Regimen 1month supply 6f','6f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 6f\n 6f\n \n 2019-01-10 17:30:56 UTC\n \n 2021-01-28 01:47:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 312\n Clients-newly-initiated-6f OR Clients-seen-given-1-month-supply-6f\n \n \n Clients-newly-initiated-6f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-6f\n \n \n \n \n \n \n','2019-01-10 17:30:56',4,'2021-01-28 01:47:31',4,0,NULL,NULL,NULL,'5b53d187-636a-4b70-9d6a-56be8a998fe5'),(313,'CMP_ART Regimen 1month supply 5h','5h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 5h\n 5h\n \n 2019-01-10 17:40:48 UTC\n \n 2021-01-28 01:08:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 313\n Clients-newly-initiated-5h OR Clients-seen-given-1-month-supply-5h\n \n \n Clients-newly-initiated-5h\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-5h\n \n \n \n \n \n \n','2019-01-10 17:40:48',4,'2021-01-28 01:08:05',4,0,NULL,NULL,NULL,'817075e8-f801-429c-8ffa-b5b9ce9967ff'),(314,'CMP_ART Regimen 1month supply 4g','4g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 4g\n 4g\n \n 2019-01-10 17:54:49 UTC\n \n 2021-01-27 23:58:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 314\n Clients-newly-initiated-4g OR Clients-seen-given-1-month-supply-4g\n \n \n Clients-newly-initiated-4g\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-4g\n \n \n \n \n \n \n','2019-01-10 17:54:49',4,'2021-01-27 23:58:55',4,0,NULL,NULL,NULL,'41d660e4-321c-42e4-995f-073161a5a1f0'),(315,'CMP_ART Regimen 1month supply 4h','4h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 4h\n 4h\n \n 2019-01-10 18:05:16 UTC\n \n 2021-01-28 00:02:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 315\n Clients-newly-initiated-4h OR Clients-seen-given-1-month-supply-4h\n \n \n Clients-newly-initiated-4h\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-4h\n \n \n \n \n \n \n','2019-01-10 18:05:16',4,'2021-01-28 00:02:33',4,0,NULL,NULL,NULL,'0f5b1812-4fd6-4ded-b64e-16def8e64d81'),(316,'CMP_ART Regimen 1month supply 4j','4j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 4j\n 4j\n \n 2019-01-10 18:17:31 UTC\n \n 2021-01-28 00:08:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 316\n Clients-newly-initiated-4j OR Clients-seen-given-1-month-supply-4j\n \n \n Clients-newly-initiated-4j\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-4j\n \n \n \n \n \n \n','2019-01-10 18:17:31',4,'2021-01-28 00:08:32',4,0,NULL,NULL,NULL,'9f6b4f25-5941-4798-ac05-75721fc60f5a'),(317,'CMP_ART Regimen 1month supply 4k','4k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 4k\n 4k\n \n 2019-01-10 18:25:53 UTC\n \n 2021-01-28 00:14:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 317\n Clients-newly-initiated-4k OR Clients-seen-given-1-month-supply-4k\n \n \n Clients-newly-initiated-4k\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-4k\n \n \n \n \n \n \n','2019-01-10 18:25:53',4,'2021-01-28 00:14:25',4,0,NULL,NULL,NULL,'edfa3d6d-49de-4b92-80e3-06fbf1ac7064'),(318,'CMP_ART Regimen 1month supply 5c','5c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 5c\n 5c\n \n 2019-01-10 18:32:59 UTC\n \n 2021-01-28 00:32:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 318\n Clients-seen-given-1-month-supply-5c OR Clients-newly-initiated-5c\n \n \n Clients-seen-given-1-month-supply-5c\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-5c\n \n \n \n \n \n \n','2019-01-10 18:32:59',4,'2021-01-28 00:32:35',4,0,NULL,NULL,NULL,'e7054506-95ba-4086-8f65-bd053e845fcf'),(319,'CMP_ART Regimen 1month supply 5d','5d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 5d\n 5d\n \n 2019-01-10 18:40:05 UTC\n \n 2021-01-28 00:37:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 319\n Clients-seen-given-1-month-supply-5d OR Clients-newly-initiated-5d\n \n \n Clients-seen-given-1-month-supply-5d\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-5d\n \n \n \n \n \n \n','2019-01-10 18:40:05',4,'2021-01-28 00:37:52',4,0,NULL,NULL,NULL,'78bbfb25-ec26-40c2-8077-f300dabe0a0f'),(320,'CMP_ART Regimen 1month supply 5e','5e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 5e\n 5e\n \n 2019-01-10 18:44:24 UTC\n \n 2021-01-28 00:45:23 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 320\n Clients-newly-initiated-5e OR Clients-seen-given-1-month-supply-5e\n \n \n Clients-newly-initiated-5e\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-5e\n \n \n \n \n \n \n','2019-01-10 18:44:24',4,'2021-01-28 00:45:23',4,0,NULL,NULL,NULL,'4efdb85c-372c-4623-808d-7c9bc93eeff1'),(321,'CMP_ART Regimen 1month supply 5f','5f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 5f\n 5f\n \n 2019-01-10 18:49:28 UTC\n \n 2021-01-28 00:49:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 321\n Clients-newly-initiated-5f OR Clients-seen-given-1-month-supply-5f\n \n \n Clients-newly-initiated-5f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-5f\n \n \n \n \n \n \n','2019-01-10 18:49:28',4,'2021-01-28 00:49:51',4,0,NULL,NULL,NULL,'2b09727b-e984-4c6f-841b-6e73c973622c'),(322,'Clients enroled on PreART exlcuding those with an ART start date','Combines client enrolled on PreART and excludes clients with an ART start date before end of period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients enroled on PreART exlcuding those with an ART start date\n Combines client enrolled on PreART and excludes clients with an ART start date before end of period\n \n 2019-01-23 08:29:09 UTC\n \n 2019-01-23 08:45:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n java.util.List\n true\n \n \n 322\n Date-enrolled-in-Pre-ART AND Clients-ever-enrolled-on-ART\n \n \n Date-enrolled-in-Pre-ART\n \n \n \n \n locationList\n ${location}\n \n \n value2\n ${endDate}\n \n \n value1\n ${startDate}\n \n \n \n \n \n Clients-ever-enrolled-on-ART\n \n \n \n \n locationList\n ${location}\n \n \n value1\n ${endDate}\n \n \n \n \n \n','2019-01-23 10:29:09',4,'2019-01-23 10:45:31',4,0,NULL,NULL,NULL,'1feca9b1-e0d7-4c4e-b898-0dc32b0cc71b'),(323,'CITest33: Clients enrolled on PreART','Testing','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CITest33: Clients enrolled on PreART\n Testing\n \n 2019-01-23 08:37:15 UTC\n \n 2019-01-23 08:38:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n java.util.List\n true\n \n \n 323\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-01-23 10:37:15',4,'2019-01-23 10:38:29',4,0,NULL,NULL,NULL,'2e5bfe4e-6d66-4087-80db-71b46d544763'),(325,'Test Client Enrolled in PreART Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Test Client Enrolled in PreART Data Set\n \n 2019-01-23 08:39:18 UTC\n \n 2019-03-26 13:22:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 325\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n TXCurrPrev\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n','2019-01-23 08:39:18',4,'2019-03-26 13:22:19',4,0,NULL,NULL,NULL,'127b8507-13c4-4484-8957-880f8a03fbfd'),(326,'Pre-ART clients seen in previous months','preart multi month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Pre-ART clients seen in previous months\n preart multi month\n \n 2019-01-23 10:54:36 UTC\n \n 2019-01-23 10:54:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 326\n','2019-01-23 12:54:36',4,'2019-01-23 12:54:46',4,0,NULL,NULL,NULL,'9becf662-98cd-4606-bbb2-e8dffabf1be0'),(328,'Clients not seen for unknown reasons','defaulters and missed','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients not seen for unknown reasons\n defaulters and missed\n \n 2019-01-23 13:50:54 UTC\n \n 2019-02-03 11:02:39 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n 328\n ART-clients-with-Missed-Appointments OR ART-clients-who-Defaulted\n \n \n ART-clients-with-Missed-Appointments\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n ART-clients-who-Defaulted\n \n \n \n \n \n \n','2019-01-23 13:50:54',4,'2019-02-03 11:02:39',4,0,NULL,NULL,NULL,'b97be60d-0f0b-44bc-a6e6-fa57577e7889'),(329,'PreART Clients not initiated on ART','enrolled but no ART start date','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PreART Clients not initiated on ART\n enrolled but no ART start date\n \n 2019-01-24 12:41:36 UTC\n \n 2019-01-24 13:04:43 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 329\n select distinct person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 2223 \nand person_id not in ( \n select distinct person_id \n from obs os inner join location l on os.location_id = l.location_id \n where (os.location_id =:location or parent_location =:location) \n and os.concept_id = 2249 \n )\n','2019-01-24 12:41:36',4,'2019-01-24 13:04:43',4,0,NULL,NULL,NULL,'d0381567-7eab-475a-8525-9d9bd207ea6d'),(330,'New Persons enrolled in Pre ART','enrolled and no art start','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n New Persons enrolled in Pre ART\n enrolled and no art start\n \n 2019-01-24 13:57:17 UTC\n \n 2019-01-31 20:30:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 330\n PreART-Clients-not-initiated-on-ART AND Date-enrolled-in-Pre-ART\n \n \n PreART-Clients-not-initiated-on-ART\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n \n \n Date-enrolled-in-Pre-ART-SQL\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2019-01-24 13:57:17',4,'2019-01-31 20:30:08',4,0,NULL,NULL,NULL,'e7aaf7be-3ce1-4d84-9e78-2da603a5961f'),(331,'clients given multi month ARVs 2 or 3mnths','clients given multi month ARVs 2 or 3mnths','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n clients given multi month ARVs 2 or 3mnths\n clients given multi month ARVs 2 or 3mnths\n \n 2019-01-29 21:03:46 UTC\n \n 2019-03-29 07:50:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 331\n select distinct Id from \n (select distinct Id from \n ( \n (select distinct o.person_id AS Id \n from obs o \n inner join location l on o.location_id = l.location_id \n where ( o.location_id = :location or parent_location = :location) \n and o.concept_id = 2250 \n and o.value_coded in (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n and o.voided = 0 \n and obs_datetime BETWEEN :startDate and DATE_ADD(:endDate, INTERVAL 1 DAY) \n ) \n \n UNION \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -28 DAY)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -28 DAY)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175,4176.4177,4245,4246,4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -28 DAY)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -28 DAY)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id = :location or parent_location = :location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE ( o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded in (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n ) \n) as regimen \nwhere Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 AND obs_datetime < DATE_ADD(:endDate, INTERVAL 1 DAY)) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate, INTERVAL 1 DAY) \n and dead = 1 \n ) \n )as final\n','2019-01-29 21:03:46',4,'2019-03-29 07:50:08',4,0,NULL,NULL,NULL,'c8709121-d393-4861-b808-559fd29dfd7d'),(332,'clients given multi month ARVs 3mnths','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n clients given multi month ARVs 3mnths\n \n \n 2019-01-29 21:28:52 UTC\n \n 2019-03-29 07:53:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 332\n select distinct Id from \n(select id from \n ( \n ( \n select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded IN (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n ) \n \n UNION \n \n ( \n select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded IN (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n ) \n \n UNION \n \n ( \n select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded IN (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n ) \n \n UNION \n \n ( \n select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded IN (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n ) \n \n UNION \n \n ( \n select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded IN (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n ) \n \n UNION \n \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in(4175,4146,4177,4245,4246,4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id = :location or parent_location = :location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded IN (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n \n ) \n \nUNION \n \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in(4175,4146,4177,4245,4246,4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id = :location or parent_location = :location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded IN (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n \n ) \n \nUNION \n \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in(4175,4146,4177,4245,4246,4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id = :location or parent_location = :location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded IN (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n \n ) \n \nUNION \n \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in(4175,4146,4177,4245,4246,4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id = :location or parent_location = :location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded IN (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n \n ) \n \nUNION \n \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in(4175,4146,4177,4245,4246,4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id = :location or parent_location = :location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded IN (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n \n ) \n \nUNION \n \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(DATE_ADD(:endDate,INTERVAL 1 DAY), INTERVAL -28 DAY)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(DATE_ADD(:endDate,INTERVAL 1 DAY), INTERVAL -28 DAY)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in(4175,4146,4177,4245,4246,4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id = :location or parent_location = :location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded IN (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n \n ) \n) as regimen \n \nwhere Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 AND obs_datetime < :endDate) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < :endDate \n and dead = 1 \n ) \n) \nas final\n','2019-01-29 21:28:52',4,'2019-03-29 07:53:17',4,0,NULL,NULL,NULL,'4cdbc901-cea1-4995-84b6-0b6d46c49e03'),(333,'Appointment NOT scheduled','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CodedObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Appointment NOT scheduled\n \n \n 2019-01-29 21:45:38 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n ANY\n \n \n \n \n NOT_IN\n \n \n \n','2019-01-29 21:45:38',4,NULL,NULL,0,NULL,NULL,NULL,'b3da29d2-311a-4264-bef4-5b1b0629704e'),(334,'Clients who picked up ARVs on time','Clients who picked up ARVs on time','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients who picked up ARVs on time\n Clients who picked up ARVs on time\n \n 2019-01-29 21:46:50 UTC\n \n 2019-03-29 08:00:58 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 334\n Clients-given-2weeks-ARV OR clients-given-multi-month-ARVs-3mnths OR clients-given-multi-month-ARVs-2-or-3mnths AND Clients-with-scheduled-appointments-SQL\n \n \n Clients-given-2weeks-ARV\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n clients-given-multi-month-ARVs-3mnths\n \n \n \n \n \n \n clients-given-multi-month-ARVs-2-or-3mnths\n \n \n \n \n \n \n Clients-with-scheduled-appointments-SQL\n \n \n \n \n \n \n','2019-01-29 21:46:50',4,'2019-03-29 08:00:58',4,0,NULL,NULL,NULL,'937a56fd-e654-414a-b1bb-9499ba8d99e5'),(335,'clients not on appointement','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n clients not on appointement\n \n \n 2019-01-29 21:53:00 UTC\n \n 2019-01-29 21:54:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 335\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n','2019-01-29 21:53:00',4,'2019-01-29 21:54:40',4,0,NULL,NULL,NULL,'eb1bf76e-95e8-474d-b856-05c69ce9bcdd'),(336,'clients given 2 or 3mnths ARVs','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n clients given 2 or 3mnths ARVs\n \n \n 2019-01-29 21:55:47 UTC\n \n 2019-01-29 21:56:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 336\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-01-29 21:55:47',4,'2019-01-29 21:56:53',4,0,NULL,NULL,NULL,'3c92647f-a1dd-4218-b440-3272663aa92d'),(337,'clients given 3mnths ARVs ','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n clients given 3mnths ARVs \n \n \n 2019-01-29 21:57:48 UTC\n \n 2019-01-29 21:58:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 337\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-01-29 21:57:48',4,'2019-01-29 21:58:37',4,0,NULL,NULL,NULL,'a4a2ee04-3761-40c9-b9b9-962fa502780d'),(338,'Clients on appointment','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients on appointment\n \n \n 2019-01-29 22:00:24 UTC\n \n 2019-01-29 22:01:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 338\n COUNT\n \n \n \n \n locationList\n ${location}\n \n \n onOrBefore\n ${endDate}\n \n \n onOrAfter\n ${startDate}\n \n \n \n','2019-01-29 22:00:24',4,'2019-01-29 22:01:08',4,0,NULL,NULL,NULL,'dc060565-40ef-4a71-b515-28cd018fb5d6'),(339,'Discordant couples SQL','Discordant couples','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Discordant couples SQL\n Discordant couples\n \n 2019-01-31 04:56:06 UTC\n \n 2019-01-31 05:06:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 339\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 4225 and o.value_coded = 2146\n','2019-01-31 04:56:06',4,'2019-01-31 05:06:40',4,0,NULL,NULL,NULL,'b3b772a7-7fc2-40d4-bbaa-8fe6e5eb9bd9'),(340,'ART Start date SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART Start date SQL\n \n \n 2019-01-31 08:49:55 UTC\n \n 2022-05-19 08:30:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 340\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.person_id in \n(SELECT Id \nFROM \n (select distinct patient.patient_id AS Id, \n patient_identifier.identifier AS patientIdentifier, \n concat(person_name.given_name, ' ', person_name.family_name) AS patientName, \n floor(datediff(CAST(:endDate AS DATE), person.birthdate)/365) AS Age, \n person.gender AS Gender, \n observed_age_group.name AS age_group, \n observed_age_group.sort_order AS sort_order \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 and o.voided = 0 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 and os.voided = 0 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id AND person_name.preferred = 1 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n INNER JOIN reporting_age_group AS observed_age_group ON \n CAST(:endDate AS DATE) BETWEEN (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.min_years YEAR), INTERVAL observed_age_group.min_days DAY)) \n AND (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.max_years YEAR), INTERVAL observed_age_group.max_days DAY)) \n WHERE observed_age_group.report_group_name = 'Modified_Ages') AS Newly_Initiated_ART_Clients \nORDER BY Newly_Initiated_ART_Clients.Age)\n','2019-01-31 08:49:55',4,'2022-05-19 08:30:24',4,0,NULL,NULL,NULL,'6f37715f-711c-48fa-8f56-e3360233d885'),(341,'ART restart date SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART restart date SQL\n \n \n 2019-01-31 09:40:55 UTC\n \n 2022-04-27 11:03:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 341\n select distinct o.person_id \nfrom obs o \n-- PATIENTS WITH NO CLINICAL CONTACT OR ARV PICK-UP FOR GREATER THAN 28 DAYS \n-- SINCE THEIR LAST EXPECTED CONTACT WHO RESTARTED ARVs WITHIN THE REPORTING PERIOD \ninner join location l on o.location_id = l.location_id \nINNER JOIN patient ON o.person_id = patient.patient_id \nAND patient.voided = 0 AND o.voided = 0 \nAND o.person_id in ( \n select person_id \n from \n (select oss.person_id, MAX(oss.obs_datetime) as max_observation, SUBSTRING(MAX(CONCAT(oss.obs_datetime, oss.value_datetime)), 20) AS latest_follow_up \n from obs oss \n inner join person p on oss.person_id=p.person_id and oss.concept_id = 3752 and oss.voided=0 \n and oss.obs_datetime < cast(:startDate as DATE) \n group by p.person_id \n having datediff(CAST(DATE_ADD(CAST(:startDate AS DATE), INTERVAL -1 DAY) AS DATE), latest_follow_up) > 28) as Missed_Greater_Than_28Days \n ) \n \n -- Client Seen: As either patient OR Treatment Buddy \n AND ( \n o.person_id in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n \n ) \n \n -- Client Seen and Date Restarted picked \n OR o.person_id in ( \n select distinct os.person_id \n from obs os \n where os.concept_id = 3708 AND os.value_datetime BETWEEN CAST(:startDate AS DATE) AND CAST(:endDate AS DATE) \n ) \n ) \n -- Still on treatment at the end of the reporting period \n AND o.person_id in ( \n select person_id \n from \n (select oss.person_id, MAX(oss.obs_datetime) as max_observation, SUBSTRING(MAX(CONCAT(oss.obs_datetime, oss.value_datetime)), 20) AS latest_follow_up \n from obs oss \n inner join person p on oss.person_id=p.person_id and oss.concept_id = 3752 and oss.voided=0 \n and oss.obs_datetime >= cast(:startDate as DATE) and oss.obs_datetime <= cast(:endDate as DATE) \n group by p.person_id \n having datediff(CAST(:endDate AS DATE), latest_follow_up) <= 28) as Still_On_Treatment_End_Period \n ) \n \n -- Transfered Out to Another Site during their latest encounter before the start date \n AND o.person_id not in ( \n select person_id \n from \n (select oss.person_id, MAX(oss.obs_datetime) as max_observation, SUBSTRING(MAX(CONCAT(oss.obs_datetime, oss.value_coded)), 20) AS last_obs_tout \n from obs oss \n inner join person p on oss.person_id=p.person_id and oss.concept_id = 4155 and oss.voided=0 \n and oss.obs_datetime < cast(:startDate as DATE) \n group by p.person_id \n having last_obs_tout = 2146) as Transfered_Out_In_Last_Encounter \n ) \n \n-- NOT Transfered In from another Site \n AND o.person_id not in ( \n select os.person_id \n from obs os \n where (os.concept_id = 2253 AND DATE(os.value_datetime) BETWEEN CAST(:startDate AS DATE) AND CAST(:endDate AS DATE)) \n AND os.voided = 0 \n ) \n \n AND o.person_id not in ( \n select person_id \n from person \n where death_date <= CAST(:endDate AS DATE) \n and dead = 1 \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \nWHERE (o.location_id =:location or parent_location =:location) \n\n','2019-01-31 09:40:55',4,'2022-04-27 11:03:30',4,0,NULL,NULL,NULL,'f1a22112-f4e3-47eb-a3c8-beff0cc47bd4'),(342,'ART clients seen SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART clients seen SQL\n \n \n 2019-01-31 10:45:08 UTC\n \n 2022-06-02 16:25:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 342\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.person_id in \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id, \n patient_identifier.identifier AS patientIdentifier, \n concat(person_name.given_name, ' ', person_name.family_name) AS patientName, \n floor(datediff(CAST(:endDate AS DATE), person.birthdate)/365) AS Age, \n person.gender AS Gender, \n observed_age_group.name AS age_group, \n observed_age_group.sort_order AS sort_order \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id AND person_name.preferred = 1 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n INNER JOIN reporting_age_group AS observed_age_group ON \n CAST(:endDate AS DATE) BETWEEN (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.min_years YEAR), INTERVAL observed_age_group.min_days DAY)) \n AND (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.max_years YEAR), INTERVAL observed_age_group.max_days DAY)) \n WHERE observed_age_group.report_group_name = 'Modified_Ages' \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 and o.voided = 0 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n and os.voided = 0 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 and os.voided = 0 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 and os.voided = 0 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n \n \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 and os.voided = 0 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n and voided = 0 \n ) \n and o.voided = 0 \n ) \n \nORDER BY Clients_Seen.Age) \n\n','2019-01-31 10:45:08',4,'2022-06-02 16:25:17',4,0,NULL,NULL,NULL,'092398d1-86b9-4486-97ff-2864ef7871e9'),(343,'ART Clients transferred in SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART Clients transferred in SQL\n \n \n 2019-01-31 10:53:28 UTC\n \n 2022-04-28 13:11:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 343\n select distinct o.person_id \nfrom obs o \nwhere o.concept_id = 2253 and o.voided = 0 \nand MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \nand YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE))\n','2019-01-31 10:53:28',4,'2022-04-28 13:11:52',4,0,NULL,NULL,NULL,'08280ca8-e857-4730-8350-950ab55aee95'),(344,'ART Clients transferred out SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART Clients transferred out SQL\n \n \n 2019-01-31 11:08:01 UTC\n \n 2022-04-28 12:52:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 344\n select distinct person_id \n from \n (select oss.person_id, MAX(oss.obs_datetime) as max_observation, SUBSTRING(MAX(CONCAT(oss.obs_datetime, oss.value_datetime)), 20) AS latest_follow_up \n from obs oss \n inner join person p on oss.person_id=p.person_id and oss.concept_id = 3752 and oss.voided=0 \n and oss.obs_datetime < cast(:endDate as DATE) \n group by p.person_id \n having datediff(CAST(latest_follow_up as DATE), CAST(:endDate AS DATE)) < 0 \n and MONTH(CAST(latest_follow_up AS DATE)) = MONTH(CAST(:endDate AS DATE)) \n and YEAR(CAST(latest_follow_up AS DATE)) = YEAR(CAST(:endDate AS DATE)) \n and oss.person_id in ( \n -- Transfered Out to Another Site \n select distinct os.person_id \n from obs os \n where os.concept_id = 4155 and os.value_coded = 2146 \n AND os.obs_datetime <= CAST(:endDate AS DATE) \n \n ) \n and oss.person_id not in ( \n -- Died \n select distinct person_id \n from person \n where death_date <= CAST(:endDate AS DATE) \n and dead = 1 \n ) \n )T_Outs\n','2019-01-31 11:08:01',4,'2022-04-28 12:52:24',4,0,NULL,NULL,NULL,'ab08b4d3-0971-427c-b3e9-8784299dbee7'),(345,'Tx Curr Previous months SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Tx Curr Previous months SQL\n \n \n 2019-01-31 11:21:16 UTC\n \n 2019-01-31 11:24:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 345\n clients-given-multi-month-ARVs-3mnths OR clients-given-multi-month-ARVs-2-or-3mnths\n \n \n clients-given-multi-month-ARVs-3mnths\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n clients-given-multi-month-ARVs-2-or-3mnths\n \n \n \n \n \n \n','2019-01-31 11:21:16',4,'2019-01-31 11:24:10',4,0,NULL,NULL,NULL,'9563340e-e1d1-4725-bff2-e89edbf454e2'),(346,'Clients given CTX SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given CTX SQL\n \n \n 2019-01-31 19:15:31 UTC\n \n 2019-02-03 11:38:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 346\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 3728 \nand o.value_numeric < 31 \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate \n\n','2019-01-31 19:15:31',4,'2019-02-03 11:38:00',4,0,NULL,NULL,NULL,'e0ae8042-353d-41e9-a70f-4df0c6bcf58b'),(347,'Pre-ART Clients seen','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Pre-ART Clients seen\n \n \n 2019-01-31 19:45:15 UTC\n \n 2019-01-31 20:04:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 347\n PreART-Clients-not-initiated-on-ART AND ART-clients-seen-SQL\n \n \n PreART-Clients-not-initiated-on-ART\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n \n \n \n ART-clients-seen-SQL\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2019-01-31 19:45:15',4,'2019-01-31 20:04:38',4,0,NULL,NULL,NULL,'66c8ee04-f791-4774-84f7-597e039a4f94'),(348,'Date Confirmed HIV positive SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Date Confirmed HIV positive SQL\n \n \n 2019-01-31 20:09:36 UTC\n \n 2019-01-31 20:10:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 348\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 2222 \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2019-01-31 20:09:36',4,'2019-01-31 20:10:20',4,0,NULL,NULL,NULL,'209fc83a-9c42-44aa-afe2-583e6e19cb56'),(349,'Date enrolled in Pre-ART SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Date enrolled in Pre-ART SQL\n \n \n 2019-01-31 20:24:03 UTC\n \n 2019-01-31 20:25:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 349\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 2223 \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2019-01-31 20:24:03',4,'2019-01-31 20:25:29',4,0,NULL,NULL,NULL,'f2c9e963-4199-471b-aac4-23627e6d0d71'),(350,'Date enrolled in Pre-ART','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Date enrolled in Pre-ART\n \n \n 2019-01-31 20:39:42 UTC\n \n 2019-01-31 20:40:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 350\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-01-31 20:39:42',4,'2019-01-31 20:40:34',4,0,NULL,NULL,NULL,'5356e185-cedb-417f-a685-7a84a0e828f8'),(351,'HIV Care clients screened for TB SQL','HIV Care clients screened for TB SQL','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HIV Care clients screened for TB SQL\n HIV Care clients screened for TB SQL\n \n 2019-02-03 09:35:06 UTC\n \n 2019-02-03 09:45:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 351\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 3710 \nand o.value_coded in (3709,1876,3639) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2019-02-03 09:35:06',4,'2019-02-03 09:45:13',4,0,NULL,NULL,NULL,'0494f7f1-1aad-4673-b341-507b34e995e0'),(352,'Presumptive tb HIV care SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Presumptive tb HIV care SQL\n \n \n 2019-02-03 09:48:54 UTC\n \n 2019-02-03 09:49:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 352\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 3710 \nand o.value_coded in (1876) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2019-02-03 09:48:54',4,'2019-02-03 09:49:51',4,0,NULL,NULL,NULL,'f494b5e5-474b-4ef7-b987-77e6fbd1d5f9'),(353,'Diagnosed with TB and started treatment SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Diagnosed with TB and started treatment SQL\n \n \n 2019-02-03 09:53:12 UTC\n \n 2019-03-29 06:31:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 353\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand (o.concept_id in (2237,2358) or (o.concept_id = 3789 and value_coded = 3790)) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2019-02-03 09:53:12',4,'2019-03-29 06:31:40',4,0,NULL,NULL,NULL,'e1467c7d-a287-43ab-ac11-8cc32e4a2723'),(354,'Clients with scheduled appointments SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with scheduled appointments SQL\n \n \n 2019-02-03 11:14:21 UTC\n \n 2019-03-29 07:43:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 354\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 3751 \nand o.value_coded = 2146 \n\n','2019-02-03 11:14:21',4,'2019-03-29 07:43:21',4,0,NULL,NULL,NULL,'1231a6ce-dd01-49ef-b585-9dbff0c4f663'),(355,'Clients given CTX 2mnths SQL ','CTX > 60','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given CTX 2mnths SQL \n CTX > 60\n \n 2019-02-03 11:39:04 UTC\n \n 2019-02-03 11:46:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 355\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 3728 \nand o.value_numeric > 31 \nand o.value_numeric < 62 \nand MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \nand YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \nand o.voided = 0\n','2019-02-03 11:39:04',4,'2019-02-03 11:46:11',4,0,NULL,NULL,NULL,'23c9999f-939a-477e-8343-782a5e9ba2b2'),(356,'Clients given CTX 3mnths SQL ','CTX <100','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given CTX 3mnths SQL \n CTX <100\n \n 2019-02-03 11:47:00 UTC\n \n 2019-02-04 07:05:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 356\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 3728 \nand o.value_numeric <= 100 \nand MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \nand YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \nand o.voided = 0;\n','2019-02-03 11:47:00',4,'2019-02-04 07:05:42',4,0,NULL,NULL,NULL,'9c8b100f-b3bf-469d-ae65-772cfc53c9ba'),(357,'Clients given curret and multi month CTX','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given curret and multi month CTX\n \n \n 2019-02-03 11:50:40 UTC\n \n 2019-02-03 11:53:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 357\n Clients-given-CTX-2mnths-SQL- OR Clients-given-CTX-3mnths-SQL- OR Clients-given-CTX-SQL\n \n \n Clients-given-CTX-2mnths-SQL-\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-given-CTX-3mnths-SQL-\n \n \n \n \n \n \n Clients-given-CTX-SQL\n \n \n \n \n \n \n','2019-02-03 11:50:40',4,'2019-02-03 11:53:12',4,0,NULL,NULL,NULL,'4a42a3bb-7340-496f-ab20-a29bb11953a7'),(358,'Newly enrolled in HIV Care,Started IPT SQL','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Newly enrolled in HIV Care,Started IPT SQL\n \n \n 2019-02-03 19:37:54 UTC\n \n 2019-02-03 20:31:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 358\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 2227 \nand o.value_coded = 2146 \nand o.person_id in \n( \nselect person_id \nfrom obs \nwhere concept_id = 2223 \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate \n) \nand o.person_id not in \n( \nselect person_id \nfrom obs \nwhere concept_id = 2249 \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate \n) \nand o.obs_datetime >=:startDate \nand o.obs_datetime <=:endDate;\n','2019-02-03 19:37:54',4,'2019-02-03 20:31:26',4,0,NULL,NULL,NULL,'2b679b8c-165e-4dbe-8b9d-e7f685a6dae8'),(359,'Clients newly started on ART and IPT','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly started on ART and IPT\n \n \n 2019-02-03 19:59:50 UTC\n \n 2019-02-03 20:09:02 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 359\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 2227 \nand o.value_coded = 2146 \nand o.person_id in \n( \nselect person_id \nfrom obs \nwhere concept_id = 2249 \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate \n) \nand o.obs_datetime >=:startDate \nand o.obs_datetime <=:endDate;\n','2019-02-03 19:59:50',4,'2019-02-03 20:09:02',4,0,NULL,NULL,NULL,'a10eb64a-10db-4cc9-a69a-e9659e634918'),(360,'pre art test new diagnosed','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n pre art test new diagnosed\n \n \n 2019-02-04 07:51:40 UTC\n \n 2019-02-04 07:56:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 360\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 2222 \nand o.person_id in \n( \nselect person_id \nfrom obs \nwhere concept_id = 2223 \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate \n) \nand o.person_id not in \n( \nselect person_id \nfrom obs \nwhere concept_id = 2249 \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate \n) \nand o.obs_datetime >=:startDate \nand o.obs_datetime <=:endDate;\n','2019-02-04 07:51:40',4,'2019-02-04 07:56:11',4,0,NULL,NULL,NULL,'44860f5e-0ce8-466d-8c01-c2ff60737256'),(361,'pre art test newly enrolled','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n pre art test newly enrolled\n \n \n 2019-02-04 08:07:56 UTC\n \n 2019-02-04 08:14:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 361\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 2223 \nand o.person_id not in \n( \nselect person_id \nfrom obs \nwhere concept_id = 2249 \n) \nand o.obs_datetime >=:startDate \nand o.obs_datetime <=:endDate;\n','2019-02-04 08:07:56',4,'2019-02-04 08:14:46',4,0,NULL,NULL,NULL,'1796e0e3-bf74-436b-8b98-4258885a7d1f'),(362,'Clients seen in previous 1 through 6 months SQL','All clients seen in previous 1 through 6 months given multi month supply','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen in previous 1 through 6 months SQL\n All clients seen in previous 1 through 6 months given multi month supply\n \n 2019-02-04 13:45:38 UTC\n \n 2022-06-02 16:19:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 362\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.person_id in \n(SELECT Id \nFROM ( \n \n (SELECT Id, patientIdentifier , patientName, Age, Gender, age_group, 'Seen_Previous' AS 'Program_Status', sort_order \n FROM \n (select distinct patient.patient_id AS Id, \n patient_identifier.identifier AS patientIdentifier, \n concat(person_name.given_name, ' ', person_name.family_name) AS patientName, \n floor(datediff(CAST(:endDate AS DATE), person.birthdate)/365) AS Age, \n person.gender AS Gender, \n observed_age_group.name AS age_group, \n observed_age_group.sort_order AS sort_order \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n -- begin \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n and voided = 0 \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 and voided = 0 \n and A.observation_id = B.obs_group_id \n and B.voided = 0 \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.voided = 0 \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 and os.voided =0 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and os.voided = 0 \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 and os.voided = 0 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 and voided = 0 \n ) \n ) \n -- end \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id AND person_name.preferred = 1 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n INNER JOIN reporting_age_group AS observed_age_group ON \n CAST(:endDate AS DATE) BETWEEN (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.min_years YEAR), INTERVAL observed_age_group.min_days DAY)) \n AND (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.max_years YEAR), INTERVAL observed_age_group.max_days DAY)) \n WHERE observed_age_group.report_group_name = 'Modified_Ages') AS Seen_Previous_ART_Clients \nORDER BY Seen_Previous_ART_Clients.patientName) \n)AS Seen_Prev) \n\n','2019-02-04 13:45:38',4,'2022-06-02 16:19:08',4,0,NULL,NULL,NULL,'6f3593ef-a36c-4d2c-a10b-801b5bc8596b'),(363,'Clients with baseline CD4 counts 12mnths','Clients with baseline CD4 counts 12mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with baseline CD4 counts 12mnths\n Clients with baseline CD4 counts 12mnths\n \n 2019-02-05 08:52:36 UTC\n \n 2019-02-05 08:53:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 363\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 10:52:36',4,'2019-02-05 10:53:32',4,0,NULL,NULL,NULL,'fa2725bc-529d-43a8-8153-815da5e1cfca'),(364,'Clients with baseline CD4 counts 6mnths','Clients with baseline CD4 counts 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with baseline CD4 counts 6mnths\n Clients with baseline CD4 counts 6mnths\n \n 2019-02-05 08:54:13 UTC\n \n 2019-02-05 08:57:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 364\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 10:54:13',4,'2019-02-05 10:57:42',4,0,NULL,NULL,NULL,'f47faba9-8813-4593-8f6a-a6fe13d0e378'),(365,'Clients still on original firstline 6mnths','Clients still on original firstline 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients still on original firstline 6mnths\n Clients still on original firstline 6mnths\n \n 2019-02-05 08:59:32 UTC\n \n 2019-02-05 09:00:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 365\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 10:59:32',4,'2019-02-05 11:00:54',4,0,NULL,NULL,NULL,'8b0102ef-3c90-49f8-8d7c-f49f3af9d70e'),(366,'Clients still on original firstline 12mnths','Clients still on original firstline 12mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients still on original firstline 12mnths\n Clients still on original firstline 12mnths\n \n 2019-02-05 09:01:30 UTC\n \n 2019-02-05 09:02:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 366\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:01:30',4,'2019-02-05 11:02:20',4,0,NULL,NULL,NULL,'63f43e63-76e4-4d5a-b680-5e1fb48a419d'),(367,'Clients on alternative 1st line 6mnths','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients on alternative 1st line 6mnths\n \n \n 2019-02-05 09:03:10 UTC\n \n 2019-02-05 09:05:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 367\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:03:10',4,'2019-02-05 11:05:30',4,0,NULL,NULL,NULL,'3512308a-d7a1-4695-bee3-fe760dd7da54'),(368,'Clients on alternative 1st line 12mnths','Clients on alternative 1st line 12mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients on alternative 1st line 12mnths\n Clients on alternative 1st line 12mnths\n \n 2019-02-05 09:06:09 UTC\n \n 2019-02-05 09:06:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 368\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:06:09',4,'2019-02-05 11:06:51',4,0,NULL,NULL,NULL,'9ffbb2d4-8048-48bd-b851-b82557ca72d6'),(369,'Clients switched to 2nd line 6mnths','Clients switched to 2nd line 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients switched to 2nd line 6mnths\n Clients switched to 2nd line 6mnths\n \n 2019-02-05 09:08:12 UTC\n \n 2019-02-05 09:09:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 369\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:08:12',4,'2019-02-05 11:09:28',4,0,NULL,NULL,NULL,'b4c517ae-ed0c-4bf3-9f3e-8d94304b8659'),(370,'Clients switched to 2nd line 12mnths','Clients switched to 2nd line 12mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients switched to 2nd line 12mnths\n Clients switched to 2nd line 12mnths\n \n 2019-02-05 09:10:26 UTC\n \n 2019-02-05 09:11:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 370\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:10:26',4,'2019-02-05 11:11:30',4,0,NULL,NULL,NULL,'74e22b7b-d25f-4b23-864e-afd719a2ebc6'),(371,'Clients with follow up CD4 6mnths','Clients with follow up CD4 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with follow up CD4 6mnths\n Clients with follow up CD4 6mnths\n \n 2019-02-05 09:12:07 UTC\n \n 2019-02-05 09:15:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 371\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:12:07',4,'2019-02-05 11:15:04',4,0,NULL,NULL,NULL,'7b66107d-e6fb-48a3-ad99-d6a81b1269d9'),(372,'Clients with follow up CD4 12mnths','Clients with follow up CD4 12mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with follow up CD4 12mnths\n Clients with follow up CD4 12mnths\n \n 2019-02-05 09:15:54 UTC\n \n 2019-02-05 09:17:58 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 372\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:15:54',4,'2019-02-05 11:17:58',4,0,NULL,NULL,NULL,'e1ae9120-353f-4c65-85b9-184be1542760'),(373,'Clients with follow up Viral Load 6mnths','Clients with follow up Viral Load 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with follow up Viral Load 6mnths\n Clients with follow up Viral Load 6mnths\n \n 2019-02-05 09:19:41 UTC\n \n 2019-02-05 09:21:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 373\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:19:41',4,'2019-02-05 11:21:35',4,0,NULL,NULL,NULL,'5aa44431-8661-4c1e-92fe-8c117831f418'),(374,'Clients with follow up Viral Load 12mnths','Clients with follow up Viral Load 12mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients with follow up Viral Load 12mnths\n Clients with follow up Viral Load 12mnths\n \n 2019-02-05 09:22:53 UTC\n \n 2019-02-05 09:25:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 374\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:22:53',4,'2019-02-05 11:25:34',4,0,NULL,NULL,NULL,'eb510470-5a6d-45a4-bdeb-6d905570bd0d'),(375,'Clients lost to follow up 6mnths','Clients lost to follow up 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients lost to follow up 6mnths\n Clients lost to follow up 6mnths\n \n 2019-02-05 09:26:21 UTC\n \n 2019-02-05 09:28:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 375\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:26:21',4,'2019-02-05 11:28:11',4,0,NULL,NULL,NULL,'3efb72d7-384b-4492-8ef5-1e158fecae2a'),(376,'Clients lost to follow up 12mnths','Clients lost to follow up 12mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients lost to follow up 12mnths\n Clients lost to follow up 12mnths\n \n 2019-02-05 09:28:53 UTC\n \n 2019-02-05 09:31:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 376\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:28:53',4,'2019-02-05 11:31:22',4,0,NULL,NULL,NULL,'3e0765e1-b5cc-43ca-bc89-4585f5e9e7fb'),(377,'Clients dead 6mnths','Clients dead 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients dead 6mnths\n Clients dead 6mnths\n \n 2019-02-05 09:32:07 UTC\n \n 2019-02-05 09:33:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 377\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:32:07',4,'2019-02-05 11:33:08',4,0,NULL,NULL,NULL,'1f29b6b1-21b8-4931-9a38-a1cefbc302d3'),(378,'Clients dead 12 mnths','Clients dead 12mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients dead 12 mnths\n Clients dead 12mnths\n \n 2019-02-05 09:33:37 UTC\n \n 2019-02-05 09:34:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 378\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:33:37',4,'2019-02-05 11:34:30',4,0,NULL,NULL,NULL,'991435d7-ccd5-4e80-882f-bb8e3bf4f8b8'),(379,'Clients stopped 6mnths','Clients stopped 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients stopped 6mnths\n Clients stopped 6mnths\n \n 2019-02-05 09:35:01 UTC\n \n 2019-02-05 09:36:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 379\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:35:01',4,'2019-02-05 11:36:07',4,0,NULL,NULL,NULL,'c72f56a8-b67f-43ad-a2e4-a10be338e482'),(380,'Clients stopped 12 mnths','Clients stopped 12mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients stopped 12 mnths\n Clients stopped 12mnths\n \n 2019-02-05 09:36:39 UTC\n \n 2019-02-05 09:37:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 380\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-02-05 11:36:39',4,'2019-02-05 11:37:32',4,0,NULL,NULL,NULL,'8effc480-73a0-4806-9555-44ac56e09d6e'),(382,'Clients newly initiated 1c','1c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1c\n 1c\n \n 2019-02-06 15:02:44 UTC\n \n 2021-01-27 14:36:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 382\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 2201 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:02:44',4,'2021-01-27 14:36:25',4,0,NULL,NULL,NULL,'eb143dfc-1a1c-4e1c-b2d9-243ca86dd111'),(383,'Clients newly initiated 1d ','1d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1d \n 1d\n \n 2019-02-06 15:13:24 UTC\n \n 2021-01-27 14:38:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 383\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 2203 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:13:24',4,'2021-01-27 14:38:16',4,0,NULL,NULL,NULL,'3d4080ed-278a-4c48-a9a9-4d1c9359b3c5'),(384,'Clients newly initiated 1e','1e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1e\n 1e\n \n 2019-02-06 15:15:37 UTC\n \n 2021-01-27 14:39:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 384\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 2205 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:15:37',4,'2021-01-27 14:39:22',4,0,NULL,NULL,NULL,'d1b27fb7-6798-4562-bbe2-7d2d71ccba59'),(385,'Clients newly initiated 1f','1f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1f\n 1f\n \n 2019-02-06 15:16:38 UTC\n \n 2021-01-27 14:39:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 385\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 2207 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:16:38',4,'2021-01-27 14:39:57',4,0,NULL,NULL,NULL,'ce0026fa-a5a0-4729-9442-76d4e651f94a'),(386,'Clients newly initiated 1g ','1g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1g \n 1g\n \n 2019-02-06 15:18:38 UTC\n \n 2021-01-27 14:40:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 386\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3672 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:18:38',4,'2021-01-27 14:40:32',4,0,NULL,NULL,NULL,'05918dc5-51c4-4556-be64-efa548ddc957'),(387,'Clients newly initiated 1h','1h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1h\n 1h\n \n 2019-02-06 15:20:41 UTC\n \n 2021-01-27 14:41:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 387\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3673 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:20:41',4,'2021-01-27 14:41:11',4,0,NULL,NULL,NULL,'5147b850-5fee-42d3-b2bf-0c074c9eca96'),(388,'Clients newly initiated 2c','2c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2c\n 2c\n \n 2019-02-06 15:23:30 UTC\n \n 2021-01-27 14:52:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 388\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 2210 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:23:30',4,'2021-01-27 14:52:56',4,0,NULL,NULL,NULL,'14d94e25-3c55-4434-b0ad-64e23f6a5404'),(389,'Clients newly initiated 2d','2d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2d\n 2d\n \n 2019-02-06 15:25:19 UTC\n \n 2021-01-27 14:53:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 389\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 2209 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:25:19',4,'2021-01-27 14:53:48',4,0,NULL,NULL,NULL,'03f49548-9c17-4f5f-94d9-4e616d2758b8'),(390,'Clients newly initiated 2e','2e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2e\n 2e\n \n 2019-02-06 15:26:27 UTC\n \n 2021-01-27 14:54:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 390\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3674 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:26:27',4,'2021-01-27 14:54:34',4,0,NULL,NULL,NULL,'db68cb15-10f6-4f65-bee5-3c69d079c441'),(391,'Clients newly initiated 2f ','2f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2f \n 2f\n \n 2019-02-06 15:27:26 UTC\n \n 2021-01-27 14:55:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 391\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3675 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:27:26',4,'2021-01-27 14:55:21',4,0,NULL,NULL,NULL,'d3645a04-6157-4855-b645-d19c73b2827c'),(392,'Clients newly initiated 2g','2g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2g\n 2g\n \n 2019-02-06 15:28:29 UTC\n \n 2021-01-27 14:57:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 392\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3676 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:28:29',4,'2021-01-27 14:57:07',4,0,NULL,NULL,NULL,'0d4335ea-74f0-4cca-8ed7-ca4fa033880e'),(393,'Clients newly initiated 2h','2h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2h\n 2h\n \n 2019-02-06 15:29:20 UTC\n \n 2021-01-27 14:57:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 393\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3677 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-06 15:29:20',4,'2021-01-27 14:57:48',4,0,NULL,NULL,NULL,'4d44a02b-fe31-450d-887a-c5e769a13cb1'),(394,'Clients newly initiated 3a','3a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 3a\n 3a\n \n 2019-02-07 08:20:56 UTC\n \n 2021-01-27 15:12:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 394\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3683 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-07 08:20:56',4,'2021-01-27 15:12:32',4,0,NULL,NULL,NULL,'995ebf26-1945-4e6a-b041-c401c06d4b90'),(395,'Clients newly initiated 3b','3b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 3b\n 3b\n \n 2019-02-07 08:21:56 UTC\n \n 2021-01-27 15:14:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 395\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3684 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-07 08:21:56',4,'2021-01-27 15:14:28',4,0,NULL,NULL,NULL,'b447da00-0b30-4205-8027-ebe5951ed320'),(400,'Clients seen 4c','4c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 4c\n 4c\n \n 2019-02-07 10:22:40 UTC\n \n 2019-05-08 09:05:39 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 400\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2202 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-02-07 10:22:40',4,'2019-05-08 09:05:39',4,0,NULL,NULL,NULL,'568c8c09-01b5-4a1c-8892-f558350b2abf'),(401,'Clients seen 4d','4d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 4d\n 4d\n \n 2019-02-07 10:24:59 UTC\n \n 2019-05-08 09:53:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 401\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 2204 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date < :endDate \n and dead = 1 \n ) \n \n \n','2019-02-07 10:24:59',4,'2019-05-08 09:53:30',4,0,NULL,NULL,NULL,'df3b2c47-8c25-4a90-a9cf-4a98a52d87de'),(402,'Clients seen 4e','4e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 4e\n 4e\n \n 2019-02-07 10:28:19 UTC\n \n 2019-05-08 09:54:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 402\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3679 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-02-07 10:28:19',4,'2019-05-08 09:54:32',4,0,NULL,NULL,NULL,'37ad57a6-6821-4f3b-bc29-05ab90bc774a'),(403,'Clients seen 4f','4f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 4f\n 4f\n \n 2019-02-07 10:29:37 UTC\n \n 2019-05-08 09:55:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 403\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3680 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date < :endDate \n and dead = 1 \n ) \n \n \n','2019-02-07 10:29:37',4,'2019-05-08 09:55:25',4,0,NULL,NULL,NULL,'ad3ba0a3-3589-4b24-8645-ea12a81be5bf'),(404,'Clients seen 6a','6a RAL-EFV-LPV','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 6a\n 6a RAL-EFV-LPV\n \n 2019-02-07 10:39:49 UTC\n \n 2019-05-08 10:48:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 404\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3686 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-02-07 10:39:49',4,'2019-05-08 10:48:52',4,0,NULL,NULL,NULL,'a20a7a05-5360-43b9-b48e-81294d4f06e9'),(406,'Clients newly initiated 3c','3c as 6a under dhis2 adults 3rd line','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 3c\n 3c as 6a under dhis2 adults 3rd line\n \n 2019-02-07 11:02:00 UTC\n \n 2021-01-27 15:20:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 406\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3685 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2019-02-07 11:02:00',4,'2021-01-27 15:20:40',4,0,NULL,NULL,NULL,'354eee1a-35a6-473c-9029-4e4e66042646'),(407,'Clients seen 3c','3c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 3c\n 3c\n \n 2019-02-07 13:35:11 UTC\n \n 2019-05-08 10:38:50 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 407\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-02-07 13:35:11',4,'2019-05-08 10:38:50',4,0,NULL,NULL,NULL,'604a75e1-4aac-413b-be90-3c3f5f0e1506'),(408,'Clients multi month 3c','3c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients multi month 3c\n 3c\n \n 2019-02-07 13:57:32 UTC\n \n 2019-05-09 09:40:39 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 408\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176,4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177,4245,4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONTHS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245, 4246 ,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246,4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n ) \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4175)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4176)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n ) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4177)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n ) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4245)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \nAND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n ) \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4246)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n ) \n \n ) \n \n \n \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded in (4247)) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location )) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location ) \n AND o.person_id in ( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3685 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n ) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location )) \nand Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0) \nAND Id not in ( \n \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate,interval 1 DAY) \n and dead = 1 \n ) \nAND Id not in( \n select distinct Id from \n (select distinct person_id as Id, max(value_datetime), datediff(CAST(:endDate AS DATE), max(value_datetime)) AS Num_Days \n FROM obs \n WHERE concept_id = 3752 \n group by person_id \n HAVING Num_Days >= 7) as finalised \n )\n','2019-02-07 13:57:32',4,'2019-05-09 09:40:39',4,0,NULL,NULL,NULL,'30fa519d-6d87-453f-a68f-fbfe97d650b9'),(409,'Clients seen given 1 month supply 4c','4c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 4c\n 4c\n \n 2019-02-07 14:01:00 UTC\n \n 2021-02-04 07:31:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 409\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 2202) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 2202 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(CAST(os.value_datetime AS DATE)), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(CAST(os.value_datetime AS DATE)) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2019-02-07 14:01:00',4,'2021-02-04 07:31:35',4,0,NULL,NULL,NULL,'537bfeb1-7f85-4387-81c1-79f35d6b8193'),(410,'Clients seen given 1 month supply 4d','4d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 4d\n 4d\n \n 2019-02-07 14:02:06 UTC\n \n 2021-02-04 07:32:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 410\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 2204) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 2204 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(CAST(os.value_datetime AS DATE)), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(CAST(os.value_datetime AS DATE)) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2019-02-07 14:02:06',4,'2021-02-04 07:32:24',4,0,NULL,NULL,NULL,'306b1f50-9652-42e5-9f9f-bacb1a1f3ed1'),(411,'Clients seen given 1 month supply 4e','4e ','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 4e\n 4e \n \n 2019-02-07 14:05:31 UTC\n \n 2021-02-04 07:35:39 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 411\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3679) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 3679 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(CAST(os.value_datetime AS DATE)), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(CAST(os.value_datetime AS DATE)) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2019-02-07 14:05:31',4,'2021-02-04 07:35:39',4,0,NULL,NULL,NULL,'7bd605b0-4f07-4730-b79e-ea885c4dc22a'),(412,'Clients seen given 1 month supply 4f','4f ','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 4f\n 4f \n \n 2019-02-07 14:09:36 UTC\n \n 2021-02-04 07:36:27 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 412\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3680) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 3680 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(CAST(os.value_datetime AS DATE)), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(CAST(os.value_datetime AS DATE)) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2019-02-07 14:09:36',4,'2021-02-04 07:36:27',4,0,NULL,NULL,NULL,'61c10574-82e0-409f-b573-2ed12e5234ef'),(413,'Clients seen given 1 month supply 5a','5a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 5a\n 5a\n \n 2019-02-07 14:14:11 UTC\n \n 2021-02-04 07:47:50 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 413\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3681) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 3681 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(CAST(os.value_datetime AS DATE)), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(CAST(os.value_datetime AS DATE)) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2019-02-07 14:14:11',4,'2021-02-04 07:47:50',4,0,NULL,NULL,NULL,'35491dfa-1e7f-4a01-9c4c-3d741887d1fc'),(414,'Clients seen given 1 month supply 5b','5b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 5b\n 5b\n \n 2019-02-07 14:16:20 UTC\n \n 2021-02-04 07:55:49 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 414\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3682) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 3682 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(CAST(os.value_datetime AS DATE)), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(CAST(os.value_datetime AS DATE)) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2019-02-07 14:16:20',4,'2021-02-04 07:55:49',4,0,NULL,NULL,NULL,'b828f7ad-12f5-42fa-9217-e1deb46fb67b'),(415,'Clients seen 5a','5a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 5a\n 5a\n \n 2019-02-07 14:18:43 UTC\n \n 2019-05-08 10:18:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 415\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3681 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-02-07 14:18:43',4,'2019-05-08 10:18:10',4,0,NULL,NULL,NULL,'79aeb902-4831-4559-9766-1fcfe976732d'),(416,'Clients seen 5b','5b 2 or 3mnths','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen 5b\n 5b 2 or 3mnths\n \n 2019-02-07 14:19:37 UTC\n \n 2019-05-08 10:21:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 416\n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \nWHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in( \n select distinct person_id \n from obs \n -- All patients given 1F regimen during a particular period \n where concept_id = 2250 and value_coded = 3682 \n AND obs_datetime between :startDate AND :endDate \n) \nand patient.patient_id not in -- CLIENTS NEWLY INITIATED ON ART \n (select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND :endDate) \n AND patient.voided = 0 AND o.voided = 0 \n and patient.patient_id not in( \n select distinct os.person_id from obs os \n where os.concept_id = 2396 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND :endDate) \n \n ) \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n and obs_datetime <= :endDate \n group by person_id) one, \n \n (select person_id,obs_datetime \n from obs \n where concept_id = 3843 \n and obs_datetime <= :endDate) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \n \nAND patient.patient_id not in \n ( \n select distinct person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n \n','2019-02-07 14:19:37',4,'2019-05-08 10:21:05',4,0,NULL,NULL,NULL,'08e17546-29ca-41a6-8457-faa0da7126d1'),(417,'CMP_ART Regimen 1month supply 5g','5g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 5g\n 5g\n \n 2019-02-07 14:22:10 UTC\n \n 2021-01-28 00:57:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 417\n Clients-newly-initiated-5g OR Clients-seen-given-1-month-supply-5g\n \n \n Clients-newly-initiated-5g\n \n \n \n \n endDate\n ${}\n \n \n location\n ${}\n \n \n startDate\n ${}\n \n \n \n \n \n Clients-seen-given-1-month-supply-5g\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2019-02-07 14:22:10',4,'2021-01-28 00:57:28',4,0,NULL,NULL,NULL,'c90d4873-21fb-444f-94f3-0c29f7e1c723'),(418,'CMP_ART Regimen 1month supply 4c','4c ','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 4c\n 4c \n \n 2019-02-07 14:28:09 UTC\n \n 2021-01-27 23:38:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 418\n Clients-seen-given-1-month-supply-4c OR Clients-newly-initiated-4c\n \n \n Clients-seen-given-1-month-supply-4c\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-4c\n \n \n \n \n \n \n','2019-02-07 14:28:09',4,'2021-01-27 23:38:54',4,0,NULL,NULL,NULL,'b734b3a4-c03d-4870-aee6-ae72d7cd09a3'),(419,'CMP_ART Regimen 1month supply 4d','4d ','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 4d\n 4d \n \n 2019-02-07 14:33:46 UTC\n \n 2021-01-27 23:48:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 419\n Clients-newly-initiated-4d OR Clients-seen-given-1-month-supply-4d\n \n \n Clients-newly-initiated-4d\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-4d\n \n \n \n \n \n \n','2019-02-07 14:33:46',4,'2021-01-27 23:48:30',4,0,NULL,NULL,NULL,'6fd05fe9-d0f9-4df1-af32-f779445dfa47'),(420,'CMP_ART Regimen 1month supply 4e','4e ','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 4e\n 4e \n \n 2019-02-07 14:48:47 UTC\n \n 2021-01-27 23:52:23 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 420\n Clients-newly-initiated-4e OR Clients-seen-given-1-month-supply-4e\n \n \n Clients-newly-initiated-4e\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-4e\n \n \n \n \n \n \n','2019-02-07 14:48:47',4,'2021-01-27 23:52:23',4,0,NULL,NULL,NULL,'4c813098-94b5-4e1d-8e8a-baeccd78bad2'),(421,'CMP_ART Regimen 1month supply 4f','4f ','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 4f\n 4f \n \n 2019-02-07 14:53:34 UTC\n \n 2021-01-27 23:55:36 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 421\n Clients-newly-initiated-4f OR Clients-seen-given-1-month-supply-4f\n \n \n Clients-newly-initiated-4f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-4f\n \n \n \n \n \n \n','2019-02-07 14:53:34',4,'2021-01-27 23:55:36',4,0,NULL,NULL,NULL,'33d92626-132a-476e-8c20-0738c0517731'),(424,'CMP_ART Regimen 1month supply 5a','5a ','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 5a\n 5a \n \n 2019-02-07 15:09:01 UTC\n \n 2021-01-28 00:23:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 424\n Clients-seen-given-1-month-supply-5a OR Clients-newly-initiated-5a\n \n \n Clients-seen-given-1-month-supply-5a\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-5a\n \n \n \n \n \n \n','2019-02-07 15:09:01',4,'2021-01-28 00:23:10',4,0,NULL,NULL,NULL,'e5755cdd-222c-4005-b535-2b7b2027a776'),(425,'Clients given 5a current and multi month','5a 1-3mnths','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 5a current and multi month\n 5a 1-3mnths\n \n 2019-02-07 15:16:38 UTC\n \n 2019-02-07 15:17:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 425\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 2250 \nand o.value_coded = 3681 \nand o.voided = 0 \nand obs_datetime between :startDate and :endDate;\n','2019-02-07 15:16:38',4,'2019-02-07 15:17:59',4,0,NULL,NULL,NULL,'f69352a8-954a-409e-9bcc-72c382522568'),(426,'CMP_ART Regimen 1month supply 5b','5b ','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 5b\n 5b \n \n 2019-02-07 15:20:08 UTC\n \n 2021-01-28 00:28:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 426\n Clients-seen-given-1-month-supply-5b OR Clients-newly-initiated-5b\n \n \n Clients-seen-given-1-month-supply-5b\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-5b\n \n \n \n \n \n \n','2019-02-07 15:20:08',4,'2021-01-28 00:28:10',4,0,NULL,NULL,NULL,'776337cf-5614-4b95-9c43-b322b1a2bd3b'),(427,'CMP_ART Regimen 1month supply 6a','6a ','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 6a\n 6a \n \n 2019-02-07 15:24:04 UTC\n \n 2021-01-28 01:16:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 427\n Clients-seen-given-1-month-supply-6a OR Clients-newly-initiated-6a\n \n \n Clients-seen-given-1-month-supply-6a\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-6a\n \n \n \n \n \n \n','2019-02-07 15:24:04',4,'2021-01-28 01:16:54',4,0,NULL,NULL,NULL,'dba3de7f-67e9-4b23-b63e-7c58c308165d'),(428,'Clients seen given 1 month supply 6a','6a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 6a\n 6a\n \n 2019-02-07 15:28:03 UTC\n \n 2021-02-04 08:14:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 428\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4175,4243)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3686) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded in (4175,4243) \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(CAST(os.value_datetime AS DATE), CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 3686 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(CAST(os.value_datetime AS DATE)), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(CAST(os.value_datetime AS DATE)) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2019-02-07 15:28:03',4,'2021-02-04 08:14:10',4,0,NULL,NULL,NULL,'53316cf7-0a79-49e4-9dd4-5f00f847b3b1'),(429,'TESTING','ALL TESTS','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n TESTING\n ALL TESTS\n \n 2019-02-12 09:23:54 UTC\n \n 2019-02-19 10:51:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 429\n select distinct person_id \nfrom obs \nwhere concept_id = 3843 \nand value_coded in (3841) \nAND (DATE(obs_datetime) BETWEEN :startDate AND addDate(:endDate, 1)); \n \n\n','2019-02-12 09:23:54',4,'2019-02-19 10:51:01',4,0,NULL,NULL,NULL,'0e162295-6055-46ea-8c17-5fca300d0054'),(430,'testing','n/a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n testing\n n/a\n \n 2019-02-13 14:14:05 UTC\n \n 2020-07-06 07:28:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 430\n (select o.person_id,CAST(value_datetime AS DATE) as blood_drawn \nfrom obs o \ninner join \n (select person_id,max(obs_datetime) maxdate \n from obs a \n where obs_datetime <= :endDate \n and concept_id = 4267 \n group by person_id \n )latest \n on latest.person_id = o.person_id \n where concept_id = 4267 \n and o.obs_datetime = maxdate \n )\n','2019-02-13 14:14:05',4,'2020-07-06 07:28:05',4,0,NULL,NULL,NULL,'dd019ae7-3549-4fd7-b3ee-b7ac841707f2'),(431,'lets see','N/A','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n lets see\n N/A\n \n 2019-02-15 10:05:49 UTC\n \n 2019-02-15 12:46:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 431\n SELECT DISTINCT Id \nFROM \n \n( \nselect distinct patient.patient_id AS Id \n \n from obs o \n \n \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD('2019-01-31', INTERVAL -1 MONTH)) \n and YEAR(o.obs_datetime) = YEAR(DATE_ADD('2019-01-31', INTERVAL -1 MONTH)) \n AND patient.voided = 0 \n AND o.voided = 0 \n AND (o.concept_id = 4174 and (o.value_coded in (4176,4177,4245,4246,4247))) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id \n AND patient_identifier.identifier_type = 3 \n \n \n \nUNION \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD('2019-01-31', INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD('2019-01-31', INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4175 \n AND o.person_id in ( \n select distinct os.person_id from obs os \n \n where MONTH(os.obs_datetime) = MONTH(DATE_ADD('2019-01-31', INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD('2019-01-31', INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 \n AND DATEDIFF(os.value_datetime, '2019-01-31') BETWEEN 0 AND 28 \n \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 \n \n \n \n) AS ARTCurrent_PrevMonths \n \nWHERE Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN '2019-01-01' AND addDate('2019-01-31', 1)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id \n AND patient_identifier.identifier_type = 3 \nWHERE patient.patient_id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \nINNER JOIN patient ON o.person_id = patient.patient_id \nAND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN '2019-01-01' AND addDate('2019-01-31', 1)) \nAND patient.voided = 0 AND o.voided = 0 \n \nAND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND DATE(os.obs_datetime) BETWEEN '2019-01-01' AND addDate('2019-01-31', 1) \n \n ) \n ))\n','2019-02-15 10:05:49',4,'2019-02-15 12:46:15',4,0,NULL,NULL,NULL,'82d59123-ac4a-4c14-8218-0738d4ade605'),(432,'Clients given 4mnths 1f in previous 3mnths','1f 4mnths ago','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 4mnths 1f in previous 3mnths\n 1f 4mnths ago\n \n 2019-02-19 09:39:58 UTC\n \n 2019-02-19 09:58:09 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 432\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 4174 and o.value_coded in (4245,4246) \n \nand o.person_id in ( \n select distinct os.person_id \n from obs os \n where os.concept_id = 2250 \n and os.value_coded = 2207 \n and MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n and YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n) \n \nand MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \nand YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \nand o.voided = 0\n','2019-02-19 09:39:58',4,'2019-02-19 09:58:09',4,0,NULL,NULL,NULL,'c2adcb8a-c735-4860-a9d8-9509ac29d363'),(433,'Clients given 5mnths 1f in previous m4nths','1f 5mnths ago','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 5mnths 1f in previous m4nths\n 1f 5mnths ago\n \n 2019-02-19 09:59:13 UTC\n \n 2019-02-19 10:02:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 433\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand o.concept_id = 4174 and o.value_coded in (4246) \n \nand o.person_id in ( \n select distinct os.person_id \n from obs os \n where os.concept_id = 2250 \n and os.value_coded = 2207 \n and MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n and YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n) \n \nand MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \nand YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \nand o.voided = 0\n','2019-02-19 09:59:13',4,'2019-02-19 10:02:40',4,0,NULL,NULL,NULL,'809ab22c-a795-46ba-b8af-1a21a51551e4'),(435,'Master HIVTC report Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Master HIVTC report Data Set\n \n 2019-02-21 14:56:31 UTC\n \n 2019-03-01 10:34:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 435\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n DM_Weight_Updated\n \n \n \n \n \n \n \n \n 1ST4c3.9F\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 03to3.9kg\n \n \n \n \n \n 1st4c3.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 03to3.9kg\n \n \n \n \n \n 1st4c5.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 04to5.9kg\n \n \n \n \n \n 1st4c5.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 04to5.9kg\n \n \n \n \n \n 1st4d13.9F\n \n \n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 10to13.9kg\n \n \n \n \n \n 1st4d13.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 10to13.9kg\n \n \n \n \n \n 1st4d19.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 14to19.9kg\n \n \n \n \n \n 1st4d19.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 14to19.9kg\n \n \n \n \n \n 1st4d24.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 20to24.9kg\n \n \n \n \n \n 1st4d24.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 20to24.9kg\n \n \n \n \n \n 1st4d25F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 25+kg\n \n \n \n \n \n 1st4d25M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 25+kg\n \n \n \n \n \n 1st4d3.9F\n \n \n \n \n \n \n 1st4d3.9M\n \n \n \n \n \n \n 1st4d5.9F\n \n \n \n \n \n \n 1st4d5.9M\n \n \n \n \n \n \n 1st4d9.9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 06to9.9kg\n \n \n \n \n \n 1st4d9.9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n DM_Weight_Updated\n 06to9.9kg\n \n \n \n \n \n 1stlineCF\n \n \n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n 1stlineCM\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Adults\n \n \n \n \n \n 1stlineDF\n \n \n \n \n \n \n \n \n \n 1stlineDM\n \n \n \n \n \n \n 1stlineEF\n \n \n \n \n \n \n \n \n \n 1stlineEM\n \n \n \n \n \n \n 1stlineFF\n \n \n \n \n \n \n \n \n \n 1stlineFM\n \n \n \n \n \n \n 1stlineGF\n \n \n \n \n \n \n \n \n \n 1stlineGM\n \n \n \n \n \n \n 1stlineHF\n \n \n \n \n \n \n \n \n \n 1stlineHM\n \n \n \n \n \n \n','2019-02-21 14:56:31',4,'2019-03-01 10:34:21',4,0,NULL,NULL,NULL,'41857c4c-d7eb-4ab2-8266-3bb1cdb084f0'),(436,'clients seen 2months ago','2mnths+','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n clients seen 2months ago\n 2mnths+\n \n 2019-02-27 10:29:03 UTC\n \n 2019-02-27 10:29:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 436\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n and YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and (o.value_coded = 4176 or o.value_coded = 4177 or o.value_coded = 4245 or o.value_coded = 4246 or o.value_coded = 4247)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id \n AND patient_identifier.identifier_type = 3 \n WHERE (o.location_id =:location or parent_location =:location) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4175 \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -1 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 \n WHERE (o.location_id =:location or parent_location =:location) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4176 \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 \n WHERE (o.location_id =:location or parent_location =:location) \n ) \n \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND addDate(:endDate, 1)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id \n AND patient_identifier.identifier_type = 3 \nand patient.patient_id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND addDate(:endDate, 1)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND addDate(:endDate, 1) \n \n ) \n ) \n WHERE (o.location_id =:location or parent_location =:location) \n)\n','2019-02-27 10:29:03',4,'2019-02-27 10:29:19',4,0,NULL,NULL,NULL,'a5bf5837-dafc-404e-9eb8-77501187ac6f'),(437,'clients seen 3months ago','3mnths+','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n clients seen 3months ago\n 3mnths+\n \n 2019-02-27 10:30:44 UTC\n \n 2019-02-27 10:34:49 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 437\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 2 MONTHS AND WAS GIVEN (3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -2 MONTH)) \n AND patient.voided = 0 \n AND o.voided = 0 \n AND o.concept_id = 4174 \n and (o.value_coded = 4177 or o.value_coded = 4245 or o.value_coded = 4246 or o.value_coded = 4247) \n INNER JOIN person ON person.person_id = patient.patient_id \n AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id \n AND patient_identifier.identifier_type = 3 \n WHERE (o.location_id =:location or parent_location =:location) \n ) \n \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4177 \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 \n WHERE (o.location_id =:location or parent_location =:location) \n ) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND addDate(:endDate, 1)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id \n AND patient_identifier.identifier_type = 3 \nand patient.patient_id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND addDate(:endDate, 1)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND addDate(:endDate, 1) \n \n ) \n ) \n WHERE (o.location_id =:location or parent_location =:location) \n)\n','2019-02-27 10:30:44',4,'2019-02-27 10:34:49',4,0,NULL,NULL,NULL,'21c776ca-7cbc-4388-a623-06e351469a20'),(438,'clients seen 4months ago','4mnths+','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n clients seen 4months ago\n 4mnths+\n \n 2019-02-27 10:37:22 UTC\n \n 2019-02-27 10:37:36 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 438\n SELECT DISTINCT Id \nFROM \n( \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 3 MONTHS AND WAS GIVEN (4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -3 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and (o.value_coded = 4245 or o.value_coded = 4246 or o.value_coded = 4247) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 \n WHERE (o.location_id =:location or parent_location =:location) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4245 \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 \n WHERE (o.location_id =:location or parent_location =:location) \n ) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND addDate(:endDate, 1)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id \n AND patient_identifier.identifier_type = 3 \nand patient.patient_id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND addDate(:endDate, 1)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND addDate(:endDate, 1) \n \n ) \n ) \n WHERE (o.location_id =:location or parent_location =:location) \n)\n','2019-02-27 10:37:22',4,'2019-02-27 10:37:36',4,0,NULL,NULL,NULL,'41a0d5e0-f46f-4cd7-a361-ea6ea3b5933e'),(439,'clients seen 5mnths ago','5mnths +','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n clients seen 5mnths ago\n 5mnths +\n \n 2019-02-27 10:45:50 UTC\n \n 2019-02-27 10:47:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 439\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 4 MONTHS AND WAS GIVEN (5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -4 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and (o.value_coded = 4246 or o.value_coded = 4247) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 \n WHERE (o.location_id =:location or parent_location =:location) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4246 \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 \n WHERE (o.location_id =:location or parent_location =:location) \n \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND addDate(:endDate, 1)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id \n AND patient_identifier.identifier_type = 3 \nand patient.patient_id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND addDate(:endDate, 1)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND addDate(:endDate, 1) \n \n ) \n ) \n WHERE (o.location_id =:location or parent_location =:location) \n)\n','2019-02-27 10:45:50',4,'2019-02-27 10:47:06',4,0,NULL,NULL,NULL,'7cef2932-533c-42ca-96fa-90f10ea3badb'),(440,'clients seen 6months ago','6mnths +','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n clients seen 6months ago\n 6mnths +\n \n 2019-02-27 10:49:11 UTC\n \n 2019-02-27 10:50:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 440\n SELECT DISTINCT Id \nFROM \n( \n \n(select distinct patient.patient_id AS Id \n \n from obs o \n -- CAME IN PREVIOUS 5 MONTHS AND WAS GIVEN (6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -5 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 \n WHERE (o.location_id =:location or parent_location =:location) \n ) \nUNION \n \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.concept_id = 4174 and o.value_coded = 4247 \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id =:location or parent_location =:location)) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 \n WHERE (o.location_id =:location or parent_location =:location) \n ) \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.Id not in ( \n select distinct patient.patient_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND (DATE(o.obs_datetime) BETWEEN :startDate AND addDate(:endDate, 1)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id \n AND patient_identifier.identifier_type = 3 \nand patient.patient_id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 AND DATE(o.value_datetime) BETWEEN :startDate AND addDate(:endDate, 1)) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND DATE(os.obs_datetime) BETWEEN :startDate AND addDate(:endDate, 1) \n \n ) \n ) \n WHERE (o.location_id =:location or parent_location =:location) \n)\n','2019-02-27 10:49:11',4,'2019-02-27 10:50:14',4,0,NULL,NULL,NULL,'5f4b2a04-8b0c-4add-b7c9-7b70515f603d'),(441,'clients seen 2 to 6mnths ago','composition','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n clients seen 2 to 6mnths ago\n composition\n \n 2019-02-27 10:59:28 UTC\n \n 2019-02-27 14:18:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 441\n clients-seen-3months-ago OR clients-seen-2months-ago\n \n \n clients-seen-3months-ago\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2019-02-27 10:59:28',4,'2019-02-27 14:18:26',4,0,NULL,NULL,NULL,'8f521b14-95ad-4e4c-b03d-10c0b7b3a0aa'),(442,'Clients on ARV who died','Clients on ARV who died','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients on ARV who died\n Clients on ARV who died\n \n 2019-03-29 06:48:55 UTC\n \n 2022-04-28 08:21:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 442\n select person_id \n from person \n where death_date <= CAST(:endDate AS DATE) \n AND MONTH(death_date) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(death_date) = YEAR(CAST(:endDate AS DATE)) \n and dead = 1\n','2019-03-29 06:48:55',4,'2022-04-28 08:21:40',4,0,NULL,NULL,NULL,'914d4f42-66e2-4fce-b1da-d3fce7f95f15'),(443,'Clients given 2weeks ARV','Clients given 2weeks ARV','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 2weeks ARV\n Clients given 2weeks ARV\n \n 2019-03-29 07:53:59 UTC\n \n 2019-03-29 07:57:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 443\n select distinct Id from( \nselect distinct Id from \n( \n (select distinct o.person_id AS Id \n from obs o \n inner join location l on o.location_id = l.location_id \n where (o.location_id = :location or parent_location = :location) \n and o.concept_id = 2250 \n and o.value_coded in (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n and o.person_id in ( \n select distinct o.person_id \n from obs o \n where (o.concept_id = 4174 and o.value_coded = 4243) \n and obs_datetime BETWEEN :startDate and DATE_ADD(:endDate, INTERVAL 1 DAY) \n ) \n \n and o.voided = 0 \n and obs_datetime BETWEEN :startDate and DATE_ADD(:endDate, INTERVAL 1 DAY) \n ) \n UNION \n(select distinct patient.patient_id AS Id \n from obs o \n INNER JOIN patient ON o.person_id = patient.patient_id \n INNER JOIN location l on o.location_id = l.location_id \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -28 DAY)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -28 DAY)) \n AND patient.voided = 0 AND o.voided = 0 \n AND (o.concept_id = 4174 and o.value_coded = 4243) \n AND o.person_id in ( \n select distinct os.person_id from obs os \n INNER JOIN patient ON os.person_id = patient.patient_id \n INNER JOIN location l on os.location_id = l.location_id \n where MONTH(os.obs_datetime) = MONTH(DATE_ADD(:endDate, INTERVAL -28 DAY)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(:endDate, INTERVAL -28 DAY)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, :endDate) BETWEEN 0 AND 28 \n AND (os.location_id = :location or parent_location = :location ) \n ) \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n WHERE (o.location_id = :location or parent_location = :location ) \n and o.person_id in( \n select distinct person_id from obs os \n where os.concept_id = 2250 \n and os.value_coded in (2201,2203,2205,2207,3672,3673,2210,2209,3674,3675,3676,3677,3683,3684,3685,2202,2204,3679,3680,3681,3682,3686,2143) \n ) \n ) \n) as regimen \nwhere Id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < DATE_ADD(:endDate, INTERVAL 1 DAY)) \n ) \nAND Id not in ( \n select person_id \n from person \n where death_date < DATE_ADD(:endDate, INTERVAL 1 DAY) \n and dead = 1 \n ) \n )as final\n','2019-03-29 07:53:59',4,'2019-03-29 07:57:45',4,0,NULL,NULL,NULL,'d8bb0175-47c0-461b-b457-498c8ef3cf27'),(445,'Total 1F Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Total 1F Data Set\n \n 2019-04-24 08:11:13 UTC\n \n 2019-04-24 08:14:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 445\n \n \n DM_Sex\n \n \n \n \n \n \n \n \n 1Line1fF\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n \n \n \n 1stLine1FM\n \n \n \n \n DM_Sex\n Males\n \n \n \n \n \n','2019-04-24 08:11:13',4,'2019-04-24 08:14:21',4,0,NULL,NULL,NULL,'9169293f-f54e-4905-a477-15f43395d28a'),(446,'SQL Version Total Clients Registered for ART','SQL Version Total Clients Registered for ART','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n SQL Version Total Clients Registered for ART\n SQL Version Total Clients Registered for ART\n \n 2019-07-10 12:51:51 UTC\n \n 2019-07-14 09:11:43 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n 446\n SELECT DISTINCT p.person_id as id \nFROM visit v \n JOIN person p on p.person_id = v.patient_id \n JOIN patient_identifier pi on v.patient_id = pi.patient_id and pi.identifier_type=5 \n JOIN encounter en on en.visit_id = v.visit_id and en.voided=0 \n JOIN obs o on o.encounter_id=en.encounter_id \n JOIN location l on v.location_id = l.location_id and l.retired=0 \n and (l.location_id=:location or l.parent_location =:location) \nWHERE en.encounter_datetime <= :endDate and o.date_created <= :endDate \n \n\n','2019-07-10 14:51:51',4,'2019-07-14 11:11:43',4,0,NULL,NULL,NULL,'dabb33fe-f6f9-479c-82a0-d93c5a681b36'),(447,'SQL Version Total Registered ART Client with Intakes captured','SQL Version Total Registered ART Client with Intakes captured','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n SQL Version Total Registered ART Client with Intakes captured\n SQL Version Total Registered ART Client with Intakes captured\n \n 2019-07-11 01:08:18 UTC\n \n 2019-07-12 10:30:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 447\n SELECT DISTINCT p.person_id as id \nFROM visit v \n JOIN person p on p.person_id = v.patient_id \n JOIN patient_identifier pi on v.patient_id = pi.patient_id and pi.identifier_type=5 \n JOIN encounter en on en.visit_id = v.visit_id and en.voided=0 \n JOIN obs o on o.encounter_id=en.encounter_id and o.concept_id=2249 \n JOIN location l on v.location_id = l.location_id and l.retired=0 \n and (l.location_id=:location or l.parent_location =:location) \nWHERE en.encounter_datetime <= :endDate and o.date_created <= :endDate \n \n\n','2019-07-11 03:08:18',4,'2019-07-12 12:30:48',4,0,NULL,NULL,NULL,'f7926250-cdd1-4446-9106-bfe81ce908f5'),(448,'CI36: Total Registered ART Clients','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI36: Total Registered ART Clients\n \n \n 2019-07-11 01:17:50 UTC\n \n 2019-07-11 01:21:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 448\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-07-11 03:17:50',4,'2019-07-11 03:21:53',4,0,NULL,NULL,NULL,'860c7123-a8a4-46d1-8c5e-2c33ac1a2632'),(449,'CI37: Total Registered ART Clients with Intakes Captured','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI37: Total Registered ART Clients with Intakes Captured\n \n \n 2019-07-11 01:19:42 UTC\n \n 2019-07-11 01:22:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 449\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-07-11 03:19:42',4,'2019-07-11 03:22:26',4,0,NULL,NULL,NULL,'817d04b5-b407-4ede-a59a-8eac041616cd'),(450,'PIR13: Registered ART Clients with Intakes Progress Report','Period Indicator report for all ART client registered who have their intake form captured in eRegister','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR13: Registered ART Clients with Intakes Progress Report\n Period Indicator report for all ART client registered who have their intake form captured in eRegister\n \n 2019-07-11 01:24:13 UTC\n \n 2019-07-11 02:03:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 450\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2019-07-11 03:24:13',4,'2019-07-11 04:03:08',4,0,NULL,NULL,NULL,'987a79c2-7ba9-47ff-8623-984851a6ae0e'),(451,'Total Registered ART Clients with Intakes Progress Report Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Total Registered ART Clients with Intakes Progress Report Data Set\n \n 2019-07-11 01:24:17 UTC\n \n 2019-07-11 01:26:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 451\n \n \n \n IntakesReg\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n Registered\n \n \n \n \n \n \n \n \n \n','2019-07-11 03:24:17',4,'2019-07-11 03:26:20',4,0,NULL,NULL,NULL,'78f64364-5e5a-4ddd-aba9-b27bda9fe14d'),(452,'SQL Version Total ART Clients with Registered Visits','SQL Version Total ART Clients with Registered Visits','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n SQL Version Total ART Clients with Registered Visits\n SQL Version Total ART Clients with Registered Visits\n \n 2019-07-14 09:03:29 UTC\n \n 2019-07-14 09:37:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 452\n SELECT DISTINCT p.person_id \nFROM visit v \n JOIN person p on p.person_id = v.patient_id \n JOIN patient_identifier pi on v.patient_id = pi.patient_id and pi.identifier_type=5 \n JOIN encounter en on en.visit_id = v.visit_id and en.voided=0 and en.encounter_type = 2 \n JOIN obs o on o.encounter_id=en.encounter_id \n JOIN location l on v.location_id = l.location_id and l.retired=0 \n and (l.location_id=:location or l.parent_location =:location) \nWHERE en.encounter_datetime >= :startDate and en.encounter_datetime <= :endDate \n \n\n','2019-07-14 11:03:29',4,'2019-07-14 11:37:46',4,0,NULL,NULL,NULL,'0181b364-876e-4307-bd8c-e986ea00f614'),(453,'SQL Version Clients with Visits with Consultations','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n SQL Version Clients with Visits with Consultations\n \n \n 2019-07-14 09:14:07 UTC\n \n 2019-07-14 09:18:02 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 453\n SELECT DISTINCT p.person_id as id \nFROM visit v \n JOIN person p on p.person_id = v.patient_id \n JOIN patient_identifier pi on v.patient_id = pi.patient_id and pi.identifier_type=5 \n JOIN encounter en on en.visit_id = v.visit_id and en.voided=0 and en.encounter_type = 1 \n JOIN obs o on o.encounter_id=en.encounter_id and o.concept_id=3843 \n JOIN location l on v.location_id = l.location_id and l.retired=0 \n and (l.location_id=:location or l.parent_location =:location) \nWHERE en.encounter_datetime >= :startDate and en.encounter_datetime <= :endDate \n \n\n','2019-07-14 11:14:07',4,'2019-07-14 11:18:02',4,0,NULL,NULL,NULL,'08bfa6d5-d894-4fc1-8bb2-2db094829434'),(454,'CI38: Total ART Clients with Visits','Total ART Clients with Visits','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI38: Total ART Clients with Visits\n Total ART Clients with Visits\n \n 2019-07-14 09:25:12 UTC\n \n 2019-07-14 09:25:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 454\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-07-14 11:25:12',4,'2019-07-14 11:25:52',4,0,NULL,NULL,NULL,'9250be3a-1ae9-421e-9504-2bd10456a657'),(455,'CI39: Visiting ART Clients with Consultations','Visiting ART Clients with Consultations','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI39: Visiting ART Clients with Consultations\n Visiting ART Clients with Consultations\n \n 2019-07-14 09:26:59 UTC\n \n 2019-07-14 09:27:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 455\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2019-07-14 11:26:59',4,'2019-07-14 11:27:44',4,0,NULL,NULL,NULL,'4eccec5c-c7a8-436e-acec-88ed04f477cc'),(456,'PIR14: Total ART Clients with Consultations Process Report','Total ART Clients with Consultations Process Report','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR14: Total ART Clients with Consultations Process Report\n Total ART Clients with Consultations Process Report\n \n 2019-07-14 09:29:43 UTC\n \n 2019-07-14 09:29:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 456\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2019-07-14 11:29:43',4,'2019-07-14 11:29:46',4,0,NULL,NULL,NULL,'d45c4571-c987-4271-8012-ad3e6e693d3d'),(457,'PIR14: Total ART Clients with Consultations Process Report Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PIR14: Total ART Clients with Consultations Process Report Data Set\n \n 2019-07-14 09:29:46 UTC\n \n 2021-12-16 12:12:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 457\n \n \n \n ARTConsult\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n ARTVisits\n \n \n \n \n \n \n \n \n \n Pending1mn\n \n \n \n \n \n \n \n \n \n Pending2mn\n \n \n \n \n \n \n \n \n \n Pending3mn\n \n \n \n \n \n \n \n \n \n TPTComplet\n \n \n \n \n \n \n \n \n \n TPTContinu\n \n \n \n \n \n \n \n \n \n TPTStarted\n \n \n \n \n \n \n \n \n \n VLDraws3mn\n \n \n \n \n \n \n \n \n \n VLResul3mn\n \n \n \n \n \n \n \n \n \n VLResults\n \n \n \n \n \n \n \n \n \n','2019-07-14 11:29:46',4,'2021-12-16 14:12:13',4,0,NULL,NULL,NULL,'80c015cc-fa7f-4423-ad3f-07e7838ed1cb'),(458,'PITC','PITC section of HTS form','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PITC\n PITC section of HTS form\n \n 2020-04-24 12:00:15 UTC\n \n 2020-04-24 12:00:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 458\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-04-24 12:00:15',4,'2020-04-24 12:00:18',4,0,NULL,NULL,NULL,'6bca981c-5d78-4a63-84e4-9185ea3356e9'),(459,'PITC Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PITC Data Set\n \n 2020-04-24 12:00:18 UTC\n \n 2020-05-11 07:42:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 459\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n PInewNe14F\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n PInewNe14M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n PInewNe19F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n PInewNe19M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n PInewNe24F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n PInewNe24M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n PInewNe29F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 25to29yrs\n \n \n \n \n \n PInewNe29M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 25to29yrs\n \n \n \n \n \n PInewNe34F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 30to34yrs\n \n \n \n \n \n PInewNe34M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 30to34yrs\n \n \n \n \n \n PInewNe39F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 35to39yrs\n \n \n \n \n \n PInewNe39M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 35to39yrs\n \n \n \n \n \n PInewNe44F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 40to44yrs\n \n \n \n \n \n PInewNe44M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 40to44yrs\n \n \n \n \n \n PInewNe49F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 45to49yrs\n \n \n \n \n \n PInewNe49M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 45to49yrs\n \n \n \n \n \n PInewNe50F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 50to100yrs\n \n \n \n \n \n PInewNe50M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 50to100yrs\n \n \n \n \n \n PInewNeg1F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n PInewNeg1M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n PInewNeg4F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n PInewNeg4M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n PInewNeg9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 05to09yrs\n \n \n \n \n \n PInewNeg9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 05to09yrs\n \n \n \n \n \n PInewPo14F\n \n \n \n \n \n \n \n \n \n PInewPo14M\n \n \n \n \n \n \n PInewPo19F\n \n \n \n \n \n \n PInewPo19M\n \n \n \n \n \n \n PInewPo24F\n \n \n \n \n \n \n PInewPo24M\n \n \n \n \n \n \n PInewPo29F\n \n \n \n \n \n \n PInewPo29M\n \n \n \n \n \n \n PInewPo34F\n \n \n \n \n \n \n PInewPo34M\n \n \n \n \n \n \n PInewPo39F\n \n \n \n \n \n \n PInewPo39M\n \n \n \n \n \n \n PInewPo44F\n \n \n \n \n \n \n PInewPo44M\n \n \n \n \n \n \n PInewPo49F\n \n \n \n \n \n \n PInewPo49M\n \n \n \n \n \n \n PInewPo50F\n \n \n \n \n \n \n PInewPo50M\n \n \n \n \n \n \n PInewPos1F\n \n \n \n \n \n \n PInewPos1M\n \n \n \n \n \n \n PInewPos4F\n \n \n \n \n \n \n PInewPos4M\n \n \n \n \n \n \n PInewPos9F\n \n \n \n \n \n \n PInewPos9M\n \n \n \n \n \n \n PIrepNe14F\n \n \n \n \n \n \n \n \n \n PIrepNe14M\n \n \n \n \n \n \n PIrepNe19F\n \n \n \n \n \n \n PIrepNe19M\n \n \n \n \n \n \n PIrepNe24F\n \n \n \n \n \n \n PIrepNe24M\n \n \n \n \n \n \n PIrepNe29F\n \n \n \n \n \n \n PIrepNe29M\n \n \n \n \n \n \n PIrepNe34F\n \n \n \n \n \n \n PIrepNe34M\n \n \n \n \n \n \n PIrepNe39F\n \n \n \n \n \n \n PIrepNe39M\n \n \n \n \n \n \n PIrepNe44F\n \n \n \n \n \n \n PIrepNe44M\n \n \n \n \n \n \n PIrepNe49F\n \n \n \n \n \n \n PIrepNe49M\n \n \n \n \n \n \n PIrepNe50F\n \n \n \n \n \n \n PIrepNe50M\n \n \n \n \n \n \n PIrepNeg1F\n \n \n \n \n \n \n PIrepNeg1M\n \n \n \n \n \n \n PIrepNeg4F\n \n \n \n \n \n \n PIrepNeg4M\n \n \n \n \n \n \n PIrepNeg9F\n \n \n \n \n \n \n PIrepNeg9M\n \n \n \n \n \n \n PIrepPo14F\n \n \n \n \n \n \n \n \n \n PIrepPo14M\n \n \n \n \n \n \n PIrepPo19F\n \n \n \n \n \n \n PIrepPo19M\n \n \n \n \n \n \n PIrepPo24F\n \n \n \n \n \n \n PIrepPo24M\n \n \n \n \n \n \n PIrepPo29F\n \n \n \n \n \n \n PIrepPo29M\n \n \n \n \n \n \n PIrepPo34F\n \n \n \n \n \n \n PIrepPo34M\n \n \n \n \n \n \n PIrepPo39F\n \n \n \n \n \n \n PIrepPo39M\n \n \n \n \n \n \n PIrepPo44F\n \n \n \n \n \n \n PIrepPo44M\n \n \n \n \n \n \n PIrepPo49F\n \n \n \n \n \n \n PIrepPo49M\n \n \n \n \n \n \n PIrepPo50F\n \n \n \n \n \n \n PIrepPo50M\n \n \n \n \n \n \n PIrepPos1F\n \n \n \n \n \n \n PIrepPos1M\n \n \n \n \n \n \n PIrepPos4F\n \n \n \n \n \n \n PIrepPos4M\n \n \n \n \n \n \n PIrepPos9F\n \n \n \n \n \n \n PIrepPos9M\n \n \n \n \n \n \n','2020-04-24 12:00:18',4,'2020-05-11 07:42:03',4,0,NULL,NULL,NULL,'d6f4d251-130b-4380-aba8-ddfeae303d42'),(460,'PITC_New_Negative','PITC_New_Negative clients','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PITC_New_Negative\n PITC_New_Negative clients\n \n 2020-04-24 12:18:19 UTC\n \n 2021-07-22 18:12:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 460\n select distinct patient.patient_id AS Id \n \nfrom obs o \n-- HTS CLIENTS WITH NEGATIVE HIV STATUS BY SEX AND AGE \nINNER JOIN patient ON o.person_id = patient.patient_id \nAND o.concept_id = 2165 and o.value_coded = 1016 \nAND patient.voided = 0 AND o.voided = 0 \nAND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n \n-- PROVIDER INITIATED TESTING AND COUNSELING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 4228 and os.value_coded = 4227 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \n-- NEW TESTER, DOES NOT HAVE A HISTORY OF PREVIOUS TESTING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 2137 and os.value_coded = 2147 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \nINNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n-- Observations inside the HIV Testing and Couseling Form \nAND o.obs_group_id in ( \nselect og.obs_id from obs og where og.concept_id = 2385 \n) \ninner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location)\n','2020-04-24 17:48:19',4,'2021-07-22 23:42:46',4,0,NULL,NULL,NULL,'e9556cb4-8e7f-4de4-9384-0b1ebacad149'),(461,'PITC_New_Positive','new tested positive clients','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PITC_New_Positive\n new tested positive clients\n \n 2020-04-24 12:22:19 UTC\n \n 2021-07-22 18:14:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 461\n select distinct patient.patient_id AS Id \n \nfrom obs o \n-- HTS CLIENTS WITH HIV STATUS BY SEX AND AGE \nINNER JOIN patient ON o.person_id = patient.patient_id \nAND o.concept_id = 2165 and o.value_coded = 1738 \nAND patient.voided = 0 AND o.voided = 0 \nAND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n \n-- PROVIDER INITIATED TESTING AND COUNSELING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 4228 and os.value_coded = 4227 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \n-- NEW TESTER, DOES NOT HAVE A HISTORY OF PREVIOUS TESTING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 2137 and os.value_coded = 2147 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \nINNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n-- Observations inside the HIV Testing and Couseling Form \nAND o.obs_group_id in ( \nselect og.obs_id from obs og where og.concept_id = 2385 \n) \ninner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location)\n','2020-04-24 17:52:19',4,'2021-07-22 23:44:17',4,0,NULL,NULL,NULL,'1a4da7db-09d2-4d28-b38d-bed4cf703253'),(462,'PITC_Repeat_Negative','PITC repeat negative clients','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PITC_Repeat_Negative\n PITC repeat negative clients\n \n 2020-04-24 12:28:12 UTC\n \n 2021-07-22 18:15:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 462\n select distinct patient.patient_id AS Id \n \nfrom obs o \n-- HTS CLIENTS WITH NEGATIVE HIV STATUS BY SEX AND AGE \nINNER JOIN patient ON o.person_id = patient.patient_id \nAND o.concept_id = 2165 and o.value_coded = 1016 \nAND patient.voided = 0 AND o.voided = 0 \nAND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n \n-- PROVIDER INITIATED TESTING AND COUNSELING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 4228 and os.value_coded = 4227 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \n-- REPEAT TESTER, AVE A HISTORY OF PREVIOUS TESTING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 2137 and os.value_coded = 2146 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \nINNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n-- Observations inside the HIV Testing and Couseling Form \nAND o.obs_group_id in ( \nselect og.obs_id from obs og where og.concept_id = 2385 \n) \ninner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location)\n','2020-04-24 17:58:12',4,'2021-07-22 23:45:21',4,0,NULL,NULL,NULL,'0750dd97-8565-4679-a1c2-052dc049f345'),(463,'PITC_Repeat_Positive','repeat positive clients','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PITC_Repeat_Positive\n repeat positive clients\n \n 2020-04-24 12:31:42 UTC\n \n 2021-07-22 18:16:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 463\n select distinct patient.patient_id AS Id \n \nfrom obs o \n-- HTS CLIENTS WITH POSITIVE HIV STATUS BY SEX AND AGE \nINNER JOIN patient ON o.person_id = patient.patient_id \nAND o.concept_id = 2165 and o.value_coded = 1738 \nAND patient.voided = 0 AND o.voided = 0 \nAND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n \n-- PROVIDER INITIATED TESTING AND COUNSELING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 4228 and os.value_coded = 4227 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \n-- REPEAT TESTER, AVE A HISTORY OF PREVIOUS TESTING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 2137 and os.value_coded = 2146 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \nINNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n-- Observations inside the HIV Testing and Couseling Form \nAND o.obs_group_id in ( \nselect og.obs_id from obs og where og.concept_id = 2385 \n) \ninner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location)\n','2020-04-24 18:01:42',4,'2021-07-22 23:46:15',4,0,NULL,NULL,NULL,'9bba9c3a-f886-477f-997f-a7325a668ee7'),(464,'PITC New Negative','PITC New Negative','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PITC New Negative\n PITC New Negative\n \n 2020-04-24 12:38:16 UTC\n \n 2020-04-24 12:39:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 464\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-04-24 12:38:16',4,'2020-04-24 12:39:14',4,0,NULL,NULL,NULL,'e4a53f3d-9351-4ba9-a039-c1f772b53b05'),(465,'PITC_New_Positive','new positives','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PITC_New_Positive\n new positives\n \n 2020-04-24 12:45:45 UTC\n \n 2020-04-24 12:46:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 465\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-04-24 12:45:45',4,'2020-04-24 12:46:35',4,0,NULL,NULL,NULL,'5038a34b-49da-411b-8bb9-bf7ea784fb7e'),(466,'PITC repeat negative','repeat clients who tested negative','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PITC repeat negative\n repeat clients who tested negative\n \n 2020-04-24 12:48:17 UTC\n \n 2020-04-24 12:49:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 466\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-04-24 12:48:17',4,'2020-04-24 12:49:08',4,0,NULL,NULL,NULL,'e951ced0-d54a-4614-ba74-27a78e8e18df'),(467,'PITC repeat positive','repeating clients who tested positive','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n PITC repeat positive\n repeating clients who tested positive\n \n 2020-04-24 12:50:04 UTC\n \n 2020-04-24 12:50:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 467\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-04-24 12:50:04',4,'2020-04-24 12:50:52',4,0,NULL,NULL,NULL,'e359947f-9dd8-490f-a1c2-056afb801816'),(468,'CITC_Repeat_Positive','repeat clients tested positve','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CITC_Repeat_Positive\n repeat clients tested positve\n \n 2020-04-27 05:28:31 UTC\n \n 2021-07-22 18:11:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 468\n select distinct patient.patient_id AS Id \n \nfrom obs o \n-- HTS CLIENTS WITH POSITIVE HIV STATUS BY SEX AND AGE \nINNER JOIN patient ON o.person_id = patient.patient_id \nAND o.concept_id = 2165 and o.value_coded = 1738 \nAND patient.voided = 0 AND o.voided = 0 \nAND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n \n-- CLIENT INITIATED TESTING AND COUNSELING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 4228 and os.value_coded = 4226 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \n-- REPEAT TESTER, HAVE A HISTORY OF PREVIOUS TESTING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 2137 and os.value_coded = 2146 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \nINNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n-- Observations inside the HIV Testing and Couseling Form \nAND o.obs_group_id in ( \nselect og.obs_id from obs og where og.concept_id = 2385 \n) \ninner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location)\n','2020-04-27 10:58:31',4,'2021-07-22 23:41:40',4,0,NULL,NULL,NULL,'3b0f9835-29a4-418d-aaa6-3f8f1d141ece'),(469,'CITC_Repeat_Negative','clients tested negative on repeat visit','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CITC_Repeat_Negative\n clients tested negative on repeat visit\n \n 2020-04-27 05:30:31 UTC\n \n 2021-07-22 18:10:47 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 469\n select distinct patient.patient_id AS Id \n \nfrom obs o \n-- HTS CLIENTS WITH NEGATIVE HIV STATUS BY SEX AND AGE \nINNER JOIN patient ON o.person_id = patient.patient_id \nAND o.concept_id = 2165 and o.value_coded = 1016 \nAND patient.voided = 0 AND o.voided = 0 \nAND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n \n-- CLIENT INITIATED TESTING AND COUNSELING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 4228 and os.value_coded = 4226 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \n-- REPEAT TESTER, HAVE A HISTORY OF PREVIOUS TESTING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 2137 and os.value_coded = 2146 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \nINNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n-- Observations inside the HIV Testing and Couseling Form \nAND o.obs_group_id in ( \nselect og.obs_id from obs og where og.concept_id = 2385 \n) \ninner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location)\n','2020-04-27 11:00:31',4,'2021-07-22 23:40:47',4,0,NULL,NULL,NULL,'a4daa5d2-8e61-44d1-bc37-1b6aba7a6d55'),(470,'CITC_New_Positive','new clients tested positive','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CITC_New_Positive\n new clients tested positive\n \n 2020-04-27 05:33:15 UTC\n \n 2021-07-22 18:09:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 470\n select distinct patient.patient_id AS Id \n \nfrom obs o \n-- HTS CLIENTS WITH POSITIVE HIV STATUS BY SEX AND AGE \nINNER JOIN patient ON o.person_id = patient.patient_id \nAND o.concept_id = 2165 and o.value_coded = 1738 \nAND patient.voided = 0 AND o.voided = 0 \nAND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n \n-- CLIENT INITIATED TESTING AND COUNSELING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 4228 and os.value_coded = 4226 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \n-- NEW TESTER, AVE A HISTORY OF PREVIOUS TESTING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 2137 and os.value_coded = 2147 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \nINNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n-- Observations inside the HIV Testing and Couseling Form \nAND o.obs_group_id in ( \nselect og.obs_id from obs og where og.concept_id = 2385 \n) \ninner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location)\n','2020-04-27 11:03:15',4,'2021-07-22 23:39:48',4,0,NULL,NULL,NULL,'9cd47068-2982-4ca1-a040-bc19ca313349'),(471,'CITC_New_Negative','clients tested negative','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CITC_New_Negative\n clients tested negative\n \n 2020-04-27 05:37:47 UTC\n \n 2021-07-22 18:05:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 471\n Select distinct patient.patient_id AS Id \n \nfrom obs o \n-- HTS CLIENTS WITH NEGATIVE HIV STATUS BY SEX AND AGE \nINNER JOIN patient ON o.person_id = patient.patient_id \nAND o.concept_id = 2165 and o.value_coded = 1016 \nAND patient.voided = 0 AND o.voided = 0 \nAND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n \n-- CLIENT INITIATED TESTING AND COUNSELING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 4228 and os.value_coded = 4226 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \n-- NEW TESTER, AVE A HISTORY OF PREVIOUS TESTING \nAND o.person_id in ( \nselect distinct os.person_id \nfrom obs os \nwhere os.concept_id = 2137 and os.value_coded = 2147 \nAND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \nAND patient.voided = 0 AND o.voided = 0 \n) \n \nINNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n-- Observations inside the HIV Testing and Couseling Form \nAND o.obs_group_id in ( \nselect og.obs_id from obs og where og.concept_id = 2385 \n) \ninner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location)\n','2020-04-27 11:07:47',4,'2021-07-22 23:35:11',4,0,NULL,NULL,NULL,'ebf8843c-2e45-4156-8bbf-867273775513'),(472,'CITC New Positive','CITC New Positive','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CITC New Positive\n CITC New Positive\n \n 2020-04-27 05:39:50 UTC\n \n 2020-04-27 05:41:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 472\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-04-27 05:39:50',4,'2020-04-27 05:41:21',4,0,NULL,NULL,NULL,'512d2da0-391c-4ec8-b8cc-d9f3028bf456'),(473,'CITC New Negative','CITC New Negative','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CITC New Negative\n CITC New Negative\n \n 2020-04-27 05:42:28 UTC\n \n 2020-04-27 05:44:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 473\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-04-27 05:42:28',4,'2020-04-27 05:44:08',4,0,NULL,NULL,NULL,'2c87a371-a86c-4980-aade-4303463e95a5'),(474,'CITC Repeat Positive','CITC Repeat Positive','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CITC Repeat Positive\n CITC Repeat Positive\n \n 2020-04-27 05:46:33 UTC\n \n 2020-04-27 05:47:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 474\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-04-27 05:46:33',4,'2020-04-27 05:47:32',4,0,NULL,NULL,NULL,'71f59662-0e07-40f6-9c6c-0570bc3ef36f'),(475,'CITC Repeat Negative','CITC Repeat Negative','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CITC Repeat Negative\n CITC Repeat Negative\n \n 2020-04-27 05:50:11 UTC\n \n 2020-04-27 05:54:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 475\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-04-27 05:50:11',4,'2020-04-27 05:54:46',4,0,NULL,NULL,NULL,'e42b4a1d-bc07-4ab9-b60b-30896100d112'),(476,'CITC','Client Initiated Testing and Counseling section of HTS form','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CITC\n Client Initiated Testing and Counseling section of HTS form\n \n 2020-04-27 05:56:14 UTC\n \n 2020-04-27 05:56:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 476\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-04-27 05:56:14',4,'2020-04-27 05:56:21',4,0,NULL,NULL,NULL,'87d3cf9f-40bc-4516-960e-03c17a6b6a09'),(477,'CITC Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CITC Data Set\n \n 2020-04-27 05:56:21 UTC\n \n 2020-04-27 10:39:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 477\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n CInewNe14F\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n CInewNe14M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n CInewNe19F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n CInewNe19M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n CInewNe24F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n CInewNe24M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n CInewNe29F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 25to29yrs\n \n \n \n \n \n CInewNe29M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 25to29yrs\n \n \n \n \n \n CInewNe34F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 30to34yrs\n \n \n \n \n \n CInewNe34M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 30to34yrs\n \n \n \n \n \n CInewNe39F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 35to39yrs\n \n \n \n \n \n CInewNe39M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 35to39yrs\n \n \n \n \n \n CInewNe44F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 40to44yrs\n \n \n \n \n \n CInewNe44M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 40to44yrs\n \n \n \n \n \n CInewNe49F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 45to49yrs\n \n \n \n \n \n CInewNe49M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 45to49yrs\n \n \n \n \n \n CInewNe50F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 50to100yrs\n \n \n \n \n \n CInewNe50M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 50to100yrs\n \n \n \n \n \n CInewNeg1F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n CInewNeg1M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n CInewNeg4F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n CInewNeg4M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n CInewNeg9F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 05to09yrs\n \n \n \n \n \n CInewNeg9M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 05to09yrs\n \n \n \n \n \n CInewPo14F\n \n \n \n \n \n \n \n \n \n CInewPo14M\n \n \n \n \n \n \n CInewPo19F\n \n \n \n \n \n \n CInewPo19M\n \n \n \n \n \n \n CInewPo24F\n \n \n \n \n \n \n CInewPo24M\n \n \n \n \n \n \n CInewPo29F\n \n \n \n \n \n \n CInewPo29M\n \n \n \n \n \n \n CInewPo34F\n \n \n \n \n \n \n CInewPo34M\n \n \n \n \n \n \n CInewPo39F\n \n \n \n \n \n \n CInewPo39M\n \n \n \n \n \n \n CInewPo44F\n \n \n \n \n \n \n CInewPo44M\n \n \n \n \n \n \n CInewPo49F\n \n \n \n \n \n \n CInewPo49M\n \n \n \n \n \n \n CInewPo50F\n \n \n \n \n \n \n CInewPo50M\n \n \n \n \n \n \n CInewPos1F\n \n \n \n \n \n \n CInewPos1M\n \n \n \n \n \n \n CInewPos4F\n \n \n \n \n \n \n CInewPos4M\n \n \n \n \n \n \n CInewPos9F\n \n \n \n \n \n \n CInewPos9M\n \n \n \n \n \n \n CIrepNe14F\n \n \n \n \n \n \n \n \n \n CIrepNe14M\n \n \n \n \n \n \n CIrepNe19F\n \n \n \n \n \n \n CIrepNe19M\n \n \n \n \n \n \n CIrepNe24F\n \n \n \n \n \n \n CIrepNe24M\n \n \n \n \n \n \n CIrepNe29F\n \n \n \n \n \n \n CIrepNe29M\n \n \n \n \n \n \n CIrepNe34F\n \n \n \n \n \n \n CIrepNe34M\n \n \n \n \n \n \n \n \n \n CIrepNe39F\n \n \n \n \n \n \n CIrepNe39M\n \n \n \n \n \n \n CIrepNe44F\n \n \n \n \n \n \n CIrepNe44M\n \n \n \n \n \n \n CIrepNe49F\n \n \n \n \n \n \n CIrepNe49M\n \n \n \n \n \n \n CIrepNe50F\n \n \n \n \n \n \n CIrepNe50M\n \n \n \n \n \n \n CIrepNeg1F\n \n \n \n \n \n \n CIrepNeg1M\n \n \n \n \n \n \n CIrepNeg4F\n \n \n \n \n \n \n CIrepNeg4M\n \n \n \n \n \n \n CIrepNeg9F\n \n \n \n \n \n \n CIrepNeg9M\n \n \n \n \n \n \n CIrepPo14F\n \n \n \n \n \n \n CIrepPo14M\n \n \n \n \n \n \n CIrepPo19F\n \n \n \n \n \n \n CIrepPo19M\n \n \n \n \n \n \n CIrepPo24F\n \n \n \n \n \n \n CIrepPo24M\n \n \n \n \n \n \n CIrepPo29F\n \n \n \n \n \n \n CIrepPo29M\n \n \n \n \n \n \n CIrepPo34F\n \n \n \n \n \n \n CIrepPo34M\n \n \n \n \n \n \n CIrepPo39F\n \n \n \n \n \n \n CIrepPo39M\n \n \n \n \n \n \n CIrepPo44F\n \n \n \n \n \n \n CIrepPo44M\n \n \n \n \n \n \n CIrepPo49F\n \n \n \n \n \n \n CIrepPo49M\n \n \n \n \n \n \n CIrepPo50F\n \n \n \n \n \n \n CIrepPo50M\n \n \n \n \n \n \n CIrepPos1F\n \n \n \n \n \n \n CIrepPos1M\n \n \n \n \n \n \n CIrepPos4F\n \n \n \n \n \n \n CIrepPos4M\n \n \n \n \n \n \n CIrepPos9F\n \n \n \n \n \n \n CIrepPos9M\n \n \n \n \n \n \n','2020-04-27 05:56:21',4,'2020-04-27 10:39:40',4,0,NULL,NULL,NULL,'3b4a124e-e541-4655-bce1-07595881f037'),(478,'HTS Indeterminate','total inderminate results','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Indeterminate\n total inderminate results\n \n 2020-05-03 10:54:09 UTC\n \n 2020-05-03 10:55:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 478\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand (o.concept_id = 4223 and value_coded = 4220) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2020-05-03 10:54:09',4,'2020-05-03 10:55:12',4,0,NULL,NULL,NULL,'9d8d2a02-6b1b-4f6f-9897-7f2440d60bf5'),(479,'HTS Couple','couples','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Couple\n couples\n \n 2020-05-03 10:58:12 UTC\n \n 2020-05-03 10:59:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 479\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand (o.concept_id = 2166 and value_coded = 2146) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2020-05-03 10:58:12',4,'2020-05-03 10:59:17',4,0,NULL,NULL,NULL,'361c4fa5-4375-42da-935b-00cf7a975167'),(480,'HTS Discordant','Discordant test results','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Discordant\n Discordant test results\n \n 2020-05-03 11:00:30 UTC\n \n 2022-03-17 08:39:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 480\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand concept_id = 2164 \nand person_id in (select person_id from obs where (concept_id = 4225 and value_coded = 2146) \n and obs_datetime >=:startDate \n and obs_datetime <=:endDate \n ) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2020-05-03 11:00:30',4,'2022-03-17 08:39:24',4,0,NULL,NULL,NULL,'49027ad5-be0a-45f5-af20-0926fb6adec9'),(481,'HTS Screened','Clients screened for TB','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Screened\n Clients screened for TB\n \n 2020-05-03 11:05:45 UTC\n \n 2020-05-03 11:06:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 481\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand (o.concept_id = 2294 and value_coded = 2146) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2020-05-03 11:05:45',4,'2020-05-03 11:06:26',4,0,NULL,NULL,NULL,'3aadefe4-1302-4fff-a140-55a0a634f093'),(482,'HTS Male Condoms','Male condoms distributed','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Male Condoms\n Male condoms distributed\n \n 2020-05-03 11:07:57 UTC\n \n 2020-05-03 11:12:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 482\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand (o.concept_id = 4231 and value_coded = 4229) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2020-05-03 11:07:57',4,'2020-05-03 11:12:28',4,0,NULL,NULL,NULL,'9b9b6440-4e3a-4bc4-93eb-e52f32f36cc8'),(483,'HTS Female Condoms','Female condoms distributed','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Female Condoms\n Female condoms distributed\n \n 2020-05-03 11:13:25 UTC\n \n 2020-05-03 11:14:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 483\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand (o.concept_id = 4231 and value_coded = 4230) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2020-05-03 11:13:25',4,'2020-05-03 11:14:03',4,0,NULL,NULL,NULL,'18f0954d-4c76-4a30-92e8-306c93bb1b98'),(484,'HTS Confirmatory Negative','COnfirmatory test results negative','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Confirmatory Negative\n COnfirmatory test results negative\n \n 2020-05-03 11:18:07 UTC\n \n 2020-05-03 11:19:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 484\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand (o.concept_id = 2161 and value_coded = 1016) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2020-05-03 11:18:07',4,'2020-05-03 11:19:20',4,0,NULL,NULL,NULL,'1ec73fb7-2046-4706-bb66-109eb6ec94c3'),(485,'HTS Confirmatory Positive','Confirmatory test results positive','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Confirmatory Positive\n Confirmatory test results positive\n \n 2020-05-03 11:21:28 UTC\n \n 2020-05-03 11:22:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 485\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand (o.concept_id = 2161 and value_coded = 1738) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2020-05-03 11:21:28',4,'2020-05-03 11:22:06',4,0,NULL,NULL,NULL,'78a1c404-42d9-469d-9220-b873114308c2'),(486,'HTS SelfTest Kits','HIVST confirmed HIV positive','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS SelfTest Kits\n HIVST confirmed HIV positive\n \n 2020-05-03 11:23:54 UTC\n \n 2020-05-03 11:26:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 486\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand (o.concept_id = 2161 and value_coded = 1738) \nand person_id in (select person_id \nfrom obs \nwhere concept_id = 4662 and value_coded = 4237 \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2020-05-03 11:23:54',4,'2020-05-03 11:26:06',4,0,NULL,NULL,NULL,'1377634a-611f-45c3-b42b-0ff16dec16eb'),(487,'HTS Indeterminate','total indeterminate results','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Indeterminate\n total indeterminate results\n \n 2020-05-03 19:06:01 UTC\n \n 2020-05-03 19:07:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 487\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-05-03 19:06:01',4,'2020-05-03 19:07:14',4,0,NULL,NULL,NULL,'cbc0f41b-11d1-42c5-819d-2b256a192c7a'),(488,'HTS Couple','Couples only','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Couple\n Couples only\n \n 2020-05-03 19:09:15 UTC\n \n 2020-05-03 19:09:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 488\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-05-03 19:09:15',4,'2020-05-03 19:09:57',4,0,NULL,NULL,NULL,'4eae8f2e-2b61-4b25-91f4-027131d2a8e7'),(489,'HTS Discordant','Discordant test results','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Discordant\n Discordant test results\n \n 2020-05-03 19:12:07 UTC\n \n 2020-05-03 19:12:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 489\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-05-03 19:12:07',4,'2020-05-03 19:12:54',4,0,NULL,NULL,NULL,'42279637-8cd0-4097-8948-7ac931af776b'),(490,'HTS Screened','HTS clients screened for TB','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Screened\n HTS clients screened for TB\n \n 2020-05-03 19:13:57 UTC\n \n 2022-03-17 14:20:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 490\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-05-03 19:13:57',4,'2022-03-17 14:20:03',4,0,NULL,NULL,NULL,'80d07406-6d62-4289-8d32-887363807775'),(491,'HTS Female Condoms distributed','Condoms distributed','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Female Condoms distributed\n Condoms distributed\n \n 2020-05-03 19:18:56 UTC\n \n 2020-05-03 19:21:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 491\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-05-03 19:18:56',4,'2020-05-03 19:21:45',4,0,NULL,NULL,NULL,'9c177ce6-5697-4b84-9093-8e30ac78e3e3'),(492,'HTS Male Condoms','Male condoms distributed','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Male Condoms\n Male condoms distributed\n \n 2020-05-03 19:22:24 UTC\n \n 2020-05-03 19:23:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 492\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-05-03 19:22:24',4,'2020-05-03 19:23:18',4,0,NULL,NULL,NULL,'5c760a04-22f9-40aa-94a5-397340c8b638'),(493,'HTS Confirmatory Negative','Confirmatory Negative','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Confirmatory Negative\n Confirmatory Negative\n \n 2020-05-03 19:24:40 UTC\n \n 2020-05-03 19:25:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 493\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-05-03 19:24:40',4,'2020-05-03 19:25:28',4,0,NULL,NULL,NULL,'f1f06a0f-0afb-4aaa-8542-dd54ff94b6ce'),(494,'HTS Confirmatory Positive','Confirmatory Positive','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Confirmatory Positive\n Confirmatory Positive\n \n 2020-05-03 19:26:24 UTC\n \n 2020-05-03 19:27:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 494\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-05-03 19:26:24',4,'2020-05-03 19:27:46',4,0,NULL,NULL,NULL,'5fefbf51-d124-4c3d-a6bd-69bfb0b78f64'),(495,'HTS Self Test Kits','Self Test Kits','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Self Test Kits\n Self Test Kits\n \n 2020-05-03 19:29:29 UTC\n \n 2021-10-19 12:01:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 495\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-05-03 21:29:29',4,'2021-10-19 14:01:42',4,0,NULL,NULL,NULL,'89fdd6f1-5744-4a2b-9d08-00ef77bb50d8'),(496,'HTS Period Indicator Report','indeterminate,couples,discordant couples,screened for TB,Condoms distribution and confirmatory test results','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Period Indicator Report\n indeterminate,couples,discordant couples,screened for TB,Condoms distribution and confirmatory test results\n \n 2020-05-03 19:38:28 UTC\n \n 2020-05-03 19:38:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 496\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-05-03 19:38:28',4,'2020-05-03 19:38:31',4,0,NULL,NULL,NULL,'dafef277-1393-484d-a947-936a507e03a1'),(497,'HTS Period Indicator Report Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Period Indicator Report Data Set\n \n 2020-05-03 19:38:31 UTC\n \n 2020-05-26 13:54:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 497\n \n \n DM_Sex\n \n \n \n \n \n \n \n \n Confirm_N\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n Confirm_P\n \n \n \n \n \n \n \n \n \n Couples\n \n \n \n \n \n \n \n \n \n Discordant\n \n \n \n \n \n \n \n \n \n DistriCD_F\n \n \n \n \n \n \n \n \n \n DistriCD_M\n \n \n \n \n \n \n \n \n \n IND_result\n \n \n \n \n \n \n \n \n \n Indetermin\n \n \n \n \n \n \n \n \n \n Screened_F\n \n \n \n \n \n \n \n DM_Sex\n Females\n \n \n \n \n \n Screened_M\n \n \n \n \n DM_Sex\n Males\n \n \n \n \n \n','2020-05-03 19:38:31',4,'2020-05-26 13:54:52',4,0,NULL,NULL,NULL,'f25de016-f5c5-4638-b08c-ee3a31c63121'),(498,'HTS Self Test Report','Self Test Kits Distributed and Returned','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Self Test Report\n Self Test Kits Distributed and Returned\n \n 2020-05-03 19:50:04 UTC\n \n 2022-03-09 07:17:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 498\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-05-04 01:20:04',4,'2022-03-09 12:47:59',4,0,NULL,NULL,NULL,'92c28a1a-1d44-40b4-b11f-61a620cea4ea'),(499,'HTS Self Test Kits Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Self Test Kits Data Set\n \n 2020-05-03 19:50:07 UTC\n \n 2022-04-05 07:47:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 499\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n Dis10to14F\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n Dis10to14M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n Dis15+_M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n Dis15to19F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n Dis15to19M\n \n \n \n \n \n \n Dis20to24F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n Dis20to24M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n Dis25to29F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 25to29yrs\n \n \n \n \n \n Dis25to29M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 25to29yrs\n \n \n \n \n \n Dis30to34F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 30to34yrs\n \n \n \n \n \n Dis30to34M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 30to34yrs\n \n \n \n \n \n Dis35to39F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 35to39yrs\n \n \n \n \n \n Dis35to39M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 35to39yrs\n \n \n \n \n \n Dis40to44F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 40to44yrs\n \n \n \n \n \n Dis40to44M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 40to44yrs\n \n \n \n \n \n Dis45to49F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 45to49yrs\n \n \n \n \n \n Dis45to49M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 45to49yrs\n \n \n \n \n \n Dis50_F\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 50to100yrs\n \n \n \n \n \n Dis50_M\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 50to100yrs\n \n \n \n \n \n Po10to14_F\n \n \n \n \n \n \n \n \n \n Po10to14_M\n \n \n \n \n \n \n Po15to19_F\n \n \n \n \n \n \n Po15to19_M\n \n \n \n \n \n \n Po20to24_F\n \n \n \n \n \n \n Po20to24_M\n \n \n \n \n \n \n Po25to29_F\n \n \n \n \n \n \n Po25to29_M\n \n \n \n \n \n \n Po30to34_F\n \n \n \n \n \n \n Po30to34_M\n \n \n \n \n \n \n Po35to39_F\n \n \n \n \n \n \n Po35to39_M\n \n \n \n \n \n \n Po40to44_F\n \n \n \n \n \n \n Po40to44_M\n \n \n \n \n \n \n Po45to49_F\n \n \n \n \n \n \n Po45to49_M\n \n \n \n \n \n \n Po50_F\n \n \n \n \n \n \n Po50_M\n \n \n \n \n \n \n Ret10to14F\n \n \n \n \n \n \n \n \n \n Ret10to14M\n \n \n \n \n \n \n Ret15to19F\n \n \n \n \n \n \n Ret15to19M\n \n \n \n \n \n \n Ret20to24F\n \n \n \n \n \n \n Ret20to24M\n \n \n \n \n \n \n Ret25to29F\n \n \n \n \n \n \n Ret25to29M\n \n \n \n \n \n \n Ret30to34F\n \n \n \n \n \n \n Ret30to34M\n \n \n \n \n \n \n Ret35to39F\n \n \n \n \n \n \n Ret35to39M\n \n \n \n \n \n \n Ret40to44F\n \n \n \n \n \n \n Ret40to44M\n \n \n \n \n \n \n Ret45to49F\n \n \n \n \n \n \n Ret45to49M\n \n \n \n \n \n \n Ret50_F\n \n \n \n \n \n \n Ret50_M\n \n \n \n \n \n \n','2020-05-03 19:50:07',4,'2022-04-05 07:47:13',4,0,NULL,NULL,NULL,'613de36b-b418-42b6-b2db-37cd706fc3fd'),(500,'HTS Indeterminate results','results indeterminate','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Indeterminate results\n results indeterminate\n \n 2020-05-26 13:50:27 UTC\n \n 2020-05-26 13:53:47 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 500\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-05-26 13:50:27',4,'2020-05-26 13:53:47',4,0,NULL,NULL,NULL,'c15c5dfa-0d7e-463f-a69d-95576f0ebdba'),(501,'HTS Indeterminate results','results indeterminate','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n HTS Indeterminate results\n results indeterminate\n \n 2020-05-26 13:52:43 UTC\n \n 2020-05-26 13:52:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 501\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id =:location or parent_location =:location) \nand (o.concept_id = 4223 and value_coded = 4220) \nand obs_datetime >=:startDate \nand obs_datetime <=:endDate\n','2020-05-26 13:52:43',4,'2020-05-26 13:52:53',4,0,NULL,NULL,NULL,'e5b3353e-8bf6-483a-95a4-cc15c2df3ec9'),(502,'adult_arv_1c_1mnth','clients given 1month supply of 1c ','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_1mnth\n clients given 1month supply of 1c \n \n 2020-06-04 10:51:42 UTC\n \n 2020-06-04 11:05:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 502\n select distinct o.person_id \nfrom obs o \ninner join (select o.person_id \n from obs o \n inner join \n (select person_id,max(obs_datetime) maxdate \n from obs a \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2201 \n group by person_id \n )latest \n on latest.person_id = o.person_id \n where concept_id = 2250 and value_coded = 2201 \n and obs_datetime BETWEEN :startDate AND :endDate \n and o.obs_datetime = maxdate \n )b on b.person_id = o.person_id \ninner join \n (select o.person_id \n from obs o \n inner join \n (select person_id,max(obs_datetime) maxdate \n from obs a \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n group by person_id \n )latest \n on latest.person_id = o.person_id \n where concept_id = 4174 and value_coded = 4175 \n and obs_datetime BETWEEN :startDate AND :endDate \n and o.obs_datetime = maxdate) a on a.person_id = o.person_id \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0\n','2020-06-04 10:51:42',4,'2020-06-04 11:05:55',4,0,NULL,NULL,NULL,'0a6886b5-4642-4477-9218-319ed4782e1d'),(503,'adult_arv_1d_1mnth','clients given 1mnth supply of 1d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_1mnth\n clients given 1mnth supply of 1d\n \n 2020-06-04 11:07:29 UTC\n \n 2020-06-16 10:38:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 503\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2203 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:07:29',4,'2020-06-16 10:38:11',4,0,NULL,NULL,NULL,'d4cdfdf6-35b1-40bb-b177-9c226a164810'),(504,'adult_arv_1e_1mnth','clients given 1month supply of 1e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_1mnth\n clients given 1month supply of 1e\n \n 2020-06-04 11:11:23 UTC\n \n 2020-06-16 10:38:36 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 504\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2205 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:11:23',4,'2020-06-16 10:38:36',4,0,NULL,NULL,NULL,'3b4e39fc-f4d0-493e-b4e5-7effd305b929'),(505,'adult_arv_1f_1mnth','clients given 1month supply of 1f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_1mnth\n clients given 1month supply of 1f\n \n 2020-06-04 11:17:19 UTC\n \n 2020-11-20 10:16:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 505\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4175) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4175) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 2207)\n','2020-06-04 13:17:19',4,'2020-11-20 12:16:19',4,0,NULL,NULL,NULL,'f059b928-f6d1-4629-87ab-2c9f1c2d4166'),(506,'adult_arv_1g_1mnth','clients given 1month supply of 1g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_1mnth\n clients given 1month supply of 1g\n \n 2020-06-04 11:18:32 UTC\n \n 2020-06-16 10:42:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 506\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3672 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:18:32',4,'2020-06-16 10:42:06',4,0,NULL,NULL,NULL,'3badd804-dd17-4f9f-aee1-01ebab4449b9'),(507,'adult_arv_1h_1mnth','clients given 1month supply of 1h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_1mnth\n clients given 1month supply of 1h\n \n 2020-06-04 11:20:23 UTC\n \n 2020-06-16 10:42:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 507\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3673 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:20:23',4,'2020-06-16 10:42:34',4,0,NULL,NULL,NULL,'4263e276-f261-406b-bcd0-56cda9464190'),(508,'adult_arv_1j_1mnth','clients given 1 month supply of 1j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_1mnth\n clients given 1 month supply of 1j\n \n 2020-06-04 11:22:33 UTC\n \n 2020-11-20 10:56:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 508\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4175) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4175) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 4678)\n','2020-06-04 13:22:33',4,'2020-11-20 12:56:17',4,0,NULL,NULL,NULL,'dd8a7cca-c5ee-4aba-8064-4fbe4ab6b3f1'),(509,'adult_arv_1k_1mnth','clients given 1month supply of 1k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_1mnth\n clients given 1month supply of 1k\n \n 2020-06-04 11:23:48 UTC\n \n 2020-06-16 10:44:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 509\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4679 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:23:48',4,'2020-06-16 10:44:08',4,0,NULL,NULL,NULL,'2b7d8866-e84b-4ccf-9ffa-1707557910f1'); -INSERT INTO `serialized_object` VALUES (510,'adult_arv_1m_1mnth','clients given 1month supply of 1m','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_1mnth\n clients given 1month supply of 1m\n \n 2020-06-04 11:26:24 UTC\n \n 2020-06-16 10:45:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 510\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4680 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:26:24',4,'2020-06-16 10:45:33',4,0,NULL,NULL,NULL,'8b668641-8cd1-4710-9900-e14afa11d477'),(511,'adult_arv_1n_1mnth','clients given 1month supply of 1n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_1mnth\n clients given 1month supply of 1n\n \n 2020-06-04 11:27:29 UTC\n \n 2020-06-16 10:45:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 511\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4681 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:27:29',4,'2020-06-16 10:45:05',4,0,NULL,NULL,NULL,'a22dae13-6bc7-4d24-9e4d-a0fefab2c9fd'),(512,'adult_arv_1p_1mnth','clients given 1month supply of 1p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_1mnth\n clients given 1month supply of 1p\n \n 2020-06-04 11:30:16 UTC\n \n 2020-06-16 10:46:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 512\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4682 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:30:16',4,'2020-06-16 10:46:13',4,0,NULL,NULL,NULL,'a1837be3-878d-423d-8684-808738f28305'),(513,'adult_arv_1q_1mnth','clients given 1 month supply of 1q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_1mnth\n clients given 1 month supply of 1q\n \n 2020-06-04 11:31:28 UTC\n \n 2020-06-16 10:46:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 513\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4683 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:31:28',4,'2020-06-16 10:46:57',4,0,NULL,NULL,NULL,'c4e93e64-91fe-48e4-a432-8553a70a138b'),(514,'adult_arv_other_1mnth','clients given 1month supply of other arv','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_1mnth\n clients given 1month supply of other arv\n \n 2020-06-04 11:35:49 UTC\n \n 2020-06-16 10:48:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 514\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2143 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:35:49',4,'2020-06-16 10:48:03',4,0,NULL,NULL,NULL,'7c04bae3-26e2-44bb-9f14-46bd23abf3b7'),(515,'adult_arv_1c_3mnth','3mnths supply of 1c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_3mnth\n 3mnths supply of 1c\n \n 2020-06-04 11:41:08 UTC\n \n 2020-06-16 10:49:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 515\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2201 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 11:41:08',4,'2020-06-16 10:49:04',4,0,NULL,NULL,NULL,'238a43b6-79ac-46a7-907f-a1e351c5caaa'),(516,'adult_arv_1d_3mnth','3mnths supply of 1d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_3mnth\n 3mnths supply of 1d\n \n 2020-06-04 11:42:06 UTC\n \n 2020-06-16 10:49:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 516\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2203 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 11:42:06',4,'2020-06-16 10:49:30',4,0,NULL,NULL,NULL,'1e1e9500-f32d-4290-aab4-935a88bfe130'),(517,'adult_arv_1e_3mnth','3mnths supply of 1e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_3mnth\n 3mnths supply of 1e\n \n 2020-06-04 11:46:30 UTC\n \n 2020-06-16 10:49:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 517\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2205 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 11:46:30',4,'2020-06-16 10:49:53',4,0,NULL,NULL,NULL,'db80a24f-af5f-4553-bc8c-9958d082feb4'),(518,'adult_arv_1f_3mnth','3mnths supply of 1f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_3mnth\n 3mnths supply of 1f\n \n 2020-06-04 11:48:17 UTC\n \n 2020-11-20 10:53:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 518\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4177) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4177) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 2207)\n','2020-06-04 13:48:17',4,'2020-11-20 12:53:53',4,0,NULL,NULL,NULL,'22c820ef-4629-49cb-8ca1-bd2b25c3ff59'),(519,'adult_arv_1g_3mnth','3mnths supply of 1g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_3mnth\n 3mnths supply of 1g\n \n 2020-06-04 11:49:57 UTC\n \n 2020-06-16 10:51:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 519\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3672 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 11:49:57',4,'2020-06-16 10:51:22',4,0,NULL,NULL,NULL,'b048d9e0-11c1-4092-8c31-ba6e3acea989'),(520,'adult_arv_1h_3mnth','3mnths supply of 1h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_3mnth\n 3mnths supply of 1h\n \n 2020-06-04 11:55:26 UTC\n \n 2020-06-04 11:57:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 520\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3673 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 11:55:26',4,'2020-06-04 11:57:44',4,0,NULL,NULL,NULL,'1ff080c3-e4fb-4884-bcdb-431d8cf59157'),(521,'adult_arv_1j_3mnth','3mnths supply of 1j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_3mnth\n 3mnths supply of 1j\n \n 2020-06-04 11:59:08 UTC\n \n 2020-11-20 10:49:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 521\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4177) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4177) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 4678)\n','2020-06-04 13:59:08',4,'2020-11-20 12:49:56',4,0,NULL,NULL,NULL,'5ed7e3c1-afba-4802-a334-a611a9102cc5'),(522,'adult_arv_1k_3mnth','3mnths supply of 1k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_3mnth\n 3mnths supply of 1k\n \n 2020-06-04 13:10:45 UTC\n \n 2020-06-04 13:21:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 522\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4679 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:10:45',4,'2020-06-04 13:21:56',4,0,NULL,NULL,NULL,'5ee29b38-8294-44d6-bca4-6fd3a2e668ed'),(523,'adult_arv_1m_3mnth','3mnths supply of 1m','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_3mnth\n 3mnths supply of 1m\n \n 2020-06-04 13:23:09 UTC\n \n 2020-06-04 13:24:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 523\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4680 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:23:09',4,'2020-06-04 13:24:04',4,0,NULL,NULL,NULL,'063a7963-5a7f-4ab4-a444-0db599f8c5a8'),(524,'adult_arv_1n_3mnth','3mnths supply of 1n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_3mnth\n 3mnths supply of 1n\n \n 2020-06-04 13:25:04 UTC\n \n 2020-06-04 13:25:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 524\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4681 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:25:04',4,'2020-06-04 13:25:38',4,0,NULL,NULL,NULL,'03237de9-f7dc-4446-a8b0-07c73bbf780b'),(525,'adult_arv_1p_3mnth','3mnths supply of 1p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_3mnth\n 3mnths supply of 1p\n \n 2020-06-04 13:27:08 UTC\n \n 2020-06-04 13:27:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 525\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4682 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:27:08',4,'2020-06-04 13:27:34',4,0,NULL,NULL,NULL,'5224e59b-88b4-4586-81f5-11719fd1c1ee'),(526,'adult_arv_1q_3mnth','3mnths supply of 1q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_3mnth\n 3mnths supply of 1q\n \n 2020-06-04 13:30:23 UTC\n \n 2020-06-04 13:30:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 526\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4683 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:30:23',4,'2020-06-04 13:30:44',4,0,NULL,NULL,NULL,'9cc207d2-97db-47a0-8ff5-e687843138c8'),(527,'adult_arv_other_3mnth','3mnths supply of other regimen','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_3mnth\n 3mnths supply of other regimen\n \n 2020-06-04 13:34:17 UTC\n \n 2020-06-04 13:34:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 527\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4679 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:34:17',4,'2020-06-04 13:34:55',4,0,NULL,NULL,NULL,'4d6e10d0-413f-4647-941a-3ae707d69e4d'),(528,'adult_arv_1c_6mnth','6mnths supply of 1c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_6mnth\n 6mnths supply of 1c\n \n 2020-06-04 13:45:59 UTC\n \n 2020-06-05 07:42:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 528\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2201 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 15:45:59',4,'2020-06-05 09:42:05',4,0,NULL,NULL,NULL,'8f096880-4dfb-4ef9-9234-f1ad19ed9fbd'),(529,'adult_arv_1d_6mnth','6mnths supply of 1d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_6mnth\n 6mnths supply of 1d\n \n 2020-06-04 13:47:33 UTC\n \n 2020-06-05 07:42:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 529\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2203 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 15:47:33',4,'2020-06-05 09:42:33',4,0,NULL,NULL,NULL,'fdb3a5d9-0f52-4594-862d-32a7067bbf33'),(530,'adult_arv_1e_6mnth','6mnths supply of 1e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_6mnth\n 6mnths supply of 1e\n \n 2020-06-04 13:51:21 UTC\n \n 2020-07-15 00:44:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 530\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nand o.person_id in (select os.person_id \n from obs os \n where os.obs_datetime BETWEEN :startDate AND :endDate \n and os.concept_id = 2250 and os.value_coded = 2205 \n ) \nand o.person_id in \n (select os.person_id \n from obs os \n where os.obs_datetime BETWEEN :startDate AND :endDate \n and os.concept_id = 4174 and os.value_coded = 4247 \n) \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0\n','2020-06-04 13:51:21',4,'2020-07-15 00:44:56',4,0,NULL,NULL,NULL,'13ec01be-4c41-4cab-8776-03c2be53fb90'),(531,'adult_arv_1f_6mnth','6mnths supply of 1f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_6mnth\n 6mnths supply of 1f\n \n 2020-06-04 13:53:31 UTC\n \n 2020-11-20 10:54:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 531\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4247) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4247) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 2207)\n','2020-06-04 15:53:31',4,'2020-11-20 12:54:18',4,0,NULL,NULL,NULL,'87396003-00c4-433b-b3c1-eb201bd2775c'),(532,'adult_arv_1g_6mnth','6mnths supply of 1g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_6mnth\n 6mnths supply of 1g\n \n 2020-06-04 13:54:26 UTC\n \n 2020-06-05 07:44:36 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 532\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3672 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 15:54:26',4,'2020-06-05 09:44:36',4,0,NULL,NULL,NULL,'884dbb74-6589-4ee4-85af-a349f88cb8e1'),(533,'adult_arv_1h_6mnth','6mnths supply of 1h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_6mnth\n 6mnths supply of 1h\n \n 2020-06-04 13:55:28 UTC\n \n 2020-06-16 10:59:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 533\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3673 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 13:55:28',4,'2020-06-16 10:59:55',4,0,NULL,NULL,NULL,'dc3ece21-bfe0-4460-9c09-a12a1663b679'),(534,'adult_arv_1j_6mnth','6mnths supply of 1j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_6mnth\n 6mnths supply of 1j\n \n 2020-06-04 13:57:18 UTC\n \n 2020-11-20 10:57:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 534\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4247) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4247) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 4678)\n','2020-06-04 15:57:18',4,'2020-11-20 12:57:08',4,0,NULL,NULL,NULL,'4becb473-e1ce-4e72-b4e2-9cf84fcc2366'),(535,'adult_arv_1k_6mnth','6mnths supply of 1k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_6mnth\n 6mnths supply of 1k\n \n 2020-06-04 13:58:40 UTC\n \n 2020-06-05 07:46:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 535\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4679 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 15:58:40',4,'2020-06-05 09:46:03',4,0,NULL,NULL,NULL,'3f9ce8e5-1b4a-49b0-bc6d-decfb8fb88c1'),(536,'adult_arv_1m_6mnth','6mnths supply of 1m','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_6mnth\n 6mnths supply of 1m\n \n 2020-06-04 14:00:09 UTC\n \n 2020-06-05 07:46:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 536\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4680 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 16:00:09',4,'2020-06-05 09:46:33',4,0,NULL,NULL,NULL,'d7b93a16-4442-49c0-817c-8a1c4b7097ca'),(537,'adult_arv_1n_6mnth','6mnths supply of 1n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_6mnth\n 6mnths supply of 1n\n \n 2020-06-04 14:01:31 UTC\n \n 2020-06-05 07:47:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 537\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4681 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 16:01:31',4,'2020-06-05 09:47:14',4,0,NULL,NULL,NULL,'9d4cbcb3-f873-45bf-b00f-32556db829f7'),(538,'adult_arv_1p_6mnth','6mnths supply of 1p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_6mnth\n 6mnths supply of 1p\n \n 2020-06-04 14:02:37 UTC\n \n 2020-06-05 07:47:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 538\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4682 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 16:02:37',4,'2020-06-05 09:47:37',4,0,NULL,NULL,NULL,'6c977b93-8224-48bd-bfcc-fbb1430524ee'),(539,'adult_arv_1q_6mnth','6mnths supply of 1q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_6mnth\n 6mnths supply of 1q\n \n 2020-06-04 14:04:18 UTC\n \n 2020-06-05 07:47:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 539\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4683 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 16:04:18',4,'2020-06-05 09:47:57',4,0,NULL,NULL,NULL,'3925978c-31f1-42dc-a61c-d4c66cb14fdd'),(540,'adult_arv_other_6mnth','6mnths supply of other regimen','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_6mnth\n 6mnths supply of other regimen\n \n 2020-06-04 14:05:17 UTC\n \n 2020-06-05 07:48:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 540\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2143 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 16:05:17',4,'2020-06-05 09:48:28',4,0,NULL,NULL,NULL,'8b73f162-d9b5-4e96-8139-86586e839271'),(541,'adult_arv_1c_other_months','2wks,1,4,6 months supply of 1c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_other_months\n 2wks,1,4,6 months supply of 1c\n \n 2020-06-05 06:57:29 UTC\n \n 2020-06-05 07:48:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 541\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2201 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 08:57:29',4,'2020-06-05 09:48:57',4,0,NULL,NULL,NULL,'66511f62-2da4-4c63-8641-034e01c16939'),(542,'adult_arv_1d_other_months','other durations supply of 1d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_other_months\n other durations supply of 1d\n \n 2020-06-05 06:58:54 UTC\n \n 2020-07-15 03:10:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 542\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select os.person_id \n from obs os \n where os.obs_datetime BETWEEN :startDate AND :endDate \n and os.concept_id = 2250 and os.value_coded = 2203 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where oss.obs_datetime BETWEEN :startDate AND :endDate \n and oss.concept_id = 4174 and oss.value_coded in (4243, 4176, 4245, 4246) \n ) \n)\n','2020-06-05 06:58:54',4,'2020-07-15 03:10:40',4,0,NULL,NULL,NULL,'5f87f57a-7059-49f4-986e-783823f5cbab'),(543,'adult_arv_1e_other_months','other duration supply of 1e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_other_months\n other duration supply of 1e\n \n 2020-06-05 06:59:45 UTC\n \n 2020-07-15 03:15:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 543\n select distinct(o.person_id) \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select os.person_id \n from obs os \n where os.obs_datetime BETWEEN :startDate AND :endDate \n and os.concept_id = 2250 and os.value_coded = 2205 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where oss.obs_datetime BETWEEN :startDate AND :endDate \n and oss.concept_id = 4174 and oss.value_coded in (4243, 4176, 4245, 4246) \n ) \n)\n','2020-06-05 06:59:45',4,'2020-07-15 03:15:48',4,0,NULL,NULL,NULL,'597e713b-7181-46ce-ae93-07605c62ec37'),(544,'adult_arv_1f_other_months','other duration supply of 1f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_other_months\n other duration supply of 1f\n \n 2020-06-05 07:00:40 UTC\n \n 2020-11-20 10:54:47 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 544\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4243,4176,4245,4246) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4243,4176,4245,4246) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 2207)\n','2020-06-05 09:00:40',4,'2020-11-20 12:54:47',4,0,NULL,NULL,NULL,'c83bc608-76be-4774-8065-9e5def272804'),(545,'adult_arv_1g_other_months','other duration supply of 1g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_other_months\n other duration supply of 1g\n \n 2020-06-05 07:05:30 UTC\n \n 2020-06-05 07:05:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 545\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3672 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:05:30',4,'2020-06-05 09:05:57',4,0,NULL,NULL,NULL,'da485ef1-77d0-4d3d-865d-d8011e6a7560'),(546,'adult_arv_1h_other_months','other duration suppply of 1h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_other_months\n other duration suppply of 1h\n \n 2020-06-05 07:06:48 UTC\n \n 2020-07-15 03:11:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 546\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select os.person_id \n from obs os \n where os.obs_datetime BETWEEN :startDate AND :endDate \n and os.concept_id = 2250 and os.value_coded = 3673 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where oss.obs_datetime BETWEEN :startDate AND :endDate \n and oss.concept_id = 4174 and oss.value_coded in (4243, 4176, 4245, 4246) \n ) \n)\n','2020-06-05 07:06:48',4,'2020-07-15 03:11:35',4,0,NULL,NULL,NULL,'4856375f-ed15-4b80-8a69-230643d6918e'),(547,'adult_arv_1j_other_months','other duration supply of 1j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_other_months\n other duration supply of 1j\n \n 2020-06-05 07:07:37 UTC\n \n 2020-11-20 10:57:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 547\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4243,4176,4245,4246) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4243,4176,4245,4246) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 4678)\n','2020-06-05 09:07:37',4,'2020-11-20 12:57:31',4,0,NULL,NULL,NULL,'a4b6d688-df41-4817-a621-6be6ab32ea59'),(548,'adult_arv_1k_other_months','other duration supply of 1k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_other_months\n other duration supply of 1k\n \n 2020-06-05 07:08:26 UTC\n \n 2020-06-05 07:08:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 548\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4679 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:08:26',4,'2020-06-05 09:08:46',4,0,NULL,NULL,NULL,'eec6e550-453f-4cb5-a27d-fe60c9dcfdf2'),(549,'adult_arv_1m_other_months','other duration supply of 1m','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_other_months\n other duration supply of 1m\n \n 2020-06-05 07:09:19 UTC\n \n 2020-06-05 07:09:41 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 549\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4680 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:09:19',4,'2020-06-05 09:09:41',4,0,NULL,NULL,NULL,'7b67d262-9d16-401d-b604-d91cc253865c'),(550,'adult_arv_1n_other_months','other duration supply of 1n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_other_months\n other duration supply of 1n\n \n 2020-06-05 07:10:29 UTC\n \n 2020-06-16 13:34:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 550\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4681 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 07:10:29',4,'2020-06-16 13:34:20',4,0,NULL,NULL,NULL,'952e2836-4856-4364-a91b-b293d5b851d6'),(551,'adult_arv_1p_other_months','other duration supply of 1p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_other_months\n other duration supply of 1p\n \n 2020-06-05 07:16:58 UTC\n \n 2020-06-05 07:17:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 551\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4682 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:16:58',4,'2020-06-05 09:17:16',4,0,NULL,NULL,NULL,'be570315-7ba8-466b-8b22-e61f30e0e4c3'),(552,'adult_arv_1q_other_months','other duration supply of 1q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_other_months\n other duration supply of 1q\n \n 2020-06-05 07:17:50 UTC\n \n 2020-06-05 07:18:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 552\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4683 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:17:50',4,'2020-06-05 09:18:06',4,0,NULL,NULL,NULL,'10da0e87-2ff1-4e44-9503-81b78ef95b8b'),(553,'adult_arv_other_other_months','other duration supply of other regimen','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_other_months\n other duration supply of other regimen\n \n 2020-06-05 07:18:56 UTC\n \n 2020-06-05 07:19:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 553\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2143 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:18:56',4,'2020-06-05 09:19:10',4,0,NULL,NULL,NULL,'6f6651ce-3b9c-46e2-9408-1af9b76331bb'),(554,'2020_Pre_ART','pre art PIR for new ART dataset','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_Pre_ART\n pre art PIR for new ART dataset\n \n 2020-06-05 07:21:23 UTC\n \n 2020-06-05 07:21:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 554\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-06-05 09:21:23',4,'2020-06-05 09:21:25',4,0,NULL,NULL,NULL,'825334cf-ea81-4d70-8166-4479b7656543'),(555,'2020_Pre_ART Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_Pre_ART Data Set\n \n 2020-06-05 07:21:25 UTC\n \n 2020-08-04 16:20:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 555\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n EverF14\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n EverF15\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n EverM14\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n EverM15\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n PreF14\n \n \n \n \n \n \n \n \n \n PreF15\n \n \n \n \n \n \n PreM14\n \n \n \n \n \n \n PreM15\n \n \n \n \n \n \n','2020-06-05 07:21:25',4,'2020-08-04 16:20:06',4,0,NULL,NULL,NULL,'a758fb74-1fc9-4fce-a6d8-531decf8be2a'),(557,'2020_ART_Current Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_ART_Current Data Set\n \n 2020-06-05 07:26:21 UTC\n \n 2020-09-14 13:54:47 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 557\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Finer_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n \n \n DefaultF1-\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n DefaultF10\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n DefaultF15\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n DefaultF20\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n DefaultF25\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 25to29yrs\n \n \n \n \n \n DefaultF30\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 30to34yrs\n \n \n \n \n \n DefaultF35\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 35to39yrs\n \n \n \n \n \n DefaultF40\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 40to44yrs\n \n \n \n \n \n DefaultF45\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 45to49yrs\n \n \n \n \n \n DefaultF5-\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 05to09yrs\n \n \n \n \n \n DefaultF50\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 50+yrs\n \n \n \n \n \n DefaultF<1\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n DefaultM1-\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n DefaultM10\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n DefaultM15\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n DefaultM20\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n DefaultM25\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 25to29yrs\n \n \n \n \n \n DefaultM30\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 30to34yrs\n \n \n \n \n \n DefaultM35\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 35to39yrs\n \n \n \n \n \n DefaultM40\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 40to44yrs\n \n \n \n \n \n DefaultM45\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 45to49yrs\n \n \n \n \n \n DefaultM5-\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 05to09yrs\n \n \n \n \n \n DefaultM50\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 50+yrs\n \n \n \n \n \n DefaultM<1\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n DiedClient\n \n \n \n \n \n \n \n \n \n LostToFU\n \n \n \n \n \n \n \n \n \n MMD_F1-4\n \n \n \n \n \n \n \n \n \n MMD_F10-14\n \n \n \n \n \n \n MMD_F15-19\n \n \n \n \n \n \n MMD_F20-24\n \n \n \n \n \n \n MMD_F25-29\n \n \n \n \n \n \n MMD_F30-34\n \n \n \n \n \n \n MMD_F35-39\n \n \n \n \n \n \n MMD_F40-44\n \n \n \n \n \n \n MMD_F45-49\n \n \n \n \n \n \n MMD_F5-9\n \n \n \n \n \n \n MMD_F50\n \n \n \n \n \n \n MMD_F<1\n \n \n \n \n \n \n MMD_M1-4\n \n \n \n \n \n \n MMD_M10-14\n \n \n \n \n \n \n MMD_M15-19\n \n \n \n \n \n \n MMD_M20-24\n \n \n \n \n \n \n MMD_M25-29\n \n \n \n \n \n \n MMD_M30-34\n \n \n \n \n \n \n MMD_M35-39\n \n \n \n \n \n \n MMD_M40-44\n \n \n \n \n \n \n MMD_M45-49\n \n \n \n \n \n \n MMD_M5-9\n \n \n \n \n \n \n MMD_M50\n \n \n \n \n \n \n MMD_M<1\n \n \n \n \n \n \n MissedF1-4\n \n \n \n \n \n \n \n \n \n MissedF10-\n \n \n \n \n \n \n MissedF15-\n \n \n \n \n \n \n MissedF20-\n \n \n \n \n \n \n MissedF25-\n \n \n \n \n \n \n MissedF30-\n \n \n \n \n \n \n MissedF35-\n \n \n \n \n \n \n MissedF40-\n \n \n \n \n \n \n MissedF45-\n \n \n \n \n \n \n MissedF5-9\n \n \n \n \n \n \n MissedF50\n \n \n \n \n \n \n MissedF<1\n \n \n \n \n \n \n MissedM1-4\n \n \n \n \n \n \n MissedM10-\n \n \n \n \n \n \n MissedM15-\n \n \n \n \n \n \n MissedM20-\n \n \n \n \n \n \n MissedM25-\n \n \n \n \n \n \n MissedM30-\n \n \n \n \n \n \n MissedM35-\n \n \n \n \n \n \n MissedM40\n \n \n \n \n \n \n MissedM45-\n \n \n \n \n \n \n MissedM5-9\n \n \n \n \n \n \n MissedM50\n \n \n \n \n \n \n MissedM<1\n \n \n \n \n \n \n Restarted\n \n \n \n \n \n \n \n \n \n SeenFema1-\n \n \n \n \n \n \n \n \n \n SeenFema10\n \n \n \n \n \n \n SeenFema15\n \n \n \n \n \n \n SeenFema20\n \n \n \n \n \n \n SeenFema25\n \n \n \n \n \n \n SeenFema30\n \n \n \n \n \n \n SeenFema35\n \n \n \n \n \n \n SeenFema40\n \n \n \n \n \n \n SeenFema45\n \n \n \n \n \n \n SeenFema5-\n \n \n \n \n \n \n SeenFema50\n \n \n \n \n \n \n SeenFema<1\n \n \n \n \n \n \n SeenMale1-\n \n \n \n \n \n \n SeenMale10\n \n \n \n \n \n \n SeenMale15\n \n \n \n \n \n \n SeenMale20\n \n \n \n \n \n \n SeenMale25\n \n \n \n \n \n \n SeenMale30\n \n \n \n \n \n \n SeenMale35\n \n \n \n \n \n \n SeenMale40\n \n \n \n \n \n \n SeenMale45\n \n \n \n \n \n \n SeenMale5-\n \n \n \n \n \n \n SeenMale50\n \n \n \n \n \n \n SeenMale<1\n \n \n \n \n \n \n StoppedART\n \n \n \n \n \n \n \n \n \n TransferIn\n \n \n \n \n \n \n \n \n \n TransferOu\n \n \n \n \n \n \n \n \n \n newFema1-4\n \n \n \n \n \n \n \n \n \n newFema10-\n \n \n \n \n \n \n newFema15-\n \n \n \n \n \n \n newFema20-\n \n \n \n \n \n \n newFema25-\n \n \n \n \n \n \n newFema30-\n \n \n \n \n \n \n newFema35-\n \n \n \n \n \n \n newFema40-\n \n \n \n \n \n \n newFema45-\n \n \n \n \n \n \n newFema5-9\n \n \n \n \n \n \n newFema50\n \n \n \n \n \n \n newFemale1\n \n \n \n \n \n \n newMale1\n \n \n \n \n \n \n newMale1-4\n \n \n \n \n \n \n newMale10-\n \n \n \n \n \n \n newMale15-\n \n \n \n \n \n \n newMale20-\n \n \n \n \n \n \n newMale25-\n \n \n \n \n \n \n newMale30-\n \n \n \n \n \n \n newMale35-\n \n \n \n \n \n \n newMale40-\n \n \n \n \n \n \n newMale45-\n \n \n \n \n \n \n newMale5-9\n \n \n \n \n \n \n newMale50\n \n \n \n \n \n \n','2020-06-05 09:26:21',4,'2020-09-14 15:54:47',4,0,NULL,NULL,NULL,'81fbbedc-d10c-42aa-9156-e5c93cfd3741'),(558,'adult_arv_2c_1mnth','1month supply of 2c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2c_1mnth\n 1month supply of 2c\n \n 2020-06-05 08:32:14 UTC\n \n 2020-06-16 13:39:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 558\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2210 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:32:14',4,'2020-06-16 13:39:37',4,0,NULL,NULL,NULL,'4a32ce1f-8c3b-4ae7-85dc-eea24672d4d7'),(559,'adult_arv_2d_1mnth','1month supply of 2d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2d_1mnth\n 1month supply of 2d\n \n 2020-06-05 08:33:29 UTC\n \n 2020-06-16 13:40:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 559\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2203 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:33:29',4,'2020-06-16 13:40:52',4,0,NULL,NULL,NULL,'863a96d9-1dcc-4b5c-9277-5b236057bd76'),(560,'adult_arv_2e_1mnth','1month supply of 2e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2e_1mnth\n 1month supply of 2e\n \n 2020-06-05 08:34:22 UTC\n \n 2020-06-16 13:41:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 560\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3674 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:34:22',4,'2020-06-16 13:41:45',4,0,NULL,NULL,NULL,'8d6cded5-67a7-4121-8f10-0e99e5ee0102'),(561,'adult_arv_2f_1mnth','1month supply of 2f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2f_1mnth\n 1month supply of 2f\n \n 2020-06-05 08:35:08 UTC\n \n 2020-06-16 13:42:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 561\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3675 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:35:08',4,'2020-06-16 13:42:00',4,0,NULL,NULL,NULL,'04265c85-d096-469c-ac3e-6a78f938ed67'),(562,'adult_arv_2g_1mnth','1month supply of 2g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2g_1mnth\n 1month supply of 2g\n \n 2020-06-05 08:35:54 UTC\n \n 2020-06-16 13:42:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 562\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3676 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:35:54',4,'2020-06-16 13:42:18',4,0,NULL,NULL,NULL,'630e20f6-dc99-460f-a0e2-54b1eea5a00c'),(563,'adult_arv_2h_1mnth','1month supply of 2h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2h_1mnth\n 1month supply of 2h\n \n 2020-06-05 08:37:24 UTC\n \n 2020-06-16 13:42:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 563\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3677 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:37:24',4,'2020-06-16 13:42:37',4,0,NULL,NULL,NULL,'974cf406-f3d5-4b42-b351-5dcb94f75017'),(564,'adult_arv_2j_1mnth','1month supply of 2j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2j_1mnth\n 1month supply of 2j\n \n 2020-06-05 08:39:19 UTC\n \n 2020-06-16 13:48:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 564\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4689 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:39:19',4,'2020-06-16 13:48:26',4,0,NULL,NULL,NULL,'4d64975e-b01c-46ed-bec8-137a544b7bc7'),(565,'adult_arv_2k_1mnth','1month supply of 2k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2k_1mnth\n 1month supply of 2k\n \n 2020-06-05 08:40:07 UTC\n \n 2020-06-16 13:42:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 565\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4690 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:40:07',4,'2020-06-16 13:42:56',4,0,NULL,NULL,NULL,'3c3d19f1-dad1-4b7b-b994-975f47b7445a'),(566,'adult_arv_2l_1mnth','1month supply of 2l','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2l_1mnth\n 1month supply of 2l\n \n 2020-06-05 08:41:30 UTC\n \n 2020-06-16 13:43:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 566\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4691 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:41:30',4,'2020-06-16 13:43:15',4,0,NULL,NULL,NULL,'b22e2178-de68-4fc6-ae05-601245b6a5b2'),(567,'adult_arv_2m_1mnth','1month supply','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2m_1mnth\n 1month supply\n \n 2020-06-05 08:44:35 UTC\n \n 2020-06-16 13:43:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 567\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4692 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:44:35',4,'2020-06-16 13:43:30',4,0,NULL,NULL,NULL,'a38fa644-0c38-4463-ab26-5c926f886dc9'),(568,'adult_arv_2n_1mnth','1month supply of 2n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2n_1mnth\n 1month supply of 2n\n \n 2020-06-05 08:46:20 UTC\n \n 2020-06-16 13:43:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 568\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4693 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:46:20',4,'2020-06-16 13:43:46',4,0,NULL,NULL,NULL,'2a93bd17-c3eb-4fc4-86fc-ce5849b76bd4'),(569,'adult_arv_2o_1mnth','1month supply of 2o','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2o_1mnth\n 1month supply of 2o\n \n 2020-06-05 08:47:30 UTC\n \n 2020-06-16 13:44:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 569\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4694 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:47:30',4,'2020-06-16 13:44:03',4,0,NULL,NULL,NULL,'eb37ce3b-5110-41b8-a3f0-40f0f3b5db75'),(570,'adult_arv_2p_1mnth','1month supply of 2p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2p_1mnth\n 1month supply of 2p\n \n 2020-06-05 08:48:45 UTC\n \n 2020-06-16 13:49:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 570\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4695 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:48:45',4,'2020-06-16 13:49:22',4,0,NULL,NULL,NULL,'9a54959a-25c3-4cd1-8382-e00379577eeb'),(571,'adult_arv_2q_1mnth','1month supply of 2q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2q_1mnth\n 1month supply of 2q\n \n 2020-06-05 08:49:34 UTC\n \n 2020-11-20 11:31:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 571\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4849 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 10:49:34',4,'2020-11-20 13:31:18',4,0,NULL,NULL,NULL,'149baa8e-a071-41bf-99fb-97a781d12330'),(572,'Clients seen given 1 month supply 3a','1month supply of 3a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3a\n 1month supply of 3a\n \n 2020-06-05 08:51:33 UTC\n \n 2021-07-25 15:37:23 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 572\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3683)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:51:33',4,'2021-07-25 15:37:23',4,0,NULL,NULL,NULL,'ad771405-a581-4e57-bb60-e2326ee778ca'),(573,'Clients seen given 1 month supply 3b','1month supply of 3b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3b\n 1month supply of 3b\n \n 2020-06-05 08:52:22 UTC\n \n 2021-07-13 15:10:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 573\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3684)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:52:22',4,'2021-07-13 15:10:31',4,0,NULL,NULL,NULL,'8ce36691-8f7b-42ff-9638-84dc3ce7b473'),(574,'Clients seen given 1 month supply 3c','1month supply of 3c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3c\n 1month supply of 3c\n \n 2020-06-05 08:53:22 UTC\n \n 2021-07-13 15:11:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 574\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3685)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:53:22',4,'2021-07-13 15:11:00',4,0,NULL,NULL,NULL,'97e72602-8099-4ead-8ed8-63c18ddc337f'),(575,'Clients seen given 1 month supply 3d','1month supply of 3d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3d\n 1month supply of 3d\n \n 2020-06-05 08:54:01 UTC\n \n 2021-07-13 15:11:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 575\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4706)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:54:01',4,'2021-07-13 15:11:33',4,0,NULL,NULL,NULL,'19fff766-eb8f-41f2-8d76-8f6505bbb9b9'),(576,'Clients seen given 1 month supply 3e','1month supply of 3e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3e\n 1month supply of 3e\n \n 2020-06-05 08:54:50 UTC\n \n 2021-07-13 15:11:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 576\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4707)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:54:50',4,'2021-07-13 15:11:57',4,0,NULL,NULL,NULL,'b2e90223-56f5-4e04-89e1-d9cc1fc34b17'),(577,'Clients seen given 1 month supply 3f','1month supply of 3f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3f\n 1month supply of 3f\n \n 2020-06-05 08:58:16 UTC\n \n 2021-07-13 15:12:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 577\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4708)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:58:16',4,'2021-07-13 15:12:26',4,0,NULL,NULL,NULL,'fdc65c1d-6a93-4a2d-bfc8-19f93d762531'),(578,'Clients seen given 1 month supply 3g','1month supply of 3g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3g\n 1month supply of 3g\n \n 2020-06-05 08:59:44 UTC\n \n 2021-07-13 15:12:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 578\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4709)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:59:44',4,'2021-07-13 15:12:55',4,0,NULL,NULL,NULL,'72a63ae5-4204-4f3a-803a-6ede62fee967'),(579,'Clients seen given 1 month supply 3h','1month supply of 3h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3h\n 1month supply of 3h\n \n 2020-06-05 09:00:47 UTC\n \n 2021-07-13 15:13:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 579\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4710)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 09:00:47',4,'2021-07-13 15:13:35',4,0,NULL,NULL,NULL,'a1042d17-e93e-407e-a91e-e6cdf2930ab6'),(580,'adult_arv_2c_3mnth','3months supply of 2c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2c_3mnth\n 3months supply of 2c\n \n 2020-06-05 09:02:19 UTC\n \n 2020-06-05 09:02:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 580\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2210 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:02:19',4,'2020-06-05 11:02:33',4,0,NULL,NULL,NULL,'d0c31b7a-ea56-4f12-a574-924391d2dcb0'),(581,'adult_arv_2d_3mnth','3months supply of 2d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2d_3mnth\n 3months supply of 2d\n \n 2020-06-05 09:03:04 UTC\n \n 2020-06-05 09:03:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 581\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2209 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:03:04',4,'2020-06-05 11:03:19',4,0,NULL,NULL,NULL,'0f6c5bd6-8635-463f-80c8-d5322e97fe54'),(582,'adult_arv_2e_3mnth','3months aupply of 2e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2e_3mnth\n 3months aupply of 2e\n \n 2020-06-05 09:03:56 UTC\n \n 2020-06-05 09:04:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 582\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2205 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:03:56',4,'2020-06-05 11:04:38',4,0,NULL,NULL,NULL,'62d0a57e-51b0-4f3e-967a-12ce18b24778'),(583,'adult_arv_2f_3mnth','3mnths supply of 2f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2f_3mnth\n 3mnths supply of 2f\n \n 2020-06-05 09:09:02 UTC\n \n 2020-06-05 09:09:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 583\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3675 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:09:02',4,'2020-06-05 11:09:21',4,0,NULL,NULL,NULL,'969c9f38-af5e-4595-af5e-346abc080fb5'),(584,'adult_arv_2g_3mnth','3months supply of 2g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2g_3mnth\n 3months supply of 2g\n \n 2020-06-05 09:15:50 UTC\n \n 2020-06-05 09:16:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 584\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3676 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:15:50',4,'2020-06-05 11:16:07',4,0,NULL,NULL,NULL,'c0193c8c-6d28-4787-990e-bb7a38eb6284'),(585,'adult_arv_2h_3mnth','3months supply of 2h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2h_3mnth\n 3months supply of 2h\n \n 2020-06-05 09:17:00 UTC\n \n 2020-06-05 09:19:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 585\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3677 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:17:00',4,'2020-06-05 11:19:06',4,0,NULL,NULL,NULL,'b675b59a-567a-45eb-bb4f-04843ed1719f'),(586,'adult_arv_2j_3mnth','3months supply of 2j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2j_3mnth\n 3months supply of 2j\n \n 2020-06-05 09:19:35 UTC\n \n 2020-06-05 09:19:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 586\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4689 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:19:35',4,'2020-06-05 11:19:53',4,0,NULL,NULL,NULL,'32aaed67-7f8c-40bc-829a-959b7dcb1bfe'),(587,'adult_arv_2k_3mnth','3months supply of 2k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2k_3mnth\n 3months supply of 2k\n \n 2020-06-05 09:21:52 UTC\n \n 2020-06-05 09:22:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 587\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4690 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:21:52',4,'2020-06-05 11:22:08',4,0,NULL,NULL,NULL,'3333bc62-d534-423c-bc79-b477f5296f51'),(588,'adult_arv_2l_3mnth','3months supply of 2l','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2l_3mnth\n 3months supply of 2l\n \n 2020-06-05 09:23:04 UTC\n \n 2020-06-05 09:23:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 588\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2201 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4691 \n)\n','2020-06-05 11:23:04',4,'2020-06-05 11:23:19',4,0,NULL,NULL,NULL,'aa37e85b-a2fb-41af-97b1-d25b86a87ad5'),(589,'adult_arv_2m_3mnth','3months supply of 2m','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2m_3mnth\n 3months supply of 2m\n \n 2020-06-05 09:23:46 UTC\n \n 2020-06-05 09:24:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 589\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4692 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:23:46',4,'2020-06-05 11:24:00',4,0,NULL,NULL,NULL,'d67a7838-10cf-4ae8-a536-38ba96c2ca9a'),(590,'adult_arv_2n_3mnth','3mnths supply of 2n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2n_3mnth\n 3mnths supply of 2n\n \n 2020-06-05 09:24:28 UTC\n \n 2020-06-05 09:24:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 590\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4693 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:24:28',4,'2020-06-05 11:24:46',4,0,NULL,NULL,NULL,'05a68334-52b7-4a39-8221-f4f3c02b26f6'),(591,'adult_arv_2o_3mnth','3mnths supply of 2o','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2o_3mnth\n 3mnths supply of 2o\n \n 2020-06-05 09:25:16 UTC\n \n 2020-06-05 09:25:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 591\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4694 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:25:16',4,'2020-06-05 11:25:40',4,0,NULL,NULL,NULL,'fe8ca75f-be0f-4047-b0a8-3836ad3c8220'),(592,'adult_arv_2p_3mnth','3months supply of 2p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2p_3mnth\n 3months supply of 2p\n \n 2020-06-05 09:26:29 UTC\n \n 2020-06-05 09:26:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 592\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4695 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:26:29',4,'2020-06-05 11:26:46',4,0,NULL,NULL,NULL,'34c0a5a2-e192-4423-9067-6c15c57534ea'),(593,'2020_TB_Screening','new dataset TB Screening','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_TB_Screening\n new dataset TB Screening\n \n 2020-06-05 09:27:25 UTC\n \n 2020-06-05 09:27:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 593\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-06-05 11:27:25',4,'2020-06-05 11:27:28',4,0,NULL,NULL,NULL,'5f5679ca-795d-434b-a3e0-354fec02f6e8'),(594,'2020_TB_Screening Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_TB_Screening Data Set\n \n 2020-06-05 09:27:28 UTC\n \n 2020-08-04 17:36:49 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 594\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n TBCaseAdF\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n TBCaseAdM\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n TBCaseChF\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n TBCaseChM\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n TBTreatAdF\n \n \n \n \n \n \n \n \n \n TBTreatAdM\n \n \n \n \n \n \n TBTreatChF\n \n \n \n \n \n \n TBTreatChM\n \n \n \n \n \n \n screen14F\n \n \n \n \n \n \n \n \n \n screen14M\n \n \n \n \n \n \n screen15+F\n \n \n \n \n \n \n screen15+M\n \n \n \n \n \n \n seen14F\n \n \n \n \n \n \n \n \n \n seen14M\n \n \n \n \n \n \n seen15+F\n \n \n \n \n \n \n seen15+M\n \n \n \n \n \n \n start14F\n \n \n \n \n \n \n start14M\n \n \n \n \n \n \n start15+F\n \n \n \n \n \n \n start15+M\n \n \n \n \n \n \n','2020-06-05 09:27:28',4,'2020-08-04 17:36:49',4,0,NULL,NULL,NULL,'4d895f5d-ede9-42b0-ae52-7e97a646c2d7'),(595,'adult_arv_2q_3mnth','3mnths supply of 2q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2q_3mnth\n 3mnths supply of 2q\n \n 2020-06-05 09:29:55 UTC\n \n 2020-11-20 11:33:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 595\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4849 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:29:55',4,'2020-11-20 13:33:12',4,0,NULL,NULL,NULL,'5e16b0e3-6356-4963-8a44-259095ecfb88'),(596,'Clients newly initiated 4c','4c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4c\n 4c\n \n 2020-06-05 09:51:25 UTC\n \n 2021-01-27 22:08:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 596\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 2202 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:51:25',4,'2021-01-27 22:08:31',4,0,NULL,NULL,NULL,'e9bdc7db-4154-4d56-ae30-e5e22cd2276d'),(597,'Clients newly initiated 4d','4d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4d\n 4d\n \n 2020-06-05 09:54:04 UTC\n \n 2021-01-27 22:19:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 597\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 2204 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:54:04',4,'2021-01-27 22:19:28',4,0,NULL,NULL,NULL,'2f6f3d47-f7f2-4059-a098-e1164c572f36'),(598,'Clients newly initiated 4e','4e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4e\n 4e\n \n 2020-06-05 09:54:44 UTC\n \n 2021-01-27 22:21:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 598\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3679 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:54:44',4,'2021-01-27 22:21:19',4,0,NULL,NULL,NULL,'3b4b75da-e900-4fdf-8594-c25d3a20e047'),(599,'Clients newly initiated 4f','4f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4f\n 4f\n \n 2020-06-05 09:56:08 UTC\n \n 2021-01-27 22:22:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 599\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3680 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:56:08',4,'2021-01-27 22:22:42',4,0,NULL,NULL,NULL,'07ea75ac-aa04-47ef-aec5-5c56aaa7143e'),(600,'Clients newly initiated 4g','4g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4g\n 4g\n \n 2020-06-05 09:56:57 UTC\n \n 2021-01-27 22:24:27 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 600\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4684 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:56:57',4,'2021-01-27 22:24:27',4,0,NULL,NULL,NULL,'e0d57b65-99fd-4058-8626-143e4dff86c9'),(601,'Clients newly initiated 4h','4h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4h\n 4h\n \n 2020-06-05 09:58:19 UTC\n \n 2021-01-27 22:25:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 601\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4685 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:58:19',4,'2021-01-27 22:25:35',4,0,NULL,NULL,NULL,'d56c2ea1-4ddf-4d2d-85e3-b25806f12a50'),(602,'Clients newly initiated 4k','4k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4k\n 4k\n \n 2020-06-05 09:59:20 UTC\n \n 2021-01-27 22:29:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 602\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4687 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:59:20',4,'2021-01-27 22:29:03',4,0,NULL,NULL,NULL,'938aad64-3bc8-46d7-aaec-36522d65e24b'),(603,'Clients newly initiated 4L','4L','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4L\n 4L\n \n 2020-06-05 10:05:28 UTC\n \n 2021-01-27 22:30:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 603\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4688 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:05:28',4,'2021-01-27 22:30:13',4,0,NULL,NULL,NULL,'368e8627-12e2-4d50-81ce-ac338ad1c858'),(604,'Clients newly initiated 5a','5a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5a\n 5a\n \n 2020-06-05 10:07:35 UTC\n \n 2021-01-27 22:32:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 604\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3681 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:07:35',4,'2021-01-27 22:32:44',4,0,NULL,NULL,NULL,'2dd7cbae-8054-4270-bf2a-9ec98eef1747'),(605,'Clients newly initiated 5b','5b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5b\n 5b\n \n 2020-06-05 10:09:31 UTC\n \n 2021-01-27 22:35:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 605\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3682 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:09:31',4,'2021-01-27 22:35:45',4,0,NULL,NULL,NULL,'d8c18842-91aa-4102-a19a-1f48780c4daa'),(606,'Clients newly initiated 5c','5c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5c\n 5c\n \n 2020-06-05 10:11:40 UTC\n \n 2021-01-27 22:37:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 606\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4696 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:11:40',4,'2021-01-27 22:37:24',4,0,NULL,NULL,NULL,'655a6791-e753-405e-831f-c527d63386ab'),(607,'Clients newly initiated 5d','5d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5d\n 5d\n \n 2020-06-05 10:12:25 UTC\n \n 2021-01-27 22:39:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 607\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4697 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:12:25',4,'2021-01-27 22:39:19',4,0,NULL,NULL,NULL,'c7e733d9-f5ec-4799-bb83-0f8e38f9a5e1'),(608,'Clients newly initiated 5e','5e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5e\n 5e\n \n 2020-06-05 10:13:16 UTC\n \n 2021-01-27 22:40:36 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 608\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4698 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:13:16',4,'2021-01-27 22:40:36',4,0,NULL,NULL,NULL,'09ce91e0-7242-41fa-b68f-551daabefd2e'),(609,'Clients newly initiated 5g','5g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5g\n 5g\n \n 2020-06-05 10:15:17 UTC\n \n 2021-01-27 22:44:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 609\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4700 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:15:17',4,'2021-01-27 22:44:28',4,0,NULL,NULL,NULL,'c529cc30-cff7-4a9b-8ca6-9bccd505139e'),(610,'Clients newly initiated 5h','5h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5h\n 5h\n \n 2020-06-05 10:15:50 UTC\n \n 2021-01-27 22:46:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 610\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4701 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:15:50',4,'2021-01-27 22:46:38',4,0,NULL,NULL,NULL,'e316ba5b-a507-493a-8183-3b48bdea3c65'),(611,'Clients newly initiated 6a','6a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6a\n 6a\n \n 2020-06-05 10:16:53 UTC\n \n 2021-01-27 22:49:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 611\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3686 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:16:53',4,'2021-01-27 22:49:29',4,0,NULL,NULL,NULL,'7cd2486f-34f5-4a78-a016-70512f5b4830'),(612,'Clients newly initiated 6b','6b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6b\n 6b\n \n 2020-06-05 10:18:54 UTC\n \n 2021-01-27 22:56:39 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 612\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3687 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:18:54',4,'2021-01-27 22:56:39',4,0,NULL,NULL,NULL,'4b8c4474-fcb5-43e5-9eb8-75695ee52205'),(613,'Clients newly initiated 6c','6c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6c\n 6c\n \n 2020-06-05 10:19:34 UTC\n \n 2021-01-27 22:58:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 613\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4702 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:19:34',4,'2021-01-27 22:58:59',4,0,NULL,NULL,NULL,'f3536aac-02a4-42ec-ab92-e43da022e09b'),(614,'2020_COTRIMOX PROPHYLAXIS/DAPSONE','new dataset clients who received CTX','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_COTRIMOX PROPHYLAXIS/DAPSONE\n new dataset clients who received CTX\n \n 2020-06-05 10:20:14 UTC\n \n 2020-06-05 10:20:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 614\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-06-05 12:20:14',4,'2020-06-05 12:20:17',4,0,NULL,NULL,NULL,'8dc80efd-3c35-4d1a-ad4e-5f9f26caeaf5'),(615,'2020_COTRIMOX PROPHYLAXIS/DAPSONE Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_COTRIMOX PROPHYLAXIS/DAPSONE Data Set\n \n 2020-06-05 10:20:17 UTC\n \n 2020-06-06 18:16:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 615\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n CTX_F1-4\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n CTX_F5-14\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 05yrsto14yrs\n \n \n \n \n \n CTX_F<1\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n CTX_FAdult\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n CTX_M1-4\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n CTX_M5-14\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 05yrsto14yrs\n \n \n \n \n \n CTX_M<1\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n CTX_MAdult\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Adults\n \n \n \n \n \n','2020-06-05 12:20:17',4,'2020-06-06 20:16:22',4,0,NULL,NULL,NULL,'9661c0bc-601a-4b16-b0de-4d891c2d93bc'),(616,'Clients newly initiated 6d','6d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6d\n 6d\n \n 2020-06-05 10:20:21 UTC\n \n 2021-01-27 23:00:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 616\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4703 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:20:21',4,'2021-01-27 23:00:12',4,0,NULL,NULL,NULL,'26bd109c-b9bf-41cd-8b76-027713846950'),(617,'Clients newly initiated 6e','6e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6e\n 6e\n \n 2020-06-05 10:21:00 UTC\n \n 2021-01-27 23:03:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 617\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4704 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:21:00',4,'2021-01-27 23:03:14',4,0,NULL,NULL,NULL,'9dfe2b8b-dc4c-4708-8672-977b5de9526d'),(618,'Clients newly initiated 6f','6f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6f\n 6f\n \n 2020-06-05 10:22:22 UTC\n \n 2021-01-27 23:04:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 618\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4705 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:22:22',4,'2021-01-27 23:04:14',4,0,NULL,NULL,NULL,'10f50f0b-9282-4d68-9e57-13c17e37b411'),(619,'adult_arv_1c_1mnth','1c 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_1mnth\n 1c 1mnth\n \n 2020-06-05 10:42:17 UTC\n \n 2021-01-27 15:47:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 619\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 10:42:17',4,'2021-01-27 15:47:12',4,0,NULL,NULL,NULL,'4d8b2d8b-a165-42ba-abdb-2d881d7cdd0c'),(621,'Clients given CTX in the month','ctx','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given CTX in the month\n ctx\n \n 2020-06-05 10:51:40 UTC\n \n 2020-06-05 10:52:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 621\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 3728 and value_numeric > 1\n','2020-06-05 12:51:40',4,'2020-06-05 12:52:11',4,0,NULL,NULL,NULL,'afa0260d-641b-45bd-a341-7582b02f70a6'),(622,'adult_arv_1d_1mnth','1d 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_1mnth\n 1d 1mnth\n \n 2020-06-05 10:51:52 UTC\n \n 2021-01-27 15:58:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 622\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 10:51:52',4,'2021-01-27 15:58:19',4,0,NULL,NULL,NULL,'00a20283-36e6-43cc-99c3-a9555937e320'),(623,'adult_arv_1e_1mnth','1e 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_1mnth\n 1e 1mnth\n \n 2020-06-05 10:54:44 UTC\n \n 2021-01-27 16:12:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 623\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 10:54:44',4,'2021-01-27 16:12:51',4,0,NULL,NULL,NULL,'b693cd81-554d-4b98-ab19-547ef5d1316d'),(624,'adult_arv_1f_1mnth','1f 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_1mnth\n 1f 1mnth\n \n 2020-06-05 11:02:36 UTC\n \n 2020-06-05 11:03:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 624\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:02:36',4,'2020-06-05 13:03:17',4,0,NULL,NULL,NULL,'c1745a07-d769-478c-b703-9e00ef10c3fc'),(625,'Plumpy Nut given in the month','RUFT','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Plumpy Nut given in the month\n RUFT\n \n 2020-06-05 11:02:38 UTC\n \n 2020-06-05 11:02:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 625\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 4167 and value_coded = 4163\n','2020-06-05 13:02:38',4,'2020-06-05 13:02:51',4,0,NULL,NULL,NULL,'085fe744-3c4e-4d96-9621-af1ffeda1e8d'),(626,'F100 given in the month','F100','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n F100 given in the month\n F100\n \n 2020-06-05 11:03:21 UTC\n \n 2020-06-05 11:03:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 626\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 4167 and value_coded = 4164\n','2020-06-05 13:03:21',4,'2020-06-05 13:03:34',4,0,NULL,NULL,NULL,'1a858146-5ad0-4914-90c6-78770ebc7045'),(627,'F75 given in the month','F75','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n F75 given in the month\n F75\n \n 2020-06-05 11:04:35 UTC\n \n 2020-06-05 11:04:50 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 627\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 4167 and value_coded = 4165\n','2020-06-05 13:04:35',4,'2020-06-05 13:04:50',4,0,NULL,NULL,NULL,'a1c3f512-58d0-4b3c-ba09-22f38d76850e'),(628,'adult_arv_1g_1mnth','1g 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_1mnth\n 1g 1mnth\n \n 2020-06-05 11:04:39 UTC\n \n 2021-01-27 16:24:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 628\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:04:39',4,'2021-01-27 16:24:35',4,0,NULL,NULL,NULL,'6133c572-3574-4a36-a383-8ba8f154ae4b'),(629,'Other Nutritional Supplement given in the month','other supplement','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Other Nutritional Supplement given in the month\n other supplement\n \n 2020-06-05 11:06:00 UTC\n \n 2020-06-05 11:06:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 629\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 4167 and value_coded = 4166\n','2020-06-05 13:06:00',4,'2020-06-05 13:06:13',4,0,NULL,NULL,NULL,'5dcaf597-94b6-40d7-9967-8f145c4c1a54'),(630,'adult_arv_1h_1mnth','1h 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_1mnth\n 1h 1mnth\n \n 2020-06-05 11:06:29 UTC\n \n 2021-01-27 16:39:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 630\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:06:29',4,'2021-01-27 16:39:22',4,0,NULL,NULL,NULL,'b36e2da3-c211-4c2d-a01f-4fa0a0fe1fd8'),(631,'adult_arv_1j_1mnth','1j 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_1mnth\n 1j 1mnth\n \n 2020-06-05 11:11:22 UTC\n \n 2021-01-27 16:53:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 631\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:11:22',4,'2021-01-27 16:53:30',4,0,NULL,NULL,NULL,'9560bddf-1def-45f3-8606-ce4adbbfcc19'),(632,'adult_arv_1k_1mnth','1k 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_1mnth\n 1k 1mnth\n \n 2020-06-05 11:12:57 UTC\n \n 2021-01-27 16:59:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 632\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:12:57',4,'2021-01-27 16:59:54',4,0,NULL,NULL,NULL,'44fcfb57-e804-4f3e-a7f3-bc488400c481'),(633,'adult_arv_1m_1mnth','1m 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_1mnth\n 1m 1mnth\n \n 2020-06-05 11:14:18 UTC\n \n 2021-01-27 17:12:50 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 633\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:14:18',4,'2021-01-27 17:12:50',4,0,NULL,NULL,NULL,'6dc933e8-a8d7-4b43-89b8-90edc570311a'),(634,'adult_arv_1n_1mnth','1n 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_1mnth\n 1n 1mnth\n \n 2020-06-05 11:16:41 UTC\n \n 2021-01-27 17:29:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 634\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:16:41',4,'2021-01-27 17:29:59',4,0,NULL,NULL,NULL,'cb2ca745-f914-4258-aad0-5b57ea870dbd'),(635,'adult_arv_1p_1mnth','1p 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_1mnth\n 1p 1mnth\n \n 2020-06-05 11:18:07 UTC\n \n 2021-01-27 17:44:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 635\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:18:07',4,'2021-01-27 17:44:00',4,0,NULL,NULL,NULL,'15aedfaf-51f7-4d96-b706-b3a3280c560a'),(636,'adult_arv_1q_1mnth','1q 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_1mnth\n 1q 1mnth\n \n 2020-06-05 11:19:15 UTC\n \n 2021-01-27 17:58:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 636\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:19:15',4,'2021-01-27 17:58:21',4,0,NULL,NULL,NULL,'31689512-e2e3-4401-ad27-ea802bdc3617'),(637,'adult_arv_other_1mnth','other 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_1mnth\n other 1mnth\n \n 2020-06-05 11:21:51 UTC\n \n 2021-07-13 11:05:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 637\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:21:51',4,'2021-07-13 11:05:33',4,0,NULL,NULL,NULL,'449d0ce8-0a40-4591-a309-040dfb083198'),(638,'adult_arv_1c_3mnth','1c 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_3mnth\n 1c 3mnths\n \n 2020-06-05 11:24:27 UTC\n \n 2021-01-27 15:49:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 638\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:24:27',4,'2021-01-27 15:49:31',4,0,NULL,NULL,NULL,'2c077d8b-0aa7-401d-aba3-788473928468'),(639,'adult_arv_1d_3mnths','1d 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_3mnths\n 1d 3mnths\n \n 2020-06-05 11:25:44 UTC\n \n 2021-01-27 16:00:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 639\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:25:44',4,'2021-01-27 16:00:17',4,0,NULL,NULL,NULL,'e39e1c56-fece-4095-a279-da8ae718544f'),(640,'adult_arv_1e_3mnths','1e 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_3mnths\n 1e 3mnths\n \n 2020-06-05 11:27:12 UTC\n \n 2021-01-27 16:16:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 640\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:27:12',4,'2021-01-27 16:16:45',4,0,NULL,NULL,NULL,'6068ee9b-96b7-4c60-ad99-59f129fb2a86'),(641,'adult_arv_1f_3mnths','1f 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_3mnths\n 1f 3mnths\n \n 2020-06-05 11:28:37 UTC\n \n 2020-06-05 11:29:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 641\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:28:37',4,'2020-06-05 13:29:15',4,0,NULL,NULL,NULL,'66122df9-8b00-44eb-9895-faabe0421c6c'),(642,'adult_arv_1g_3mnths','1g 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_3mnths\n 1g 3mnths\n \n 2020-06-05 11:29:54 UTC\n \n 2021-01-27 16:32:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 642\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:29:54',4,'2021-01-27 16:32:52',4,0,NULL,NULL,NULL,'2e325001-abd4-4c5a-82b9-0ac9886ecbb6'),(643,'adult_arv_1h_3mnths','1h 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_3mnths\n 1h 3mnths\n \n 2020-06-05 11:30:54 UTC\n \n 2021-01-27 16:42:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 643\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:30:54',4,'2021-01-27 16:42:06',4,0,NULL,NULL,NULL,'c15f9357-fba2-46f7-96a1-44b25379ccea'),(644,'adult_arv_1j_3mnths','1j 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_3mnths\n 1j 3mnths\n \n 2020-06-05 11:32:13 UTC\n \n 2021-01-27 16:55:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 644\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:32:13',4,'2021-01-27 16:55:38',4,0,NULL,NULL,NULL,'e1b0c0ec-23b6-44c7-b80a-851b276f6238'),(645,'adult_arv_1k_3mnths','1k 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_3mnths\n 1k 3mnths\n \n 2020-06-05 11:35:55 UTC\n \n 2021-01-27 17:05:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 645\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:35:55',4,'2021-01-27 17:05:10',4,0,NULL,NULL,NULL,'2e6cd3c8-b48e-4e64-ac85-11c34fdeb49c'),(646,'adult_arv_1m_3mnths','1m 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_3mnths\n 1m 3mnths\n \n 2020-06-05 11:37:06 UTC\n \n 2021-01-27 17:14:41 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 646\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:37:06',4,'2021-01-27 17:14:41',4,0,NULL,NULL,NULL,'ac70448a-01bd-4e80-b1b4-9dffa36380a0'),(647,'adult_arv_1n_3mnths','1n 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_3mnths\n 1n 3mnths\n \n 2020-06-05 11:38:09 UTC\n \n 2021-01-27 17:34:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 647\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:38:09',4,'2021-01-27 17:34:59',4,0,NULL,NULL,NULL,'15d01fbf-abf1-4394-9da3-6d2a2b8f02f6'),(648,'adult_arv_1p_3mnths','1p 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_3mnths\n 1p 3mnths\n \n 2020-06-05 11:39:05 UTC\n \n 2021-01-27 17:54:50 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 648\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:39:05',4,'2021-01-27 17:54:50',4,0,NULL,NULL,NULL,'222eaf25-8e7a-4d38-bca4-41642991fe3d'),(649,'adult_arv_1q_3mnths','1q 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_3mnths\n 1q 3mnths\n \n 2020-06-05 11:40:02 UTC\n \n 2021-01-27 17:53:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 649\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:40:02',4,'2021-01-27 17:53:15',4,0,NULL,NULL,NULL,'f6d560ce-615d-4607-a3d0-8ae3435535fe'),(650,'adult_arv_other_3mnths','other 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_3mnths\n other 3mnths\n \n 2020-06-05 11:41:25 UTC\n \n 2021-02-04 09:03:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 650\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:41:25',4,'2021-02-04 09:03:37',4,0,NULL,NULL,NULL,'6ab6f0c1-401a-4a74-842f-c97983880745'),(651,'adult_arv_1c_6mnths','1c 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_6mnths\n 1c 6mnths\n \n 2020-06-05 11:43:07 UTC\n \n 2021-01-27 15:53:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 651\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:43:07',4,'2021-01-27 15:53:25',4,0,NULL,NULL,NULL,'4b1fc9fe-27bd-4473-b7dd-3f756a47ccb7'),(652,'adult_arv_1d_6mnths','1d 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_6mnths\n 1d 6mnths\n \n 2020-06-05 11:44:21 UTC\n \n 2021-01-27 16:08:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 652\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:44:21',4,'2021-01-27 16:08:01',4,0,NULL,NULL,NULL,'eab3ea99-52e0-4ea9-83f3-6711754e40e1'),(653,'adult_arv_1e_6mnths','1e 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_6mnths\n 1e 6mnths\n \n 2020-06-05 11:45:53 UTC\n \n 2021-01-27 16:19:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 653\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:45:53',4,'2021-01-27 16:19:28',4,0,NULL,NULL,NULL,'a7fd11c7-b7e0-43ea-b6aa-6c51ec395bcb'),(654,'adult_arv_1f_6mnths','1f 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_6mnths\n 1f 6mnths\n \n 2020-06-05 11:47:04 UTC\n \n 2020-06-05 11:47:39 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 654\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:47:04',4,'2020-06-05 13:47:39',4,0,NULL,NULL,NULL,'1f821fff-33b0-42b0-b62c-430af9d77512'),(655,'adult_arv_1g_6mnths','1g 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_6mnths\n 1g 6mnths\n \n 2020-06-05 11:48:04 UTC\n \n 2021-01-27 16:34:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 655\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:48:04',4,'2021-01-27 16:34:52',4,0,NULL,NULL,NULL,'96765b0d-eef0-4990-9602-d27fb6627270'),(656,'adult_arv_1h_6mnths','1h 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_6mnths\n 1h 6mnths\n \n 2020-06-05 11:49:10 UTC\n \n 2021-01-27 16:44:47 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 656\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:49:10',4,'2021-01-27 16:44:47',4,0,NULL,NULL,NULL,'bd0a9a38-fcfc-4dd7-89bd-3d3901b6f37f'),(657,'adult_arv_1j_6mnths','1j 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_6mnths\n 1j 6mnths\n \n 2020-06-05 11:51:11 UTC\n \n 2021-01-27 16:57:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 657\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:51:11',4,'2021-01-27 16:57:42',4,0,NULL,NULL,NULL,'f1d1b1e3-7805-49f6-b6e1-3e51ee5ca3c1'),(658,'adult_arv_1k_6mnths','1k 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_6mnths\n 1k 6mnths\n \n 2020-06-05 11:52:20 UTC\n \n 2021-01-27 17:07:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 658\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:52:20',4,'2021-01-27 17:07:04',4,0,NULL,NULL,NULL,'508ebf4a-5097-447f-a087-b722c8784233'),(659,'adult_arv_1m_6mnths','1m 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_6mnths\n 1m 6mnths\n \n 2020-06-05 11:53:19 UTC\n \n 2021-01-27 17:17:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 659\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:53:19',4,'2021-01-27 17:17:08',4,0,NULL,NULL,NULL,'08b21870-a277-4cf5-83da-3802031cd02d'),(660,'adult_arv_1n_6mnths','1n 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_6mnths\n 1n 6mnths\n \n 2020-06-05 11:55:16 UTC\n \n 2021-01-27 17:38:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 660\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:55:16',4,'2021-01-27 17:38:14',4,0,NULL,NULL,NULL,'078738ed-db38-4f25-9963-74e150af6157'),(661,'adult_arv_1p_6mnths','1p 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_6mnths\n 1p 6mnths\n \n 2020-06-05 11:56:46 UTC\n \n 2021-01-27 17:36:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 661\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:56:46',4,'2021-01-27 17:36:45',4,0,NULL,NULL,NULL,'a2dcd6db-39bc-469e-ac03-8bfedec4c18f'),(662,'adult_arv_1q_6mnths','1q 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_6mnths\n 1q 6mnths\n \n 2020-06-05 11:58:12 UTC\n \n 2021-01-27 18:00:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 662\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:58:12',4,'2021-01-27 18:00:44',4,0,NULL,NULL,NULL,'71007fca-4c23-43ab-81db-9090baa8fb01'),(663,'adult_arv_other_6mnths','other 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_6mnths\n other 6mnths\n \n 2020-06-05 11:59:58 UTC\n \n 2021-02-04 09:05:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 663\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:59:58',4,'2021-02-04 09:05:16',4,0,NULL,NULL,NULL,'24d02723-dc41-4afa-8f45-6da91778130a'),(664,'adult_arv_1c_other_mnths','1c other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_other_mnths\n 1c other supply\n \n 2020-06-05 12:03:30 UTC\n \n 2021-01-27 15:56:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 664\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:03:30',4,'2021-01-27 15:56:35',4,0,NULL,NULL,NULL,'fc0771aa-32dc-43da-b4eb-283519fedfd1'),(665,'adult_arv_1d_other_mnths','1d other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_other_mnths\n 1d other supply\n \n 2020-06-05 12:07:38 UTC\n \n 2021-01-27 16:10:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 665\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:07:38',4,'2021-01-27 16:10:12',4,0,NULL,NULL,NULL,'99e2601c-ddcc-42be-a3af-b659bbfdd9ea'),(666,'adult_arv_1e_other_mnths','1e other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_other_mnths\n 1e other supply\n \n 2020-06-05 12:09:09 UTC\n \n 2021-01-27 16:20:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 666\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:09:09',4,'2021-01-27 16:20:56',4,0,NULL,NULL,NULL,'5ee5c1d7-9ccf-44f3-b620-c849f9e502cb'),(667,'adult_arv_1f_other_mnths','1f other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_other_mnths\n 1f other supply\n \n 2020-06-05 12:10:11 UTC\n \n 2020-06-05 12:10:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 667\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 14:10:11',4,'2020-06-05 14:10:46',4,0,NULL,NULL,NULL,'c54c9e70-972e-475e-accd-d590158089aa'),(668,'adult_arv_1g_other_mnths','1g other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_other_mnths\n 1g other supply\n \n 2020-06-05 12:11:10 UTC\n \n 2020-06-05 12:11:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 668\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 14:11:10',4,'2020-06-05 14:11:48',4,0,NULL,NULL,NULL,'6f497b96-793f-444c-b599-b8c84802c8ce'),(669,'adult_arv_1h_other_mnths','1h other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_other_mnths\n 1h other supply\n \n 2020-06-05 12:12:15 UTC\n \n 2021-01-27 16:50:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 669\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:12:15',4,'2021-01-27 16:50:25',4,0,NULL,NULL,NULL,'6d91768d-95ad-42ff-a2e8-b994e7af2f3a'),(670,'adult_arv_1j_other_mnths','1j other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_other_mnths\n 1j other supply\n \n 2020-06-05 12:14:44 UTC\n \n 2020-06-05 12:15:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 670\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 14:14:44',4,'2020-06-05 14:15:18',4,0,NULL,NULL,NULL,'6176f910-0ee7-4ba9-997e-ce7585f83ae8'),(671,'adult_arv_1k_other_mnths','1k other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_other_mnths\n 1k other supply\n \n 2020-06-05 12:15:41 UTC\n \n 2021-01-27 17:08:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 671\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:15:41',4,'2021-01-27 17:08:52',4,0,NULL,NULL,NULL,'6e5cbb5d-f451-47ea-a2fd-9bff1f28f555'),(672,'Missed or defaulted under 28days','missed or defaulted < 28','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Missed or defaulted under 28days\n missed or defaulted < 28\n \n 2020-06-05 12:16:25 UTC\n \n 2022-05-04 07:07:49 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 672\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \n and l.location_id = :location or l.parent_location = :location \n -- PATIENTS WHO HAVE NOT SHOWED UP FOR THEIR APPOINTMENT FOR 4 WEEKS to 3 MONTHS (i.e. 29 to 89 days) \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n -- begin \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n and voided = 0 \n group by B.person_id \n ) as active_clients \n where active_clients.latest_follow_up < cast(:endDate as date) \n and DATEDIFF(CAST(:endDate AS DATE),latest_follow_up) > 0 \n and DATEDIFF(CAST(:endDate AS DATE),latest_follow_up) <= 28 \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.voided = 0 \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 and os.voided = 0 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.obs_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2398 and os.voided = 0 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 and voided = 0 \n ) \n ) \n -- end \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id AND person_name.preferred = 1 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n INNER JOIN reporting_age_group AS observed_age_group ON \n CAST(:endDate AS DATE) BETWEEN (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.min_years YEAR), INTERVAL observed_age_group.min_days DAY)) \n AND (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.max_years YEAR), INTERVAL observed_age_group.max_days DAY)) \n WHERE observed_age_group.report_group_name = 'Modified_Ages' \n','2020-06-05 12:16:25',4,'2022-05-04 07:07:49',4,0,NULL,NULL,NULL,'a7064d93-cb9d-44f7-b7cb-f0d38313fdb3'),(673,'adult_arv_1m_other_mnths','1m other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_other_mnths\n 1m other supply\n \n 2020-06-05 12:16:47 UTC\n \n 2021-01-27 17:18:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 673\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:16:47',4,'2021-01-27 17:18:26',4,0,NULL,NULL,NULL,'9ebb3d1c-52e8-40e7-abc2-871abfdd6ffa'),(674,'adult_arv_1n_other_mnths','1n other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_other_mnths\n 1n other supply\n \n 2020-06-05 12:17:46 UTC\n \n 2021-01-27 17:41:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 674\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:17:46',4,'2021-01-27 17:41:01',4,0,NULL,NULL,NULL,'b829a556-e0e5-4856-8800-ea2560894f62'),(675,'adult_arv_1p_other_mnths','1p other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_other_mnths\n 1p other supply\n \n 2020-06-05 12:20:31 UTC\n \n 2021-01-27 17:49:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 675\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:20:31',4,'2021-01-27 17:49:53',4,0,NULL,NULL,NULL,'6843123f-248a-4232-9008-a51ffdc43c5b'),(676,'adult_arv_1q_other_mnths','1q other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_other_mnths\n 1q other supply\n \n 2020-06-05 12:21:42 UTC\n \n 2021-01-27 18:07:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 676\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:21:42',4,'2021-01-27 18:07:21',4,0,NULL,NULL,NULL,'762d08de-74a3-40fe-9240-1fc904fcb69e'),(677,'Missed or defaulted between 29 and 89 days','missed >29\r\nmissed < 90','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Missed or defaulted between 29 and 89 days\n missed >29 \nmissed < 90\n \n 2020-06-05 12:22:30 UTC\n \n 2022-06-02 16:35:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 677\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \n and l.location_id = :location or l.parent_location = :location \n -- PATIENTS WHO HAVE NOT SHOWED UP FOR THEIR APPOINTMENT FOR 4 WEEKS to 3 MONTHS (i.e. 29 to 89 days) \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n -- begin \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n and voided = 0 \n group by B.person_id \n ) as active_clients \n where active_clients.latest_follow_up < cast(:endDate as date) \n and DATEDIFF(CAST(:endDate AS DATE),latest_follow_up) > 28 \n and DATEDIFF(CAST(:endDate AS DATE),latest_follow_up) <= 89 \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND os.voided = 0 \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND os.voided = 0 \n ) \n \n and active_clients.person_id not in ( \n \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.obs_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2398 \n AND os.voided = 0 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 and voided = 0 \n ) \n ) \n -- end \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id AND person_name.preferred = 1 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n INNER JOIN reporting_age_group AS observed_age_group ON \n CAST(:endDate AS DATE) BETWEEN (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.min_years YEAR), INTERVAL observed_age_group.min_days DAY)) \n AND (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.max_years YEAR), INTERVAL observed_age_group.max_days DAY)) \n WHERE observed_age_group.report_group_name = 'Modified_Ages' \n \n','2020-06-05 12:22:30',4,'2022-06-02 16:35:33',4,0,NULL,NULL,NULL,'5be87aeb-a57c-4a02-83e7-93d560d49fbb'),(678,'adult_arv_other_other_mnths','other other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_other_mnths\n other other supply\n \n 2020-06-05 12:23:07 UTC\n \n 2021-02-04 09:06:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 678\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:23:07',4,'2021-02-04 09:06:31',4,0,NULL,NULL,NULL,'c53c49b3-0557-4f1a-9006-1a88e542519d'),(679,'adult_arv_2c_1mnth','2c 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2c_1mnth\n 2c 1mnth\n \n 2020-06-05 12:36:06 UTC\n \n 2021-07-13 14:26:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 679\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:36:06',4,'2021-07-13 14:26:45',4,0,NULL,NULL,NULL,'69830812-bc46-428a-b10e-43a31a982e02'),(680,'LTFU this month','lost to follow up','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n LTFU this month\n lost to follow up\n \n 2020-06-05 12:37:18 UTC\n \n 2020-06-05 12:38:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 680\n select distinct o.person_id \nFROM obs o \nINNER JOIN patient ON o.person_id = patient.patient_id \nand o.concept_id = 3752 \nand o.value_datetime in \n ( \n select latestFU from \n ( \n select distinct os.person_id, max(os.value_datetime) AS latestFU, datediff(CAST(:endDate AS DATE), max(value_datetime)) AS \n Num_Days \n from obs os \n inner join person_name pn on os.person_id = pn.person_id \n inner join patient p on pn.person_id = p.patient_id and pn.voided = 0 \n inner join person ps on ps.person_id = p.patient_id and ps.voided = 0 \n where os.concept_id = 3752 \n and obs_datetime <= :endDate \n group by os.person_id \n having Num_Days > 7 \n and Num_Days < 30 \n ) as lost \n ) \nand o.person_id in \n ( \n select person_id from \n ( \n select distinct os.person_id, max(os.value_datetime) AS latestFU, datediff(CAST(:endDate AS DATE), \n max(value_datetime)) AS Num_Days \n from obs os \n inner join person_name pn on os.person_id = pn.person_id \n inner join patient p on pn.person_id = p.patient_id and pn.voided = 0 \n inner join person ps on ps.person_id = p.patient_id and ps.voided = 0 \n where os.concept_id = 3752 \n and obs_datetime <= :endDate \n group by os.person_id \n having Num_Days > 90 \n ) as lost \n ) \n \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 ) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND o.person_id not in ( \n select person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n;\n','2020-06-05 14:37:18',4,'2020-06-05 14:38:18',4,0,NULL,NULL,NULL,'f5c2691c-0977-4a4d-957e-2cf973e37bb7'),(681,'adult_arv_2d_1mnth','2d 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2d_1mnth\n 2d 1mnth\n \n 2020-06-05 12:37:55 UTC\n \n 2021-07-13 14:30:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 681\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:37:55',4,'2021-07-13 14:30:11',4,0,NULL,NULL,NULL,'456f6967-04cc-4c2a-8e50-7c99e799eb29'),(682,'adult_arv_2e_1mnth','2e 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2e_1mnth\n 2e 1mnth\n \n 2020-06-05 12:39:33 UTC\n \n 2021-07-13 14:30:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 682\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:39:33',4,'2021-07-13 14:30:44',4,0,NULL,NULL,NULL,'e5b6e482-9ccb-411c-bdf4-8dc43d421947'),(683,'adult_arv_2f_1mnth','2f 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2f_1mnth\n 2f 1mnth\n \n 2020-06-05 12:40:45 UTC\n \n 2021-07-13 14:34:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 683\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:40:45',4,'2021-07-13 14:34:37',4,0,NULL,NULL,NULL,'11aa9360-825c-4aac-ab2a-65d21642765e'),(684,'adult_arv_2g_1mnth','2g 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2g_1mnth\n 2g 1mnth\n \n 2020-06-05 12:41:52 UTC\n \n 2021-07-13 14:35:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 684\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:41:52',4,'2021-07-13 14:35:21',4,0,NULL,NULL,NULL,'b55997df-2560-4087-89ad-f80379b46dd4'),(685,'adult_arv_2h_1mnth','2h 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2h_1mnth\n 2h 1mnth\n \n 2020-06-05 12:43:08 UTC\n \n 2021-07-13 14:36:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 685\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:43:08',4,'2021-07-13 14:36:13',4,0,NULL,NULL,NULL,'4420cacb-9f9e-46ca-b86d-6d03e30a6f3e'),(686,'adult_arv_2j_1mnth','2j 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2j_1mnth\n 2j 1mnth\n \n 2020-06-05 12:44:01 UTC\n \n 2021-07-13 14:37:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 686\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:44:01',4,'2021-07-13 14:37:45',4,0,NULL,NULL,NULL,'e0941c5d-4a20-400b-a0db-862be83470e1'),(687,'adult_arv_2k_1mnth','2k 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2k_1mnth\n 2k 1mnth\n \n 2020-06-05 12:45:06 UTC\n \n 2021-07-13 14:39:23 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 687\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:45:06',4,'2021-07-13 14:39:23',4,0,NULL,NULL,NULL,'171a878c-c036-4486-a58d-798bc80c7447'),(688,'adult_arv_2l_1mnth','2l 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2l_1mnth\n 2l 1mnth\n \n 2020-06-05 12:46:11 UTC\n \n 2021-07-13 14:39:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 688\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:46:11',4,'2021-07-13 14:39:38',4,0,NULL,NULL,NULL,'ae5dd3df-007d-4ef2-bcdb-0ef68ff8bc7a'),(689,'adult_arv_2m_1mnth','2m 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2m_1mnth\n 2m 1mnth\n \n 2020-06-05 12:47:05 UTC\n \n 2021-07-13 14:41:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 689\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:47:05',4,'2021-07-13 14:41:45',4,0,NULL,NULL,NULL,'041a095c-5497-447e-9387-97b4d34df6ab'),(690,'adult_arv_2n_1mnth','2n 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2n_1mnth\n 2n 1mnth\n \n 2020-06-05 12:48:07 UTC\n \n 2021-07-13 14:41:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 690\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:48:07',4,'2021-07-13 14:41:59',4,0,NULL,NULL,NULL,'d64e6398-89a2-4612-985f-dc20dafa92b5'),(691,'adult_arv_2o_1mnth','2o 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2o_1mnth\n 2o 1mnth\n \n 2020-06-05 12:49:21 UTC\n \n 2021-07-13 14:45:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 691\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:49:21',4,'2021-07-13 14:45:11',4,0,NULL,NULL,NULL,'e5455427-d2fd-4398-88d8-372654f69bf7'),(692,'adult_arv_2p_1mnth','2p 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2p_1mnth\n 2p 1mnth\n \n 2020-06-05 12:50:20 UTC\n \n 2021-07-13 14:44:58 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 692\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:50:20',4,'2021-07-13 14:44:58',4,0,NULL,NULL,NULL,'f299f60d-7b3b-471e-b575-684c94c9ee57'),(693,'adult_arv_2q_1mnth','2q 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2q_1mnth\n 2q 1mnth\n \n 2020-06-05 12:51:42 UTC\n \n 2021-07-13 14:48:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 693\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:51:42',4,'2021-07-13 14:48:08',4,0,NULL,NULL,NULL,'be23c602-cbb1-43ac-b3c8-4c508cc65d66'),(694,'adult_arv_2c_3mnth','2c 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2c_3mnth\n 2c 3mnths\n \n 2020-06-05 12:56:13 UTC\n \n 2021-07-12 09:53:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 694\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:56:13',4,'2021-07-12 09:53:59',4,0,NULL,NULL,NULL,'04215a53-92bb-448c-bc0c-bdf13968fc4a'),(695,'adult_arv_2d_3mnths','2d 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2d_3mnths\n 2d 3mnths\n \n 2020-06-05 12:57:46 UTC\n \n 2020-07-26 12:39:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 695\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:57:46',4,'2020-07-26 12:39:30',4,0,NULL,NULL,NULL,'c9657610-a606-46db-8f55-24ded88ddf65'),(696,'Stopped ART this month','stopped ART','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Stopped ART this month\n stopped ART\n \n 2020-06-05 12:59:50 UTC\n \n 2020-06-05 13:00:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 696\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n where (o.location_id =:location or parent_location =:location) \n AND o.voided = 0 \n and concept_id = 2300 \n AND obs_datetime between :startDate AND :endDate\n','2020-06-05 14:59:50',4,'2020-06-05 15:00:33',4,0,NULL,NULL,NULL,'90747232-9c64-460b-b297-556853c19d27'),(697,'adult_arv_2e_3mnths','2e 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2e_3mnths\n 2e 3mnths\n \n 2020-06-05 13:02:16 UTC\n \n 2020-07-26 12:41:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 697\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:02:16',4,'2020-07-26 12:41:25',4,0,NULL,NULL,NULL,'10f3e3f4-f73e-4d8d-8024-108020886525'),(698,'adult_arv_2f_3mnths','2f 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2f_3mnths\n 2f 3mnths\n \n 2020-06-05 13:04:23 UTC\n \n 2020-07-26 12:43:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 698\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:04:23',4,'2020-07-26 12:43:52',4,0,NULL,NULL,NULL,'c2d8398b-5983-4f3b-b03a-81ca63635377'),(699,'adult_arv_2g_3mnths','2g 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2g_3mnths\n 2g 3mnths\n \n 2020-06-05 13:08:33 UTC\n \n 2020-07-26 12:49:39 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 699\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:08:33',4,'2020-07-26 12:49:39',4,0,NULL,NULL,NULL,'6a63e39d-88e4-49f2-84d1-63b1a1f1118d'),(700,'adult_arv_2h_3mnths','2h 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2h_3mnths\n 2h 3mnths\n \n 2020-06-05 13:10:20 UTC\n \n 2020-07-26 12:48:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 700\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:10:20',4,'2020-07-26 12:48:18',4,0,NULL,NULL,NULL,'3e13b024-8c5e-4004-b6de-fa643e50b752'),(701,'adult_arv_2j_3mnths','2j 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2j_3mnths\n 2j 3mnths\n \n 2020-06-05 13:11:27 UTC\n \n 2020-07-26 12:51:05 UTC\n \n \n \n \n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 701\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:11:27',4,'2020-07-26 12:51:05',4,0,NULL,NULL,NULL,'1a3b524f-388a-4692-aadf-c2c5c9832870'),(702,'adult_arv_2k_3mnths','2k 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2k_3mnths\n 2k 3mnths\n \n 2020-06-05 13:13:02 UTC\n \n 2020-07-26 12:56:02 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 702\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:13:02',4,'2020-07-26 12:56:02',4,0,NULL,NULL,NULL,'462e353e-3349-4334-8547-4361d310dd1f'),(703,'adult_arv_2l_3mnths','2l 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2l_3mnths\n 2l 3mnths\n \n 2020-06-05 13:14:56 UTC\n \n 2020-07-26 12:58:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 703\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:14:56',4,'2020-07-26 12:58:05',4,0,NULL,NULL,NULL,'762a506b-5142-4d0b-9a34-7364511b3804'),(704,'4c=AZT-3TC-NVP','4c','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4c=AZT-3TC-NVP\n 4c\n \n 2020-06-05 13:15:30 UTC\n \n 2021-07-01 09:54:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 704\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:15:30',4,'2021-07-01 09:54:14',4,0,NULL,NULL,NULL,'2333dba3-e4ab-4c96-b28d-b8a55cde3d1d'),(705,'adult_arv_2m_3mnths','2m 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2m_3mnths\n 2m 3mnths\n \n 2020-06-05 13:15:54 UTC\n \n 2020-07-26 13:00:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 705\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:15:54',4,'2020-07-26 13:00:52',4,0,NULL,NULL,NULL,'e39e9c25-717b-4e07-9cf0-9f7f3abfc08e'),(706,'adult_arv_2n_3mnths','2n 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2n_3mnths\n 2n 3mnths\n \n 2020-06-05 13:17:12 UTC\n \n 2020-07-26 13:03:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 706\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:17:12',4,'2020-07-26 13:03:32',4,0,NULL,NULL,NULL,'ff9adb70-4a63-4b77-b3ec-d3425b98afa4'),(707,'4d=AZT-3TC-EFV','4D','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4d=AZT-3TC-EFV\n 4D\n \n 2020-06-05 13:17:34 UTC\n \n 2021-07-01 09:54:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 707\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:17:34',4,'2021-07-01 09:54:59',4,0,NULL,NULL,NULL,'2090f6ca-5e65-4d41-98e3-b70f29abc483'),(708,'4e=ABC-3TC-NVP','4E','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4e=ABC-3TC-NVP\n 4E\n \n 2020-06-05 13:19:26 UTC\n \n 2021-07-01 09:55:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 708\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:19:26',4,'2021-07-01 09:55:40',4,0,NULL,NULL,NULL,'ee076dba-cc07-4b13-bc62-4d0d32193e03'),(709,'adult_arv_2o_3mnths','2o 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2o_3mnths\n 2o 3mnths\n \n 2020-06-05 13:19:40 UTC\n \n 2020-07-26 13:06:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 709\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:19:40',4,'2020-07-26 13:06:34',4,0,NULL,NULL,NULL,'738cb550-b15d-453e-bb7d-defc4b362956'),(710,'adult_arv_2p_3mnths','2p 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2p_3mnths\n 2p 3mnths\n \n 2020-06-05 13:20:54 UTC\n \n 2020-07-26 13:09:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 710\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:20:54',4,'2020-07-26 13:09:53',4,0,NULL,NULL,NULL,'60662d72-cea5-4ad5-93b0-ce12922fc834'),(711,'adult_arv_2q_3mnths','2q 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2q_3mnths\n 2q 3mnths\n \n 2020-06-05 13:22:02 UTC\n \n 2020-07-26 13:11:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 711\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:22:02',4,'2020-07-26 13:11:26',4,0,NULL,NULL,NULL,'9ea4bf50-06f1-4028-ab9f-d276a5ea38da'),(712,'4f=ABC-3TC-EFV','4F','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4f=ABC-3TC-EFV\n 4F\n \n 2020-06-05 13:22:28 UTC\n \n 2021-07-01 09:56:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 712\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:22:28',4,'2021-07-01 09:56:17',4,0,NULL,NULL,NULL,'eb90af68-e363-449b-810c-f1075ba677f0'),(713,'4g=AZT-3TC-LPV/r','4g','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4g=AZT-3TC-LPV/r\n 4g\n \n 2020-06-05 13:24:33 UTC\n \n 2021-07-01 09:57:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 713\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:24:33',4,'2021-07-01 09:57:45',4,0,NULL,NULL,NULL,'3da73ab3-5e2d-4416-adf8-69fda1030aff'),(714,'CI20a: Adult 3rd Line 1month supply 3a','3a 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI20a: Adult 3rd Line 1month supply 3a\n 3a 1mnth\n \n 2020-06-05 13:24:35 UTC\n \n 2021-07-13 15:19:02 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 714\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:24:35',4,'2021-07-13 15:19:02',4,0,NULL,NULL,NULL,'d5ac0964-e25b-4ac9-bde2-216933143835'),(715,'CI21a: Adult 3rd Line 1month supply 3b','3b 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI21a: Adult 3rd Line 1month supply 3b\n 3b 1mnth\n \n 2020-06-05 13:25:50 UTC\n \n 2021-07-13 15:20:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 715\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:25:50',4,'2021-07-13 15:20:07',4,0,NULL,NULL,NULL,'aecf3360-f578-4223-a2b9-8167716b3ded'),(716,'4h=ABC-3TC-LPV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4h=ABC-3TC-LPV/r\n \n \n 2020-06-05 13:25:57 UTC\n \n 2021-07-01 10:01:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 716\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:25:57',4,'2021-07-01 10:01:31',4,0,NULL,NULL,NULL,'ae250ccd-298b-4520-868e-14f945a7cc19'),(717,'CI22a: Adult 3rd Line 1month supply 3c','3c 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI22a: Adult 3rd Line 1month supply 3c\n 3c 1mnth\n \n 2020-06-05 13:26:59 UTC\n \n 2021-07-13 15:20:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 717\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:26:59',4,'2021-07-13 15:20:22',4,0,NULL,NULL,NULL,'9e32a97e-1aec-4924-8e31-c2870428b351'),(718,'4j=TDF-3TC-DTG(TLD)','4J','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4j=TDF-3TC-DTG(TLD)\n 4J\n \n 2020-06-05 13:27:32 UTC\n \n 2021-07-01 10:02:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 718\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:27:32',4,'2021-07-01 10:02:22',4,0,NULL,NULL,NULL,'30e58b2b-51ad-45c4-ba54-dfa0ee46192f'),(719,'CI40a: Adult 3rd Line 1month supply 3d','3d 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI40a: Adult 3rd Line 1month supply 3d\n 3d 1mnth\n \n 2020-06-05 13:28:21 UTC\n \n 2021-07-13 15:23:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 719\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:28:21',4,'2021-07-13 15:23:54',4,0,NULL,NULL,NULL,'e96450ab-af66-468b-9fe6-59e6dc7039a1'),(720,'CI41a: Adult 3rd Line 1month supply 3e','3e 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI41a: Adult 3rd Line 1month supply 3e\n 3e 1mnth\n \n 2020-06-05 13:29:18 UTC\n \n 2021-07-13 15:24:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 720\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:29:18',4,'2021-07-13 15:24:08',4,0,NULL,NULL,NULL,'9b325a21-8147-4294-8de3-11fe91804147'),(721,'Clients newly initiated 4j','4j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4j\n 4j\n \n 2020-06-05 13:30:13 UTC\n \n 2021-01-27 22:27:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 721\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4686 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 13:30:13',4,'2021-01-27 22:27:00',4,0,NULL,NULL,NULL,'98e00266-550e-4ac2-ad86-d1bfd1edad02'),(722,'CI42a: Adult 3rd Line 1month supply 3f','3f 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI42a: Adult 3rd Line 1month supply 3f\n 3f 1mnth\n \n 2020-06-05 13:30:30 UTC\n \n 2021-07-13 15:24:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 722\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:30:30',4,'2021-07-13 15:24:22',4,0,NULL,NULL,NULL,'0ec32115-a8ab-4989-8693-4a3b02a2f57f'),(723,'CI43a: Adult 3rd Line 1month supply 3g','3g 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI43a: Adult 3rd Line 1month supply 3g\n 3g 1mnth\n \n 2020-06-05 13:31:51 UTC\n \n 2021-07-13 15:25:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 723\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:31:51',4,'2021-07-13 15:25:40',4,0,NULL,NULL,NULL,'30f95dc0-e9d9-45e0-8780-13b386d0e1ed'),(724,'4k=ABC-3TC-DTG','4K','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4k=ABC-3TC-DTG\n 4K\n \n 2020-06-05 13:31:57 UTC\n \n 2021-07-01 10:03:27 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 724\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:31:57',4,'2021-07-01 10:03:27',4,0,NULL,NULL,NULL,'788332e7-cc9f-4abb-983a-9c85c218367e'),(725,'CI44a: Adult 3rd Line 1month supply 3h','3h 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI44a: Adult 3rd Line 1month supply 3h\n 3h 1mnth\n \n 2020-06-05 13:32:56 UTC\n \n 2021-07-13 15:25:58 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 725\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:32:56',4,'2021-07-13 15:25:58',4,0,NULL,NULL,NULL,'18a4ba21-a27a-41a1-a3a1-407d94e3b6af'),(726,'4L=AZT-3TC-DTG','4L','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4L=AZT-3TC-DTG\n 4L\n \n 2020-06-05 13:33:21 UTC\n \n 2021-07-01 10:03:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 726\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:33:21',4,'2021-07-01 10:03:40',4,0,NULL,NULL,NULL,'9e98473d-8542-491f-ba7a-72eed5bb8cc9'),(727,'5a=AZT-3TC-LPV/r','5a','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5a=AZT-3TC-LPV/r\n 5a\n \n 2020-06-05 13:37:09 UTC\n \n 2021-07-01 10:04:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 727\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:37:09',4,'2021-07-01 10:04:56',4,0,NULL,NULL,NULL,'90e1122b-ae81-4c9a-85bd-4718d62e8555'),(728,'5b=ABC-3TC-LPV/r','5B','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5b=ABC-3TC-LPV/r\n 5B\n \n 2020-06-05 13:38:40 UTC\n \n 2021-07-01 10:05:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 728\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:38:40',4,'2021-07-01 10:05:12',4,0,NULL,NULL,NULL,'5724ff33-4897-408c-8c0f-bd4f492421cf'),(729,'5c=ABC-3TC-DRV/r','5C','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5c=ABC-3TC-DRV/r\n 5C\n \n 2020-06-05 13:41:08 UTC\n \n 2021-07-01 10:06:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 729\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:41:08',4,'2021-07-01 10:06:05',4,0,NULL,NULL,NULL,'fcba5f96-f8b0-4cee-a432-d8a812214c91'),(730,'5d=AZT-3TC-DRV/r','5D','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5d=AZT-3TC-DRV/r\n 5D\n \n 2020-06-05 13:43:45 UTC\n \n 2021-07-01 10:06:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 730\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:43:45',4,'2021-07-01 10:06:20',4,0,NULL,NULL,NULL,'c755ea49-186f-44fc-b6c6-9063230d3480'),(731,'5e=AZT-3TC-ABC','5e','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5e=AZT-3TC-ABC\n 5e\n \n 2020-06-05 13:44:53 UTC\n \n 2021-07-01 10:07:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 731\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:44:53',4,'2021-07-01 10:07:11',4,0,NULL,NULL,NULL,'19dddce8-40b7-4851-ae3a-c3a1cb14eb91'),(732,'5f=AZT-3TC-DTG','5f','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5f=AZT-3TC-DTG\n 5f\n \n 2020-06-05 13:47:24 UTC\n \n 2021-07-01 10:07:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 732\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:47:24',4,'2021-07-01 10:07:29',4,0,NULL,NULL,NULL,'949e2eab-7153-4142-b71a-59e1a1defede'),(733,'Clients newly initiated 5f','5f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5f\n 5f\n \n 2020-06-05 13:48:37 UTC\n \n 2021-01-27 22:42:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 733\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4699 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 13:48:37',4,'2021-01-27 22:42:15',4,0,NULL,NULL,NULL,'c2568b3b-6226-4d7b-a190-b337501d1731'),(734,'5g=AZT-3TC-ATVr/','5G','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5g=AZT-3TC-ATVr/\n 5G\n \n 2020-06-05 13:50:29 UTC\n \n 2021-07-01 10:08:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 734\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:50:29',4,'2021-07-01 10:08:22',4,0,NULL,NULL,NULL,'286bc570-0ccd-48ff-862d-211475082a7a'),(735,'5h=ABC-3TC-ATV/r','5h','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5h=ABC-3TC-ATV/r\n 5h\n \n 2020-06-05 13:52:03 UTC\n \n 2021-07-01 10:09:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 735\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:52:03',4,'2021-07-01 10:09:01',4,0,NULL,NULL,NULL,'8d6b09b2-2781-4559-bfc0-a3c5678536b4'),(736,'6a=RAL-ETV-LPV/r','6a','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6a=RAL-ETV-LPV/r\n 6a\n \n 2020-06-05 13:53:49 UTC\n \n 2021-07-01 10:09:36 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 736\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:53:49',4,'2021-07-01 10:09:36',4,0,NULL,NULL,NULL,'23792b6c-5b46-4a98-9fe6-1d26d4f91e9e'),(737,'6b=RAL-ETV-DRV/r','6b','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6b=RAL-ETV-DRV/r\n 6b\n \n 2020-06-05 13:55:09 UTC\n \n 2021-07-01 10:09:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 737\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:55:09',4,'2021-07-01 10:09:59',4,0,NULL,NULL,NULL,'5449106c-244d-4d19-ad83-bba3f01589e7'),(738,'6c=RAL+ETV+DRV/r','6C','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6c=RAL+ETV+DRV/r\n 6C\n \n 2020-06-05 13:57:19 UTC\n \n 2021-07-01 10:10:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 738\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:57:19',4,'2021-07-01 10:10:51',4,0,NULL,NULL,NULL,'aa99445e-54bd-4de8-9ef1-9a888fd68239'),(739,'6d=TDF-3TC-DRV/r+RAL','6D','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6d=TDF-3TC-DRV/r+RAL\n 6D\n \n 2020-06-05 13:59:01 UTC\n \n 2021-07-01 10:11:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 739\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:59:01',4,'2021-07-01 10:11:04',4,0,NULL,NULL,NULL,'367ded00-770e-478f-a366-2c5ca91c2567'),(740,'6e=RAL+DRV/r','6E','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6e=RAL+DRV/r\n 6E\n \n 2020-06-05 14:00:26 UTC\n \n 2021-07-01 10:12:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 740\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 14:00:26',4,'2021-07-01 10:12:05',4,0,NULL,NULL,NULL,'a8e0b35d-cf9a-4f1f-8995-c7a9e28b1103'),(741,'6f=AZT+3TC+DRV/r+ETV','6F','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6f=AZT+3TC+DRV/r+ETV\n 6F\n \n 2020-06-05 14:02:22 UTC\n \n 2021-07-01 10:12:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 741\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 14:02:22',4,'2021-07-01 10:12:20',4,0,NULL,NULL,NULL,'0952cfb3-6f9b-4d27-b94b-4c25ba0c99e7'),(742,'Cotrimox Prophylaxis/Dapsone','CTX','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Cotrimox Prophylaxis/Dapsone\n CTX\n \n 2020-06-05 14:06:03 UTC\n \n 2020-06-05 14:06:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 742\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:06:03',4,'2020-06-05 16:06:48',4,0,NULL,NULL,NULL,'12dfb355-bf17-4ee3-a267-b047f38a89b8'),(743,'Missed or defaulted under 28days','missed appointments under 28 days','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Missed or defaulted under 28days\n missed appointments under 28 days\n \n 2020-06-05 14:06:51 UTC\n \n 2020-06-05 14:08:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 743\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:06:51',4,'2020-06-05 16:08:00',4,0,NULL,NULL,NULL,'26fb300b-c224-45ae-a82e-94786101c82d'),(744,'RUFT','Plumpy-nut','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n RUFT\n Plumpy-nut\n \n 2020-06-05 14:08:10 UTC\n \n 2020-06-05 14:09:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 744\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:08:10',4,'2020-06-05 16:09:03',4,0,NULL,NULL,NULL,'e72ff52c-b8c7-4728-bf7b-747e208b3e06'),(745,'Missed or defaulted between 29 and 89 days','Missed or defaulted between 29 and 89 days','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Missed or defaulted between 29 and 89 days\n Missed or defaulted between 29 and 89 days\n \n 2020-06-05 14:08:54 UTC\n \n 2020-06-05 14:09:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 745\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:08:54',4,'2020-06-05 16:09:29',4,0,NULL,NULL,NULL,'6ec03f54-c1f7-49b4-9332-c7c9aa994579'),(746,'Given F100 in the month','F100','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Given F100 in the month\n F100\n \n 2020-06-05 14:09:44 UTC\n \n 2020-06-05 14:10:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 746\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:09:44',4,'2020-06-05 16:10:29',4,0,NULL,NULL,NULL,'052f159f-57d1-4597-94ae-d81c0876610d'),(747,'Given F75 in the month','F75','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Given F75 in the month\n F75\n \n 2020-06-05 14:10:52 UTC\n \n 2020-06-05 14:12:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 747\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:10:52',4,'2020-06-05 16:12:03',4,0,NULL,NULL,NULL,'a63995e1-38a2-4c49-8189-7e2eff852513'),(748,'Other Nutritional Supplement given in the month','other','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Other Nutritional Supplement given in the month\n other\n \n 2020-06-05 14:12:35 UTC\n \n 2020-06-05 14:13:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 748\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:12:35',4,'2020-06-05 16:13:16',4,0,NULL,NULL,NULL,'092667a0-a0a3-4f6e-b25d-963a76c74814'),(750,'Children ARV Regimen Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children ARV Regimen Data Set\n \n 2020-06-05 14:19:22 UTC\n \n 2020-06-05 16:09:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 750\n \n \n DM_Weight\n \n \n \n \n \n \n \n \n 4L03to3.9\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Weight\n 03to3.9kg\n \n \n \n \n \n 4L10to13.9\n \n \n \n \n DM_Weight\n 10to13.9kg\n \n \n \n \n \n 4L14to19.9\n \n \n \n \n DM_Weight\n 14to19.9kg\n \n \n \n \n \n 4L20to24.9\n \n \n \n \n DM_Weight\n 20to24.9kg\n \n \n \n \n \n 4L25to34.9\n \n \n \n \n DM_Weight\n 25to34.9kg\n \n \n \n \n \n 4L4to5.9\n \n \n \n \n DM_Weight\n 04to5.9kg\n \n \n \n \n \n 4L6to9.9\n \n \n \n \n DM_Weight\n 06to9.9kg\n \n \n \n \n \n 4c03to3.9\n \n \n \n \n \n \n \n \n \n 4c10to13.9\n \n \n \n \n \n \n 4c14to19.9\n \n \n \n \n \n \n 4c20to24.9\n \n \n \n \n \n \n 4c25to34.9\n \n \n \n \n \n \n 4c4to5.9\n \n \n \n \n \n \n 4c6to9.9\n \n \n \n \n \n \n 4d0.3to3.9\n \n \n \n \n \n \n \n \n \n 4d10to13.9\n \n \n \n \n \n \n 4d14to19.9\n \n \n \n \n \n \n 4d20to24.9\n \n \n \n \n \n \n 4d25to34.9\n \n \n \n \n \n \n 4d4to5.9\n \n \n \n \n \n \n 4d6to9.9\n \n \n \n \n \n \n 4e0.3to3.9\n \n \n \n \n \n \n \n \n \n 4e10to13.9\n \n \n \n \n \n \n 4e14to19.9\n \n \n \n \n \n \n 4e20to24.9\n \n \n \n \n \n \n 4e25to34.9\n \n \n \n \n \n \n 4e4to5.9\n \n \n \n \n \n \n 4e6to9.9\n \n \n \n \n \n \n 4f0.3to3.9\n \n \n \n \n \n \n \n \n \n 4f10to13.9\n \n \n \n \n \n \n 4f14to19.9\n \n \n \n \n \n \n 4f20to24.9\n \n \n \n \n \n \n 4f25to34.9\n \n \n \n \n \n \n 4f4to5.9\n \n \n \n \n \n \n 4f6to9.9\n \n \n \n \n \n \n 4g0.3to3.9\n \n \n \n \n \n \n \n \n \n 4g10to13.9\n \n \n \n \n \n \n 4g14to19.9\n \n \n \n \n \n \n 4g20to24.9\n \n \n \n \n \n \n 4g25to34.9\n \n \n \n \n \n \n 4g4to5.9\n \n \n \n \n \n \n 4g6to9.9\n \n \n \n \n \n \n 4h0.3to3.9\n \n \n \n \n \n \n \n \n \n 4h10to13.9\n \n \n \n \n \n \n 4h14to19.9\n \n \n \n \n \n \n 4h20to24.9\n \n \n \n \n \n \n 4h25to34.9\n \n \n \n \n \n \n 4h4to5.9\n \n \n \n \n \n \n 4h6to9.9\n \n \n \n \n \n \n 4j0.3to3.9\n \n \n \n \n \n \n \n \n \n 4j10to13.9\n \n \n \n \n \n \n 4j14to19.9\n \n \n \n \n \n \n 4j20to24.9\n \n \n \n \n \n \n 4j25to34.9\n \n \n \n \n \n \n 4j4to5.9\n \n \n \n \n \n \n 4j6to9.9\n \n \n \n \n \n \n 4k0.3to3.9\n \n \n \n \n \n \n \n \n \n 4k10to13.9\n \n \n \n \n \n \n 4k14to19.9\n \n \n \n \n \n \n 4k20to24.9\n \n \n \n \n \n \n 4k25to34.9\n \n \n \n \n \n \n 4k4to5.9\n \n \n \n \n \n \n 4k6to9.9\n \n \n \n \n \n \n','2020-06-05 16:19:22',4,'2020-06-05 18:09:53',4,0,NULL,NULL,NULL,'86987ed4-9fb6-46c9-9376-124ca29b26cb'),(751,'Stopped ART this month','stopped this month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Stopped ART this month\n stopped this month\n \n 2020-06-05 15:34:17 UTC\n \n 2020-06-05 15:37:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 751\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 17:34:17',4,'2020-06-05 17:37:55',4,0,NULL,NULL,NULL,'3339dfc7-cd36-4231-b31e-5390963065ab'),(752,'2020_adult_arv_1stline_regimen','new dataset ADULT ARV REGIMEN AT THE END OF THE MONTH (15+)','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_adult_arv_1stline_regimen\n new dataset ADULT ARV REGIMEN AT THE END OF THE MONTH (15+)\n \n 2020-06-05 15:51:46 UTC\n \n 2020-07-26 09:11:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 752\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-06-05 15:51:46',4,'2020-07-26 09:11:25',4,0,NULL,NULL,NULL,'bf495055-881f-4d8f-a313-034368641292'),(753,'2020_ADULT ARV REGIMEN AT THE END OF THE MONTH (15+) Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_ADULT ARV REGIMEN AT THE END OF THE MONTH (15+) Data Set\n \n 2020-06-05 15:51:49 UTC\n \n 2021-01-27 14:00:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 753\n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n 1c_1mnth\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n 1c_3mnths\n \n \n \n \n \n \n \n \n \n 1c_6mnths\n \n \n \n \n \n \n \n \n \n 1c_other\n \n \n \n \n \n \n \n \n \n 1d_1mnth\n \n \n \n \n \n \n \n \n \n 1d_3mnths\n \n \n \n \n \n \n \n \n \n 1d_6mnths\n \n \n \n \n \n \n \n \n \n 1d_other\n \n \n \n \n \n \n \n \n \n 1e_1mnth\n \n \n \n \n \n \n \n \n \n 1e_3mnths\n \n \n \n \n \n \n \n \n \n 1e_6mnths\n \n \n \n \n \n \n \n \n \n 1e_other\n \n \n \n \n \n \n \n \n \n 1f_1mnth\n \n \n \n \n \n \n \n \n \n 1f_3mnths\n \n \n \n \n \n \n \n \n \n 1f_6mnths\n \n \n \n \n \n \n \n \n \n 1f_othmnth\n \n \n \n \n \n \n \n \n \n 1g_1mnth\n \n \n \n \n \n \n \n \n \n 1g_3mnths\n \n \n \n \n \n \n \n \n \n 1g_6mnths\n \n \n \n \n \n \n \n \n \n 1g_other\n \n \n \n \n \n \n \n \n \n 1h_1mnth\n \n \n \n \n \n \n \n \n \n 1h_3mnths\n \n \n \n \n \n \n \n \n \n 1h_6mnths\n \n \n \n \n \n \n \n \n \n 1h_other\n \n \n \n \n \n \n \n \n \n 1j_1mnth\n \n \n \n \n \n \n \n \n \n 1j_3mnths\n \n \n \n \n \n \n \n \n \n 1j_6mnths\n \n \n \n \n \n \n \n \n \n 1j_other\n \n \n \n \n \n \n \n \n \n 1k_1mnth\n \n \n \n \n \n \n \n \n \n 1k_3mnths\n \n \n \n \n \n \n \n \n \n 1k_6mnths\n \n \n \n \n \n \n \n \n \n 1k_other\n \n \n \n \n \n \n \n \n \n 1m_1mnth\n \n \n \n \n \n \n \n \n \n 1m_3mnths\n \n \n \n \n \n \n \n \n \n 1m_6mnths\n \n \n \n \n \n \n \n \n \n 1m_other\n \n \n \n \n \n \n \n \n \n 1n_1mnth\n \n \n \n \n \n \n \n \n \n 1n_3mnths\n \n \n \n \n \n \n \n \n \n 1n_6mnths\n \n \n \n \n \n \n \n \n \n 1n_other\n \n \n \n \n \n \n \n \n \n 1p_1mnth\n \n \n \n \n \n \n \n \n \n 1p_3mnths\n \n \n \n \n \n \n \n \n \n 1p_6mnths\n \n \n \n \n \n \n \n \n \n 1p_other\n \n \n \n \n \n \n \n \n \n 1q_1mnth\n \n \n \n \n \n \n \n \n \n 1q_3mnths\n \n \n \n \n \n \n \n \n \n 1q_6mnths\n \n \n \n \n \n \n \n \n \n 1q_other\n \n \n \n \n \n \n \n \n \n other_1mnt\n \n \n \n \n \n \n \n \n \n other_3mnt\n \n \n \n \n \n \n \n \n \n other_6mnt\n \n \n \n \n \n \n \n \n \n other_othe\n \n \n \n \n \n \n \n \n \n','2020-06-05 15:51:49',4,'2021-01-27 14:00:34',4,0,NULL,NULL,NULL,'48bdf3d1-3a1a-46b1-a53a-7db8f1a24781'),(755,'Children ARV Regimen_2ndLine Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children ARV Regimen_2ndLine Data Set\n \n 2020-06-06 16:40:08 UTC\n \n 2020-06-06 17:59:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 755\n \n \n DM_Weight\n \n \n \n \n \n \n \n \n 5a10to13.9\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Weight\n 10to13.9kg\n \n \n \n \n \n 5a14to19.9\n \n \n \n \n DM_Weight\n 14to19.9kg\n \n \n \n \n \n 5a20to24.9\n \n \n \n \n DM_Weight\n 20to24.9kg\n \n \n \n \n \n 5a25to34.9\n \n \n \n \n DM_Weight\n 25to34.9kg\n \n \n \n \n \n 5a3to3.9\n \n \n \n \n DM_Weight\n 03to3.9kg\n \n \n \n \n \n 5a4to5.9\n \n \n \n \n DM_Weight\n 04to5.9kg\n \n \n \n \n \n 5a6to9.9\n \n \n \n \n DM_Weight\n 06to9.9kg\n \n \n \n \n \n 5b10to13.9\n \n \n \n \n \n \n \n \n \n 5b14to19.9\n \n \n \n \n \n \n 5b20to24.9\n \n \n \n \n \n \n 5b25to34.9\n \n \n \n \n \n \n 5b3to3.9\n \n \n \n \n \n \n 5b4to5.9\n \n \n \n \n \n \n 5b6to9.9\n \n \n \n \n \n \n 5c10to13.9\n \n \n \n \n \n \n \n \n \n 5c14to19.9\n \n \n \n \n \n \n 5c20to24.9\n \n \n \n \n \n \n 5c25to34.9\n \n \n \n \n \n \n 5c3to3.9\n \n \n \n \n \n \n 5c4to5.9\n \n \n \n \n \n \n 5c6to9.9\n \n \n \n \n \n \n 5d10to13.9\n \n \n \n \n \n \n \n \n \n 5d14to19.9\n \n \n \n \n \n \n 5d20to24.9\n \n \n \n \n \n \n 5d25to34.9\n \n \n \n \n \n \n 5d3to3.9\n \n \n \n \n \n \n 5d4to5.9\n \n \n \n \n \n \n 5d6to9.9\n \n \n \n \n \n \n 5e10to13.9\n \n \n \n \n \n \n \n \n \n 5e14to19.9\n \n \n \n \n \n \n 5e20to24.9\n \n \n \n \n \n \n 5e25to34.9\n \n \n \n \n \n \n 5e3to3.9\n \n \n \n \n \n \n 5e4to5.9\n \n \n \n \n \n \n 5e6to9.9\n \n \n \n \n \n \n 5f10to13.9\n \n \n \n \n \n \n \n \n \n 5f14to19.9\n \n \n \n \n \n \n 5f20to24.9\n \n \n \n \n \n \n 5f25to34.9\n \n \n \n \n \n \n 5f3to3.9\n \n \n \n \n \n \n 5f4to5.9\n \n \n \n \n \n \n 5f6to9.9\n \n \n \n \n \n \n 5g10to13.9\n \n \n \n \n \n \n \n \n \n 5g14to19.9\n \n \n \n \n \n \n 5g20to24.9\n \n \n \n \n \n \n 5g25to34.9\n \n \n \n \n \n \n 5g3to3.9\n \n \n \n \n \n \n 5g4to5.9\n \n \n \n \n \n \n 5g6to9.9\n \n \n \n \n \n \n 5h10to13.9\n \n \n \n \n \n \n \n \n \n 5h14to19.9\n \n \n \n \n \n \n 5h20to24.9\n \n \n \n \n \n \n 5h25to34.9\n \n \n \n \n \n \n 5h3to3.9\n \n \n \n \n \n \n 5h4to5.9\n \n \n \n \n \n \n 5h6to9.9\n \n \n \n \n \n \n','2020-06-06 18:40:08',4,'2020-06-06 19:59:56',4,0,NULL,NULL,NULL,'b544b920-9355-4cde-91ef-1abce8a0666c'),(756,'Clients given CTX in the month','Clients given CTX in the month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given CTX in the month\n Clients given CTX in the month\n \n 2020-06-06 17:51:03 UTC\n \n 2020-06-06 17:52:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 756\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-06 19:51:03',4,'2020-06-06 19:52:29',4,0,NULL,NULL,NULL,'9227d423-f843-4299-866e-c0ef068a8faa'),(758,'Children ARV Regimen_3rdLine Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children ARV Regimen_3rdLine Data Set\n \n 2020-06-06 18:10:43 UTC\n \n 2020-06-08 08:32:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 758\n \n \n DM_Weight\n \n \n \n \n \n \n \n \n 6a10to13.9\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Weight\n 10to13.9kg\n \n \n \n \n \n 6a14to19.9\n \n \n \n \n DM_Weight\n 14to19.9kg\n \n \n \n \n \n 6a20to24.9\n \n \n \n \n DM_Weight\n 20to24.9kg\n \n \n \n \n \n 6a25to34.9\n \n \n \n \n DM_Weight\n 25to34.9kg\n \n \n \n \n \n 6a3to3.9\n \n \n \n \n DM_Weight\n 03to3.9kg\n \n \n \n \n \n 6a4to5.9\n \n \n \n \n DM_Weight\n 04to5.9kg\n \n \n \n \n \n 6a6to9.9\n \n \n \n \n DM_Weight\n 06to9.9kg\n \n \n \n \n \n 6b10to13.9\n \n \n \n \n \n \n \n \n \n 6b14to19.9\n \n \n \n \n \n \n 6b20to24.9\n \n \n \n \n \n \n 6b25to34.9\n \n \n \n \n \n \n 6b3to3.9\n \n \n \n \n \n \n 6b4to5.9\n \n \n \n \n \n \n 6b6to9.9\n \n \n \n \n \n \n 6c10to13.9\n \n \n \n \n \n \n \n \n \n 6c14to19.9\n \n \n \n \n \n \n 6c20to24.9\n \n \n \n \n \n \n 6c25to34.9\n \n \n \n \n \n \n 6c3to3.9\n \n \n \n \n \n \n 6c4to5.9\n \n \n \n \n \n \n 6c6to9.9\n \n \n \n \n \n \n 6d10to13.9\n \n \n \n \n \n \n \n \n \n 6d14to19.9\n \n \n \n \n \n \n 6d20to24.9\n \n \n \n \n \n \n 6d25to34.9\n \n \n \n \n \n \n 6d3to3.9\n \n \n \n \n \n \n 6d4to5.9\n \n \n \n \n \n \n 6d6to9.9\n \n \n \n \n \n \n 6e10to13.9\n \n \n \n \n \n \n \n \n \n 6e14to19.9\n \n \n \n \n \n \n 6e20to24.9\n \n \n \n \n \n \n 6e25to34.9\n \n \n \n \n \n \n 6e3to3.9\n \n \n \n \n \n \n 6e4to5.9\n \n \n \n \n \n \n 6e6to9.9\n \n \n \n \n \n \n 6f10to13.9\n \n \n \n \n \n \n \n \n \n 6f14to19.9\n \n \n \n \n \n \n 6f20to24.9\n \n \n \n \n \n \n 6f25to34.9\n \n \n \n \n \n \n 6f3to3.9\n \n \n \n \n \n \n 6f4to5.9\n \n \n \n \n \n \n 6f6to9.9\n \n \n \n \n \n \n','2020-06-06 20:10:43',4,'2020-06-08 10:32:22',4,0,NULL,NULL,NULL,'6e3a006d-98ce-4042-9850-7ba6ccfadebe'),(759,'2020_NUTRITIONAL SUPPLEMENT','new dataset NUTRITIONAL SUPPLEMENT','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_NUTRITIONAL SUPPLEMENT\n new dataset NUTRITIONAL SUPPLEMENT\n \n 2020-06-06 18:19:59 UTC\n \n 2020-06-06 18:20:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 759\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-06-06 20:19:59',4,'2020-06-06 20:20:03',4,0,NULL,NULL,NULL,'bb75a854-ddeb-4ce5-b822-f76dd8bf22ad'),(760,'2020_NUTRITIONAL SUPPLEMENT Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_NUTRITIONAL SUPPLEMENT Data Set\n \n 2020-06-06 18:20:03 UTC\n \n 2020-06-08 10:00:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 760\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n F100FAdult\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n F100FChild\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n F100MAdult\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Adults\n \n \n \n \n \n F100MChild\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n F75FAdult\n \n \n \n \n \n \n \n \n \n F75FChild\n \n \n \n \n \n \n F75MAdult\n \n \n \n \n \n \n F75MChild\n \n \n \n \n \n \n OtherFAdul\n \n \n \n \n \n \n \n \n \n OtherFChil\n \n \n \n \n \n \n OtherMAdul\n \n \n \n \n \n \n OtherMChil\n \n \n \n \n \n \n PlumpFAdul\n \n \n \n \n \n \n \n \n \n PlumpFChil\n \n \n \n \n \n \n PlumpMAdul\n \n \n \n \n \n \n PlumpMChil\n \n \n \n \n \n \n cereal-F14\n \n \n \n \n \n \n \n \n \n cereal_F15\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n cereal-M14\n \n \n \n \n \n \n cereal_M15\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n','2020-06-06 20:20:03',4,'2020-06-08 12:00:54',4,0,NULL,NULL,NULL,'acc0e9d9-fe35-4d6d-8707-818221deeaa9'),(761,'Plumpy Nut given in the month','Plumpy Nut given in the month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Plumpy Nut given in the month\n Plumpy Nut given in the month\n \n 2020-06-06 18:30:00 UTC\n \n 2020-06-06 18:30:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 761\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-06 20:30:00',4,'2020-06-06 20:30:55',4,0,NULL,NULL,NULL,'1a8809c1-0866-4b11-8ed9-2ca4fc02154e'),(762,'F100 given in the month','F100 given in the month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n F100 given in the month\n F100 given in the month\n \n 2020-06-06 18:32:13 UTC\n \n 2020-06-06 18:33:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 762\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-06 20:32:13',4,'2020-06-06 20:33:54',4,0,NULL,NULL,NULL,'5d68b260-ac27-417d-b075-27c258ed6e5d'),(763,'F75 given in the month','F75 given in the month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n F75 given in the month\n F75 given in the month\n \n 2020-06-06 18:34:41 UTC\n \n 2020-06-06 18:35:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 763\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-06 20:34:41',4,'2020-06-06 20:35:51',4,0,NULL,NULL,NULL,'f72d3c94-b272-489a-af95-c198ac632230'),(764,'Other Nutritional Supplement given in the month','Other Nutritional Supplement given in the month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Other Nutritional Supplement given in the month\n Other Nutritional Supplement given in the month\n \n 2020-06-06 18:37:18 UTC\n \n 2020-06-06 18:38:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 764\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-06 20:37:18',4,'2020-06-06 20:38:33',4,0,NULL,NULL,NULL,'49f802d9-a927-432f-9ecc-5320277583a1'),(765,'Given Super Cereal in the month','super cereal','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Given Super Cereal in the month\n super cereal\n \n 2020-06-08 09:14:51 UTC\n \n 2020-07-07 10:18:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 765\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 4167 and value_coded = 4815\n','2020-06-08 09:14:51',4,'2020-07-07 10:18:22',4,0,NULL,NULL,NULL,'7e88e4d8-d827-49ba-85ce-942847494e02'),(766,'Given Super Cereal in the month','super cereal','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Given Super Cereal in the month\n super cereal\n \n 2020-06-08 09:16:05 UTC\n \n 2020-06-08 09:16:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 766\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-08 11:16:05',4,'2020-06-08 11:16:54',4,0,NULL,NULL,NULL,'7873e38f-7b02-46fc-8002-a0e6fcc7bde8'),(768,'testing Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n testing Data Set\n \n 2020-06-16 09:29:58 UTC\n \n 2020-06-16 09:35:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 768\n \n \n DM_Weight\n \n \n \n \n \n \n \n \n 1\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Weight\n 03to3.9kg\n \n \n \n \n \n 2\n \n \n \n \n DM_Weight\n 06to9.9kg\n \n \n \n \n \n 3\n \n \n \n \n DM_Weight\n 10to13.9kg\n \n \n \n \n \n 4\n \n \n \n \n DM_Weight\n 14to19.9kg\n \n \n \n \n \n 5\n \n \n \n \n DM_Weight\n 20to24.9kg\n \n \n \n \n \n 6\n \n \n \n \n DM_Weight\n 25to34.9kg\n \n \n \n \n \n','2020-06-16 09:29:58',4,'2020-06-16 09:35:38',4,0,NULL,NULL,NULL,'bf5ad6aa-84e3-4553-8feb-3c3f5a6b7270'),(769,'Clients enrolled this month','Clients enrolled this month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients enrolled this month\n Clients enrolled this month\n \n 2020-06-19 08:31:52 UTC\n \n 2022-04-26 14:50:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 769\n select distinct o.person_id \n from obs o \n inner join location l on o.location_id = l.location_id \n -- Retesting Results Pos \n INNER JOIN person ON person.person_id = o.person_id \n where o.concept_id = 4817 and o.value_coded = 1738 \n AND o.voided = 0 \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.person_id in( \n select distinct os.person_id \n from obs os \n -- Not Linked to Care \n where os.concept_id = 4239 and os.value_coded = 2147 \n and os.voided = 0 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n )\n','2020-06-19 08:31:52',4,'2022-04-26 14:50:16',4,0,NULL,NULL,NULL,'7037562b-4e82-493e-8858-78e0d5d8fbbf'),(770,'Clients ever enrolled on PrE ART','Clients ever enrolled on care','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients ever enrolled on PrE ART\n Clients ever enrolled on care\n \n 2020-06-19 08:35:31 UTC\n \n 2022-04-27 09:49:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 770\n select distinct o.person_id \n from obs o \n inner join location l on o.location_id = l.location_id \n -- Retesting Results Positive \n INNER JOIN person ON person.person_id = o.person_id \n where o.concept_id = 4817 and o.value_coded = 1738 \n AND o.voided = 0 \n AND o.person_id in( \n select distinct os.person_id \n from obs os \n -- Not Linked to Care \n where os.concept_id = 4239 and os.value_coded = 2147 \n and os.voided = 0 \n ) \n AND o.person_id not in ( \n -- Current period Pre-ART \n select distinct o.person_id \n from obs o \n inner join location l on o.location_id = l.location_id \n -- Retesting Results Pos \n INNER JOIN person ON person.person_id = o.person_id \n where o.concept_id = 4817 and o.value_coded = 1738 \n AND o.voided = 0 \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.person_id in( \n select distinct os.person_id \n from obs os \n -- Not Linked to Care \n where os.concept_id = 4239 and os.value_coded = 2147 \n and os.voided = 0 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n \n )\n','2020-06-19 08:35:31',4,'2022-04-27 09:49:54',4,0,NULL,NULL,NULL,'ca1c2a0a-48f5-4370-b46a-2678e49bc163'),(771,'ART and Pre ART Seen this month','ART and Pre ART Seen this month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART and Pre ART Seen this month\n ART and Pre ART Seen this month\n \n 2020-06-19 08:43:33 UTC\n \n 2022-07-20 14:18:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 771\n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN location l on o.location_id = l.location_id \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n \n LEFT JOIN ( \n SELECT person_id FROM obs \n WHERE concept_id = 2223 \n ) preart \n ON o.person_id = preart.person_id \n WHERE (o.location_id =:location or parent_location =:location) \n','2020-06-19 10:43:33',4,'2022-07-20 16:18:20',4,0,NULL,NULL,NULL,'05ced471-b115-479a-976c-318595d37af4'),(772,'ART and Pre ART Screened this month','screened','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART and Pre ART Screened this month\n screened\n \n 2020-06-19 09:06:15 UTC\n \n 2021-12-16 16:03:41 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 772\n select distinct id \nfrom \n( \n(select distinct o.person_id as id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id AND person.voided = 0 \n WHERE o.concept_id = 3843 AND o.value_coded in (3841,3842) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n AND (o.location_id =:location or parent_location =:location) \n AND o.person_id in ( \n select person_id from obs os \n where os.concept_id = 3710 \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND os.voided = 0 \n -- order by 1 \n ) \n \n) \n \nUNION \n \n(select B.person_id \n from obs B \n inner join location l on B.location_id = l.location_id \n INNER JOIN person ON person.person_id = B.person_id AND person.voided = 0 \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 2386 \n and obs_datetime <= cast(:endDate as date) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND voided = 0 \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 2294 and value_coded = 2146 \n and A.observation_id = B.obs_group_id \n and B.voided = 0 \n group by B.person_id \n and B.person_id in ( \n select person_id from obs os \n -- Final HIV status is Positive i.e \n where os.concept_id = 2165 and value_coded = 1738 \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND os.voided = 0 \n group by person_id \n ) \n ))X\n','2020-06-19 11:06:15',4,'2021-12-16 18:03:41',4,0,NULL,NULL,NULL,'71bce2a2-eb67-4815-b88a-27b4cd6c99ba'),(773,'Presumptive TB cases this month','Presumptive TB cases this month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Presumptive TB cases this month\n Presumptive TB cases this month\n \n 2020-06-19 09:10:24 UTC\n \n 2020-06-19 09:11:43 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 773\n select distinct o.person_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n AND o.concept_id = 3843 AND o.value_coded in (3841,3842) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n INNER JOIN person ON person.person_id = o.person_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in ( \n select person_id from obs \n where concept_id = 2223 \n ) \n \nand o.person_id in ( \n select person_id from obs \n where concept_id = 3710 and value_coded = 1876 \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n )\n','2020-06-19 09:10:24',4,'2020-06-19 09:11:43',4,0,NULL,NULL,NULL,'8a81c8cf-900c-4465-a136-5aba898d64d4'),(774,'Presumptive TB cases diagnosed with TB','diagnosed with TB','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Presumptive TB cases diagnosed with TB\n diagnosed with TB\n \n 2020-06-23 09:51:11 UTC\n \n 2020-06-23 09:54:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 774\n select person_id from obs \n -- genexpert \n where concept_id = 3787 and value_coded in (3816,3817) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n -- line probe \n UNION \n select person_id from obs \n where concept_id = 3805 and value_coded in (1738) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n UNION \n -- phenotypic \n select person_id from obs \n where concept_id = 3840 and value_coded in (3837,3838,3839) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE))\n','2020-06-23 09:51:11',4,'2020-06-23 09:54:51',4,0,NULL,NULL,NULL,'4d3236b4-cfb1-47cd-b616-9378de1a8d70'),(775,'Diagnosed with TB and started treatment this month','started TB this month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Diagnosed with TB and started treatment this month\n started TB this month\n \n 2020-06-23 09:58:58 UTC\n \n 2020-06-23 09:59:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 775\n select person_id from obs \nwhere concept_id = 2237 \nAND MONTH(value_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(value_datetime) = YEAR(CAST(:endDate AS DATE))\n','2020-06-23 09:58:58',4,'2020-06-23 09:59:24',4,0,NULL,NULL,NULL,'59423bc1-bdc8-467a-ad52-32e51434cfc9'),(776,'client_arv_1f','Clients given 1f regimen during reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n client_arv_1f\n Clients given 1f regimen during reporting period\n \n 2020-07-18 19:58:37 UTC\n \n','2020-07-18 19:58:37',4,NULL,NULL,0,NULL,NULL,NULL,'134439b8-8727-4186-a4d1-07d8eb8df1ec'),(777,'ARV Regimen 1f TDF-3TC-EFV SQL','Clients given 1f regimen during reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV Regimen 1f TDF-3TC-EFV SQL\n Clients given 1f regimen during reporting period\n \n 2020-07-18 19:58:37 UTC\n \n 2020-07-19 01:56:13 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 777\n select o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere o.concept_id = 2250 and o.value_coded = 2207 \n and o.location_id =:location or parent_location =:location \n and o.obs_datetime between :startDate and :endDate \n and o.voided = 0 \n and o.person_id in ( \n select oss.person_id \n from obs oss \n where oss.obs_datetime BETWEEN :startDate AND :endDate \n and oss.concept_id = 4174 and oss.value_coded in (4175, 4243) \n )\n','2020-07-18 19:58:37',4,'2020-07-19 01:56:13',4,0,NULL,NULL,NULL,'48b7c7f2-0b24-4fcb-936a-3161ccb96809'),(778,'Clients Initiated SQL','Client who were newly initiated on ART during period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients Initiated SQL\n Client who were newly initiated on ART during period\n \n 2020-07-18 20:31:33 UTC\n \n 2020-07-18 20:39:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 778\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere o.concept_id = 2249 \n and date(o.value_datetime) between cast(:startDate as date) and cast(:endDate as date) \n and o.location_id = :location or parent_location = :location \n and o.voided = 0 \n and o.person_id not in ( \n select os.person_id from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n and os.obs_datetime between cast(:startDate as date) and cast(:endDate as date) \n ) \n and o.person_id not in ( \n select person_id \n from person \n where death_date < cast(:endDate as date) \n and dead = 1 \n ) \n and o.person_id not in ( \n select os.person_id \n from obs os \n where os.concept_id = 4155 and os.value_coded = 2146 \n and os.obs_datetime between cast(:startDate as date) and cast(:endDate as date) \n )\n','2020-07-18 20:31:33',4,'2020-07-18 20:39:16',4,0,NULL,NULL,NULL,'58e7985e-69a0-4d49-846f-b9aff06675db'),(779,'CMP_ART Regimen 1month supply 1f','Active clients on ART given 1 month supply of 1f during the reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1f\n Active clients on ART given 1 month supply of 1f during the reporting period\n \n 2020-07-19 01:31:05 UTC\n \n 2020-07-19 04:00:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 779\n Clients-newly-initiated-1f OR Clients-seen-given-1-month-supply-1f\n \n \n Clients-newly-initiated-1f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-1f\n \n \n \n \n \n \n','2020-07-19 01:31:05',4,'2020-07-19 04:00:42',4,0,NULL,NULL,NULL,'1b85fc5a-285d-44ee-8d93-89823330461c'),(780,'CI07a: Adult 1st Line 1f=TDF-3TC-EFV 1month supply','Adults on 1st line 1f=TDF-3TC-EFV given 1month supply during the reporting period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI07a: Adult 1st Line 1f=TDF-3TC-EFV 1month supply\n Adults on 1st line 1f=TDF-3TC-EFV given 1month supply during the reporting period\n \n 2020-07-19 01:41:26 UTC\n \n 2021-07-13 10:53:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 780\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-19 01:41:26',4,'2021-07-13 10:53:55',4,0,NULL,NULL,NULL,'266432b4-af8d-4c1f-9964-0e18df6a8ddb'),(781,'Clients seen given 1 month supply 1f','Clients seen for ART given 1 month supply of 1f regimen during period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1f\n Clients seen for ART given 1 month supply of 1f regimen during period\n \n 2020-07-19 03:54:29 UTC\n \n 2021-07-08 14:08:48 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 781\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2207)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-19 03:54:29',4,'2021-07-08 14:08:48',4,0,NULL,NULL,NULL,'aa28ce0b-63fd-424e-a559-32afafdf1bd4'),(782,'Clients given 3 months supply 1f','Clients seen given 3 months supply and those seen in previous months given 3 months supply for the reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1f\n Clients seen given 3 months supply and those seen in previous months given 3 months supply for the reporting period\n \n 2020-07-19 04:12:20 UTC\n \n 2021-06-30 09:54:55 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 782\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2207)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-19 04:12:20',4,'2021-06-30 09:54:55',4,0,NULL,NULL,NULL,'08339268-81bc-4b91-860e-5fe9e69a96d9'),(783,'CMP_ART Regimen 3months supply 1f','Clients given 3 months supply of 1f regimen including Seen and Multi month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 3months supply 1f\n Clients given 3 months supply of 1f regimen including Seen and Multi month\n \n 2020-07-19 04:17:16 UTC\n \n 2020-07-19 04:18:45 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 783\n Clients-given-3-months-supply-1f\n \n \n Clients-given-3-months-supply-1f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-07-19 04:17:16',4,'2020-07-19 04:18:45',4,0,NULL,NULL,NULL,'3c34cfe7-e888-4dd5-8618-e0d0b3c0e7ec'),(784,'Clients given 6 months supply 1f','Clients seen given 6 months supply and those seen in previous months given 6 months supply for the reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1f\n Clients seen given 6 months supply and those seen in previous months given 6 months supply for the reporting period\n \n 2020-07-19 04:31:40 UTC\n \n 2021-06-30 11:12:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 784\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2207)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-19 04:31:40',4,'2021-06-30 11:12:29',4,0,NULL,NULL,NULL,'a96d7239-75fc-49da-8fc2-e5de7f363b3a'),(785,'Clients given Other months MMD supply 1f','Clients seen in current month given 2, 4, 5 or 7+ months supply and those seen in previous months given 2, 4, 5 or 7+ months supply for the reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1f\n Clients seen in current month given 2, 4, 5 or 7+ months supply and those seen in previous months given 2, 4, 5 or 7+ months supply for the reporting period\n \n 2020-07-19 04:43:12 UTC\n \n 2021-06-30 11:42:53 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 785\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2207)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-19 04:43:12',4,'2021-06-30 11:42:53',4,0,NULL,NULL,NULL,'769c1abe-1bbd-44ad-8151-48df3b0e7d28'),(786,'CMP_ART Regimen 6months supply 1f','Clients given 6 months supply of 1f regimen including Seen and Multi month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 6months supply 1f\n Clients given 6 months supply of 1f regimen including Seen and Multi month\n \n 2020-07-19 04:46:50 UTC\n \n 2020-07-19 04:48:17 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 786\n Clients-given-6-months-supply-1f\n \n \n Clients-given-6-months-supply-1f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-07-19 04:46:50',4,'2020-07-19 04:48:17',4,0,NULL,NULL,NULL,'18e58639-4cfd-40bf-bf06-3599464b1473'),(787,'CMP_ART Regimen Other months MMD supply 1f','Clients given 2, 4 or 5 months supply of 1f regimen including Seen and Multi month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen Other months MMD supply 1f\n Clients given 2, 4 or 5 months supply of 1f regimen including Seen and Multi month\n \n 2020-07-19 04:49:08 UTC\n \n 2020-07-19 04:50:50 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 787\n Clients-given-Other-months-MMD-supply-1f\n \n \n Clients-given-Other-months-MMD-supply-1f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-07-19 04:49:08',4,'2020-07-19 04:50:50',4,0,NULL,NULL,NULL,'f95caefd-dc5f-4243-a75e-5e3e0b7911a0'); +INSERT INTO `serialized_object` VALUES (510,'adult_arv_1m_1mnth','clients given 1month supply of 1m','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_1mnth\n clients given 1month supply of 1m\n \n 2020-06-04 11:26:24 UTC\n \n 2020-06-16 10:45:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 510\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4680 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:26:24',4,'2020-06-16 10:45:33',4,0,NULL,NULL,NULL,'8b668641-8cd1-4710-9900-e14afa11d477'),(511,'adult_arv_1n_1mnth','clients given 1month supply of 1n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_1mnth\n clients given 1month supply of 1n\n \n 2020-06-04 11:27:29 UTC\n \n 2020-06-16 10:45:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 511\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4681 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:27:29',4,'2020-06-16 10:45:05',4,0,NULL,NULL,NULL,'a22dae13-6bc7-4d24-9e4d-a0fefab2c9fd'),(512,'adult_arv_1p_1mnth','clients given 1month supply of 1p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_1mnth\n clients given 1month supply of 1p\n \n 2020-06-04 11:30:16 UTC\n \n 2020-06-16 10:46:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 512\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4682 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:30:16',4,'2020-06-16 10:46:13',4,0,NULL,NULL,NULL,'a1837be3-878d-423d-8684-808738f28305'),(513,'adult_arv_1q_1mnth','clients given 1 month supply of 1q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_1mnth\n clients given 1 month supply of 1q\n \n 2020-06-04 11:31:28 UTC\n \n 2020-06-16 10:46:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 513\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4683 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:31:28',4,'2020-06-16 10:46:57',4,0,NULL,NULL,NULL,'c4e93e64-91fe-48e4-a432-8553a70a138b'),(514,'adult_arv_other_1mnth','clients given 1month supply of other arv','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_1mnth\n clients given 1month supply of other arv\n \n 2020-06-04 11:35:49 UTC\n \n 2020-06-16 10:48:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 514\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2143 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175 \n)\n','2020-06-04 11:35:49',4,'2020-06-16 10:48:03',4,0,NULL,NULL,NULL,'7c04bae3-26e2-44bb-9f14-46bd23abf3b7'),(515,'adult_arv_1c_3mnth','3mnths supply of 1c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_3mnth\n 3mnths supply of 1c\n \n 2020-06-04 11:41:08 UTC\n \n 2020-06-16 10:49:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 515\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2201 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 11:41:08',4,'2020-06-16 10:49:04',4,0,NULL,NULL,NULL,'238a43b6-79ac-46a7-907f-a1e351c5caaa'),(516,'adult_arv_1d_3mnth','3mnths supply of 1d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_3mnth\n 3mnths supply of 1d\n \n 2020-06-04 11:42:06 UTC\n \n 2020-06-16 10:49:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 516\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2203 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 11:42:06',4,'2020-06-16 10:49:30',4,0,NULL,NULL,NULL,'1e1e9500-f32d-4290-aab4-935a88bfe130'),(517,'adult_arv_1e_3mnth','3mnths supply of 1e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_3mnth\n 3mnths supply of 1e\n \n 2020-06-04 11:46:30 UTC\n \n 2020-06-16 10:49:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 517\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2205 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 11:46:30',4,'2020-06-16 10:49:53',4,0,NULL,NULL,NULL,'db80a24f-af5f-4553-bc8c-9958d082feb4'),(518,'adult_arv_1f_3mnth','3mnths supply of 1f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_3mnth\n 3mnths supply of 1f\n \n 2020-06-04 11:48:17 UTC\n \n 2020-11-20 10:53:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 518\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4177) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4177) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 2207)\n','2020-06-04 13:48:17',4,'2020-11-20 12:53:53',4,0,NULL,NULL,NULL,'22c820ef-4629-49cb-8ca1-bd2b25c3ff59'),(519,'adult_arv_1g_3mnth','3mnths supply of 1g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_3mnth\n 3mnths supply of 1g\n \n 2020-06-04 11:49:57 UTC\n \n 2020-06-16 10:51:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 519\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3672 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 11:49:57',4,'2020-06-16 10:51:22',4,0,NULL,NULL,NULL,'b048d9e0-11c1-4092-8c31-ba6e3acea989'),(520,'adult_arv_1h_3mnth','3mnths supply of 1h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_3mnth\n 3mnths supply of 1h\n \n 2020-06-04 11:55:26 UTC\n \n 2020-06-04 11:57:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 520\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3673 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 11:55:26',4,'2020-06-04 11:57:44',4,0,NULL,NULL,NULL,'1ff080c3-e4fb-4884-bcdb-431d8cf59157'),(521,'adult_arv_1j_3mnth','3mnths supply of 1j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_3mnth\n 3mnths supply of 1j\n \n 2020-06-04 11:59:08 UTC\n \n 2020-11-20 10:49:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 521\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4177) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4177) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 4678)\n','2020-06-04 13:59:08',4,'2020-11-20 12:49:56',4,0,NULL,NULL,NULL,'5ed7e3c1-afba-4802-a334-a611a9102cc5'),(522,'adult_arv_1k_3mnth','3mnths supply of 1k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_3mnth\n 3mnths supply of 1k\n \n 2020-06-04 13:10:45 UTC\n \n 2020-06-04 13:21:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 522\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4679 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:10:45',4,'2020-06-04 13:21:56',4,0,NULL,NULL,NULL,'5ee29b38-8294-44d6-bca4-6fd3a2e668ed'),(523,'adult_arv_1m_3mnth','3mnths supply of 1m','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_3mnth\n 3mnths supply of 1m\n \n 2020-06-04 13:23:09 UTC\n \n 2020-06-04 13:24:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 523\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4680 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:23:09',4,'2020-06-04 13:24:04',4,0,NULL,NULL,NULL,'063a7963-5a7f-4ab4-a444-0db599f8c5a8'),(524,'adult_arv_1n_3mnth','3mnths supply of 1n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_3mnth\n 3mnths supply of 1n\n \n 2020-06-04 13:25:04 UTC\n \n 2020-06-04 13:25:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 524\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4681 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:25:04',4,'2020-06-04 13:25:38',4,0,NULL,NULL,NULL,'03237de9-f7dc-4446-a8b0-07c73bbf780b'),(525,'adult_arv_1p_3mnth','3mnths supply of 1p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_3mnth\n 3mnths supply of 1p\n \n 2020-06-04 13:27:08 UTC\n \n 2020-06-04 13:27:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 525\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4682 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:27:08',4,'2020-06-04 13:27:34',4,0,NULL,NULL,NULL,'5224e59b-88b4-4586-81f5-11719fd1c1ee'),(526,'adult_arv_1q_3mnth','3mnths supply of 1q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_3mnth\n 3mnths supply of 1q\n \n 2020-06-04 13:30:23 UTC\n \n 2020-06-04 13:30:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 526\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4683 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:30:23',4,'2020-06-04 13:30:44',4,0,NULL,NULL,NULL,'9cc207d2-97db-47a0-8ff5-e687843138c8'),(527,'adult_arv_other_3mnth','3mnths supply of other regimen','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_3mnth\n 3mnths supply of other regimen\n \n 2020-06-04 13:34:17 UTC\n \n 2020-06-04 13:34:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 527\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4679 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-04 13:34:17',4,'2020-06-04 13:34:55',4,0,NULL,NULL,NULL,'4d6e10d0-413f-4647-941a-3ae707d69e4d'),(528,'adult_arv_1c_6mnth','6mnths supply of 1c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_6mnth\n 6mnths supply of 1c\n \n 2020-06-04 13:45:59 UTC\n \n 2020-06-05 07:42:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 528\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2201 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 15:45:59',4,'2020-06-05 09:42:05',4,0,NULL,NULL,NULL,'8f096880-4dfb-4ef9-9234-f1ad19ed9fbd'),(529,'adult_arv_1d_6mnth','6mnths supply of 1d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_6mnth\n 6mnths supply of 1d\n \n 2020-06-04 13:47:33 UTC\n \n 2020-06-05 07:42:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 529\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2203 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 15:47:33',4,'2020-06-05 09:42:33',4,0,NULL,NULL,NULL,'fdb3a5d9-0f52-4594-862d-32a7067bbf33'),(530,'adult_arv_1e_6mnth','6mnths supply of 1e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_6mnth\n 6mnths supply of 1e\n \n 2020-06-04 13:51:21 UTC\n \n 2020-07-15 00:44:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 530\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nand o.person_id in (select os.person_id \n from obs os \n where os.obs_datetime BETWEEN :startDate AND :endDate \n and os.concept_id = 2250 and os.value_coded = 2205 \n ) \nand o.person_id in \n (select os.person_id \n from obs os \n where os.obs_datetime BETWEEN :startDate AND :endDate \n and os.concept_id = 4174 and os.value_coded = 4247 \n) \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0\n','2020-06-04 13:51:21',4,'2020-07-15 00:44:56',4,0,NULL,NULL,NULL,'13ec01be-4c41-4cab-8776-03c2be53fb90'),(531,'adult_arv_1f_6mnth','6mnths supply of 1f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_6mnth\n 6mnths supply of 1f\n \n 2020-06-04 13:53:31 UTC\n \n 2020-11-20 10:54:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 531\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4247) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4247) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 2207)\n','2020-06-04 15:53:31',4,'2020-11-20 12:54:18',4,0,NULL,NULL,NULL,'87396003-00c4-433b-b3c1-eb201bd2775c'),(532,'adult_arv_1g_6mnth','6mnths supply of 1g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_6mnth\n 6mnths supply of 1g\n \n 2020-06-04 13:54:26 UTC\n \n 2020-06-05 07:44:36 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 532\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3672 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 15:54:26',4,'2020-06-05 09:44:36',4,0,NULL,NULL,NULL,'884dbb74-6589-4ee4-85af-a349f88cb8e1'),(533,'adult_arv_1h_6mnth','6mnths supply of 1h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_6mnth\n 6mnths supply of 1h\n \n 2020-06-04 13:55:28 UTC\n \n 2020-06-16 10:59:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 533\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3673 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 13:55:28',4,'2020-06-16 10:59:55',4,0,NULL,NULL,NULL,'dc3ece21-bfe0-4460-9c09-a12a1663b679'),(534,'adult_arv_1j_6mnth','6mnths supply of 1j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_6mnth\n 6mnths supply of 1j\n \n 2020-06-04 13:57:18 UTC\n \n 2020-11-20 10:57:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 534\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4247) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4247) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 4678)\n','2020-06-04 15:57:18',4,'2020-11-20 12:57:08',4,0,NULL,NULL,NULL,'4becb473-e1ce-4e72-b4e2-9cf84fcc2366'),(535,'adult_arv_1k_6mnth','6mnths supply of 1k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_6mnth\n 6mnths supply of 1k\n \n 2020-06-04 13:58:40 UTC\n \n 2020-06-05 07:46:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 535\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4679 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 15:58:40',4,'2020-06-05 09:46:03',4,0,NULL,NULL,NULL,'3f9ce8e5-1b4a-49b0-bc6d-decfb8fb88c1'),(536,'adult_arv_1m_6mnth','6mnths supply of 1m','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_6mnth\n 6mnths supply of 1m\n \n 2020-06-04 14:00:09 UTC\n \n 2020-06-05 07:46:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 536\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4680 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 16:00:09',4,'2020-06-05 09:46:33',4,0,NULL,NULL,NULL,'d7b93a16-4442-49c0-817c-8a1c4b7097ca'),(537,'adult_arv_1n_6mnth','6mnths supply of 1n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_6mnth\n 6mnths supply of 1n\n \n 2020-06-04 14:01:31 UTC\n \n 2020-06-05 07:47:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 537\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4681 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 16:01:31',4,'2020-06-05 09:47:14',4,0,NULL,NULL,NULL,'9d4cbcb3-f873-45bf-b00f-32556db829f7'),(538,'adult_arv_1p_6mnth','6mnths supply of 1p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_6mnth\n 6mnths supply of 1p\n \n 2020-06-04 14:02:37 UTC\n \n 2020-06-05 07:47:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 538\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4682 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 16:02:37',4,'2020-06-05 09:47:37',4,0,NULL,NULL,NULL,'6c977b93-8224-48bd-bfcc-fbb1430524ee'),(539,'adult_arv_1q_6mnth','6mnths supply of 1q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_6mnth\n 6mnths supply of 1q\n \n 2020-06-04 14:04:18 UTC\n \n 2020-06-05 07:47:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 539\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4683 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 16:04:18',4,'2020-06-05 09:47:57',4,0,NULL,NULL,NULL,'3925978c-31f1-42dc-a61c-d4c66cb14fdd'),(540,'adult_arv_other_6mnth','6mnths supply of other regimen','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_6mnth\n 6mnths supply of other regimen\n \n 2020-06-04 14:05:17 UTC\n \n 2020-06-05 07:48:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 540\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2143 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4247 \n)\n','2020-06-04 16:05:17',4,'2020-06-05 09:48:28',4,0,NULL,NULL,NULL,'8b73f162-d9b5-4e96-8139-86586e839271'),(541,'adult_arv_1c_other_months','2wks,1,4,6 months supply of 1c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_other_months\n 2wks,1,4,6 months supply of 1c\n \n 2020-06-05 06:57:29 UTC\n \n 2020-06-05 07:48:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 541\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nAND o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2201 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 08:57:29',4,'2020-06-05 09:48:57',4,0,NULL,NULL,NULL,'66511f62-2da4-4c63-8641-034e01c16939'),(542,'adult_arv_1d_other_months','other durations supply of 1d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_other_months\n other durations supply of 1d\n \n 2020-06-05 06:58:54 UTC\n \n 2020-07-15 03:10:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 542\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select os.person_id \n from obs os \n where os.obs_datetime BETWEEN :startDate AND :endDate \n and os.concept_id = 2250 and os.value_coded = 2203 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where oss.obs_datetime BETWEEN :startDate AND :endDate \n and oss.concept_id = 4174 and oss.value_coded in (4243, 4176, 4245, 4246) \n ) \n)\n','2020-06-05 06:58:54',4,'2020-07-15 03:10:40',4,0,NULL,NULL,NULL,'5f87f57a-7059-49f4-986e-783823f5cbab'),(543,'adult_arv_1e_other_months','other duration supply of 1e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_other_months\n other duration supply of 1e\n \n 2020-06-05 06:59:45 UTC\n \n 2020-07-15 03:15:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 543\n select distinct(o.person_id) \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select os.person_id \n from obs os \n where os.obs_datetime BETWEEN :startDate AND :endDate \n and os.concept_id = 2250 and os.value_coded = 2205 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where oss.obs_datetime BETWEEN :startDate AND :endDate \n and oss.concept_id = 4174 and oss.value_coded in (4243, 4176, 4245, 4246) \n ) \n)\n','2020-06-05 06:59:45',4,'2020-07-15 03:15:48',4,0,NULL,NULL,NULL,'597e713b-7181-46ce-ae93-07605c62ec37'),(544,'adult_arv_1f_other_months','other duration supply of 1f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_other_months\n other duration supply of 1f\n \n 2020-06-05 07:00:40 UTC\n \n 2020-11-20 10:54:47 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 544\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4243,4176,4245,4246) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4243,4176,4245,4246) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 2207)\n','2020-06-05 09:00:40',4,'2020-11-20 12:54:47',4,0,NULL,NULL,NULL,'c83bc608-76be-4774-8065-9e5def272804'),(545,'adult_arv_1g_other_months','other duration supply of 1g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_other_months\n other duration supply of 1g\n \n 2020-06-05 07:05:30 UTC\n \n 2020-06-05 07:05:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 545\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3672 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:05:30',4,'2020-06-05 09:05:57',4,0,NULL,NULL,NULL,'da485ef1-77d0-4d3d-865d-d8011e6a7560'),(546,'adult_arv_1h_other_months','other duration suppply of 1h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_other_months\n other duration suppply of 1h\n \n 2020-06-05 07:06:48 UTC\n \n 2020-07-15 03:11:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 546\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select os.person_id \n from obs os \n where os.obs_datetime BETWEEN :startDate AND :endDate \n and os.concept_id = 2250 and os.value_coded = 3673 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where oss.obs_datetime BETWEEN :startDate AND :endDate \n and oss.concept_id = 4174 and oss.value_coded in (4243, 4176, 4245, 4246) \n ) \n)\n','2020-06-05 07:06:48',4,'2020-07-15 03:11:35',4,0,NULL,NULL,NULL,'4856375f-ed15-4b80-8a69-230643d6918e'),(547,'adult_arv_1j_other_months','other duration supply of 1j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_other_months\n other duration supply of 1j\n \n 2020-06-05 07:07:37 UTC\n \n 2020-11-20 10:57:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 547\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \ninner join person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \n \nand o.person_id in ( \n select person_id from \n (select currentreg.person_id,IFNULL(substitute_regimen,current_reg) ARV_regimen \n from \n (select os.person_id, os.value_coded as current_reg \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 2250 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4243,4176,4245,4246) \n ) \n )currentreg \n left outer JOIN \n ( \n select os.person_id, os.value_coded as substitute_regimen \n from obs os \n where MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.concept_id = 4284 \n and os.voided = 0 \n and os.person_id in ( \n select oss.person_id \n from obs oss \n where MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and oss.concept_id = 4174 and oss.value_coded in (4243,4176,4245,4246) \n ) \n )substitutereg \n on substitutereg.person_id = currentreg.person_id \n)regimen \nwhere ARV_regimen = 4678)\n','2020-06-05 09:07:37',4,'2020-11-20 12:57:31',4,0,NULL,NULL,NULL,'a4b6d688-df41-4817-a621-6be6ab32ea59'),(548,'adult_arv_1k_other_months','other duration supply of 1k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_other_months\n other duration supply of 1k\n \n 2020-06-05 07:08:26 UTC\n \n 2020-06-05 07:08:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 548\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4679 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:08:26',4,'2020-06-05 09:08:46',4,0,NULL,NULL,NULL,'eec6e550-453f-4cb5-a27d-fe60c9dcfdf2'),(549,'adult_arv_1m_other_months','other duration supply of 1m','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_other_months\n other duration supply of 1m\n \n 2020-06-05 07:09:19 UTC\n \n 2020-06-05 07:09:41 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 549\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4680 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:09:19',4,'2020-06-05 09:09:41',4,0,NULL,NULL,NULL,'7b67d262-9d16-401d-b604-d91cc253865c'),(550,'adult_arv_1n_other_months','other duration supply of 1n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_other_months\n other duration supply of 1n\n \n 2020-06-05 07:10:29 UTC\n \n 2020-06-16 13:34:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 550\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4681 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 07:10:29',4,'2020-06-16 13:34:20',4,0,NULL,NULL,NULL,'952e2836-4856-4364-a91b-b293d5b851d6'),(551,'adult_arv_1p_other_months','other duration supply of 1p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_other_months\n other duration supply of 1p\n \n 2020-06-05 07:16:58 UTC\n \n 2020-06-05 07:17:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 551\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4682 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:16:58',4,'2020-06-05 09:17:16',4,0,NULL,NULL,NULL,'be570315-7ba8-466b-8b22-e61f30e0e4c3'),(552,'adult_arv_1q_other_months','other duration supply of 1q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_other_months\n other duration supply of 1q\n \n 2020-06-05 07:17:50 UTC\n \n 2020-06-05 07:18:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 552\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4683 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:17:50',4,'2020-06-05 09:18:06',4,0,NULL,NULL,NULL,'10da0e87-2ff1-4e44-9503-81b78ef95b8b'),(553,'adult_arv_other_other_months','other duration supply of other regimen','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_other_months\n other duration supply of other regimen\n \n 2020-06-05 07:18:56 UTC\n \n 2020-06-05 07:19:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 553\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2143 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded in (4243,4176,4245,4246) \n)\n','2020-06-05 09:18:56',4,'2020-06-05 09:19:10',4,0,NULL,NULL,NULL,'6f6651ce-3b9c-46e2-9408-1af9b76331bb'),(554,'2020_Pre_ART','pre art PIR for new ART dataset','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_Pre_ART\n pre art PIR for new ART dataset\n \n 2020-06-05 07:21:23 UTC\n \n 2020-06-05 07:21:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 554\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-06-05 09:21:23',4,'2020-06-05 09:21:25',4,0,NULL,NULL,NULL,'825334cf-ea81-4d70-8166-4479b7656543'),(555,'2020_Pre_ART Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_Pre_ART Data Set\n \n 2020-06-05 07:21:25 UTC\n \n 2020-08-04 16:20:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 555\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n EverF14\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n EverF15\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n EverM14\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n EverM15\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n PreF14\n \n \n \n \n \n \n \n \n \n PreF15\n \n \n \n \n \n \n PreM14\n \n \n \n \n \n \n PreM15\n \n \n \n \n \n \n','2020-06-05 07:21:25',4,'2020-08-04 16:20:06',4,0,NULL,NULL,NULL,'a758fb74-1fc9-4fce-a6d8-531decf8be2a'),(557,'2020_ART_Current Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_ART_Current Data Set\n \n 2020-06-05 07:26:21 UTC\n \n 2020-09-14 13:54:47 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 557\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Finer_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n DM_Age\n \n \n \n \n \n \n \n \n DefaultF1-\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n DefaultF10\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n DefaultF15\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n DefaultF20\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n DefaultF25\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 25to29yrs\n \n \n \n \n \n DefaultF30\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 30to34yrs\n \n \n \n \n \n DefaultF35\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 35to39yrs\n \n \n \n \n \n DefaultF40\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 40to44yrs\n \n \n \n \n \n DefaultF45\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 45to49yrs\n \n \n \n \n \n DefaultF5-\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 05to09yrs\n \n \n \n \n \n DefaultF50\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 50+yrs\n \n \n \n \n \n DefaultF<1\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n DefaultM1-\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n DefaultM10\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 10to14yrs\n \n \n \n \n \n DefaultM15\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15to19yrs\n \n \n \n \n \n DefaultM20\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 20to24yrs\n \n \n \n \n \n DefaultM25\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 25to29yrs\n \n \n \n \n \n DefaultM30\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 30to34yrs\n \n \n \n \n \n DefaultM35\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 35to39yrs\n \n \n \n \n \n DefaultM40\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 40to44yrs\n \n \n \n \n \n DefaultM45\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 45to49yrs\n \n \n \n \n \n DefaultM5-\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 05to09yrs\n \n \n \n \n \n DefaultM50\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 50+yrs\n \n \n \n \n \n DefaultM<1\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n DiedClient\n \n \n \n \n \n \n \n \n \n LostToFU\n \n \n \n \n \n \n \n \n \n MMD_F1-4\n \n \n \n \n \n \n \n \n \n MMD_F10-14\n \n \n \n \n \n \n MMD_F15-19\n \n \n \n \n \n \n MMD_F20-24\n \n \n \n \n \n \n MMD_F25-29\n \n \n \n \n \n \n MMD_F30-34\n \n \n \n \n \n \n MMD_F35-39\n \n \n \n \n \n \n MMD_F40-44\n \n \n \n \n \n \n MMD_F45-49\n \n \n \n \n \n \n MMD_F5-9\n \n \n \n \n \n \n MMD_F50\n \n \n \n \n \n \n MMD_F<1\n \n \n \n \n \n \n MMD_M1-4\n \n \n \n \n \n \n MMD_M10-14\n \n \n \n \n \n \n MMD_M15-19\n \n \n \n \n \n \n MMD_M20-24\n \n \n \n \n \n \n MMD_M25-29\n \n \n \n \n \n \n MMD_M30-34\n \n \n \n \n \n \n MMD_M35-39\n \n \n \n \n \n \n MMD_M40-44\n \n \n \n \n \n \n MMD_M45-49\n \n \n \n \n \n \n MMD_M5-9\n \n \n \n \n \n \n MMD_M50\n \n \n \n \n \n \n MMD_M<1\n \n \n \n \n \n \n MissedF1-4\n \n \n \n \n \n \n \n \n \n MissedF10-\n \n \n \n \n \n \n MissedF15-\n \n \n \n \n \n \n MissedF20-\n \n \n \n \n \n \n MissedF25-\n \n \n \n \n \n \n MissedF30-\n \n \n \n \n \n \n MissedF35-\n \n \n \n \n \n \n MissedF40-\n \n \n \n \n \n \n MissedF45-\n \n \n \n \n \n \n MissedF5-9\n \n \n \n \n \n \n MissedF50\n \n \n \n \n \n \n MissedF<1\n \n \n \n \n \n \n MissedM1-4\n \n \n \n \n \n \n MissedM10-\n \n \n \n \n \n \n MissedM15-\n \n \n \n \n \n \n MissedM20-\n \n \n \n \n \n \n MissedM25-\n \n \n \n \n \n \n MissedM30-\n \n \n \n \n \n \n MissedM35-\n \n \n \n \n \n \n MissedM40\n \n \n \n \n \n \n MissedM45-\n \n \n \n \n \n \n MissedM5-9\n \n \n \n \n \n \n MissedM50\n \n \n \n \n \n \n MissedM<1\n \n \n \n \n \n \n Restarted\n \n \n \n \n \n \n \n \n \n SeenFema1-\n \n \n \n \n \n \n \n \n \n SeenFema10\n \n \n \n \n \n \n SeenFema15\n \n \n \n \n \n \n SeenFema20\n \n \n \n \n \n \n SeenFema25\n \n \n \n \n \n \n SeenFema30\n \n \n \n \n \n \n SeenFema35\n \n \n \n \n \n \n SeenFema40\n \n \n \n \n \n \n SeenFema45\n \n \n \n \n \n \n SeenFema5-\n \n \n \n \n \n \n SeenFema50\n \n \n \n \n \n \n SeenFema<1\n \n \n \n \n \n \n SeenMale1-\n \n \n \n \n \n \n SeenMale10\n \n \n \n \n \n \n SeenMale15\n \n \n \n \n \n \n SeenMale20\n \n \n \n \n \n \n SeenMale25\n \n \n \n \n \n \n SeenMale30\n \n \n \n \n \n \n SeenMale35\n \n \n \n \n \n \n SeenMale40\n \n \n \n \n \n \n SeenMale45\n \n \n \n \n \n \n SeenMale5-\n \n \n \n \n \n \n SeenMale50\n \n \n \n \n \n \n SeenMale<1\n \n \n \n \n \n \n StoppedART\n \n \n \n \n \n \n \n \n \n TransferIn\n \n \n \n \n \n \n \n \n \n TransferOu\n \n \n \n \n \n \n \n \n \n newFema1-4\n \n \n \n \n \n \n \n \n \n newFema10-\n \n \n \n \n \n \n newFema15-\n \n \n \n \n \n \n newFema20-\n \n \n \n \n \n \n newFema25-\n \n \n \n \n \n \n newFema30-\n \n \n \n \n \n \n newFema35-\n \n \n \n \n \n \n newFema40-\n \n \n \n \n \n \n newFema45-\n \n \n \n \n \n \n newFema5-9\n \n \n \n \n \n \n newFema50\n \n \n \n \n \n \n newFemale1\n \n \n \n \n \n \n newMale1\n \n \n \n \n \n \n newMale1-4\n \n \n \n \n \n \n newMale10-\n \n \n \n \n \n \n newMale15-\n \n \n \n \n \n \n newMale20-\n \n \n \n \n \n \n newMale25-\n \n \n \n \n \n \n newMale30-\n \n \n \n \n \n \n newMale35-\n \n \n \n \n \n \n newMale40-\n \n \n \n \n \n \n newMale45-\n \n \n \n \n \n \n newMale5-9\n \n \n \n \n \n \n newMale50\n \n \n \n \n \n \n','2020-06-05 09:26:21',4,'2020-09-14 15:54:47',4,0,NULL,NULL,NULL,'81fbbedc-d10c-42aa-9156-e5c93cfd3741'),(558,'adult_arv_2c_1mnth','1month supply of 2c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2c_1mnth\n 1month supply of 2c\n \n 2020-06-05 08:32:14 UTC\n \n 2020-06-16 13:39:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 558\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2210 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:32:14',4,'2020-06-16 13:39:37',4,0,NULL,NULL,NULL,'4a32ce1f-8c3b-4ae7-85dc-eea24672d4d7'),(559,'adult_arv_2d_1mnth','1month supply of 2d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2d_1mnth\n 1month supply of 2d\n \n 2020-06-05 08:33:29 UTC\n \n 2020-06-16 13:40:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 559\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2203 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:33:29',4,'2020-06-16 13:40:52',4,0,NULL,NULL,NULL,'863a96d9-1dcc-4b5c-9277-5b236057bd76'),(560,'adult_arv_2e_1mnth','1month supply of 2e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2e_1mnth\n 1month supply of 2e\n \n 2020-06-05 08:34:22 UTC\n \n 2020-06-16 13:41:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 560\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3674 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:34:22',4,'2020-06-16 13:41:45',4,0,NULL,NULL,NULL,'8d6cded5-67a7-4121-8f10-0e99e5ee0102'),(561,'adult_arv_2f_1mnth','1month supply of 2f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2f_1mnth\n 1month supply of 2f\n \n 2020-06-05 08:35:08 UTC\n \n 2020-06-16 13:42:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 561\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3675 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:35:08',4,'2020-06-16 13:42:00',4,0,NULL,NULL,NULL,'04265c85-d096-469c-ac3e-6a78f938ed67'),(562,'adult_arv_2g_1mnth','1month supply of 2g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2g_1mnth\n 1month supply of 2g\n \n 2020-06-05 08:35:54 UTC\n \n 2020-06-16 13:42:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 562\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3676 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:35:54',4,'2020-06-16 13:42:18',4,0,NULL,NULL,NULL,'630e20f6-dc99-460f-a0e2-54b1eea5a00c'),(563,'adult_arv_2h_1mnth','1month supply of 2h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2h_1mnth\n 1month supply of 2h\n \n 2020-06-05 08:37:24 UTC\n \n 2020-06-16 13:42:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 563\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3677 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:37:24',4,'2020-06-16 13:42:37',4,0,NULL,NULL,NULL,'974cf406-f3d5-4b42-b351-5dcb94f75017'),(564,'adult_arv_2j_1mnth','1month supply of 2j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2j_1mnth\n 1month supply of 2j\n \n 2020-06-05 08:39:19 UTC\n \n 2020-06-16 13:48:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 564\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4689 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:39:19',4,'2020-06-16 13:48:26',4,0,NULL,NULL,NULL,'4d64975e-b01c-46ed-bec8-137a544b7bc7'),(565,'adult_arv_2k_1mnth','1month supply of 2k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2k_1mnth\n 1month supply of 2k\n \n 2020-06-05 08:40:07 UTC\n \n 2020-06-16 13:42:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 565\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4690 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:40:07',4,'2020-06-16 13:42:56',4,0,NULL,NULL,NULL,'3c3d19f1-dad1-4b7b-b994-975f47b7445a'),(566,'adult_arv_2l_1mnth','1month supply of 2l','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2l_1mnth\n 1month supply of 2l\n \n 2020-06-05 08:41:30 UTC\n \n 2020-06-16 13:43:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 566\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4691 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:41:30',4,'2020-06-16 13:43:15',4,0,NULL,NULL,NULL,'b22e2178-de68-4fc6-ae05-601245b6a5b2'),(567,'adult_arv_2m_1mnth','1month supply','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2m_1mnth\n 1month supply\n \n 2020-06-05 08:44:35 UTC\n \n 2020-06-16 13:43:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 567\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4692 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:44:35',4,'2020-06-16 13:43:30',4,0,NULL,NULL,NULL,'a38fa644-0c38-4463-ab26-5c926f886dc9'),(568,'adult_arv_2n_1mnth','1month supply of 2n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2n_1mnth\n 1month supply of 2n\n \n 2020-06-05 08:46:20 UTC\n \n 2020-06-16 13:43:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 568\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4693 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:46:20',4,'2020-06-16 13:43:46',4,0,NULL,NULL,NULL,'2a93bd17-c3eb-4fc4-86fc-ce5849b76bd4'),(569,'adult_arv_2o_1mnth','1month supply of 2o','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2o_1mnth\n 1month supply of 2o\n \n 2020-06-05 08:47:30 UTC\n \n 2020-06-16 13:44:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 569\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4694 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:47:30',4,'2020-06-16 13:44:03',4,0,NULL,NULL,NULL,'eb37ce3b-5110-41b8-a3f0-40f0f3b5db75'),(570,'adult_arv_2p_1mnth','1month supply of 2p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2p_1mnth\n 1month supply of 2p\n \n 2020-06-05 08:48:45 UTC\n \n 2020-06-16 13:49:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 570\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4695 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 08:48:45',4,'2020-06-16 13:49:22',4,0,NULL,NULL,NULL,'9a54959a-25c3-4cd1-8382-e00379577eeb'),(571,'adult_arv_2q_1mnth','1month supply of 2q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2q_1mnth\n 1month supply of 2q\n \n 2020-06-05 08:49:34 UTC\n \n 2020-11-20 11:31:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 571\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4849 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-06-05 10:49:34',4,'2020-11-20 13:31:18',4,0,NULL,NULL,NULL,'149baa8e-a071-41bf-99fb-97a781d12330'),(572,'Clients seen given 1 month supply 3a','1month supply of 3a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3a\n 1month supply of 3a\n \n 2020-06-05 08:51:33 UTC\n \n 2021-07-25 15:37:23 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 572\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3683)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:51:33',4,'2021-07-25 15:37:23',4,0,NULL,NULL,NULL,'ad771405-a581-4e57-bb60-e2326ee778ca'),(573,'Clients seen given 1 month supply 3b','1month supply of 3b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3b\n 1month supply of 3b\n \n 2020-06-05 08:52:22 UTC\n \n 2021-07-13 15:10:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 573\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3684)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:52:22',4,'2021-07-13 15:10:31',4,0,NULL,NULL,NULL,'8ce36691-8f7b-42ff-9638-84dc3ce7b473'),(574,'Clients seen given 1 month supply 3c','1month supply of 3c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3c\n 1month supply of 3c\n \n 2020-06-05 08:53:22 UTC\n \n 2021-07-13 15:11:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 574\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3685)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:53:22',4,'2021-07-13 15:11:00',4,0,NULL,NULL,NULL,'97e72602-8099-4ead-8ed8-63c18ddc337f'),(575,'Clients seen given 1 month supply 3d','1month supply of 3d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3d\n 1month supply of 3d\n \n 2020-06-05 08:54:01 UTC\n \n 2021-07-13 15:11:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 575\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4706)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:54:01',4,'2021-07-13 15:11:33',4,0,NULL,NULL,NULL,'19fff766-eb8f-41f2-8d76-8f6505bbb9b9'),(576,'Clients seen given 1 month supply 3e','1month supply of 3e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3e\n 1month supply of 3e\n \n 2020-06-05 08:54:50 UTC\n \n 2021-07-13 15:11:57 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 576\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4707)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:54:50',4,'2021-07-13 15:11:57',4,0,NULL,NULL,NULL,'b2e90223-56f5-4e04-89e1-d9cc1fc34b17'),(577,'Clients seen given 1 month supply 3f','1month supply of 3f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3f\n 1month supply of 3f\n \n 2020-06-05 08:58:16 UTC\n \n 2021-07-13 15:12:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 577\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4708)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:58:16',4,'2021-07-13 15:12:26',4,0,NULL,NULL,NULL,'fdc65c1d-6a93-4a2d-bfc8-19f93d762531'),(578,'Clients seen given 1 month supply 3g','1month supply of 3g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3g\n 1month supply of 3g\n \n 2020-06-05 08:59:44 UTC\n \n 2021-07-13 15:12:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 578\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4709)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 08:59:44',4,'2021-07-13 15:12:55',4,0,NULL,NULL,NULL,'72a63ae5-4204-4f3a-803a-6ede62fee967'),(579,'Clients seen given 1 month supply 3h','1month supply of 3h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 3h\n 1month supply of 3h\n \n 2020-06-05 09:00:47 UTC\n \n 2021-07-13 15:13:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 579\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4710)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-06-05 09:00:47',4,'2021-07-13 15:13:35',4,0,NULL,NULL,NULL,'a1042d17-e93e-407e-a91e-e6cdf2930ab6'),(580,'adult_arv_2c_3mnth','3months supply of 2c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2c_3mnth\n 3months supply of 2c\n \n 2020-06-05 09:02:19 UTC\n \n 2020-06-05 09:02:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 580\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2210 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:02:19',4,'2020-06-05 11:02:33',4,0,NULL,NULL,NULL,'d0c31b7a-ea56-4f12-a574-924391d2dcb0'),(581,'adult_arv_2d_3mnth','3months supply of 2d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2d_3mnth\n 3months supply of 2d\n \n 2020-06-05 09:03:04 UTC\n \n 2020-06-05 09:03:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 581\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2209 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:03:04',4,'2020-06-05 11:03:19',4,0,NULL,NULL,NULL,'0f6c5bd6-8635-463f-80c8-d5322e97fe54'),(582,'adult_arv_2e_3mnth','3months aupply of 2e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2e_3mnth\n 3months aupply of 2e\n \n 2020-06-05 09:03:56 UTC\n \n 2020-06-05 09:04:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 582\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2205 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:03:56',4,'2020-06-05 11:04:38',4,0,NULL,NULL,NULL,'62d0a57e-51b0-4f3e-967a-12ce18b24778'),(583,'adult_arv_2f_3mnth','3mnths supply of 2f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2f_3mnth\n 3mnths supply of 2f\n \n 2020-06-05 09:09:02 UTC\n \n 2020-06-05 09:09:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 583\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3675 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:09:02',4,'2020-06-05 11:09:21',4,0,NULL,NULL,NULL,'969c9f38-af5e-4595-af5e-346abc080fb5'),(584,'adult_arv_2g_3mnth','3months supply of 2g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2g_3mnth\n 3months supply of 2g\n \n 2020-06-05 09:15:50 UTC\n \n 2020-06-05 09:16:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 584\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3676 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:15:50',4,'2020-06-05 11:16:07',4,0,NULL,NULL,NULL,'c0193c8c-6d28-4787-990e-bb7a38eb6284'),(585,'adult_arv_2h_3mnth','3months supply of 2h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2h_3mnth\n 3months supply of 2h\n \n 2020-06-05 09:17:00 UTC\n \n 2020-06-05 09:19:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 585\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 3677 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:17:00',4,'2020-06-05 11:19:06',4,0,NULL,NULL,NULL,'b675b59a-567a-45eb-bb4f-04843ed1719f'),(586,'adult_arv_2j_3mnth','3months supply of 2j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2j_3mnth\n 3months supply of 2j\n \n 2020-06-05 09:19:35 UTC\n \n 2020-06-05 09:19:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 586\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4689 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:19:35',4,'2020-06-05 11:19:53',4,0,NULL,NULL,NULL,'32aaed67-7f8c-40bc-829a-959b7dcb1bfe'),(587,'adult_arv_2k_3mnth','3months supply of 2k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2k_3mnth\n 3months supply of 2k\n \n 2020-06-05 09:21:52 UTC\n \n 2020-06-05 09:22:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 587\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4690 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:21:52',4,'2020-06-05 11:22:08',4,0,NULL,NULL,NULL,'3333bc62-d534-423c-bc79-b477f5296f51'),(588,'adult_arv_2l_3mnth','3months supply of 2l','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2l_3mnth\n 3months supply of 2l\n \n 2020-06-05 09:23:04 UTC\n \n 2020-06-05 09:23:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 588\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 2201 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4691 \n)\n','2020-06-05 11:23:04',4,'2020-06-05 11:23:19',4,0,NULL,NULL,NULL,'aa37e85b-a2fb-41af-97b1-d25b86a87ad5'),(589,'adult_arv_2m_3mnth','3months supply of 2m','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2m_3mnth\n 3months supply of 2m\n \n 2020-06-05 09:23:46 UTC\n \n 2020-06-05 09:24:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 589\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4692 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:23:46',4,'2020-06-05 11:24:00',4,0,NULL,NULL,NULL,'d67a7838-10cf-4ae8-a536-38ba96c2ca9a'),(590,'adult_arv_2n_3mnth','3mnths supply of 2n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2n_3mnth\n 3mnths supply of 2n\n \n 2020-06-05 09:24:28 UTC\n \n 2020-06-05 09:24:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 590\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4693 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:24:28',4,'2020-06-05 11:24:46',4,0,NULL,NULL,NULL,'05a68334-52b7-4a39-8221-f4f3c02b26f6'),(591,'adult_arv_2o_3mnth','3mnths supply of 2o','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2o_3mnth\n 3mnths supply of 2o\n \n 2020-06-05 09:25:16 UTC\n \n 2020-06-05 09:25:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 591\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4694 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:25:16',4,'2020-06-05 11:25:40',4,0,NULL,NULL,NULL,'fe8ca75f-be0f-4047-b0a8-3836ad3c8220'),(592,'adult_arv_2p_3mnth','3months supply of 2p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2p_3mnth\n 3months supply of 2p\n \n 2020-06-05 09:26:29 UTC\n \n 2020-06-05 09:26:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 592\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4695 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:26:29',4,'2020-06-05 11:26:46',4,0,NULL,NULL,NULL,'34c0a5a2-e192-4423-9067-6c15c57534ea'),(593,'2020_TB_Screening','new dataset TB Screening','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_TB_Screening\n new dataset TB Screening\n \n 2020-06-05 09:27:25 UTC\n \n 2020-06-05 09:27:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 593\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-06-05 11:27:25',4,'2020-06-05 11:27:28',4,0,NULL,NULL,NULL,'5f5679ca-795d-434b-a3e0-354fec02f6e8'),(594,'2020_TB_Screening Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_TB_Screening Data Set\n \n 2020-06-05 09:27:28 UTC\n \n 2020-08-04 17:36:49 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 594\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n TBCaseAdF\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n TBCaseAdM\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n TBCaseChF\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n TBCaseChM\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n TBTreatAdF\n \n \n \n \n \n \n \n \n \n TBTreatAdM\n \n \n \n \n \n \n TBTreatChF\n \n \n \n \n \n \n TBTreatChM\n \n \n \n \n \n \n screen14F\n \n \n \n \n \n \n \n \n \n screen14M\n \n \n \n \n \n \n screen15+F\n \n \n \n \n \n \n screen15+M\n \n \n \n \n \n \n seen14F\n \n \n \n \n \n \n \n \n \n seen14M\n \n \n \n \n \n \n seen15+F\n \n \n \n \n \n \n seen15+M\n \n \n \n \n \n \n start14F\n \n \n \n \n \n \n start14M\n \n \n \n \n \n \n start15+F\n \n \n \n \n \n \n start15+M\n \n \n \n \n \n \n','2020-06-05 09:27:28',4,'2020-08-04 17:36:49',4,0,NULL,NULL,NULL,'4d895f5d-ede9-42b0-ae52-7e97a646c2d7'),(595,'adult_arv_2q_3mnth','3mnths supply of 2q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2q_3mnth\n 3mnths supply of 2q\n \n 2020-06-05 09:29:55 UTC\n \n 2020-11-20 11:33:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 595\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4849 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-06-05 11:29:55',4,'2020-11-20 13:33:12',4,0,NULL,NULL,NULL,'5e16b0e3-6356-4963-8a44-259095ecfb88'),(596,'Clients newly initiated 4c','4c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4c\n 4c\n \n 2020-06-05 09:51:25 UTC\n \n 2021-01-27 22:08:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 596\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 2202 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:51:25',4,'2021-01-27 22:08:31',4,0,NULL,NULL,NULL,'e9bdc7db-4154-4d56-ae30-e5e22cd2276d'),(597,'Clients newly initiated 4d','4d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4d\n 4d\n \n 2020-06-05 09:54:04 UTC\n \n 2021-01-27 22:19:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 597\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 2204 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:54:04',4,'2021-01-27 22:19:28',4,0,NULL,NULL,NULL,'2f6f3d47-f7f2-4059-a098-e1164c572f36'),(598,'Clients newly initiated 4e','4e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4e\n 4e\n \n 2020-06-05 09:54:44 UTC\n \n 2021-01-27 22:21:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 598\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3679 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:54:44',4,'2021-01-27 22:21:19',4,0,NULL,NULL,NULL,'3b4b75da-e900-4fdf-8594-c25d3a20e047'),(599,'Clients newly initiated 4f','4f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4f\n 4f\n \n 2020-06-05 09:56:08 UTC\n \n 2021-01-27 22:22:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 599\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3680 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:56:08',4,'2021-01-27 22:22:42',4,0,NULL,NULL,NULL,'07ea75ac-aa04-47ef-aec5-5c56aaa7143e'),(600,'Clients newly initiated 4g','4g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4g\n 4g\n \n 2020-06-05 09:56:57 UTC\n \n 2021-01-27 22:24:27 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 600\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4684 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:56:57',4,'2021-01-27 22:24:27',4,0,NULL,NULL,NULL,'e0d57b65-99fd-4058-8626-143e4dff86c9'),(601,'Clients newly initiated 4h','4h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4h\n 4h\n \n 2020-06-05 09:58:19 UTC\n \n 2021-01-27 22:25:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 601\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4685 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:58:19',4,'2021-01-27 22:25:35',4,0,NULL,NULL,NULL,'d56c2ea1-4ddf-4d2d-85e3-b25806f12a50'),(602,'Clients newly initiated 4k','4k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4k\n 4k\n \n 2020-06-05 09:59:20 UTC\n \n 2021-01-27 22:29:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 602\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4687 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 09:59:20',4,'2021-01-27 22:29:03',4,0,NULL,NULL,NULL,'938aad64-3bc8-46d7-aaec-36522d65e24b'),(603,'Clients newly initiated 4L','4L','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4L\n 4L\n \n 2020-06-05 10:05:28 UTC\n \n 2021-01-27 22:30:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 603\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4688 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:05:28',4,'2021-01-27 22:30:13',4,0,NULL,NULL,NULL,'368e8627-12e2-4d50-81ce-ac338ad1c858'),(604,'Clients newly initiated 5a','5a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5a\n 5a\n \n 2020-06-05 10:07:35 UTC\n \n 2021-01-27 22:32:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 604\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3681 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:07:35',4,'2021-01-27 22:32:44',4,0,NULL,NULL,NULL,'2dd7cbae-8054-4270-bf2a-9ec98eef1747'),(605,'Clients newly initiated 5b','5b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5b\n 5b\n \n 2020-06-05 10:09:31 UTC\n \n 2021-01-27 22:35:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 605\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3682 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:09:31',4,'2021-01-27 22:35:45',4,0,NULL,NULL,NULL,'d8c18842-91aa-4102-a19a-1f48780c4daa'),(606,'Clients newly initiated 5c','5c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5c\n 5c\n \n 2020-06-05 10:11:40 UTC\n \n 2021-01-27 22:37:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 606\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4696 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:11:40',4,'2021-01-27 22:37:24',4,0,NULL,NULL,NULL,'655a6791-e753-405e-831f-c527d63386ab'),(607,'Clients newly initiated 5d','5d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5d\n 5d\n \n 2020-06-05 10:12:25 UTC\n \n 2021-01-27 22:39:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 607\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4697 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:12:25',4,'2021-01-27 22:39:19',4,0,NULL,NULL,NULL,'c7e733d9-f5ec-4799-bb83-0f8e38f9a5e1'),(608,'Clients newly initiated 5e','5e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5e\n 5e\n \n 2020-06-05 10:13:16 UTC\n \n 2021-01-27 22:40:36 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 608\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4698 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:13:16',4,'2021-01-27 22:40:36',4,0,NULL,NULL,NULL,'09ce91e0-7242-41fa-b68f-551daabefd2e'),(609,'Clients newly initiated 5g','5g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5g\n 5g\n \n 2020-06-05 10:15:17 UTC\n \n 2021-01-27 22:44:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 609\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4700 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:15:17',4,'2021-01-27 22:44:28',4,0,NULL,NULL,NULL,'c529cc30-cff7-4a9b-8ca6-9bccd505139e'),(610,'Clients newly initiated 5h','5h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5h\n 5h\n \n 2020-06-05 10:15:50 UTC\n \n 2021-01-27 22:46:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 610\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4701 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:15:50',4,'2021-01-27 22:46:38',4,0,NULL,NULL,NULL,'e316ba5b-a507-493a-8183-3b48bdea3c65'),(611,'Clients newly initiated 6a','6a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6a\n 6a\n \n 2020-06-05 10:16:53 UTC\n \n 2021-01-27 22:49:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 611\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3686 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:16:53',4,'2021-01-27 22:49:29',4,0,NULL,NULL,NULL,'7cd2486f-34f5-4a78-a016-70512f5b4830'),(612,'Clients newly initiated 6b','6b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6b\n 6b\n \n 2020-06-05 10:18:54 UTC\n \n 2021-01-27 22:56:39 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 612\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3687 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:18:54',4,'2021-01-27 22:56:39',4,0,NULL,NULL,NULL,'4b8c4474-fcb5-43e5-9eb8-75695ee52205'),(613,'Clients newly initiated 6c','6c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6c\n 6c\n \n 2020-06-05 10:19:34 UTC\n \n 2021-01-27 22:58:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 613\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4702 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:19:34',4,'2021-01-27 22:58:59',4,0,NULL,NULL,NULL,'f3536aac-02a4-42ec-ab92-e43da022e09b'),(614,'2020_COTRIMOX PROPHYLAXIS/DAPSONE','new dataset clients who received CTX','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_COTRIMOX PROPHYLAXIS/DAPSONE\n new dataset clients who received CTX\n \n 2020-06-05 10:20:14 UTC\n \n 2020-06-05 10:20:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 614\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-06-05 12:20:14',4,'2020-06-05 12:20:17',4,0,NULL,NULL,NULL,'8dc80efd-3c35-4d1a-ad4e-5f9f26caeaf5'),(615,'2020_COTRIMOX PROPHYLAXIS/DAPSONE Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_COTRIMOX PROPHYLAXIS/DAPSONE Data Set\n \n 2020-06-05 10:20:17 UTC\n \n 2020-06-06 18:16:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 615\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n CTX_F1-4\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n CTX_F5-14\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 05yrsto14yrs\n \n \n \n \n \n CTX_F<1\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n CTX_FAdult\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n CTX_M1-4\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 01to04yrs\n \n \n \n \n \n CTX_M5-14\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 05yrsto14yrs\n \n \n \n \n \n CTX_M<1\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Under 1yr\n \n \n \n \n \n CTX_MAdult\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Adults\n \n \n \n \n \n','2020-06-05 12:20:17',4,'2020-06-06 20:16:22',4,0,NULL,NULL,NULL,'9661c0bc-601a-4b16-b0de-4d891c2d93bc'),(616,'Clients newly initiated 6d','6d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6d\n 6d\n \n 2020-06-05 10:20:21 UTC\n \n 2021-01-27 23:00:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 616\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4703 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:20:21',4,'2021-01-27 23:00:12',4,0,NULL,NULL,NULL,'26bd109c-b9bf-41cd-8b76-027713846950'),(617,'Clients newly initiated 6e','6e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6e\n 6e\n \n 2020-06-05 10:21:00 UTC\n \n 2021-01-27 23:03:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 617\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4704 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:21:00',4,'2021-01-27 23:03:14',4,0,NULL,NULL,NULL,'9dfe2b8b-dc4c-4708-8672-977b5de9526d'),(618,'Clients newly initiated 6f','6f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 6f\n 6f\n \n 2020-06-05 10:22:22 UTC\n \n 2021-01-27 23:04:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 618\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4705 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 10:22:22',4,'2021-01-27 23:04:14',4,0,NULL,NULL,NULL,'10f50f0b-9282-4d68-9e57-13c17e37b411'),(619,'adult_arv_1c_1mnth','1c 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_1mnth\n 1c 1mnth\n \n 2020-06-05 10:42:17 UTC\n \n 2021-01-27 15:47:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 619\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 10:42:17',4,'2021-01-27 15:47:12',4,0,NULL,NULL,NULL,'4d8b2d8b-a165-42ba-abdb-2d881d7cdd0c'),(621,'Clients given CTX in the month','ctx','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given CTX in the month\n ctx\n \n 2020-06-05 10:51:40 UTC\n \n 2020-06-05 10:52:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 621\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 3728 and value_numeric > 1\n','2020-06-05 12:51:40',4,'2020-06-05 12:52:11',4,0,NULL,NULL,NULL,'afa0260d-641b-45bd-a341-7582b02f70a6'),(622,'adult_arv_1d_1mnth','1d 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_1mnth\n 1d 1mnth\n \n 2020-06-05 10:51:52 UTC\n \n 2021-01-27 15:58:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 622\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 10:51:52',4,'2021-01-27 15:58:19',4,0,NULL,NULL,NULL,'00a20283-36e6-43cc-99c3-a9555937e320'),(623,'adult_arv_1e_1mnth','1e 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_1mnth\n 1e 1mnth\n \n 2020-06-05 10:54:44 UTC\n \n 2021-01-27 16:12:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 623\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 10:54:44',4,'2021-01-27 16:12:51',4,0,NULL,NULL,NULL,'b693cd81-554d-4b98-ab19-547ef5d1316d'),(624,'adult_arv_1f_1mnth','1f 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_1mnth\n 1f 1mnth\n \n 2020-06-05 11:02:36 UTC\n \n 2020-06-05 11:03:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 624\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:02:36',4,'2020-06-05 13:03:17',4,0,NULL,NULL,NULL,'c1745a07-d769-478c-b703-9e00ef10c3fc'),(625,'Plumpy Nut given in the month','RUFT','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Plumpy Nut given in the month\n RUFT\n \n 2020-06-05 11:02:38 UTC\n \n 2020-06-05 11:02:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 625\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 4167 and value_coded = 4163\n','2020-06-05 13:02:38',4,'2020-06-05 13:02:51',4,0,NULL,NULL,NULL,'085fe744-3c4e-4d96-9621-af1ffeda1e8d'),(626,'F100 given in the month','F100','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n F100 given in the month\n F100\n \n 2020-06-05 11:03:21 UTC\n \n 2020-06-05 11:03:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 626\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 4167 and value_coded = 4164\n','2020-06-05 13:03:21',4,'2020-06-05 13:03:34',4,0,NULL,NULL,NULL,'1a858146-5ad0-4914-90c6-78770ebc7045'),(627,'F75 given in the month','F75','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n F75 given in the month\n F75\n \n 2020-06-05 11:04:35 UTC\n \n 2020-06-05 11:04:50 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 627\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 4167 and value_coded = 4165\n','2020-06-05 13:04:35',4,'2020-06-05 13:04:50',4,0,NULL,NULL,NULL,'a1c3f512-58d0-4b3c-ba09-22f38d76850e'),(628,'adult_arv_1g_1mnth','1g 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_1mnth\n 1g 1mnth\n \n 2020-06-05 11:04:39 UTC\n \n 2021-01-27 16:24:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 628\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:04:39',4,'2021-01-27 16:24:35',4,0,NULL,NULL,NULL,'6133c572-3574-4a36-a383-8ba8f154ae4b'),(629,'Other Nutritional Supplement given in the month','other supplement','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Other Nutritional Supplement given in the month\n other supplement\n \n 2020-06-05 11:06:00 UTC\n \n 2020-06-05 11:06:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 629\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 4167 and value_coded = 4166\n','2020-06-05 13:06:00',4,'2020-06-05 13:06:13',4,0,NULL,NULL,NULL,'5dcaf597-94b6-40d7-9967-8f145c4c1a54'),(630,'adult_arv_1h_1mnth','1h 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_1mnth\n 1h 1mnth\n \n 2020-06-05 11:06:29 UTC\n \n 2021-01-27 16:39:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 630\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:06:29',4,'2021-01-27 16:39:22',4,0,NULL,NULL,NULL,'b36e2da3-c211-4c2d-a01f-4fa0a0fe1fd8'),(631,'adult_arv_1j_1mnth','1j 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_1mnth\n 1j 1mnth\n \n 2020-06-05 11:11:22 UTC\n \n 2021-01-27 16:53:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 631\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:11:22',4,'2021-01-27 16:53:30',4,0,NULL,NULL,NULL,'9560bddf-1def-45f3-8606-ce4adbbfcc19'),(632,'adult_arv_1k_1mnth','1k 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_1mnth\n 1k 1mnth\n \n 2020-06-05 11:12:57 UTC\n \n 2021-01-27 16:59:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 632\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:12:57',4,'2021-01-27 16:59:54',4,0,NULL,NULL,NULL,'44fcfb57-e804-4f3e-a7f3-bc488400c481'),(633,'adult_arv_1m_1mnth','1m 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_1mnth\n 1m 1mnth\n \n 2020-06-05 11:14:18 UTC\n \n 2021-01-27 17:12:50 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 633\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:14:18',4,'2021-01-27 17:12:50',4,0,NULL,NULL,NULL,'6dc933e8-a8d7-4b43-89b8-90edc570311a'),(634,'adult_arv_1n_1mnth','1n 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_1mnth\n 1n 1mnth\n \n 2020-06-05 11:16:41 UTC\n \n 2021-01-27 17:29:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 634\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:16:41',4,'2021-01-27 17:29:59',4,0,NULL,NULL,NULL,'cb2ca745-f914-4258-aad0-5b57ea870dbd'),(635,'adult_arv_1p_1mnth','1p 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_1mnth\n 1p 1mnth\n \n 2020-06-05 11:18:07 UTC\n \n 2021-01-27 17:44:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 635\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:18:07',4,'2021-01-27 17:44:00',4,0,NULL,NULL,NULL,'15aedfaf-51f7-4d96-b706-b3a3280c560a'),(636,'adult_arv_1q_1mnth','1q 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_1mnth\n 1q 1mnth\n \n 2020-06-05 11:19:15 UTC\n \n 2021-01-27 17:58:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 636\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:19:15',4,'2021-01-27 17:58:21',4,0,NULL,NULL,NULL,'31689512-e2e3-4401-ad27-ea802bdc3617'),(637,'adult_arv_other_1mnth','other 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_1mnth\n other 1mnth\n \n 2020-06-05 11:21:51 UTC\n \n 2021-07-13 11:05:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 637\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:21:51',4,'2021-07-13 11:05:33',4,0,NULL,NULL,NULL,'449d0ce8-0a40-4591-a309-040dfb083198'),(638,'adult_arv_1c_3mnth','1c 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_3mnth\n 1c 3mnths\n \n 2020-06-05 11:24:27 UTC\n \n 2021-01-27 15:49:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 638\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:24:27',4,'2021-01-27 15:49:31',4,0,NULL,NULL,NULL,'2c077d8b-0aa7-401d-aba3-788473928468'),(639,'adult_arv_1d_3mnths','1d 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_3mnths\n 1d 3mnths\n \n 2020-06-05 11:25:44 UTC\n \n 2021-01-27 16:00:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 639\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:25:44',4,'2021-01-27 16:00:17',4,0,NULL,NULL,NULL,'e39e1c56-fece-4095-a279-da8ae718544f'),(640,'adult_arv_1e_3mnths','1e 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_3mnths\n 1e 3mnths\n \n 2020-06-05 11:27:12 UTC\n \n 2021-01-27 16:16:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 640\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:27:12',4,'2021-01-27 16:16:45',4,0,NULL,NULL,NULL,'6068ee9b-96b7-4c60-ad99-59f129fb2a86'),(641,'adult_arv_1f_3mnths','1f 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_3mnths\n 1f 3mnths\n \n 2020-06-05 11:28:37 UTC\n \n 2020-06-05 11:29:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 641\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:28:37',4,'2020-06-05 13:29:15',4,0,NULL,NULL,NULL,'66122df9-8b00-44eb-9895-faabe0421c6c'),(642,'adult_arv_1g_3mnths','1g 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_3mnths\n 1g 3mnths\n \n 2020-06-05 11:29:54 UTC\n \n 2021-01-27 16:32:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 642\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:29:54',4,'2021-01-27 16:32:52',4,0,NULL,NULL,NULL,'2e325001-abd4-4c5a-82b9-0ac9886ecbb6'),(643,'adult_arv_1h_3mnths','1h 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_3mnths\n 1h 3mnths\n \n 2020-06-05 11:30:54 UTC\n \n 2021-01-27 16:42:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 643\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:30:54',4,'2021-01-27 16:42:06',4,0,NULL,NULL,NULL,'c15f9357-fba2-46f7-96a1-44b25379ccea'),(644,'adult_arv_1j_3mnths','1j 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_3mnths\n 1j 3mnths\n \n 2020-06-05 11:32:13 UTC\n \n 2021-01-27 16:55:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 644\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:32:13',4,'2021-01-27 16:55:38',4,0,NULL,NULL,NULL,'e1b0c0ec-23b6-44c7-b80a-851b276f6238'),(645,'adult_arv_1k_3mnths','1k 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_3mnths\n 1k 3mnths\n \n 2020-06-05 11:35:55 UTC\n \n 2021-01-27 17:05:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 645\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:35:55',4,'2021-01-27 17:05:10',4,0,NULL,NULL,NULL,'2e6cd3c8-b48e-4e64-ac85-11c34fdeb49c'),(646,'adult_arv_1m_3mnths','1m 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_3mnths\n 1m 3mnths\n \n 2020-06-05 11:37:06 UTC\n \n 2021-01-27 17:14:41 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 646\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:37:06',4,'2021-01-27 17:14:41',4,0,NULL,NULL,NULL,'ac70448a-01bd-4e80-b1b4-9dffa36380a0'),(647,'adult_arv_1n_3mnths','1n 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_3mnths\n 1n 3mnths\n \n 2020-06-05 11:38:09 UTC\n \n 2021-01-27 17:34:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 647\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:38:09',4,'2021-01-27 17:34:59',4,0,NULL,NULL,NULL,'15d01fbf-abf1-4394-9da3-6d2a2b8f02f6'),(648,'adult_arv_1p_3mnths','1p 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_3mnths\n 1p 3mnths\n \n 2020-06-05 11:39:05 UTC\n \n 2021-01-27 17:54:50 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 648\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:39:05',4,'2021-01-27 17:54:50',4,0,NULL,NULL,NULL,'222eaf25-8e7a-4d38-bca4-41642991fe3d'),(649,'adult_arv_1q_3mnths','1q 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_3mnths\n 1q 3mnths\n \n 2020-06-05 11:40:02 UTC\n \n 2021-01-27 17:53:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 649\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:40:02',4,'2021-01-27 17:53:15',4,0,NULL,NULL,NULL,'f6d560ce-615d-4607-a3d0-8ae3435535fe'),(650,'adult_arv_other_3mnths','other 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_3mnths\n other 3mnths\n \n 2020-06-05 11:41:25 UTC\n \n 2021-02-04 09:03:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 650\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:41:25',4,'2021-02-04 09:03:37',4,0,NULL,NULL,NULL,'6ab6f0c1-401a-4a74-842f-c97983880745'),(651,'adult_arv_1c_6mnths','1c 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_6mnths\n 1c 6mnths\n \n 2020-06-05 11:43:07 UTC\n \n 2021-01-27 15:53:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 651\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:43:07',4,'2021-01-27 15:53:25',4,0,NULL,NULL,NULL,'4b1fc9fe-27bd-4473-b7dd-3f756a47ccb7'),(652,'adult_arv_1d_6mnths','1d 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_6mnths\n 1d 6mnths\n \n 2020-06-05 11:44:21 UTC\n \n 2021-01-27 16:08:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 652\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:44:21',4,'2021-01-27 16:08:01',4,0,NULL,NULL,NULL,'eab3ea99-52e0-4ea9-83f3-6711754e40e1'),(653,'adult_arv_1e_6mnths','1e 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_6mnths\n 1e 6mnths\n \n 2020-06-05 11:45:53 UTC\n \n 2021-01-27 16:19:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 653\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:45:53',4,'2021-01-27 16:19:28',4,0,NULL,NULL,NULL,'a7fd11c7-b7e0-43ea-b6aa-6c51ec395bcb'),(654,'adult_arv_1f_6mnths','1f 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_6mnths\n 1f 6mnths\n \n 2020-06-05 11:47:04 UTC\n \n 2020-06-05 11:47:39 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 654\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:47:04',4,'2020-06-05 13:47:39',4,0,NULL,NULL,NULL,'1f821fff-33b0-42b0-b62c-430af9d77512'),(655,'adult_arv_1g_6mnths','1g 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_6mnths\n 1g 6mnths\n \n 2020-06-05 11:48:04 UTC\n \n 2021-01-27 16:34:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 655\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:48:04',4,'2021-01-27 16:34:52',4,0,NULL,NULL,NULL,'96765b0d-eef0-4990-9602-d27fb6627270'),(656,'adult_arv_1h_6mnths','1h 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_6mnths\n 1h 6mnths\n \n 2020-06-05 11:49:10 UTC\n \n 2021-01-27 16:44:47 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 656\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:49:10',4,'2021-01-27 16:44:47',4,0,NULL,NULL,NULL,'bd0a9a38-fcfc-4dd7-89bd-3d3901b6f37f'),(657,'adult_arv_1j_6mnths','1j 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_6mnths\n 1j 6mnths\n \n 2020-06-05 11:51:11 UTC\n \n 2021-01-27 16:57:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 657\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:51:11',4,'2021-01-27 16:57:42',4,0,NULL,NULL,NULL,'f1d1b1e3-7805-49f6-b6e1-3e51ee5ca3c1'),(658,'adult_arv_1k_6mnths','1k 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_6mnths\n 1k 6mnths\n \n 2020-06-05 11:52:20 UTC\n \n 2021-01-27 17:07:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 658\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:52:20',4,'2021-01-27 17:07:04',4,0,NULL,NULL,NULL,'508ebf4a-5097-447f-a087-b722c8784233'),(659,'adult_arv_1m_6mnths','1m 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_6mnths\n 1m 6mnths\n \n 2020-06-05 11:53:19 UTC\n \n 2021-01-27 17:17:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 659\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:53:19',4,'2021-01-27 17:17:08',4,0,NULL,NULL,NULL,'08b21870-a277-4cf5-83da-3802031cd02d'),(660,'adult_arv_1n_6mnths','1n 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_6mnths\n 1n 6mnths\n \n 2020-06-05 11:55:16 UTC\n \n 2021-01-27 17:38:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 660\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:55:16',4,'2021-01-27 17:38:14',4,0,NULL,NULL,NULL,'078738ed-db38-4f25-9963-74e150af6157'),(661,'adult_arv_1p_6mnths','1p 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_6mnths\n 1p 6mnths\n \n 2020-06-05 11:56:46 UTC\n \n 2021-01-27 17:36:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 661\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:56:46',4,'2021-01-27 17:36:45',4,0,NULL,NULL,NULL,'a2dcd6db-39bc-469e-ac03-8bfedec4c18f'),(662,'adult_arv_1q_6mnths','1q 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_6mnths\n 1q 6mnths\n \n 2020-06-05 11:58:12 UTC\n \n 2021-01-27 18:00:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 662\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:58:12',4,'2021-01-27 18:00:44',4,0,NULL,NULL,NULL,'71007fca-4c23-43ab-81db-9090baa8fb01'),(663,'adult_arv_other_6mnths','other 6mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_6mnths\n other 6mnths\n \n 2020-06-05 11:59:58 UTC\n \n 2021-02-04 09:05:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 663\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 11:59:58',4,'2021-02-04 09:05:16',4,0,NULL,NULL,NULL,'24d02723-dc41-4afa-8f45-6da91778130a'),(664,'adult_arv_1c_other_mnths','1c other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1c_other_mnths\n 1c other supply\n \n 2020-06-05 12:03:30 UTC\n \n 2021-01-27 15:56:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 664\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:03:30',4,'2021-01-27 15:56:35',4,0,NULL,NULL,NULL,'fc0771aa-32dc-43da-b4eb-283519fedfd1'),(665,'adult_arv_1d_other_mnths','1d other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1d_other_mnths\n 1d other supply\n \n 2020-06-05 12:07:38 UTC\n \n 2021-01-27 16:10:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 665\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:07:38',4,'2021-01-27 16:10:12',4,0,NULL,NULL,NULL,'99e2601c-ddcc-42be-a3af-b659bbfdd9ea'),(666,'adult_arv_1e_other_mnths','1e other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1e_other_mnths\n 1e other supply\n \n 2020-06-05 12:09:09 UTC\n \n 2021-01-27 16:20:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 666\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:09:09',4,'2021-01-27 16:20:56',4,0,NULL,NULL,NULL,'5ee5c1d7-9ccf-44f3-b620-c849f9e502cb'),(667,'adult_arv_1f_other_mnths','1f other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1f_other_mnths\n 1f other supply\n \n 2020-06-05 12:10:11 UTC\n \n 2020-06-05 12:10:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 667\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 14:10:11',4,'2020-06-05 14:10:46',4,0,NULL,NULL,NULL,'c54c9e70-972e-475e-accd-d590158089aa'),(668,'adult_arv_1g_other_mnths','1g other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1g_other_mnths\n 1g other supply\n \n 2020-06-05 12:11:10 UTC\n \n 2020-06-05 12:11:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 668\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 14:11:10',4,'2020-06-05 14:11:48',4,0,NULL,NULL,NULL,'6f497b96-793f-444c-b599-b8c84802c8ce'),(669,'adult_arv_1h_other_mnths','1h other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1h_other_mnths\n 1h other supply\n \n 2020-06-05 12:12:15 UTC\n \n 2021-01-27 16:50:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 669\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:12:15',4,'2021-01-27 16:50:25',4,0,NULL,NULL,NULL,'6d91768d-95ad-42ff-a2e8-b994e7af2f3a'),(670,'adult_arv_1j_other_mnths','1j other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1j_other_mnths\n 1j other supply\n \n 2020-06-05 12:14:44 UTC\n \n 2020-06-05 12:15:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 670\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 14:14:44',4,'2020-06-05 14:15:18',4,0,NULL,NULL,NULL,'6176f910-0ee7-4ba9-997e-ce7585f83ae8'),(671,'adult_arv_1k_other_mnths','1k other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1k_other_mnths\n 1k other supply\n \n 2020-06-05 12:15:41 UTC\n \n 2021-01-27 17:08:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 671\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:15:41',4,'2021-01-27 17:08:52',4,0,NULL,NULL,NULL,'6e5cbb5d-f451-47ea-a2fd-9bff1f28f555'),(672,'Missed or defaulted under 28days','missed or defaulted < 28','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Missed or defaulted under 28days\n missed or defaulted < 28\n \n 2020-06-05 12:16:25 UTC\n \n 2022-05-04 07:07:49 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 672\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \n and l.location_id = :location or l.parent_location = :location \n -- PATIENTS WHO HAVE NOT SHOWED UP FOR THEIR APPOINTMENT FOR 4 WEEKS to 3 MONTHS (i.e. 29 to 89 days) \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n -- begin \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n and voided = 0 \n group by B.person_id \n ) as active_clients \n where active_clients.latest_follow_up < cast(:endDate as date) \n and DATEDIFF(CAST(:endDate AS DATE),latest_follow_up) > 0 \n and DATEDIFF(CAST(:endDate AS DATE),latest_follow_up) <= 28 \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and os.voided = 0 \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 and os.voided = 0 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.obs_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2398 and os.voided = 0 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 and voided = 0 \n ) \n ) \n -- end \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id AND person_name.preferred = 1 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n INNER JOIN reporting_age_group AS observed_age_group ON \n CAST(:endDate AS DATE) BETWEEN (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.min_years YEAR), INTERVAL observed_age_group.min_days DAY)) \n AND (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.max_years YEAR), INTERVAL observed_age_group.max_days DAY)) \n WHERE observed_age_group.report_group_name = 'Modified_Ages' \n','2020-06-05 12:16:25',4,'2022-05-04 07:07:49',4,0,NULL,NULL,NULL,'a7064d93-cb9d-44f7-b7cb-f0d38313fdb3'),(673,'adult_arv_1m_other_mnths','1m other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1m_other_mnths\n 1m other supply\n \n 2020-06-05 12:16:47 UTC\n \n 2021-01-27 17:18:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 673\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:16:47',4,'2021-01-27 17:18:26',4,0,NULL,NULL,NULL,'9ebb3d1c-52e8-40e7-abc2-871abfdd6ffa'),(674,'adult_arv_1n_other_mnths','1n other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1n_other_mnths\n 1n other supply\n \n 2020-06-05 12:17:46 UTC\n \n 2021-01-27 17:41:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 674\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:17:46',4,'2021-01-27 17:41:01',4,0,NULL,NULL,NULL,'b829a556-e0e5-4856-8800-ea2560894f62'),(675,'adult_arv_1p_other_mnths','1p other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1p_other_mnths\n 1p other supply\n \n 2020-06-05 12:20:31 UTC\n \n 2021-01-27 17:49:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 675\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:20:31',4,'2021-01-27 17:49:53',4,0,NULL,NULL,NULL,'6843123f-248a-4232-9008-a51ffdc43c5b'),(676,'adult_arv_1q_other_mnths','1q other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_1q_other_mnths\n 1q other supply\n \n 2020-06-05 12:21:42 UTC\n \n 2021-01-27 18:07:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 676\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:21:42',4,'2021-01-27 18:07:21',4,0,NULL,NULL,NULL,'762d08de-74a3-40fe-9240-1fc904fcb69e'),(677,'Missed or defaulted between 29 and 89 days','missed >29\r\nmissed < 90','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Missed or defaulted between 29 and 89 days\n missed >29 \nmissed < 90\n \n 2020-06-05 12:22:30 UTC\n \n 2022-06-02 16:35:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 677\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \n and l.location_id = :location or l.parent_location = :location \n -- PATIENTS WHO HAVE NOT SHOWED UP FOR THEIR APPOINTMENT FOR 4 WEEKS to 3 MONTHS (i.e. 29 to 89 days) \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n -- begin \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n and voided = 0 \n group by B.person_id \n ) as active_clients \n where active_clients.latest_follow_up < cast(:endDate as date) \n and DATEDIFF(CAST(:endDate AS DATE),latest_follow_up) > 28 \n and DATEDIFF(CAST(:endDate AS DATE),latest_follow_up) <= 89 \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND os.voided = 0 \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND os.voided = 0 \n ) \n \n and active_clients.person_id not in ( \n \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.obs_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2398 \n AND os.voided = 0 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 and voided = 0 \n ) \n ) \n -- end \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN person_name ON person.person_id = person_name.person_id AND person_name.preferred = 1 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n INNER JOIN reporting_age_group AS observed_age_group ON \n CAST(:endDate AS DATE) BETWEEN (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.min_years YEAR), INTERVAL observed_age_group.min_days DAY)) \n AND (DATE_ADD(DATE_ADD(person.birthdate, INTERVAL observed_age_group.max_years YEAR), INTERVAL observed_age_group.max_days DAY)) \n WHERE observed_age_group.report_group_name = 'Modified_Ages' \n \n','2020-06-05 12:22:30',4,'2022-06-02 16:35:33',4,0,NULL,NULL,NULL,'5be87aeb-a57c-4a02-83e7-93d560d49fbb'),(678,'adult_arv_other_other_mnths','other other supply','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_other_other_mnths\n other other supply\n \n 2020-06-05 12:23:07 UTC\n \n 2021-02-04 09:06:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 678\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:23:07',4,'2021-02-04 09:06:31',4,0,NULL,NULL,NULL,'c53c49b3-0557-4f1a-9006-1a88e542519d'),(679,'adult_arv_2c_1mnth','2c 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2c_1mnth\n 2c 1mnth\n \n 2020-06-05 12:36:06 UTC\n \n 2021-07-13 14:26:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 679\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:36:06',4,'2021-07-13 14:26:45',4,0,NULL,NULL,NULL,'69830812-bc46-428a-b10e-43a31a982e02'),(680,'LTFU this month','lost to follow up','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n LTFU this month\n lost to follow up\n \n 2020-06-05 12:37:18 UTC\n \n 2020-06-05 12:38:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 680\n select distinct o.person_id \nFROM obs o \nINNER JOIN patient ON o.person_id = patient.patient_id \nand o.concept_id = 3752 \nand o.value_datetime in \n ( \n select latestFU from \n ( \n select distinct os.person_id, max(os.value_datetime) AS latestFU, datediff(CAST(:endDate AS DATE), max(value_datetime)) AS \n Num_Days \n from obs os \n inner join person_name pn on os.person_id = pn.person_id \n inner join patient p on pn.person_id = p.patient_id and pn.voided = 0 \n inner join person ps on ps.person_id = p.patient_id and ps.voided = 0 \n where os.concept_id = 3752 \n and obs_datetime <= :endDate \n group by os.person_id \n having Num_Days > 7 \n and Num_Days < 30 \n ) as lost \n ) \nand o.person_id in \n ( \n select person_id from \n ( \n select distinct os.person_id, max(os.value_datetime) AS latestFU, datediff(CAST(:endDate AS DATE), \n max(value_datetime)) AS Num_Days \n from obs os \n inner join person_name pn on os.person_id = pn.person_id \n inner join patient p on pn.person_id = p.patient_id and pn.voided = 0 \n inner join person ps on ps.person_id = p.patient_id and ps.voided = 0 \n where os.concept_id = 3752 \n and obs_datetime <= :endDate \n group by os.person_id \n having Num_Days > 90 \n ) as lost \n ) \n \nAND o.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 4155 and os.value_coded = 2146 and obs_datetime < :endDate and person_id not in \n (select person_id from \n (select person_id who, max(value_datetime) latest \n from obs \n where concept_ID = 2266 \n group by person_id) one, \n \n ( \n select person_id,obs_datetime \n from obs \n where concept_id = 3843 ) two \n \n where who = person_id \n and DATE(obs_datetime) > DATE(latest)) \n ) \n ) \nAND o.person_id not in ( \n select person_id \n from person \n where death_date <= :endDate \n and dead = 1 \n ) \n \n;\n','2020-06-05 14:37:18',4,'2020-06-05 14:38:18',4,0,NULL,NULL,NULL,'f5c2691c-0977-4a4d-957e-2cf973e37bb7'),(681,'adult_arv_2d_1mnth','2d 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2d_1mnth\n 2d 1mnth\n \n 2020-06-05 12:37:55 UTC\n \n 2021-07-13 14:30:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 681\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:37:55',4,'2021-07-13 14:30:11',4,0,NULL,NULL,NULL,'456f6967-04cc-4c2a-8e50-7c99e799eb29'),(682,'adult_arv_2e_1mnth','2e 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2e_1mnth\n 2e 1mnth\n \n 2020-06-05 12:39:33 UTC\n \n 2021-07-13 14:30:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 682\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:39:33',4,'2021-07-13 14:30:44',4,0,NULL,NULL,NULL,'e5b6e482-9ccb-411c-bdf4-8dc43d421947'),(683,'adult_arv_2f_1mnth','2f 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2f_1mnth\n 2f 1mnth\n \n 2020-06-05 12:40:45 UTC\n \n 2021-07-13 14:34:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 683\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:40:45',4,'2021-07-13 14:34:37',4,0,NULL,NULL,NULL,'11aa9360-825c-4aac-ab2a-65d21642765e'),(684,'adult_arv_2g_1mnth','2g 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2g_1mnth\n 2g 1mnth\n \n 2020-06-05 12:41:52 UTC\n \n 2021-07-13 14:35:21 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 684\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:41:52',4,'2021-07-13 14:35:21',4,0,NULL,NULL,NULL,'b55997df-2560-4087-89ad-f80379b46dd4'),(685,'adult_arv_2h_1mnth','2h 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2h_1mnth\n 2h 1mnth\n \n 2020-06-05 12:43:08 UTC\n \n 2021-07-13 14:36:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 685\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:43:08',4,'2021-07-13 14:36:13',4,0,NULL,NULL,NULL,'4420cacb-9f9e-46ca-b86d-6d03e30a6f3e'),(686,'adult_arv_2j_1mnth','2j 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2j_1mnth\n 2j 1mnth\n \n 2020-06-05 12:44:01 UTC\n \n 2021-07-13 14:37:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 686\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:44:01',4,'2021-07-13 14:37:45',4,0,NULL,NULL,NULL,'e0941c5d-4a20-400b-a0db-862be83470e1'),(687,'adult_arv_2k_1mnth','2k 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2k_1mnth\n 2k 1mnth\n \n 2020-06-05 12:45:06 UTC\n \n 2021-07-13 14:39:23 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 687\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:45:06',4,'2021-07-13 14:39:23',4,0,NULL,NULL,NULL,'171a878c-c036-4486-a58d-798bc80c7447'),(688,'adult_arv_2l_1mnth','2l 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2l_1mnth\n 2l 1mnth\n \n 2020-06-05 12:46:11 UTC\n \n 2021-07-13 14:39:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 688\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:46:11',4,'2021-07-13 14:39:38',4,0,NULL,NULL,NULL,'ae5dd3df-007d-4ef2-bcdb-0ef68ff8bc7a'),(689,'adult_arv_2m_1mnth','2m 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2m_1mnth\n 2m 1mnth\n \n 2020-06-05 12:47:05 UTC\n \n 2021-07-13 14:41:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 689\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:47:05',4,'2021-07-13 14:41:45',4,0,NULL,NULL,NULL,'041a095c-5497-447e-9387-97b4d34df6ab'),(690,'adult_arv_2n_1mnth','2n 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2n_1mnth\n 2n 1mnth\n \n 2020-06-05 12:48:07 UTC\n \n 2021-07-13 14:41:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 690\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:48:07',4,'2021-07-13 14:41:59',4,0,NULL,NULL,NULL,'d64e6398-89a2-4612-985f-dc20dafa92b5'),(691,'adult_arv_2o_1mnth','2o 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2o_1mnth\n 2o 1mnth\n \n 2020-06-05 12:49:21 UTC\n \n 2021-07-13 14:45:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 691\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:49:21',4,'2021-07-13 14:45:11',4,0,NULL,NULL,NULL,'e5455427-d2fd-4398-88d8-372654f69bf7'),(692,'adult_arv_2p_1mnth','2p 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2p_1mnth\n 2p 1mnth\n \n 2020-06-05 12:50:20 UTC\n \n 2021-07-13 14:44:58 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 692\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:50:20',4,'2021-07-13 14:44:58',4,0,NULL,NULL,NULL,'f299f60d-7b3b-471e-b575-684c94c9ee57'),(693,'adult_arv_2q_1mnth','2q 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2q_1mnth\n 2q 1mnth\n \n 2020-06-05 12:51:42 UTC\n \n 2021-07-13 14:48:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 693\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:51:42',4,'2021-07-13 14:48:08',4,0,NULL,NULL,NULL,'be23c602-cbb1-43ac-b3c8-4c508cc65d66'),(694,'adult_arv_2c_3mnth','2c 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2c_3mnth\n 2c 3mnths\n \n 2020-06-05 12:56:13 UTC\n \n 2021-07-12 09:53:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 694\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:56:13',4,'2021-07-12 09:53:59',4,0,NULL,NULL,NULL,'04215a53-92bb-448c-bc0c-bdf13968fc4a'),(695,'adult_arv_2d_3mnths','2d 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2d_3mnths\n 2d 3mnths\n \n 2020-06-05 12:57:46 UTC\n \n 2020-07-26 12:39:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 695\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 12:57:46',4,'2020-07-26 12:39:30',4,0,NULL,NULL,NULL,'c9657610-a606-46db-8f55-24ded88ddf65'),(696,'Stopped ART this month','stopped ART','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Stopped ART this month\n stopped ART\n \n 2020-06-05 12:59:50 UTC\n \n 2020-06-05 13:00:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 696\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n where (o.location_id =:location or parent_location =:location) \n AND o.voided = 0 \n and concept_id = 2300 \n AND obs_datetime between :startDate AND :endDate\n','2020-06-05 14:59:50',4,'2020-06-05 15:00:33',4,0,NULL,NULL,NULL,'90747232-9c64-460b-b297-556853c19d27'),(697,'adult_arv_2e_3mnths','2e 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2e_3mnths\n 2e 3mnths\n \n 2020-06-05 13:02:16 UTC\n \n 2020-07-26 12:41:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 697\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:02:16',4,'2020-07-26 12:41:25',4,0,NULL,NULL,NULL,'10f3e3f4-f73e-4d8d-8024-108020886525'),(698,'adult_arv_2f_3mnths','2f 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2f_3mnths\n 2f 3mnths\n \n 2020-06-05 13:04:23 UTC\n \n 2020-07-26 12:43:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 698\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:04:23',4,'2020-07-26 12:43:52',4,0,NULL,NULL,NULL,'c2d8398b-5983-4f3b-b03a-81ca63635377'),(699,'adult_arv_2g_3mnths','2g 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2g_3mnths\n 2g 3mnths\n \n 2020-06-05 13:08:33 UTC\n \n 2020-07-26 12:49:39 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 699\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:08:33',4,'2020-07-26 12:49:39',4,0,NULL,NULL,NULL,'6a63e39d-88e4-49f2-84d1-63b1a1f1118d'),(700,'adult_arv_2h_3mnths','2h 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2h_3mnths\n 2h 3mnths\n \n 2020-06-05 13:10:20 UTC\n \n 2020-07-26 12:48:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 700\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:10:20',4,'2020-07-26 12:48:18',4,0,NULL,NULL,NULL,'3e13b024-8c5e-4004-b6de-fa643e50b752'),(701,'adult_arv_2j_3mnths','2j 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2j_3mnths\n 2j 3mnths\n \n 2020-06-05 13:11:27 UTC\n \n 2020-07-26 12:51:05 UTC\n \n \n \n \n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 701\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:11:27',4,'2020-07-26 12:51:05',4,0,NULL,NULL,NULL,'1a3b524f-388a-4692-aadf-c2c5c9832870'),(702,'adult_arv_2k_3mnths','2k 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2k_3mnths\n 2k 3mnths\n \n 2020-06-05 13:13:02 UTC\n \n 2020-07-26 12:56:02 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 702\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:13:02',4,'2020-07-26 12:56:02',4,0,NULL,NULL,NULL,'462e353e-3349-4334-8547-4361d310dd1f'),(703,'adult_arv_2l_3mnths','2l 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2l_3mnths\n 2l 3mnths\n \n 2020-06-05 13:14:56 UTC\n \n 2020-07-26 12:58:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 703\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:14:56',4,'2020-07-26 12:58:05',4,0,NULL,NULL,NULL,'762a506b-5142-4d0b-9a34-7364511b3804'),(704,'4c=AZT-3TC-NVP','4c','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4c=AZT-3TC-NVP\n 4c\n \n 2020-06-05 13:15:30 UTC\n \n 2021-07-01 09:54:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 704\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:15:30',4,'2021-07-01 09:54:14',4,0,NULL,NULL,NULL,'2333dba3-e4ab-4c96-b28d-b8a55cde3d1d'),(705,'adult_arv_2m_3mnths','2m 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2m_3mnths\n 2m 3mnths\n \n 2020-06-05 13:15:54 UTC\n \n 2020-07-26 13:00:52 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 705\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:15:54',4,'2020-07-26 13:00:52',4,0,NULL,NULL,NULL,'e39e9c25-717b-4e07-9cf0-9f7f3abfc08e'),(706,'adult_arv_2n_3mnths','2n 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2n_3mnths\n 2n 3mnths\n \n 2020-06-05 13:17:12 UTC\n \n 2020-07-26 13:03:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 706\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:17:12',4,'2020-07-26 13:03:32',4,0,NULL,NULL,NULL,'ff9adb70-4a63-4b77-b3ec-d3425b98afa4'),(707,'4d=AZT-3TC-EFV','4D','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4d=AZT-3TC-EFV\n 4D\n \n 2020-06-05 13:17:34 UTC\n \n 2021-07-01 09:54:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 707\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:17:34',4,'2021-07-01 09:54:59',4,0,NULL,NULL,NULL,'2090f6ca-5e65-4d41-98e3-b70f29abc483'),(708,'4e=ABC-3TC-NVP','4E','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4e=ABC-3TC-NVP\n 4E\n \n 2020-06-05 13:19:26 UTC\n \n 2021-07-01 09:55:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 708\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:19:26',4,'2021-07-01 09:55:40',4,0,NULL,NULL,NULL,'ee076dba-cc07-4b13-bc62-4d0d32193e03'),(709,'adult_arv_2o_3mnths','2o 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2o_3mnths\n 2o 3mnths\n \n 2020-06-05 13:19:40 UTC\n \n 2020-07-26 13:06:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 709\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:19:40',4,'2020-07-26 13:06:34',4,0,NULL,NULL,NULL,'738cb550-b15d-453e-bb7d-defc4b362956'),(710,'adult_arv_2p_3mnths','2p 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2p_3mnths\n 2p 3mnths\n \n 2020-06-05 13:20:54 UTC\n \n 2020-07-26 13:09:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 710\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:20:54',4,'2020-07-26 13:09:53',4,0,NULL,NULL,NULL,'60662d72-cea5-4ad5-93b0-ce12922fc834'),(711,'adult_arv_2q_3mnths','2q 3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2q_3mnths\n 2q 3mnths\n \n 2020-06-05 13:22:02 UTC\n \n 2020-07-26 13:11:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 711\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:22:02',4,'2020-07-26 13:11:26',4,0,NULL,NULL,NULL,'9ea4bf50-06f1-4028-ab9f-d276a5ea38da'),(712,'4f=ABC-3TC-EFV','4F','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4f=ABC-3TC-EFV\n 4F\n \n 2020-06-05 13:22:28 UTC\n \n 2021-07-01 09:56:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 712\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:22:28',4,'2021-07-01 09:56:17',4,0,NULL,NULL,NULL,'eb90af68-e363-449b-810c-f1075ba677f0'),(713,'4g=AZT-3TC-LPV/r','4g','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4g=AZT-3TC-LPV/r\n 4g\n \n 2020-06-05 13:24:33 UTC\n \n 2021-07-01 09:57:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 713\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:24:33',4,'2021-07-01 09:57:45',4,0,NULL,NULL,NULL,'3da73ab3-5e2d-4416-adf8-69fda1030aff'),(714,'CI20a: Adult 3rd Line 1month supply 3a','3a 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI20a: Adult 3rd Line 1month supply 3a\n 3a 1mnth\n \n 2020-06-05 13:24:35 UTC\n \n 2021-07-13 15:19:02 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 714\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:24:35',4,'2021-07-13 15:19:02',4,0,NULL,NULL,NULL,'d5ac0964-e25b-4ac9-bde2-216933143835'),(715,'CI21a: Adult 3rd Line 1month supply 3b','3b 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI21a: Adult 3rd Line 1month supply 3b\n 3b 1mnth\n \n 2020-06-05 13:25:50 UTC\n \n 2021-07-13 15:20:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 715\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:25:50',4,'2021-07-13 15:20:07',4,0,NULL,NULL,NULL,'aecf3360-f578-4223-a2b9-8167716b3ded'),(716,'4h=ABC-3TC-LPV/r','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4h=ABC-3TC-LPV/r\n \n \n 2020-06-05 13:25:57 UTC\n \n 2021-07-01 10:01:31 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 716\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:25:57',4,'2021-07-01 10:01:31',4,0,NULL,NULL,NULL,'ae250ccd-298b-4520-868e-14f945a7cc19'),(717,'CI22a: Adult 3rd Line 1month supply 3c','3c 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI22a: Adult 3rd Line 1month supply 3c\n 3c 1mnth\n \n 2020-06-05 13:26:59 UTC\n \n 2021-07-13 15:20:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 717\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:26:59',4,'2021-07-13 15:20:22',4,0,NULL,NULL,NULL,'9e32a97e-1aec-4924-8e31-c2870428b351'),(718,'4j=TDF-3TC-DTG(TLD)','4J','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4j=TDF-3TC-DTG(TLD)\n 4J\n \n 2020-06-05 13:27:32 UTC\n \n 2021-07-01 10:02:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 718\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:27:32',4,'2021-07-01 10:02:22',4,0,NULL,NULL,NULL,'30e58b2b-51ad-45c4-ba54-dfa0ee46192f'),(719,'CI40a: Adult 3rd Line 1month supply 3d','3d 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI40a: Adult 3rd Line 1month supply 3d\n 3d 1mnth\n \n 2020-06-05 13:28:21 UTC\n \n 2021-07-13 15:23:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 719\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:28:21',4,'2021-07-13 15:23:54',4,0,NULL,NULL,NULL,'e96450ab-af66-468b-9fe6-59e6dc7039a1'),(720,'CI41a: Adult 3rd Line 1month supply 3e','3e 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI41a: Adult 3rd Line 1month supply 3e\n 3e 1mnth\n \n 2020-06-05 13:29:18 UTC\n \n 2021-07-13 15:24:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 720\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:29:18',4,'2021-07-13 15:24:08',4,0,NULL,NULL,NULL,'9b325a21-8147-4294-8de3-11fe91804147'),(721,'Clients newly initiated 4j','4j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 4j\n 4j\n \n 2020-06-05 13:30:13 UTC\n \n 2021-01-27 22:27:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 721\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4686 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 13:30:13',4,'2021-01-27 22:27:00',4,0,NULL,NULL,NULL,'98e00266-550e-4ac2-ad86-d1bfd1edad02'),(722,'CI42a: Adult 3rd Line 1month supply 3f','3f 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI42a: Adult 3rd Line 1month supply 3f\n 3f 1mnth\n \n 2020-06-05 13:30:30 UTC\n \n 2021-07-13 15:24:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 722\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:30:30',4,'2021-07-13 15:24:22',4,0,NULL,NULL,NULL,'0ec32115-a8ab-4989-8693-4a3b02a2f57f'),(723,'CI43a: Adult 3rd Line 1month supply 3g','3g 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI43a: Adult 3rd Line 1month supply 3g\n 3g 1mnth\n \n 2020-06-05 13:31:51 UTC\n \n 2021-07-13 15:25:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 723\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:31:51',4,'2021-07-13 15:25:40',4,0,NULL,NULL,NULL,'30f95dc0-e9d9-45e0-8780-13b386d0e1ed'),(724,'4k=ABC-3TC-DTG','4K','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4k=ABC-3TC-DTG\n 4K\n \n 2020-06-05 13:31:57 UTC\n \n 2021-07-01 10:03:27 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 724\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:31:57',4,'2021-07-01 10:03:27',4,0,NULL,NULL,NULL,'788332e7-cc9f-4abb-983a-9c85c218367e'),(725,'CI44a: Adult 3rd Line 1month supply 3h','3h 1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI44a: Adult 3rd Line 1month supply 3h\n 3h 1mnth\n \n 2020-06-05 13:32:56 UTC\n \n 2021-07-13 15:25:58 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 725\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:32:56',4,'2021-07-13 15:25:58',4,0,NULL,NULL,NULL,'18a4ba21-a27a-41a1-a3a1-407d94e3b6af'),(726,'4L=AZT-3TC-DTG','4L','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4L=AZT-3TC-DTG\n 4L\n \n 2020-06-05 13:33:21 UTC\n \n 2021-07-01 10:03:40 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 726\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:33:21',4,'2021-07-01 10:03:40',4,0,NULL,NULL,NULL,'9e98473d-8542-491f-ba7a-72eed5bb8cc9'),(727,'5a=AZT-3TC-LPV/r','5a','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5a=AZT-3TC-LPV/r\n 5a\n \n 2020-06-05 13:37:09 UTC\n \n 2021-07-01 10:04:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 727\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:37:09',4,'2021-07-01 10:04:56',4,0,NULL,NULL,NULL,'90e1122b-ae81-4c9a-85bd-4718d62e8555'),(728,'5b=ABC-3TC-LPV/r','5B','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5b=ABC-3TC-LPV/r\n 5B\n \n 2020-06-05 13:38:40 UTC\n \n 2021-07-01 10:05:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 728\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:38:40',4,'2021-07-01 10:05:12',4,0,NULL,NULL,NULL,'5724ff33-4897-408c-8c0f-bd4f492421cf'),(729,'5c=ABC-3TC-DRV/r','5C','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5c=ABC-3TC-DRV/r\n 5C\n \n 2020-06-05 13:41:08 UTC\n \n 2021-07-01 10:06:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 729\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:41:08',4,'2021-07-01 10:06:05',4,0,NULL,NULL,NULL,'fcba5f96-f8b0-4cee-a432-d8a812214c91'),(730,'5d=AZT-3TC-DRV/r','5D','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5d=AZT-3TC-DRV/r\n 5D\n \n 2020-06-05 13:43:45 UTC\n \n 2021-07-01 10:06:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 730\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:43:45',4,'2021-07-01 10:06:20',4,0,NULL,NULL,NULL,'c755ea49-186f-44fc-b6c6-9063230d3480'),(731,'5e=AZT-3TC-ABC','5e','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5e=AZT-3TC-ABC\n 5e\n \n 2020-06-05 13:44:53 UTC\n \n 2021-07-01 10:07:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 731\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:44:53',4,'2021-07-01 10:07:11',4,0,NULL,NULL,NULL,'19dddce8-40b7-4851-ae3a-c3a1cb14eb91'),(732,'5f=AZT-3TC-DTG','5f','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5f=AZT-3TC-DTG\n 5f\n \n 2020-06-05 13:47:24 UTC\n \n 2021-07-01 10:07:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 732\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:47:24',4,'2021-07-01 10:07:29',4,0,NULL,NULL,NULL,'949e2eab-7153-4142-b71a-59e1a1defede'),(733,'Clients newly initiated 5f','5f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 5f\n 5f\n \n 2020-06-05 13:48:37 UTC\n \n 2021-01-27 22:42:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 733\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4699 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-06-05 13:48:37',4,'2021-01-27 22:42:15',4,0,NULL,NULL,NULL,'c2568b3b-6226-4d7b-a190-b337501d1731'),(734,'5g=AZT-3TC-ATVr/','5G','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5g=AZT-3TC-ATVr/\n 5G\n \n 2020-06-05 13:50:29 UTC\n \n 2021-07-01 10:08:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 734\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:50:29',4,'2021-07-01 10:08:22',4,0,NULL,NULL,NULL,'286bc570-0ccd-48ff-862d-211475082a7a'),(735,'5h=ABC-3TC-ATV/r','5h','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 5h=ABC-3TC-ATV/r\n 5h\n \n 2020-06-05 13:52:03 UTC\n \n 2021-07-01 10:09:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 735\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:52:03',4,'2021-07-01 10:09:01',4,0,NULL,NULL,NULL,'8d6b09b2-2781-4559-bfc0-a3c5678536b4'),(736,'6a=RAL-ETV-LPV/r','6a','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6a=RAL-ETV-LPV/r\n 6a\n \n 2020-06-05 13:53:49 UTC\n \n 2021-07-01 10:09:36 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 736\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:53:49',4,'2021-07-01 10:09:36',4,0,NULL,NULL,NULL,'23792b6c-5b46-4a98-9fe6-1d26d4f91e9e'),(737,'6b=RAL-ETV-DRV/r','6b','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6b=RAL-ETV-DRV/r\n 6b\n \n 2020-06-05 13:55:09 UTC\n \n 2021-07-01 10:09:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 737\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:55:09',4,'2021-07-01 10:09:59',4,0,NULL,NULL,NULL,'5449106c-244d-4d19-ad83-bba3f01589e7'),(738,'6c=RAL+ETV+DRV/r','6C','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6c=RAL+ETV+DRV/r\n 6C\n \n 2020-06-05 13:57:19 UTC\n \n 2021-07-01 10:10:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 738\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:57:19',4,'2021-07-01 10:10:51',4,0,NULL,NULL,NULL,'aa99445e-54bd-4de8-9ef1-9a888fd68239'),(739,'6d=TDF-3TC-DRV/r+RAL','6D','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6d=TDF-3TC-DRV/r+RAL\n 6D\n \n 2020-06-05 13:59:01 UTC\n \n 2021-07-01 10:11:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 739\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 13:59:01',4,'2021-07-01 10:11:04',4,0,NULL,NULL,NULL,'367ded00-770e-478f-a366-2c5ca91c2567'),(740,'6e=RAL+DRV/r','6E','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6e=RAL+DRV/r\n 6E\n \n 2020-06-05 14:00:26 UTC\n \n 2021-07-01 10:12:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 740\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 14:00:26',4,'2021-07-01 10:12:05',4,0,NULL,NULL,NULL,'a8e0b35d-cf9a-4f1f-8995-c7a9e28b1103'),(741,'6f=AZT+3TC+DRV/r+ETV','6F','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 6f=AZT+3TC+DRV/r+ETV\n 6F\n \n 2020-06-05 14:02:22 UTC\n \n 2021-07-01 10:12:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 741\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 14:02:22',4,'2021-07-01 10:12:20',4,0,NULL,NULL,NULL,'0952cfb3-6f9b-4d27-b94b-4c25ba0c99e7'),(742,'Cotrimox Prophylaxis/Dapsone','CTX','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Cotrimox Prophylaxis/Dapsone\n CTX\n \n 2020-06-05 14:06:03 UTC\n \n 2020-06-05 14:06:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 742\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:06:03',4,'2020-06-05 16:06:48',4,0,NULL,NULL,NULL,'12dfb355-bf17-4ee3-a267-b047f38a89b8'),(743,'Missed or defaulted under 28days','missed appointments under 28 days','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Missed or defaulted under 28days\n missed appointments under 28 days\n \n 2020-06-05 14:06:51 UTC\n \n 2020-06-05 14:08:00 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 743\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:06:51',4,'2020-06-05 16:08:00',4,0,NULL,NULL,NULL,'26fb300b-c224-45ae-a82e-94786101c82d'),(744,'RUFT','Plumpy-nut','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n RUFT\n Plumpy-nut\n \n 2020-06-05 14:08:10 UTC\n \n 2020-06-05 14:09:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 744\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:08:10',4,'2020-06-05 16:09:03',4,0,NULL,NULL,NULL,'e72ff52c-b8c7-4728-bf7b-747e208b3e06'),(745,'Missed or defaulted between 29 and 89 days','Missed or defaulted between 29 and 89 days','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Missed or defaulted between 29 and 89 days\n Missed or defaulted between 29 and 89 days\n \n 2020-06-05 14:08:54 UTC\n \n 2020-06-05 14:09:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 745\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:08:54',4,'2020-06-05 16:09:29',4,0,NULL,NULL,NULL,'6ec03f54-c1f7-49b4-9332-c7c9aa994579'),(746,'Given F100 in the month','F100','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Given F100 in the month\n F100\n \n 2020-06-05 14:09:44 UTC\n \n 2020-06-05 14:10:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 746\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:09:44',4,'2020-06-05 16:10:29',4,0,NULL,NULL,NULL,'052f159f-57d1-4597-94ae-d81c0876610d'),(747,'Given F75 in the month','F75','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Given F75 in the month\n F75\n \n 2020-06-05 14:10:52 UTC\n \n 2020-06-05 14:12:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 747\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:10:52',4,'2020-06-05 16:12:03',4,0,NULL,NULL,NULL,'a63995e1-38a2-4c49-8189-7e2eff852513'),(748,'Other Nutritional Supplement given in the month','other','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Other Nutritional Supplement given in the month\n other\n \n 2020-06-05 14:12:35 UTC\n \n 2020-06-05 14:13:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 748\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 16:12:35',4,'2020-06-05 16:13:16',4,0,NULL,NULL,NULL,'092667a0-a0a3-4f6e-b25d-963a76c74814'),(750,'Children ARV Regimen Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children ARV Regimen Data Set\n \n 2020-06-05 14:19:22 UTC\n \n 2020-06-05 16:09:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 750\n \n \n DM_Weight\n \n \n \n \n \n \n \n \n 4L03to3.9\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Weight\n 03to3.9kg\n \n \n \n \n \n 4L10to13.9\n \n \n \n \n DM_Weight\n 10to13.9kg\n \n \n \n \n \n 4L14to19.9\n \n \n \n \n DM_Weight\n 14to19.9kg\n \n \n \n \n \n 4L20to24.9\n \n \n \n \n DM_Weight\n 20to24.9kg\n \n \n \n \n \n 4L25to34.9\n \n \n \n \n DM_Weight\n 25to34.9kg\n \n \n \n \n \n 4L4to5.9\n \n \n \n \n DM_Weight\n 04to5.9kg\n \n \n \n \n \n 4L6to9.9\n \n \n \n \n DM_Weight\n 06to9.9kg\n \n \n \n \n \n 4c03to3.9\n \n \n \n \n \n \n \n \n \n 4c10to13.9\n \n \n \n \n \n \n 4c14to19.9\n \n \n \n \n \n \n 4c20to24.9\n \n \n \n \n \n \n 4c25to34.9\n \n \n \n \n \n \n 4c4to5.9\n \n \n \n \n \n \n 4c6to9.9\n \n \n \n \n \n \n 4d0.3to3.9\n \n \n \n \n \n \n \n \n \n 4d10to13.9\n \n \n \n \n \n \n 4d14to19.9\n \n \n \n \n \n \n 4d20to24.9\n \n \n \n \n \n \n 4d25to34.9\n \n \n \n \n \n \n 4d4to5.9\n \n \n \n \n \n \n 4d6to9.9\n \n \n \n \n \n \n 4e0.3to3.9\n \n \n \n \n \n \n \n \n \n 4e10to13.9\n \n \n \n \n \n \n 4e14to19.9\n \n \n \n \n \n \n 4e20to24.9\n \n \n \n \n \n \n 4e25to34.9\n \n \n \n \n \n \n 4e4to5.9\n \n \n \n \n \n \n 4e6to9.9\n \n \n \n \n \n \n 4f0.3to3.9\n \n \n \n \n \n \n \n \n \n 4f10to13.9\n \n \n \n \n \n \n 4f14to19.9\n \n \n \n \n \n \n 4f20to24.9\n \n \n \n \n \n \n 4f25to34.9\n \n \n \n \n \n \n 4f4to5.9\n \n \n \n \n \n \n 4f6to9.9\n \n \n \n \n \n \n 4g0.3to3.9\n \n \n \n \n \n \n \n \n \n 4g10to13.9\n \n \n \n \n \n \n 4g14to19.9\n \n \n \n \n \n \n 4g20to24.9\n \n \n \n \n \n \n 4g25to34.9\n \n \n \n \n \n \n 4g4to5.9\n \n \n \n \n \n \n 4g6to9.9\n \n \n \n \n \n \n 4h0.3to3.9\n \n \n \n \n \n \n \n \n \n 4h10to13.9\n \n \n \n \n \n \n 4h14to19.9\n \n \n \n \n \n \n 4h20to24.9\n \n \n \n \n \n \n 4h25to34.9\n \n \n \n \n \n \n 4h4to5.9\n \n \n \n \n \n \n 4h6to9.9\n \n \n \n \n \n \n 4j0.3to3.9\n \n \n \n \n \n \n \n \n \n 4j10to13.9\n \n \n \n \n \n \n 4j14to19.9\n \n \n \n \n \n \n 4j20to24.9\n \n \n \n \n \n \n 4j25to34.9\n \n \n \n \n \n \n 4j4to5.9\n \n \n \n \n \n \n 4j6to9.9\n \n \n \n \n \n \n 4k0.3to3.9\n \n \n \n \n \n \n \n \n \n 4k10to13.9\n \n \n \n \n \n \n 4k14to19.9\n \n \n \n \n \n \n 4k20to24.9\n \n \n \n \n \n \n 4k25to34.9\n \n \n \n \n \n \n 4k4to5.9\n \n \n \n \n \n \n 4k6to9.9\n \n \n \n \n \n \n','2020-06-05 16:19:22',4,'2020-06-05 18:09:53',4,0,NULL,NULL,NULL,'86987ed4-9fb6-46c9-9376-124ca29b26cb'),(751,'Stopped ART this month','stopped this month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Stopped ART this month\n stopped this month\n \n 2020-06-05 15:34:17 UTC\n \n 2020-06-05 15:37:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 751\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-05 17:34:17',4,'2020-06-05 17:37:55',4,0,NULL,NULL,NULL,'3339dfc7-cd36-4231-b31e-5390963065ab'),(752,'2020_adult_arv_1stline_regimen','new dataset ADULT ARV REGIMEN AT THE END OF THE MONTH (15+)','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_adult_arv_1stline_regimen\n new dataset ADULT ARV REGIMEN AT THE END OF THE MONTH (15+)\n \n 2020-06-05 15:51:46 UTC\n \n 2020-07-26 09:11:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 752\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-06-05 15:51:46',4,'2020-07-26 09:11:25',4,0,NULL,NULL,NULL,'bf495055-881f-4d8f-a313-034368641292'),(753,'2020_ADULT ARV REGIMEN AT THE END OF THE MONTH (15+) Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_ADULT ARV REGIMEN AT THE END OF THE MONTH (15+) Data Set\n \n 2020-06-05 15:51:49 UTC\n \n 2021-01-27 14:00:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 753\n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n 1c_1mnth\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n 1c_3mnths\n \n \n \n \n \n \n \n \n \n 1c_6mnths\n \n \n \n \n \n \n \n \n \n 1c_other\n \n \n \n \n \n \n \n \n \n 1d_1mnth\n \n \n \n \n \n \n \n \n \n 1d_3mnths\n \n \n \n \n \n \n \n \n \n 1d_6mnths\n \n \n \n \n \n \n \n \n \n 1d_other\n \n \n \n \n \n \n \n \n \n 1e_1mnth\n \n \n \n \n \n \n \n \n \n 1e_3mnths\n \n \n \n \n \n \n \n \n \n 1e_6mnths\n \n \n \n \n \n \n \n \n \n 1e_other\n \n \n \n \n \n \n \n \n \n 1f_1mnth\n \n \n \n \n \n \n \n \n \n 1f_3mnths\n \n \n \n \n \n \n \n \n \n 1f_6mnths\n \n \n \n \n \n \n \n \n \n 1f_othmnth\n \n \n \n \n \n \n \n \n \n 1g_1mnth\n \n \n \n \n \n \n \n \n \n 1g_3mnths\n \n \n \n \n \n \n \n \n \n 1g_6mnths\n \n \n \n \n \n \n \n \n \n 1g_other\n \n \n \n \n \n \n \n \n \n 1h_1mnth\n \n \n \n \n \n \n \n \n \n 1h_3mnths\n \n \n \n \n \n \n \n \n \n 1h_6mnths\n \n \n \n \n \n \n \n \n \n 1h_other\n \n \n \n \n \n \n \n \n \n 1j_1mnth\n \n \n \n \n \n \n \n \n \n 1j_3mnths\n \n \n \n \n \n \n \n \n \n 1j_6mnths\n \n \n \n \n \n \n \n \n \n 1j_other\n \n \n \n \n \n \n \n \n \n 1k_1mnth\n \n \n \n \n \n \n \n \n \n 1k_3mnths\n \n \n \n \n \n \n \n \n \n 1k_6mnths\n \n \n \n \n \n \n \n \n \n 1k_other\n \n \n \n \n \n \n \n \n \n 1m_1mnth\n \n \n \n \n \n \n \n \n \n 1m_3mnths\n \n \n \n \n \n \n \n \n \n 1m_6mnths\n \n \n \n \n \n \n \n \n \n 1m_other\n \n \n \n \n \n \n \n \n \n 1n_1mnth\n \n \n \n \n \n \n \n \n \n 1n_3mnths\n \n \n \n \n \n \n \n \n \n 1n_6mnths\n \n \n \n \n \n \n \n \n \n 1n_other\n \n \n \n \n \n \n \n \n \n 1p_1mnth\n \n \n \n \n \n \n \n \n \n 1p_3mnths\n \n \n \n \n \n \n \n \n \n 1p_6mnths\n \n \n \n \n \n \n \n \n \n 1p_other\n \n \n \n \n \n \n \n \n \n 1q_1mnth\n \n \n \n \n \n \n \n \n \n 1q_3mnths\n \n \n \n \n \n \n \n \n \n 1q_6mnths\n \n \n \n \n \n \n \n \n \n 1q_other\n \n \n \n \n \n \n \n \n \n other_1mnt\n \n \n \n \n \n \n \n \n \n other_3mnt\n \n \n \n \n \n \n \n \n \n other_6mnt\n \n \n \n \n \n \n \n \n \n other_othe\n \n \n \n \n \n \n \n \n \n','2020-06-05 15:51:49',4,'2021-01-27 14:00:34',4,0,NULL,NULL,NULL,'48bdf3d1-3a1a-46b1-a53a-7db8f1a24781'),(755,'Children ARV Regimen_2ndLine Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children ARV Regimen_2ndLine Data Set\n \n 2020-06-06 16:40:08 UTC\n \n 2020-06-06 17:59:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 755\n \n \n DM_Weight\n \n \n \n \n \n \n \n \n 5a10to13.9\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Weight\n 10to13.9kg\n \n \n \n \n \n 5a14to19.9\n \n \n \n \n DM_Weight\n 14to19.9kg\n \n \n \n \n \n 5a20to24.9\n \n \n \n \n DM_Weight\n 20to24.9kg\n \n \n \n \n \n 5a25to34.9\n \n \n \n \n DM_Weight\n 25to34.9kg\n \n \n \n \n \n 5a3to3.9\n \n \n \n \n DM_Weight\n 03to3.9kg\n \n \n \n \n \n 5a4to5.9\n \n \n \n \n DM_Weight\n 04to5.9kg\n \n \n \n \n \n 5a6to9.9\n \n \n \n \n DM_Weight\n 06to9.9kg\n \n \n \n \n \n 5b10to13.9\n \n \n \n \n \n \n \n \n \n 5b14to19.9\n \n \n \n \n \n \n 5b20to24.9\n \n \n \n \n \n \n 5b25to34.9\n \n \n \n \n \n \n 5b3to3.9\n \n \n \n \n \n \n 5b4to5.9\n \n \n \n \n \n \n 5b6to9.9\n \n \n \n \n \n \n 5c10to13.9\n \n \n \n \n \n \n \n \n \n 5c14to19.9\n \n \n \n \n \n \n 5c20to24.9\n \n \n \n \n \n \n 5c25to34.9\n \n \n \n \n \n \n 5c3to3.9\n \n \n \n \n \n \n 5c4to5.9\n \n \n \n \n \n \n 5c6to9.9\n \n \n \n \n \n \n 5d10to13.9\n \n \n \n \n \n \n \n \n \n 5d14to19.9\n \n \n \n \n \n \n 5d20to24.9\n \n \n \n \n \n \n 5d25to34.9\n \n \n \n \n \n \n 5d3to3.9\n \n \n \n \n \n \n 5d4to5.9\n \n \n \n \n \n \n 5d6to9.9\n \n \n \n \n \n \n 5e10to13.9\n \n \n \n \n \n \n \n \n \n 5e14to19.9\n \n \n \n \n \n \n 5e20to24.9\n \n \n \n \n \n \n 5e25to34.9\n \n \n \n \n \n \n 5e3to3.9\n \n \n \n \n \n \n 5e4to5.9\n \n \n \n \n \n \n 5e6to9.9\n \n \n \n \n \n \n 5f10to13.9\n \n \n \n \n \n \n \n \n \n 5f14to19.9\n \n \n \n \n \n \n 5f20to24.9\n \n \n \n \n \n \n 5f25to34.9\n \n \n \n \n \n \n 5f3to3.9\n \n \n \n \n \n \n 5f4to5.9\n \n \n \n \n \n \n 5f6to9.9\n \n \n \n \n \n \n 5g10to13.9\n \n \n \n \n \n \n \n \n \n 5g14to19.9\n \n \n \n \n \n \n 5g20to24.9\n \n \n \n \n \n \n 5g25to34.9\n \n \n \n \n \n \n 5g3to3.9\n \n \n \n \n \n \n 5g4to5.9\n \n \n \n \n \n \n 5g6to9.9\n \n \n \n \n \n \n 5h10to13.9\n \n \n \n \n \n \n \n \n \n 5h14to19.9\n \n \n \n \n \n \n 5h20to24.9\n \n \n \n \n \n \n 5h25to34.9\n \n \n \n \n \n \n 5h3to3.9\n \n \n \n \n \n \n 5h4to5.9\n \n \n \n \n \n \n 5h6to9.9\n \n \n \n \n \n \n','2020-06-06 18:40:08',4,'2020-06-06 19:59:56',4,0,NULL,NULL,NULL,'b544b920-9355-4cde-91ef-1abce8a0666c'),(756,'Clients given CTX in the month','Clients given CTX in the month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given CTX in the month\n Clients given CTX in the month\n \n 2020-06-06 17:51:03 UTC\n \n 2020-06-06 17:52:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 756\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-06 19:51:03',4,'2020-06-06 19:52:29',4,0,NULL,NULL,NULL,'9227d423-f843-4299-866e-c0ef068a8faa'),(758,'Children ARV Regimen_3rdLine Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children ARV Regimen_3rdLine Data Set\n \n 2020-06-06 18:10:43 UTC\n \n 2020-06-08 08:32:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 758\n \n \n DM_Weight\n \n \n \n \n \n \n \n \n 6a10to13.9\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Weight\n 10to13.9kg\n \n \n \n \n \n 6a14to19.9\n \n \n \n \n DM_Weight\n 14to19.9kg\n \n \n \n \n \n 6a20to24.9\n \n \n \n \n DM_Weight\n 20to24.9kg\n \n \n \n \n \n 6a25to34.9\n \n \n \n \n DM_Weight\n 25to34.9kg\n \n \n \n \n \n 6a3to3.9\n \n \n \n \n DM_Weight\n 03to3.9kg\n \n \n \n \n \n 6a4to5.9\n \n \n \n \n DM_Weight\n 04to5.9kg\n \n \n \n \n \n 6a6to9.9\n \n \n \n \n DM_Weight\n 06to9.9kg\n \n \n \n \n \n 6b10to13.9\n \n \n \n \n \n \n \n \n \n 6b14to19.9\n \n \n \n \n \n \n 6b20to24.9\n \n \n \n \n \n \n 6b25to34.9\n \n \n \n \n \n \n 6b3to3.9\n \n \n \n \n \n \n 6b4to5.9\n \n \n \n \n \n \n 6b6to9.9\n \n \n \n \n \n \n 6c10to13.9\n \n \n \n \n \n \n \n \n \n 6c14to19.9\n \n \n \n \n \n \n 6c20to24.9\n \n \n \n \n \n \n 6c25to34.9\n \n \n \n \n \n \n 6c3to3.9\n \n \n \n \n \n \n 6c4to5.9\n \n \n \n \n \n \n 6c6to9.9\n \n \n \n \n \n \n 6d10to13.9\n \n \n \n \n \n \n \n \n \n 6d14to19.9\n \n \n \n \n \n \n 6d20to24.9\n \n \n \n \n \n \n 6d25to34.9\n \n \n \n \n \n \n 6d3to3.9\n \n \n \n \n \n \n 6d4to5.9\n \n \n \n \n \n \n 6d6to9.9\n \n \n \n \n \n \n 6e10to13.9\n \n \n \n \n \n \n \n \n \n 6e14to19.9\n \n \n \n \n \n \n 6e20to24.9\n \n \n \n \n \n \n 6e25to34.9\n \n \n \n \n \n \n 6e3to3.9\n \n \n \n \n \n \n 6e4to5.9\n \n \n \n \n \n \n 6e6to9.9\n \n \n \n \n \n \n 6f10to13.9\n \n \n \n \n \n \n \n \n \n 6f14to19.9\n \n \n \n \n \n \n 6f20to24.9\n \n \n \n \n \n \n 6f25to34.9\n \n \n \n \n \n \n 6f3to3.9\n \n \n \n \n \n \n 6f4to5.9\n \n \n \n \n \n \n 6f6to9.9\n \n \n \n \n \n \n','2020-06-06 20:10:43',4,'2020-06-08 10:32:22',4,0,NULL,NULL,NULL,'6e3a006d-98ce-4042-9850-7ba6ccfadebe'),(759,'2020_NUTRITIONAL SUPPLEMENT','new dataset NUTRITIONAL SUPPLEMENT','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_NUTRITIONAL SUPPLEMENT\n new dataset NUTRITIONAL SUPPLEMENT\n \n 2020-06-06 18:19:59 UTC\n \n 2020-06-06 18:20:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 759\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-06-06 20:19:59',4,'2020-06-06 20:20:03',4,0,NULL,NULL,NULL,'bb75a854-ddeb-4ce5-b822-f76dd8bf22ad'),(760,'2020_NUTRITIONAL SUPPLEMENT Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_NUTRITIONAL SUPPLEMENT Data Set\n \n 2020-06-06 18:20:03 UTC\n \n 2020-06-08 10:00:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 760\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n F100FAdult\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Adults\n \n \n \n \n \n F100FChild\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n F100MAdult\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Adults\n \n \n \n \n \n F100MChild\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n F75FAdult\n \n \n \n \n \n \n \n \n \n F75FChild\n \n \n \n \n \n \n F75MAdult\n \n \n \n \n \n \n F75MChild\n \n \n \n \n \n \n OtherFAdul\n \n \n \n \n \n \n \n \n \n OtherFChil\n \n \n \n \n \n \n OtherMAdul\n \n \n \n \n \n \n OtherMChil\n \n \n \n \n \n \n PlumpFAdul\n \n \n \n \n \n \n \n \n \n PlumpFChil\n \n \n \n \n \n \n PlumpMAdul\n \n \n \n \n \n \n PlumpMChil\n \n \n \n \n \n \n cereal-F14\n \n \n \n \n \n \n \n \n \n cereal_F15\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n cereal-M14\n \n \n \n \n \n \n cereal_M15\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n','2020-06-06 20:20:03',4,'2020-06-08 12:00:54',4,0,NULL,NULL,NULL,'acc0e9d9-fe35-4d6d-8707-818221deeaa9'),(761,'Plumpy Nut given in the month','Plumpy Nut given in the month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Plumpy Nut given in the month\n Plumpy Nut given in the month\n \n 2020-06-06 18:30:00 UTC\n \n 2020-06-06 18:30:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 761\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-06 20:30:00',4,'2020-06-06 20:30:55',4,0,NULL,NULL,NULL,'1a8809c1-0866-4b11-8ed9-2ca4fc02154e'),(762,'F100 given in the month','F100 given in the month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n F100 given in the month\n F100 given in the month\n \n 2020-06-06 18:32:13 UTC\n \n 2020-06-06 18:33:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 762\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-06 20:32:13',4,'2020-06-06 20:33:54',4,0,NULL,NULL,NULL,'5d68b260-ac27-417d-b075-27c258ed6e5d'),(763,'F75 given in the month','F75 given in the month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n F75 given in the month\n F75 given in the month\n \n 2020-06-06 18:34:41 UTC\n \n 2020-06-06 18:35:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 763\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-06 20:34:41',4,'2020-06-06 20:35:51',4,0,NULL,NULL,NULL,'f72d3c94-b272-489a-af95-c198ac632230'),(764,'Other Nutritional Supplement given in the month','Other Nutritional Supplement given in the month','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Other Nutritional Supplement given in the month\n Other Nutritional Supplement given in the month\n \n 2020-06-06 18:37:18 UTC\n \n 2020-06-06 18:38:33 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 764\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-06 20:37:18',4,'2020-06-06 20:38:33',4,0,NULL,NULL,NULL,'49f802d9-a927-432f-9ecc-5320277583a1'),(765,'Given Super Cereal in the month','super cereal','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Given Super Cereal in the month\n super cereal\n \n 2020-06-08 09:14:51 UTC\n \n 2020-07-07 10:18:22 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 765\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand obs_datetime BETWEEN :startDate AND :endDate \nand concept_id = 4167 and value_coded = 4815\n','2020-06-08 09:14:51',4,'2020-07-07 10:18:22',4,0,NULL,NULL,NULL,'7e88e4d8-d827-49ba-85ce-942847494e02'),(766,'Given Super Cereal in the month','super cereal','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Given Super Cereal in the month\n super cereal\n \n 2020-06-08 09:16:05 UTC\n \n 2020-06-08 09:16:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 766\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-06-08 11:16:05',4,'2020-06-08 11:16:54',4,0,NULL,NULL,NULL,'7873e38f-7b02-46fc-8002-a0e6fcc7bde8'),(768,'testing Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n testing Data Set\n \n 2020-06-16 09:29:58 UTC\n \n 2020-06-16 09:35:38 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 768\n \n \n DM_Weight\n \n \n \n \n \n \n \n \n 1\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Weight\n 03to3.9kg\n \n \n \n \n \n 2\n \n \n \n \n DM_Weight\n 06to9.9kg\n \n \n \n \n \n 3\n \n \n \n \n DM_Weight\n 10to13.9kg\n \n \n \n \n \n 4\n \n \n \n \n DM_Weight\n 14to19.9kg\n \n \n \n \n \n 5\n \n \n \n \n DM_Weight\n 20to24.9kg\n \n \n \n \n \n 6\n \n \n \n \n DM_Weight\n 25to34.9kg\n \n \n \n \n \n','2020-06-16 09:29:58',4,'2020-06-16 09:35:38',4,0,NULL,NULL,NULL,'bf5ad6aa-84e3-4553-8feb-3c3f5a6b7270'),(769,'Clients enrolled this month','Clients enrolled this month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients enrolled this month\n Clients enrolled this month\n \n 2020-06-19 08:31:52 UTC\n \n 2022-04-26 14:50:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 769\n select distinct o.person_id \n from obs o \n inner join location l on o.location_id = l.location_id \n -- Retesting Results Pos \n INNER JOIN person ON person.person_id = o.person_id \n where o.concept_id = 4817 and o.value_coded = 1738 \n AND o.voided = 0 \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.person_id in( \n select distinct os.person_id \n from obs os \n -- Not Linked to Care \n where os.concept_id = 4239 and os.value_coded = 2147 \n and os.voided = 0 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n )\n','2020-06-19 08:31:52',4,'2022-04-26 14:50:16',4,0,NULL,NULL,NULL,'7037562b-4e82-493e-8858-78e0d5d8fbbf'),(770,'Clients ever enrolled on PrE ART','Clients ever enrolled on care','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients ever enrolled on PrE ART\n Clients ever enrolled on care\n \n 2020-06-19 08:35:31 UTC\n \n 2022-04-27 09:49:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 770\n select distinct o.person_id \n from obs o \n inner join location l on o.location_id = l.location_id \n -- Retesting Results Positive \n INNER JOIN person ON person.person_id = o.person_id \n where o.concept_id = 4817 and o.value_coded = 1738 \n AND o.voided = 0 \n AND o.person_id in( \n select distinct os.person_id \n from obs os \n -- Not Linked to Care \n where os.concept_id = 4239 and os.value_coded = 2147 \n and os.voided = 0 \n ) \n AND o.person_id not in ( \n -- Current period Pre-ART \n select distinct o.person_id \n from obs o \n inner join location l on o.location_id = l.location_id \n -- Retesting Results Pos \n INNER JOIN person ON person.person_id = o.person_id \n where o.concept_id = 4817 and o.value_coded = 1738 \n AND o.voided = 0 \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.person_id in( \n select distinct os.person_id \n from obs os \n -- Not Linked to Care \n where os.concept_id = 4239 and os.value_coded = 2147 \n and os.voided = 0 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n \n )\n','2020-06-19 08:35:31',4,'2022-04-27 09:49:54',4,0,NULL,NULL,NULL,'ca1c2a0a-48f5-4370-b46a-2678e49bc163'),(771,'ART and Pre ART Seen this month','ART and Pre ART Seen this month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART and Pre ART Seen this month\n ART and Pre ART Seen this month\n \n 2020-06-19 08:43:33 UTC\n \n 2022-07-25 14:49:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 771\n select distinct person_id \nfrom \n((select distinct o.person_id \nfrom obs o \n-- CLIENTS PHYSICALLY SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id AND person.voided = 0 \n WHERE o.concept_id = 3843 AND o.value_coded = 3842 \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n ) \n \nUNION \n \n( \n-- PreART \nselect distinct o.person_id \n from obs o \n inner join location l on o.location_id = l.location_id \n -- Retesting Results Pos \n INNER JOIN person ON person.person_id = o.person_id \n where o.concept_id = 4817 and o.value_coded = 1738 \n AND o.voided = 0 \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.person_id in( \n select distinct os.person_id \n from obs os \n -- Not Linked to Care \n where os.concept_id = 4239 and os.value_coded = 2147 \n and os.voided = 0 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n))AS Seen_and_PreART\n','2020-06-19 08:43:33',4,'2022-07-25 14:49:01',4,0,NULL,NULL,NULL,'05ced471-b115-479a-976c-318595d37af4'),(772,'ART and Pre ART Screened this month','screened','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ART and Pre ART Screened this month\n screened\n \n 2020-06-19 09:06:15 UTC\n \n 2022-07-25 15:24:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 772\n select distinct id \nfrom \n( \n(select distinct o.person_id as id \nfrom obs o \n-- CLIENTS PHYSICALLY SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id AND person.voided = 0 \n WHERE o.concept_id = 3843 AND o.value_coded = 3842 \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n AND (o.location_id =:location or parent_location =:location) \n AND o.person_id in ( \n -- TB Screening \n select distinct os.person_id from obs os \n where os.concept_id = 3710 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND os.voided = 0 \n ) \n) \n \nUNION \n \n(select HTS_TB_Screening.person_id \nfrom \n(select B.person_id \n from obs B \n inner join location l on B.location_id = l.location_id \n INNER JOIN person ON person.person_id = B.person_id AND person.voided = 0 \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n -- HTS Form \n from obs where concept_id = 2386 \n and obs_datetime <= cast(:endDate as date) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND voided = 0 \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n -- TB Screening \n where concept_id = 2294 and value_coded = 2146 \n and A.observation_id = B.obs_group_id \n and B.voided = 0 \n group by B.person_id) as HTS_TB_Screening \n inner join \n -- and A.person_id in ( \n ( \n -- PREART Clients \n select distinct o.person_id \n from obs o \n inner join location l on o.location_id = l.location_id \n -- Retesting Results Pos \n INNER JOIN person ON person.person_id = o.person_id \n where o.concept_id = 4817 and o.value_coded = 1738 \n AND o.voided = 0 \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.person_id in( \n select distinct os.person_id \n from obs os \n -- Not Linked to Care \n where os.concept_id = 4239 and os.value_coded = 2147 \n and os.voided = 0 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n ) Pre_ART \n on HTS_TB_Screening.person_id = Pre_ART.person_id \n ))TB_Screening_ART_and_PreART\n','2020-06-19 09:06:15',4,'2022-07-25 15:24:46',4,0,NULL,NULL,NULL,'71bce2a2-eb67-4815-b88a-27b4cd6c99ba'),(773,'Presumptive TB cases this month','Presumptive TB cases this month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Presumptive TB cases this month\n Presumptive TB cases this month\n \n 2020-06-19 09:10:24 UTC\n \n 2020-06-19 09:11:43 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 773\n select distinct o.person_id \nfrom obs o \n-- CLIENTS SEEN FOR ART \n inner join location l on o.location_id = l.location_id \n AND o.concept_id = 3843 AND o.value_coded in (3841,3842) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n INNER JOIN person ON person.person_id = o.person_id AND person.voided = 0 \n WHERE (o.location_id =:location or parent_location =:location) \nand o.person_id in ( \n select person_id from obs \n where concept_id = 2223 \n ) \n \nand o.person_id in ( \n select person_id from obs \n where concept_id = 3710 and value_coded = 1876 \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n )\n','2020-06-19 09:10:24',4,'2020-06-19 09:11:43',4,0,NULL,NULL,NULL,'8a81c8cf-900c-4465-a136-5aba898d64d4'),(774,'Presumptive TB cases diagnosed with TB','diagnosed with TB','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Presumptive TB cases diagnosed with TB\n diagnosed with TB\n \n 2020-06-23 09:51:11 UTC\n \n 2020-06-23 09:54:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 774\n select person_id from obs \n -- genexpert \n where concept_id = 3787 and value_coded in (3816,3817) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n -- line probe \n UNION \n select person_id from obs \n where concept_id = 3805 and value_coded in (1738) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n UNION \n -- phenotypic \n select person_id from obs \n where concept_id = 3840 and value_coded in (3837,3838,3839) \n AND MONTH(obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(obs_datetime) = YEAR(CAST(:endDate AS DATE))\n','2020-06-23 09:51:11',4,'2020-06-23 09:54:51',4,0,NULL,NULL,NULL,'4d3236b4-cfb1-47cd-b616-9378de1a8d70'),(775,'Diagnosed with TB and started treatment this month','started TB this month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Diagnosed with TB and started treatment this month\n started TB this month\n \n 2020-06-23 09:58:58 UTC\n \n 2020-06-23 09:59:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 775\n select person_id from obs \nwhere concept_id = 2237 \nAND MONTH(value_datetime) = MONTH(CAST(:endDate AS DATE)) \nAND YEAR(value_datetime) = YEAR(CAST(:endDate AS DATE))\n','2020-06-23 09:58:58',4,'2020-06-23 09:59:24',4,0,NULL,NULL,NULL,'59423bc1-bdc8-467a-ad52-32e51434cfc9'),(776,'client_arv_1f','Clients given 1f regimen during reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n client_arv_1f\n Clients given 1f regimen during reporting period\n \n 2020-07-18 19:58:37 UTC\n \n','2020-07-18 19:58:37',4,NULL,NULL,0,NULL,NULL,NULL,'134439b8-8727-4186-a4d1-07d8eb8df1ec'),(777,'ARV Regimen 1f TDF-3TC-EFV SQL','Clients given 1f regimen during reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n ARV Regimen 1f TDF-3TC-EFV SQL\n Clients given 1f regimen during reporting period\n \n 2020-07-18 19:58:37 UTC\n \n 2020-07-19 01:56:13 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 777\n select o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere o.concept_id = 2250 and o.value_coded = 2207 \n and o.location_id =:location or parent_location =:location \n and o.obs_datetime between :startDate and :endDate \n and o.voided = 0 \n and o.person_id in ( \n select oss.person_id \n from obs oss \n where oss.obs_datetime BETWEEN :startDate AND :endDate \n and oss.concept_id = 4174 and oss.value_coded in (4175, 4243) \n )\n','2020-07-18 19:58:37',4,'2020-07-19 01:56:13',4,0,NULL,NULL,NULL,'48b7c7f2-0b24-4fcb-936a-3161ccb96809'),(778,'Clients Initiated SQL','Client who were newly initiated on ART during period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients Initiated SQL\n Client who were newly initiated on ART during period\n \n 2020-07-18 20:31:33 UTC\n \n 2020-07-18 20:39:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 778\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere o.concept_id = 2249 \n and date(o.value_datetime) between cast(:startDate as date) and cast(:endDate as date) \n and o.location_id = :location or parent_location = :location \n and o.voided = 0 \n and o.person_id not in ( \n select os.person_id from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n and os.obs_datetime between cast(:startDate as date) and cast(:endDate as date) \n ) \n and o.person_id not in ( \n select person_id \n from person \n where death_date < cast(:endDate as date) \n and dead = 1 \n ) \n and o.person_id not in ( \n select os.person_id \n from obs os \n where os.concept_id = 4155 and os.value_coded = 2146 \n and os.obs_datetime between cast(:startDate as date) and cast(:endDate as date) \n )\n','2020-07-18 20:31:33',4,'2020-07-18 20:39:16',4,0,NULL,NULL,NULL,'58e7985e-69a0-4d49-846f-b9aff06675db'),(779,'CMP_ART Regimen 1month supply 1f','Active clients on ART given 1 month supply of 1f during the reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1f\n Active clients on ART given 1 month supply of 1f during the reporting period\n \n 2020-07-19 01:31:05 UTC\n \n 2020-07-19 04:00:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 779\n Clients-newly-initiated-1f OR Clients-seen-given-1-month-supply-1f\n \n \n Clients-newly-initiated-1f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-1f\n \n \n \n \n \n \n','2020-07-19 01:31:05',4,'2020-07-19 04:00:42',4,0,NULL,NULL,NULL,'1b85fc5a-285d-44ee-8d93-89823330461c'),(780,'CI07a: Adult 1st Line 1f=TDF-3TC-EFV 1month supply','Adults on 1st line 1f=TDF-3TC-EFV given 1month supply during the reporting period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI07a: Adult 1st Line 1f=TDF-3TC-EFV 1month supply\n Adults on 1st line 1f=TDF-3TC-EFV given 1month supply during the reporting period\n \n 2020-07-19 01:41:26 UTC\n \n 2021-07-13 10:53:55 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 780\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-19 01:41:26',4,'2021-07-13 10:53:55',4,0,NULL,NULL,NULL,'266432b4-af8d-4c1f-9964-0e18df6a8ddb'),(781,'Clients seen given 1 month supply 1f','Clients seen for ART given 1 month supply of 1f regimen during period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1f\n Clients seen for ART given 1 month supply of 1f regimen during period\n \n 2020-07-19 03:54:29 UTC\n \n 2021-07-08 14:08:48 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 781\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2207)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-19 03:54:29',4,'2021-07-08 14:08:48',4,0,NULL,NULL,NULL,'aa28ce0b-63fd-424e-a559-32afafdf1bd4'),(782,'Clients given 3 months supply 1f','Clients seen given 3 months supply and those seen in previous months given 3 months supply for the reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1f\n Clients seen given 3 months supply and those seen in previous months given 3 months supply for the reporting period\n \n 2020-07-19 04:12:20 UTC\n \n 2021-06-30 09:54:55 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 782\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2207)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-19 04:12:20',4,'2021-06-30 09:54:55',4,0,NULL,NULL,NULL,'08339268-81bc-4b91-860e-5fe9e69a96d9'),(783,'CMP_ART Regimen 3months supply 1f','Clients given 3 months supply of 1f regimen including Seen and Multi month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 3months supply 1f\n Clients given 3 months supply of 1f regimen including Seen and Multi month\n \n 2020-07-19 04:17:16 UTC\n \n 2020-07-19 04:18:45 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 783\n Clients-given-3-months-supply-1f\n \n \n Clients-given-3-months-supply-1f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-07-19 04:17:16',4,'2020-07-19 04:18:45',4,0,NULL,NULL,NULL,'3c34cfe7-e888-4dd5-8618-e0d0b3c0e7ec'),(784,'Clients given 6 months supply 1f','Clients seen given 6 months supply and those seen in previous months given 6 months supply for the reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1f\n Clients seen given 6 months supply and those seen in previous months given 6 months supply for the reporting period\n \n 2020-07-19 04:31:40 UTC\n \n 2021-06-30 11:12:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 784\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2207)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-19 04:31:40',4,'2021-06-30 11:12:29',4,0,NULL,NULL,NULL,'a96d7239-75fc-49da-8fc2-e5de7f363b3a'),(785,'Clients given Other months MMD supply 1f','Clients seen in current month given 2, 4, 5 or 7+ months supply and those seen in previous months given 2, 4, 5 or 7+ months supply for the reporting period','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1f\n Clients seen in current month given 2, 4, 5 or 7+ months supply and those seen in previous months given 2, 4, 5 or 7+ months supply for the reporting period\n \n 2020-07-19 04:43:12 UTC\n \n 2021-06-30 11:42:53 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 785\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2207)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-19 04:43:12',4,'2021-06-30 11:42:53',4,0,NULL,NULL,NULL,'769c1abe-1bbd-44ad-8151-48df3b0e7d28'),(786,'CMP_ART Regimen 6months supply 1f','Clients given 6 months supply of 1f regimen including Seen and Multi month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 6months supply 1f\n Clients given 6 months supply of 1f regimen including Seen and Multi month\n \n 2020-07-19 04:46:50 UTC\n \n 2020-07-19 04:48:17 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 786\n Clients-given-6-months-supply-1f\n \n \n Clients-given-6-months-supply-1f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-07-19 04:46:50',4,'2020-07-19 04:48:17',4,0,NULL,NULL,NULL,'18e58639-4cfd-40bf-bf06-3599464b1473'),(787,'CMP_ART Regimen Other months MMD supply 1f','Clients given 2, 4 or 5 months supply of 1f regimen including Seen and Multi month','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen Other months MMD supply 1f\n Clients given 2, 4 or 5 months supply of 1f regimen including Seen and Multi month\n \n 2020-07-19 04:49:08 UTC\n \n 2020-07-19 04:50:50 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 787\n Clients-given-Other-months-MMD-supply-1f\n \n \n Clients-given-Other-months-MMD-supply-1f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-07-19 04:49:08',4,'2020-07-19 04:50:50',4,0,NULL,NULL,NULL,'f95caefd-dc5f-4243-a75e-5e3e0b7911a0'); INSERT INTO `serialized_object` VALUES (788,'CI07b: Adult 1st Line 1f=TDF-3TC-EFV 3months supply','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI07b: Adult 1st Line 1f=TDF-3TC-EFV 3months supply\n \n \n 2020-07-19 06:18:10 UTC\n \n 2020-07-19 06:19:08 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 788\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-19 06:18:10',4,'2020-07-19 06:19:08',4,0,NULL,NULL,NULL,'780982cb-6a98-4775-8e76-9baa9d6b5f1b'),(789,'CI07c: Adult 1st Line 1f=TDF-3TC-EFV 6months supply','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI07c: Adult 1st Line 1f=TDF-3TC-EFV 6months supply\n \n \n 2020-07-19 06:20:27 UTC\n \n 2020-07-19 06:21:46 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 789\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-19 06:20:27',4,'2020-07-19 06:21:46',4,0,NULL,NULL,NULL,'e973976c-ca6a-4ac1-887a-2ebfe531a534'),(790,'CI07d: Adult 1st Line 1f=TDF-3TC-EFV Other (2, 4, 5 or 7+) MMD supply','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI07d: Adult 1st Line 1f=TDF-3TC-EFV Other (2, 4, 5 or 7+) MMD supply\n \n \n 2020-07-19 06:23:06 UTC\n \n 2020-07-21 01:48:17 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 790\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-19 06:23:06',4,'2020-07-21 01:48:17',4,0,NULL,NULL,NULL,'9ab8597a-486e-4d0f-ab75-7f113a29b08a'),(791,'Clients seen given 1 month supply 1c','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1c\n \n \n 2020-07-20 03:19:19 UTC\n \n 2021-07-08 11:55:18 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 791\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2201)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:19:19',4,'2021-07-08 11:55:18',4,0,NULL,NULL,NULL,'af67b7bb-850e-4d7e-b736-07ccf3a76b09'),(792,'Clients given 3 months supply 1c','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1c\n \n \n 2020-07-20 03:20:58 UTC\n \n 2021-06-30 09:51:24 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n endDateas\n \n java.util.Date\n true\n \n \n 792\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2201)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:20:58',4,'2021-06-30 09:51:24',4,0,NULL,NULL,NULL,'60b41494-8391-41e6-8f16-103bd95b4f44'),(793,'Clients given 6 months supply 1c','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1c\n \n \n 2020-07-20 03:22:31 UTC\n \n 2021-06-30 11:05:32 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 793\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2201)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:22:31',4,'2021-06-30 11:05:32',4,0,NULL,NULL,NULL,'41a29f67-1b66-4614-86fb-d1f9a7f97bfb'),(794,'Clients given Other months MMD supply 1c','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1c\n \n \n 2020-07-20 03:23:47 UTC\n \n 2021-06-30 11:37:55 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 794\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2201)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:23:47',4,'2021-06-30 11:37:55',4,0,NULL,NULL,NULL,'96c856a3-566e-4505-a448-160539293a28'),(795,'Clients seen given 1 month supply 1d','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1d\n \n \n 2020-07-20 03:37:30 UTC\n \n 2021-07-08 11:57:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 795\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2203)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:37:30',4,'2021-07-08 11:57:56',4,0,NULL,NULL,NULL,'98353f43-868f-4509-ad15-37dc3adb0a1b'),(796,'Clients given 3 months supply 1d','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1d\n \n \n 2020-07-20 03:39:17 UTC\n \n 2021-06-30 09:52:14 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 796\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2203)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:39:17',4,'2021-06-30 09:52:14',4,0,NULL,NULL,NULL,'069f81cf-1fa0-4367-83c8-0f3c20c42f85'),(797,'Clients given 6 months supply 1d','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1d\n \n \n 2020-07-20 03:40:12 UTC\n \n 2021-06-30 11:07:24 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 797\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2203)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:40:12',4,'2021-06-30 11:07:24',4,0,NULL,NULL,NULL,'ea10a065-3af9-4102-a59b-5be824284852'),(798,'Clients given Other months MMD supply 1d','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1d\n \n \n 2020-07-20 03:41:17 UTC\n \n 2021-06-30 11:41:47 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 798\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2203)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:41:17',4,'2021-06-30 11:41:47',4,0,NULL,NULL,NULL,'6c93540e-b083-41a9-9f17-a5ed6b921c72'),(799,'Clients seen given 1 month supply 1e','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1e\n \n \n 2020-07-20 03:46:44 UTC\n \n 2021-07-08 11:58:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 799\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2205)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:46:44',4,'2021-07-08 11:58:20',4,0,NULL,NULL,NULL,'c7dd5c81-99f1-45fc-a84d-ec75465bd3d4'),(800,'Clients given 3 months supply 1e','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1e\n \n \n 2020-07-20 03:47:32 UTC\n \n 2021-06-30 09:54:23 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 800\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2205)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:47:32',4,'2021-06-30 09:54:23',4,0,NULL,NULL,NULL,'e6b6c271-1dca-4432-bbaf-58d82c4f49da'),(801,'Clients given 6 months supply 1e','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1e\n \n \n 2020-07-20 03:48:37 UTC\n \n 2021-06-30 11:11:57 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 801\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2205)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:48:37',4,'2021-06-30 11:11:57',4,0,NULL,NULL,NULL,'354b0335-23b3-48cc-8a95-c417fafcfc89'),(802,'Clients given Other months MMD supply 1e','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1e\n \n \n 2020-07-20 03:49:41 UTC\n \n 2021-06-30 11:42:23 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 802\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2205)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:49:41',4,'2021-06-30 11:42:23',4,0,NULL,NULL,NULL,'e40f765b-16fd-4a32-b7a4-eede8841f1cf'),(803,'Clients seen given 1 month supply 1g','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1g\n \n \n 2020-07-20 03:58:38 UTC\n \n 2021-07-08 14:09:31 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 803\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3672)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 03:58:38',4,'2021-07-08 14:09:31',4,0,NULL,NULL,NULL,'b3d8a75c-e786-4f83-8938-8af473c5953b'),(804,'Clients given 3 months supply 1g','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1g\n \n \n 2020-07-20 04:00:16 UTC\n \n 2021-06-30 09:55:48 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 804\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3672)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:00:16',4,'2021-06-30 09:55:48',4,0,NULL,NULL,NULL,'ffc466dd-6ba0-4c8b-b843-200ea3d86bd2'),(805,'Clients given 6 months supply 1g','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1g\n \n \n 2020-07-20 04:01:31 UTC\n \n 2021-06-30 11:14:32 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 805\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3672)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:01:31',4,'2021-06-30 11:14:32',4,0,NULL,NULL,NULL,'9062d6f9-de1a-4bd5-875c-6357ab622d92'),(806,'Clients given Other months MMD supply 1g','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1g\n \n \n 2020-07-20 04:02:23 UTC\n \n 2021-06-30 11:43:38 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 806\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3672)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:02:23',4,'2021-06-30 11:43:38',4,0,NULL,NULL,NULL,'5e27d4a7-b843-4094-8f8e-c926f758e43a'),(807,'Clients seen given 1 month supply 1h','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1h\n \n \n 2020-07-20 04:10:22 UTC\n \n 2021-07-08 14:10:03 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 807\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3673)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:10:22',4,'2021-07-08 14:10:03',4,0,NULL,NULL,NULL,'fe4a76e1-27ff-4dd1-b1e0-41906972b346'),(808,'Clients given 6 months supply 1h','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1h\n \n \n 2020-07-20 04:12:36 UTC\n \n 2021-06-30 11:15:07 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 808\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3673)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:12:36',4,'2021-06-30 11:15:07',4,0,NULL,NULL,NULL,'04df1d42-9165-4fb9-bf72-5af4edeeb4b3'),(809,'Clients given 3 months supply 1h','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1h\n \n \n 2020-07-20 04:13:53 UTC\n \n 2021-06-30 09:56:18 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 809\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3673)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:13:53',4,'2021-06-30 09:56:18',4,0,NULL,NULL,NULL,'b790398e-94da-443c-a2e6-f0d5a40b54c0'),(810,'Clients given Other months MMD supply 1h','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1h\n \n \n 2020-07-20 04:17:17 UTC\n \n 2021-06-30 11:44:24 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 810\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3673)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:17:17',4,'2021-06-30 11:44:24',4,0,NULL,NULL,NULL,'d6cee7dc-26b3-47ee-9227-25aaf080d496'),(811,'Clients newly initiated 1j','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1j\n \n \n 2020-07-20 04:25:32 UTC\n \n 2021-01-27 14:42:09 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 811\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4678 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 04:25:32',4,'2021-01-27 14:42:09',4,0,NULL,NULL,NULL,'9beae5ae-2e70-4911-9e5c-8b8472e9e035'),(812,'Clients seen given 1 month supply 1j','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1j\n \n \n 2020-07-20 04:26:51 UTC\n \n 2021-07-08 11:06:54 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 812\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4678)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:26:51',4,'2021-07-08 11:06:54',4,0,NULL,NULL,NULL,'0be4efe7-801d-482d-ba8b-4d6b5fd33883'),(813,'Clients given 3 months supply 1j','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1j\n \n \n 2020-07-20 04:28:15 UTC\n \n 2021-06-30 09:56:52 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 813\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4678)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:28:15',4,'2021-06-30 09:56:52',4,0,NULL,NULL,NULL,'15fad161-116e-42b3-b0a2-7649bce5addc'),(814,'Clients given 6 months supply 1j','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1j\n \n \n 2020-07-20 04:29:15 UTC\n \n 2021-06-30 11:16:04 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 814\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4678)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:29:15',4,'2021-06-30 11:16:04',4,0,NULL,NULL,NULL,'23ae89c1-56ed-4bc5-9602-9d0d16b08c94'),(815,'Clients given Other months MMD supply 1j','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1j\n \n \n 2020-07-20 04:30:02 UTC\n \n 2021-06-30 11:45:21 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 815\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4678)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:30:02',4,'2021-06-30 11:45:21',4,0,NULL,NULL,NULL,'ef251548-179f-46cf-9207-2cb47e47dbbc'),(816,'Clients newly initiated 1k','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1k\n \n \n 2020-07-20 04:39:49 UTC\n \n 2021-01-27 14:43:48 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 816\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4679 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 04:39:49',4,'2021-01-27 14:43:48',4,0,NULL,NULL,NULL,'ffafa46e-8967-4ad9-9825-24337956bac5'),(817,'Clients seen given 1 month supply 1k','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1k\n \n \n 2020-07-20 04:40:45 UTC\n \n 2021-07-08 14:11:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 817\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4679)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:40:45',4,'2021-07-08 14:11:07',4,0,NULL,NULL,NULL,'7685302a-4622-4230-be73-76868feec142'),(818,'Clients given 3 months supply 1k','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1k\n \n \n 2020-07-20 04:42:09 UTC\n \n 2021-06-30 09:57:45 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 818\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4679)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:42:09',4,'2021-06-30 09:57:45',4,0,NULL,NULL,NULL,'196d200b-cd91-4bbd-acbb-4f016368cad8'),(819,'Clients given 6 months supply 1k','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1k\n \n \n 2020-07-20 04:43:10 UTC\n \n 2021-06-30 11:16:48 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 819\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4679)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:43:10',4,'2021-06-30 11:16:48',4,0,NULL,NULL,NULL,'3fc19342-46e1-45af-94b5-e2c691cb69e4'),(820,'Clients given Other months MMD supply 1k','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1k\n \n \n 2020-07-20 04:44:01 UTC\n \n 2021-06-30 11:46:02 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 820\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4679)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:44:01',4,'2021-06-30 11:46:02',4,0,NULL,NULL,NULL,'e6de45f1-6b8a-4436-ba97-b13059648def'),(821,'Clients newly initiated 1m','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1m\n \n \n 2020-07-20 04:49:48 UTC\n \n 2021-01-27 14:44:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 821\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4680 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 04:49:48',4,'2021-01-27 14:44:29',4,0,NULL,NULL,NULL,'400c82ab-1ac9-4abe-af01-6eada8daf6e9'),(822,'Clients seen given 1 month supply 1m','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1m\n \n \n 2020-07-20 04:50:41 UTC\n \n 2021-07-08 14:15:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 822\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4680)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:50:41',4,'2021-07-08 14:15:35',4,0,NULL,NULL,NULL,'9b8ae57c-2fef-42fd-bbad-b45c5e983226'),(823,'Clients given 3 months supply 1m','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1m\n \n \n 2020-07-20 04:52:21 UTC\n \n 2021-06-30 09:58:16 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 823\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4680)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:52:21',4,'2021-06-30 09:58:16',4,0,NULL,NULL,NULL,'7dd2938b-6b42-45d4-a2cd-8a8624e1c42c'),(824,'Clients given 6 months supply 1m','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1m\n \n \n 2020-07-20 04:52:59 UTC\n \n 2021-06-30 11:18:09 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 824\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4680)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:52:59',4,'2021-06-30 11:18:09',4,0,NULL,NULL,NULL,'bdd8854a-8e0d-4c16-8ccd-b2c0ac7e3fe7'),(825,'Clients given Other months MMD supply 1m','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1m\n \n \n 2020-07-20 04:54:54 UTC\n \n 2021-06-30 11:46:37 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 825\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4680)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 04:54:54',4,'2021-06-30 11:46:37',4,0,NULL,NULL,NULL,'4ecbaa81-3f7c-46e5-834f-ddb6439039fc'),(826,'Clients newly initiated 1n','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1n\n \n \n 2020-07-20 06:27:02 UTC\n \n 2021-01-27 14:47:42 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 826\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4681 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 06:27:02',4,'2021-01-27 14:47:42',4,0,NULL,NULL,NULL,'963f22d5-2068-4709-905b-3ec479ccde36'),(827,'Clients seen given 1 month supply 1n','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1n\n \n \n 2020-07-20 06:29:10 UTC\n \n 2021-07-08 14:16:16 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 827\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4681)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:29:10',4,'2021-07-08 14:16:16',4,0,NULL,NULL,NULL,'2f27d810-0b99-43bb-818a-ac56ed6cc563'),(828,'Clients given 3 months supply 1n','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1n\n \n \n 2020-07-20 06:30:01 UTC\n \n 2021-06-30 09:58:59 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 828\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4681)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:30:01',4,'2021-06-30 09:58:59',4,0,NULL,NULL,NULL,'16299f28-bb97-404c-992a-0ec5df3fd70e'),(829,'Clients given 6 months supply 1n','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1n\n \n \n 2020-07-20 06:31:04 UTC\n \n 2021-06-30 11:20:58 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 829\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4681)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:31:04',4,'2021-06-30 11:20:58',4,0,NULL,NULL,NULL,'6978b1ca-2787-45ea-8552-0085b4948fdc'),(830,'Clients given Other months MMD supply 1n','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1n\n \n \n 2020-07-20 06:31:57 UTC\n \n 2021-06-30 11:47:10 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 830\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4681)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:31:57',4,'2021-06-30 11:47:10',4,0,NULL,NULL,NULL,'db874a28-7767-4d91-8cd5-9e1dd5911ad6'),(831,'Clients newly initiated 1p','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1p\n \n \n 2020-07-20 06:35:57 UTC\n \n 2021-01-27 14:48:48 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 831\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4682 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 06:35:57',4,'2021-01-27 14:48:48',4,0,NULL,NULL,NULL,'1ad60b6d-87fa-4d43-a8a6-3018aedfcd66'),(832,'Clients seen given 1 month supply 1p','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1p\n \n \n 2020-07-20 06:36:55 UTC\n \n 2021-07-08 14:16:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 832\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4682)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:36:55',4,'2021-07-08 14:16:45',4,0,NULL,NULL,NULL,'173e906f-ba1c-43bb-9d48-f11d32ce0241'),(833,'Clients given 3 months supply 1p','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1p\n \n \n 2020-07-20 06:38:16 UTC\n \n 2021-06-30 09:59:46 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 833\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4682)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:38:16',4,'2021-06-30 09:59:46',4,0,NULL,NULL,NULL,'64c658a4-cc2a-46b6-8831-5549e6d3e893'),(834,'Clients given 6 months supply 1p','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1p\n \n \n 2020-07-20 06:39:07 UTC\n \n 2021-06-30 11:21:31 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 834\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4682)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:39:07',4,'2021-06-30 11:21:31',4,0,NULL,NULL,NULL,'753da82d-feaf-46d9-bcc5-f2b08f4bf1f7'),(835,'Clients given Other months MMD supply 1p','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1p\n \n \n 2020-07-20 06:39:59 UTC\n \n 2021-06-30 11:48:00 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 835\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4682)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:39:59',4,'2021-06-30 11:48:00',4,0,NULL,NULL,NULL,'0f780026-4b19-47c2-b88a-f103b85b8493'),(836,'Clients newly initiated 1q','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 1q\n \n \n 2020-07-20 06:43:42 UTC\n \n 2021-01-27 14:50:00 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 836\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4683 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 06:43:42',4,'2021-01-27 14:50:00',4,0,NULL,NULL,NULL,'45f73eeb-68d7-442a-85b1-a2a3e5eacf79'),(837,'Clients seen given 1 month supply 1q','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 1q\n \n \n 2020-07-20 06:44:27 UTC\n \n 2021-07-08 14:17:36 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 837\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4683)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:44:27',4,'2021-07-08 14:17:36',4,0,NULL,NULL,NULL,'16822ce4-ed25-45cf-93e1-9d4de906c4c6'),(838,'Clients given 3 months supply 1q','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 1q\n \n \n 2020-07-20 06:45:34 UTC\n \n 2021-06-30 10:00:22 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 838\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4683)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:45:34',4,'2021-06-30 10:00:22',4,0,NULL,NULL,NULL,'1ed9b3ff-13e6-49eb-a21b-a3c588489a1b'),(839,'Clients given 6 months supply 1q','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 1q\n \n \n 2020-07-20 06:46:18 UTC\n \n 2021-06-30 11:23:53 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 839\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4683)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 168 AND datediff(latest_follow_up, max_observation)< 196)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:46:18',4,'2021-06-30 11:23:53',4,0,NULL,NULL,NULL,'ebb33bdb-909b-4b87-a22e-b124d146291a'),(840,'Clients given Other months MMD supply 1q','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 1q\n \n \n 2020-07-20 06:47:11 UTC\n \n 2021-06-30 11:48:27 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 840\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4683)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 AND datediff(latest_follow_up, max_observation)< 140 \n OR datediff(latest_follow_up, max_observation) >= 140 AND datediff(latest_follow_up, max_observation)< 168 \n OR datediff(latest_follow_up, max_observation) >= 196 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:47:11',4,'2021-06-30 11:48:27',4,0,NULL,NULL,NULL,'ae410b11-acaa-425d-a309-7eb491cfa3eb'),(841,'Clients seen given 1 month supply 2c','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2c\n \n \n 2020-07-20 06:53:36 UTC\n \n 2021-07-13 14:12:15 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 841\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2210)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:53:36',4,'2021-07-13 14:12:15',4,0,NULL,NULL,NULL,'c1f9e099-143c-4dd2-bfe0-8946fc5d148e'),(842,'Clients given 3 months supply 2c','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2c\n \n \n 2020-07-20 06:54:57 UTC\n \n 2021-07-08 15:15:31 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 842\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2210)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:54:57',4,'2021-07-08 15:15:31',4,0,NULL,NULL,NULL,'eca79239-2660-4146-ab21-53161a156d97'),(843,'Clients given 6 months supply 2c','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2c\n \n \n 2020-07-20 06:55:39 UTC\n \n 2021-01-26 18:53:01 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 843\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 2210) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 2210) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 2210) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 2210) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 2210) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 2210) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 2210 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 06:55:39',4,'2021-01-26 18:53:01',4,0,NULL,NULL,NULL,'f408c2e1-4417-427b-ac7d-5bb0bce3656c'),(844,'Clients given Other months MMD supply 2c','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2c\n \n \n 2020-07-20 06:57:41 UTC\n \n 2021-07-24 21:30:54 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 844\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2210)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 06:57:41',4,'2021-07-24 21:30:54',4,0,NULL,NULL,NULL,'986a2393-6ee9-4072-ae1d-04fd7b892a0d'),(845,'Clients seen given 1 month supply 2d','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2d\n \n \n 2020-07-20 10:42:25 UTC\n \n 2021-07-13 14:14:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 845\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2209)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 10:42:25',4,'2021-07-13 14:14:04',4,0,NULL,NULL,NULL,'50d1da47-5c78-46f0-81dc-11c7eb0a2e60'),(846,'Clients given 3 months supply 2d','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2d\n \n \n 2020-07-20 10:43:36 UTC\n \n 2021-07-14 08:13:38 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 846\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2209)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 10:43:36',4,'2021-07-14 08:13:38',4,0,NULL,NULL,NULL,'2ab0d6c5-13ff-453d-98f2-c02b1eb59c41'),(847,'Clients given 6 months supply 2d','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2d\n \n \n 2020-07-20 10:44:21 UTC\n \n 2021-01-26 18:57:10 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 847\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 2209) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 2209) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 2209) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 2209) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 2209) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 2209) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 2209 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 10:44:21',4,'2021-01-26 18:57:10',4,0,NULL,NULL,NULL,'99f90724-28b7-45c7-a73d-63d4d8f88dc0'),(848,'Clients given Other months MMD supply 2d','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2d\n \n \n 2020-07-20 10:45:14 UTC\n \n 2021-07-24 21:31:27 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 848\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2209)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 10:45:14',4,'2021-07-24 21:31:27',4,0,NULL,NULL,NULL,'255083b1-80a9-41dd-8664-be91528a3d37'),(850,'Clients seen given 1 month supply 2e','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2e\n \n \n 2020-07-20 12:24:17 UTC\n \n 2021-07-13 14:15:00 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 850\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3674)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 12:24:17',4,'2021-07-13 14:15:00',4,0,NULL,NULL,NULL,'226382c4-5c57-442d-ac94-dad96849df3b'),(851,'Clients given 3 months supply 2e','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2e\n \n \n 2020-07-20 12:52:35 UTC\n \n 2021-07-14 08:14:33 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 851\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3674)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 12:52:35',4,'2021-07-14 08:14:33',4,0,NULL,NULL,NULL,'69f7f4ee-f01a-433e-a758-8f616a3ff039'),(852,'Clients given 6 months supply 2e','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2e\n \n \n 2020-07-20 12:54:03 UTC\n \n 2021-01-26 18:59:19 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 852\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3674) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 3674) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3674) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3674) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3674) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3674) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 3674 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 12:54:03',4,'2021-01-26 18:59:19',4,0,NULL,NULL,NULL,'cb6971ec-8888-4435-ae57-a6179afcdcb4'),(853,'Clients given Other months MMD supply 2e','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2e\n \n \n 2020-07-20 12:54:40 UTC\n \n 2021-07-24 21:32:50 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 853\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3674)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 12:54:40',4,'2021-07-24 21:32:50',4,0,NULL,NULL,NULL,'204bc8e1-d480-469b-8e87-eeaf1842258b'),(854,'Clients seen given 1 month supply 2f','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2f\n \n \n 2020-07-20 13:01:49 UTC\n \n 2021-07-13 14:15:59 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 854\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3675)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 13:01:49',4,'2021-07-13 14:15:59',4,0,NULL,NULL,NULL,'c7c374df-995a-4c8e-b417-e9c71cd3798d'),(855,'Clients given 3 months supply 2f','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2f\n \n \n 2020-07-20 13:02:35 UTC\n \n 2021-07-14 08:15:05 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 855\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3675)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 13:02:35',4,'2021-07-14 08:15:05',4,0,NULL,NULL,NULL,'15ced29c-f6a5-4742-beca-0f6367a97bca'),(856,'Clients given 6 months supply 2f','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2f\n \n \n 2020-07-20 13:03:51 UTC\n \n 2021-01-26 19:00:50 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 856\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3675) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 3675) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3675) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3675) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3675) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3675) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 3675 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 13:03:51',4,'2021-01-26 19:00:50',4,0,NULL,NULL,NULL,'565bb065-69d1-4c09-9381-78b51e2f53bc'),(858,'Clients given Other months MMD supply 2f','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2f\n \n \n 2020-07-20 13:07:55 UTC\n \n 2021-07-24 21:33:24 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 858\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3675)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 13:07:55',4,'2021-07-24 21:33:24',4,0,NULL,NULL,NULL,'c2aaab49-9a28-4ac1-a9e7-58f87bcb3c00'); INSERT INTO `serialized_object` VALUES (859,'Clients seen given 1 month supply 2g','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2g\n \n \n 2020-07-20 13:30:40 UTC\n \n 2021-07-13 14:16:33 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 859\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3676)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 13:30:40',4,'2021-07-13 14:16:33',4,0,NULL,NULL,NULL,'e09c5f28-85e5-4df9-970d-4e771a0a12fa'),(860,'Clients given 3 months supply 2g','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2g\n \n \n 2020-07-20 13:31:29 UTC\n \n 2021-07-14 08:15:34 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 860\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3676)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 13:31:29',4,'2021-07-14 08:15:34',4,0,NULL,NULL,NULL,'7a0140a1-1dac-4d2c-b23b-54bdbcdc3cfd'),(861,'Clients given 6 months supply 2g','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2g\n \n \n 2020-07-20 13:32:15 UTC\n \n 2021-01-26 19:02:43 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 861\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3676) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 3676) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3676) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3676) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3676) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3676) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 3676 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 13:32:15',4,'2021-01-26 19:02:43',4,0,NULL,NULL,NULL,'563531db-dcac-42ed-aed1-6942a8d6adf0'),(862,'Clients given Other months MMD supply 2g','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2g\n \n \n 2020-07-20 13:34:03 UTC\n \n 2021-07-24 21:33:49 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 862\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3676)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 13:34:03',4,'2021-07-24 21:33:49',4,0,NULL,NULL,NULL,'f4085fa1-d19d-4654-ab8a-5030eed896a7'),(863,'Clients seen given 1 month supply 2h','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2h\n \n \n 2020-07-20 13:45:23 UTC\n \n 2021-07-13 14:17:29 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 863\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3677)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 13:45:23',4,'2021-07-13 14:17:29',4,0,NULL,NULL,NULL,'b4786a8b-fccd-4fe1-964f-70034909846f'),(864,'Clients given 3 months supply 2h','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2h\n \n \n 2020-07-20 13:47:29 UTC\n \n 2021-07-14 08:16:40 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 864\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3677)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 13:47:29',4,'2021-07-14 08:16:40',4,0,NULL,NULL,NULL,'4a6f7a2a-2166-487e-9add-7655727277ad'),(865,'Clients given 6 months supply 2h','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2h\n \n \n 2020-07-20 13:48:11 UTC\n \n 2021-01-26 19:04:40 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 865\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3677) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 3677) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3677) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3677) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3677) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3677) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 3677 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 13:48:11',4,'2021-01-26 19:04:40',4,0,NULL,NULL,NULL,'2c4a733e-3851-4008-93d2-7e74cfec135b'),(866,'Clients given Other months MMD supply 2h','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2h\n \n \n 2020-07-20 13:50:21 UTC\n \n 2021-07-24 21:34:22 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 866\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3677)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 13:50:21',4,'2021-07-24 21:34:22',4,0,NULL,NULL,NULL,'aebf1799-6b5c-4f7a-800a-6e1b8a35dfa8'),(867,'Clients newly initiated 2j','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2j\n \n \n 2020-07-20 15:07:10 UTC\n \n 2021-01-27 15:03:46 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 867\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4689 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 15:07:10',4,'2021-01-27 15:03:46',4,0,NULL,NULL,NULL,'83f23b67-1231-4044-9152-c654f66ebe2e'),(868,'Clients seen given 1 month supply 2j','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2j\n \n \n 2020-07-20 15:15:19 UTC\n \n 2021-07-13 14:18:45 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 868\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4689)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 15:15:19',4,'2021-07-13 14:18:45',4,0,NULL,NULL,NULL,'6a992088-7110-42bc-a8df-c65ed16cbdf4'),(869,'Clients given 3 months supply 2j','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2j\n \n \n 2020-07-20 15:16:07 UTC\n \n 2021-07-14 08:17:46 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 869\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4689)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 15:16:07',4,'2021-07-14 08:17:46',4,0,NULL,NULL,NULL,'c55d654b-82b7-4426-bd0b-ac03347dbe35'),(870,'Clients given 6 months supply 2j','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2j\n \n \n 2020-07-20 15:17:31 UTC\n \n 2021-01-26 19:17:47 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 870\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4689) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 4689) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4689) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4689) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4689) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4689) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 4689 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 15:17:31',4,'2021-01-26 19:17:47',4,0,NULL,NULL,NULL,'cf31032a-c3ae-4b18-99ae-7765a98e8937'),(871,'Clients given Other months MMD supply 2j','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2j\n \n \n 2020-07-20 15:18:22 UTC\n \n 2021-07-24 21:34:55 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 871\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4689)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 15:18:22',4,'2021-07-24 21:34:55',4,0,NULL,NULL,NULL,'b7e4159b-8045-477b-b4d9-24083d1f4fa3'),(872,'Clients newly initiated 2k','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2k\n \n \n 2020-07-20 15:29:14 UTC\n \n 2021-01-27 15:04:37 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 872\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4690 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 15:29:14',4,'2021-01-27 15:04:37',4,0,NULL,NULL,NULL,'8b592d42-c141-4d58-b770-d9c9fb2e7195'),(873,'Clients seen given 1 month supply 2k','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2k\n \n \n 2020-07-20 15:30:52 UTC\n \n 2021-07-13 14:19:27 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 873\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4690)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 15:30:52',4,'2021-07-13 14:19:27',4,0,NULL,NULL,NULL,'8e0dd16c-a83c-48ba-80ba-0415119dbee4'),(874,'Clients given 3 months supply 2k','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2k\n \n \n 2020-07-20 15:32:16 UTC\n \n 2021-07-14 08:18:19 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 874\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4690)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 15:32:16',4,'2021-07-14 08:18:19',4,0,NULL,NULL,NULL,'905f7e40-b853-43b9-a33a-5e2ff8d7874b'),(875,'Clients given 6 months supply 2k','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2k\n \n \n 2020-07-20 15:34:06 UTC\n \n 2021-01-26 19:20:27 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 875\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4690) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 4690) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4690) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4690) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4690) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4690) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 4690 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 15:34:06',4,'2021-01-26 19:20:27',4,0,NULL,NULL,NULL,'1bd5f808-95a3-4645-b2d8-f4413fba1daa'),(876,'Clients given Other months MMD supply 2k','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2k\n \n \n 2020-07-20 15:39:15 UTC\n \n 2021-07-24 22:06:18 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 876\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4690)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 15:39:15',4,'2021-07-24 22:06:18',4,0,NULL,NULL,NULL,'4ba2760b-2cef-460e-871f-1b48021fd52a'),(877,'Clients newly initiated 2l','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2l\n \n \n 2020-07-20 16:16:10 UTC\n \n 2021-01-27 15:05:15 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 877\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4691 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 16:16:10',4,'2021-01-27 15:05:15',4,0,NULL,NULL,NULL,'72c7972e-21fb-43b5-84cf-059dd3c33a1f'),(878,'Clients seen given 1 month supply 2l','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2l\n \n \n 2020-07-20 16:16:59 UTC\n \n 2021-07-13 14:20:06 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 878\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4691)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:16:59',4,'2021-07-13 14:20:06',4,0,NULL,NULL,NULL,'988f14b7-3565-4440-af9f-cb44508a59ce'),(879,'Clients given 3 months supply 2l','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2l\n \n \n 2020-07-20 16:18:06 UTC\n \n 2021-07-14 08:19:07 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 879\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4691)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:18:06',4,'2021-07-14 08:19:07',4,0,NULL,NULL,NULL,'f4580b03-d891-4203-a9c0-fcd1a8a78d14'),(880,'Clients given 6 months supply 2l','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2l\n \n \n 2020-07-20 16:19:25 UTC\n \n 2021-01-26 19:23:35 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 880\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4691) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 4691) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4691) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4691) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4691) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4691) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 4691 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 16:19:25',4,'2021-01-26 19:23:35',4,0,NULL,NULL,NULL,'e1198db3-509c-4c28-8495-b64378232599'),(881,'Clients given Other months MMD supply 2l','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2l\n \n \n 2020-07-20 16:20:39 UTC\n \n 2021-07-24 22:07:31 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 881\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4691)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:20:39',4,'2021-07-24 22:07:31',4,0,NULL,NULL,NULL,'f8cb3fb3-93ab-45d3-99a2-5f0e516de258'),(882,'Clients newly initiated 2m','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2m\n \n \n 2020-07-20 16:25:28 UTC\n \n 2021-01-27 15:05:54 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 882\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4692 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 16:25:28',4,'2021-01-27 15:05:54',4,0,NULL,NULL,NULL,'7e35c205-e70c-43c8-ab26-e79255a149f1'),(883,'Clients seen given 1 month supply 2m','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2m\n \n \n 2020-07-20 16:26:22 UTC\n \n 2021-07-13 14:20:38 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 883\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4692)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:26:22',4,'2021-07-13 14:20:38',4,0,NULL,NULL,NULL,'4d14334f-0967-4158-9449-38a640f94cc3'),(884,'Clients given 3 months supply 2m','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2m\n \n \n 2020-07-20 16:27:47 UTC\n \n 2021-07-14 08:19:37 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 884\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4692)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:27:47',4,'2021-07-14 08:19:37',4,0,NULL,NULL,NULL,'cd30e227-46d5-4866-9c1f-a72e4ed6fdb9'),(885,'Clients given 6 months supply 2m','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2m\n \n \n 2020-07-20 16:28:27 UTC\n \n 2021-01-26 19:24:35 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 885\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4692) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 4692) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4692) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4692) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4692) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4692) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 4692 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 16:28:27',4,'2021-01-26 19:24:35',4,0,NULL,NULL,NULL,'e193a848-d5e1-454a-8266-777440f7ad8d'),(886,'Clients given Other months MMD supply 2n','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2n\n \n \n 2020-07-20 16:29:19 UTC\n \n 2021-07-24 22:08:52 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 886\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4693)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:29:19',4,'2021-07-24 22:08:52',4,0,NULL,NULL,NULL,'0a95aada-1316-4abe-b2aa-0b9dde51459f'),(887,'Clients given Other months MMD supply 2m','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2m\n \n \n 2020-07-20 16:29:20 UTC\n \n 2021-07-24 22:08:24 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 887\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4692)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:29:20',4,'2021-07-24 22:08:25',4,0,NULL,NULL,NULL,'d341d266-1d27-4921-b731-8dc2ce13d82c'),(888,'Clients newly initiated 2n','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2n\n \n \n 2020-07-20 16:33:51 UTC\n \n 2021-01-27 15:06:32 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 888\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4693 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 16:33:51',4,'2021-01-27 15:06:32',4,0,NULL,NULL,NULL,'a9066bb6-bf2a-4d22-9c9b-b22db43322f7'),(889,'Clients seen given 1 month supply 2n','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2n\n \n \n 2020-07-20 16:34:42 UTC\n \n 2021-07-13 14:21:11 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 889\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4693)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:34:42',4,'2021-07-13 14:21:11',4,0,NULL,NULL,NULL,'c6422f72-825e-482d-a12d-73ab924f9528'),(890,'Clients given 3 months supply 2n','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2n\n \n \n 2020-07-20 16:35:35 UTC\n \n 2021-07-14 08:20:08 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 890\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4693)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:35:35',4,'2021-07-14 08:20:08',4,0,NULL,NULL,NULL,'e0af83be-ad0e-48b9-9ee5-fff184acc985'),(891,'Clients given 6 months supply 2n','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2n\n \n \n 2020-07-20 16:36:24 UTC\n \n 2021-01-26 19:27:24 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 891\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4693) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 4693) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4693) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4693) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4693) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4693) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 4693 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 16:36:24',4,'2021-01-26 19:27:24',4,0,NULL,NULL,NULL,'9a3d0805-b6f9-4eb2-9d05-5420deb24520'),(892,'Clients newly initiated 2o','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2o\n \n \n 2020-07-20 16:49:16 UTC\n \n 2021-01-27 15:07:14 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 892\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4694 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 16:49:16',4,'2021-01-27 15:07:14',4,0,NULL,NULL,NULL,'eb737a94-1eff-4a8b-82d4-d40159ea5817'),(893,'Clients seen given 1 month supply 2o','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2o\n \n \n 2020-07-20 16:50:04 UTC\n \n 2021-07-13 14:22:12 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 893\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4694)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:50:04',4,'2021-07-13 14:22:12',4,0,NULL,NULL,NULL,'52b8c228-c12b-4c0f-81fa-0027d615bd2a'),(894,'Clients given 3 months supply 2o','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2o\n \n \n 2020-07-20 16:51:01 UTC\n \n 2021-07-14 08:20:39 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 894\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4694)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:51:01',4,'2021-07-14 08:20:39',4,0,NULL,NULL,NULL,'69a5e670-44c6-47d9-acd8-6e12dfaa1d80'),(895,'Clients given 6 months supply 2o','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2o\n \n \n 2020-07-20 16:51:39 UTC\n \n 2021-01-26 19:29:32 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 895\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4694) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 4694) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4694) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4694) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4694) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4694) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 4694 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 16:51:39',4,'2021-01-26 19:29:32',4,0,NULL,NULL,NULL,'4622beff-06b0-46ff-9ffe-9e1a2e6a514f'),(896,'Clients given Other months MMD supply 2o','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2o\n \n \n 2020-07-20 16:52:33 UTC\n \n 2021-07-24 22:09:27 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 896\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4694)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:52:33',4,'2021-07-24 22:09:27',4,0,NULL,NULL,NULL,'34b88c09-e0c3-44b8-8cd2-a431099edd07'),(897,'Clients newly initiated 2p','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2p\n \n \n 2020-07-20 16:56:58 UTC\n \n 2021-01-27 15:07:55 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 897\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4695 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 16:56:58',4,'2021-01-27 15:07:55',4,0,NULL,NULL,NULL,'3e67e8e3-a5eb-4cf7-b55b-ef75e74711c5'),(898,'Clients seen given 1 month supply 2p','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2p\n \n \n 2020-07-20 16:57:50 UTC\n \n 2021-07-13 14:22:44 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 898\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4695)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:57:50',4,'2021-07-13 14:22:44',4,0,NULL,NULL,NULL,'48813e11-ba00-4da6-bf2f-3f11b709ce62'),(899,'Clients given 3 months supply 2p','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2p\n \n \n 2020-07-20 16:58:45 UTC\n \n 2021-07-14 08:21:20 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 899\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4695)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 16:58:45',4,'2021-07-14 08:21:20',4,0,NULL,NULL,NULL,'1a682087-9f0a-45a2-8f0b-c8600f5c6c60'),(900,'Clients given 6 months supply 2p','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2p\n \n \n 2020-07-20 17:00:01 UTC\n \n 2021-01-26 19:30:28 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 900\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4695) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 4695) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4695) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4695) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4695) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4695) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 4695 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 17:00:01',4,'2021-01-26 19:30:28',4,0,NULL,NULL,NULL,'3884fe84-f6b8-490c-a8fb-39733b570582'),(901,'Clients given Other months MMD supply 2p','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2p\n \n \n 2020-07-20 17:00:44 UTC\n \n 2021-07-24 22:10:01 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 901\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4695)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 17:00:44',4,'2021-07-24 22:10:01',4,0,NULL,NULL,NULL,'4948619f-ed82-40ed-9da5-44a3ae4169f6'),(902,'Clients newly initiated 2q','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2q\n \n \n 2020-07-20 17:03:30 UTC\n \n 2021-01-27 15:09:30 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 902\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4849 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 17:03:30',4,'2021-01-27 15:09:30',4,0,NULL,NULL,NULL,'1f60ad52-150b-4228-8089-9d440e8d0cde'),(903,'Clients seen given 1 month supply 2q','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2q\n \n \n 2020-07-20 17:04:25 UTC\n \n 2021-07-13 14:23:27 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 903\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4849)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 17:04:25',4,'2021-07-13 14:23:27',4,0,NULL,NULL,NULL,'ae79b825-cb86-42e5-8953-011f6d9008cf'),(904,'Clients given 3 months supply 2q','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2q\n \n \n 2020-07-20 17:05:14 UTC\n \n 2021-07-14 08:21:53 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 904\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4849)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 17:05:14',4,'2021-07-14 08:21:53',4,0,NULL,NULL,NULL,'1606909a-0ff0-4513-a260-b32ee03f4241'),(905,'Clients given 6 months supply 2q','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2q\n \n \n 2020-07-20 17:06:30 UTC\n \n 2021-01-26 19:31:31 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 905\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4849) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 4849) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4849) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4849) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4849) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4849) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 4849 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-07-20 17:06:30',4,'2021-01-26 19:31:31',4,0,NULL,NULL,NULL,'fd6704c7-9485-4842-b91d-1ae58c3bb265'),(906,'Clients given Other months MMD supply 2q','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2q\n \n \n 2020-07-20 17:07:20 UTC\n \n 2021-07-24 22:10:33 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 906\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4849)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-07-20 17:07:20',4,'2021-07-24 22:10:33',4,0,NULL,NULL,NULL,'851209e6-8b48-4ec2-8ee7-5d42839b0ddf'),(907,'Clients newly initiated 3d','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 3d\n \n \n 2020-07-20 17:24:03 UTC\n \n 2021-01-27 15:21:39 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 907\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4706 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 17:24:03',4,'2021-01-27 15:21:39',4,0,NULL,NULL,NULL,'eb729dfc-4ee5-4de4-aa27-e81aab012d0a'),(908,'Clients newly initiated 3e','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 3e\n \n \n 2020-07-20 17:24:57 UTC\n \n 2021-01-27 15:22:17 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 908\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4707 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 17:24:57',4,'2021-01-27 15:22:17',4,0,NULL,NULL,NULL,'1140c832-9daf-4dda-9256-227493e9fa4f'),(909,'Clients newly initiated 3f','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 3f\n \n \n 2020-07-20 17:26:42 UTC\n \n 2021-01-27 15:22:52 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 909\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4708 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 17:26:42',4,'2021-01-27 15:22:52',4,0,NULL,NULL,NULL,'cc49c25f-038c-40bd-8aaa-68be2a51c88b'),(910,'Clients newly initiated 3g','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 3g\n \n \n 2020-07-20 17:27:50 UTC\n \n 2021-01-27 15:23:36 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 910\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4709 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 17:27:50',4,'2021-01-27 15:23:36',4,0,NULL,NULL,NULL,'b14d4af3-b58c-48d9-aa33-e0b35aa06d30'),(911,'Clients newly initiated 3h','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 3h\n \n \n 2020-07-20 17:29:15 UTC\n \n 2021-01-27 15:24:37 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 911\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4710 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-07-20 17:29:15',4,'2021-01-27 15:24:37',4,0,NULL,NULL,NULL,'d8b0aecd-81dc-4d1b-badd-7949b611bd87'),(912,'CMP_ART Regimen 1month supply 1c','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1c\n \n \n 2020-07-20 19:34:44 UTC\n \n 2020-07-20 19:36:45 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 912\n Clients-newly-initiated-1c OR Clients-seen-given-1-month-supply-1c\n \n \n Clients-newly-initiated-1c\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-1c\n \n \n \n \n \n \n','2020-07-20 19:34:44',4,'2020-07-20 19:36:45',4,0,NULL,NULL,NULL,'829aeaa7-cb64-4a49-a81b-a040fbe9c8cd'),(913,'CMP_ART Regimen 1month supply 1d','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1d\n \n \n 2020-07-20 19:38:24 UTC\n \n 2020-07-20 19:40:12 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 913\n Clients-seen-given-1-month-supply-1d OR Clients-newly-initiated-1d-\n \n \n Clients-seen-given-1-month-supply-1d\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-1d-\n \n \n \n \n \n \n','2020-07-20 19:38:24',4,'2020-07-20 19:40:12',4,0,NULL,NULL,NULL,'74bef2b6-1548-4408-a0d8-f06267b194cd'),(914,'CMP_ART Regimen 1month supply 1e','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1e\n \n \n 2020-07-20 19:41:21 UTC\n \n 2020-07-20 19:43:07 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 914\n Clients-newly-initiated-1e OR Clients-seen-given-1-month-supply-1e\n \n \n Clients-newly-initiated-1e\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-1e\n \n \n \n \n \n \n','2020-07-20 19:41:21',4,'2020-07-20 19:43:07',4,0,NULL,NULL,NULL,'010de706-fc5b-46bc-af84-92e43b167718'),(915,'CMP_ART Regimen 1month supply 1g','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1g\n \n \n 2020-07-20 19:43:21 UTC\n \n 2020-07-21 00:56:20 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 915\n Clients-newly-initiated-1g- OR Clients-seen-given-1-month-supply-1g\n \n \n Clients-newly-initiated-1g-\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-1g\n \n \n \n \n \n \n','2020-07-20 19:43:21',4,'2020-07-21 00:56:20',4,0,NULL,NULL,NULL,'57d7a749-47e3-468d-b861-77762886a260'),(916,'CMP_ART Regimen 1month supply 1h','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1h\n \n \n 2020-07-21 00:56:37 UTC\n \n 2020-07-21 00:58:05 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 916\n Clients-newly-initiated-1h OR Clients-seen-given-1-month-supply-1h\n \n \n Clients-newly-initiated-1h\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-1h\n \n \n \n \n \n \n','2020-07-21 00:56:37',4,'2020-07-21 00:58:05',4,0,NULL,NULL,NULL,'dac9644e-de7d-4d01-842a-5e0bd3b04be6'),(917,'CMP_ART Regimen 1month supply 1j','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1j\n \n \n 2020-07-21 00:58:23 UTC\n \n 2020-07-21 00:59:43 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 917\n Clients-seen-given-1-month-supply-1j OR Clients-newly-initiated-1j\n \n \n Clients-seen-given-1-month-supply-1j\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-1j\n \n \n \n \n \n \n','2020-07-21 00:58:23',4,'2020-07-21 00:59:43',4,0,NULL,NULL,NULL,'6c85c1eb-bafe-4fcf-b839-ec9bac116397'),(918,'CMP_ART Regimen 1month supply 1k','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1k\n \n \n 2020-07-21 01:00:03 UTC\n \n 2020-07-21 01:01:26 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 918\n Clients-seen-given-1-month-supply-1k OR Clients-newly-initiated-1k\n \n \n Clients-seen-given-1-month-supply-1k\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-1k\n \n \n \n \n \n \n','2020-07-21 01:00:03',4,'2020-07-21 01:01:26',4,0,NULL,NULL,NULL,'df97af0c-0e5c-4c03-ac17-6fd6989c9f52'),(919,'CMP_ART Regimen 1month supply 1m','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1m\n \n \n 2020-07-21 01:01:47 UTC\n \n 2020-07-21 01:03:02 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 919\n Clients-seen-given-1-month-supply-1m OR Clients-newly-initiated-1m\n \n \n Clients-seen-given-1-month-supply-1m\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-1m\n \n \n \n \n \n \n','2020-07-21 01:01:47',4,'2020-07-21 01:03:02',4,0,NULL,NULL,NULL,'c6314f22-4686-415a-9180-aec975e149b6'),(920,'CMP_ART Regimen 1month supply 1n','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1n\n \n \n 2020-07-21 01:03:35 UTC\n \n 2020-07-21 01:04:49 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 920\n Clients-seen-given-1-month-supply-1n OR Clients-newly-initiated-1n\n \n \n Clients-seen-given-1-month-supply-1n\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-1n\n \n \n \n \n \n \n','2020-07-21 01:03:35',4,'2020-07-21 01:04:49',4,0,NULL,NULL,NULL,'d63a7ee0-2c04-4c43-a559-420c2c5833d3'),(921,'CMP_ART Regimen 1month supply 1p','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1p\n \n \n 2020-07-21 01:05:09 UTC\n \n 2020-07-21 01:06:57 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 921\n Clients-seen-given-1-month-supply-1p OR Clients-newly-initiated-1p\n \n \n Clients-seen-given-1-month-supply-1p\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-1p\n \n \n \n \n \n \n','2020-07-21 01:05:09',4,'2020-07-21 01:06:57',4,0,NULL,NULL,NULL,'dd9f9e82-0406-47c8-a725-bd696fbc3c12'),(922,'CMP_ART Regimen 1month supply 1q','','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 1q\n \n \n 2020-07-21 01:07:11 UTC\n \n 2020-07-21 01:08:27 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 922\n Clients-newly-initiated-1q OR Clients-seen-given-1-month-supply-1q\n \n \n Clients-newly-initiated-1q\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-1q\n \n \n \n \n \n \n','2020-07-21 01:07:11',4,'2020-07-21 01:08:27',4,0,NULL,NULL,NULL,'5db23287-5dac-4b0f-a298-f4b6b5280c83'),(923,'CI04a: Adult 1st Line 1month supply 1c','Adults on 1st line 1c given 1month supply during the reporting period','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI04a: Adult 1st Line 1month supply 1c\n Adults on 1st line 1c given 1month supply during the reporting period\n \n 2020-07-21 01:12:25 UTC\n \n 2021-07-13 10:51:25 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 923\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:12:25',4,'2021-07-13 10:51:25',4,0,NULL,NULL,NULL,'afc603fa-52eb-4575-b911-da59f667ab73'),(924,'CI04b: Adult 1st Line 3 months supply 1c','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI04b: Adult 1st Line 3 months supply 1c\n \n \n 2020-07-21 01:15:26 UTC\n \n 2020-07-21 01:16:56 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 924\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:15:26',4,'2020-07-21 01:16:56',4,0,NULL,NULL,NULL,'7ac59930-19d9-4d19-bd11-c5053a450a26'),(925,'CI04c: Adult 1st Line 6 months supply 1c','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI04c: Adult 1st Line 6 months supply 1c\n \n \n 2020-07-21 01:17:44 UTC\n \n 2020-07-21 01:18:44 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 925\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:17:44',4,'2020-07-21 01:18:44',4,0,NULL,NULL,NULL,'62bc19a6-55a7-42af-b32d-bc3922ccada1'),(926,'CI04d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1c','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI04d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1c\n \n \n 2020-07-21 01:20:02 UTC\n \n 2020-07-21 01:21:42 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 926\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:20:02',4,'2020-07-21 01:21:42',4,0,NULL,NULL,NULL,'e47fb0fe-b9e3-441b-8750-3aeb6835425e'),(927,'CI05a: Adult 1st Line 1month supply 1d','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI05a: Adult 1st Line 1month supply 1d\n \n \n 2020-07-21 01:23:38 UTC\n \n 2021-07-13 10:52:30 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 927\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:23:38',4,'2021-07-13 10:52:30',4,0,NULL,NULL,NULL,'5a9ccea7-0a17-4507-93a1-1c065039d658'),(928,'CI05b: Adult 1st Line 3 months supply 1d','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI05b: Adult 1st Line 3 months supply 1d\n \n \n 2020-07-21 01:25:51 UTC\n \n 2020-07-21 01:26:43 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 928\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:25:51',4,'2020-07-21 01:26:43',4,0,NULL,NULL,NULL,'f1b32cd7-2259-4d99-9f4e-807e1ee36198'),(929,'CI05c: Adult 1st Line 6 months supply 1d','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI05c: Adult 1st Line 6 months supply 1d\n \n \n 2020-07-21 01:27:34 UTC\n \n 2020-07-21 01:28:31 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 929\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:27:34',4,'2020-07-21 01:28:31',4,0,NULL,NULL,NULL,'397b18ba-7676-47d7-8b74-36fb553fce5a'),(930,'CI05d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1d','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI05d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1d\n \n \n 2020-07-21 01:29:44 UTC\n \n 2020-07-21 01:30:44 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 930\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:29:44',4,'2020-07-21 01:30:44',4,0,NULL,NULL,NULL,'f5ef0c56-b3d7-48f0-8edf-f86a9ce3a131'),(931,'CI06a: Adult 1st Line 1month supply 1e','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI06a: Adult 1st Line 1month supply 1e\n \n \n 2020-07-21 01:32:17 UTC\n \n 2021-07-13 10:53:24 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 931\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:32:17',4,'2021-07-13 10:53:24',4,0,NULL,NULL,NULL,'951db50d-c81e-4873-937c-ef24fd97341b'),(932,'CI06b: Adult 1st Line 3 months supply 1e','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI06b: Adult 1st Line 3 months supply 1e\n \n \n 2020-07-21 01:34:03 UTC\n \n 2020-07-21 01:35:29 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 932\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:34:03',4,'2020-07-21 01:35:29',4,0,NULL,NULL,NULL,'9e37c53c-e2f6-407b-98d8-74609842b178'),(933,'CI06c: Adult 1st Line 6 months supply 1e','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI06c: Adult 1st Line 6 months supply 1e\n \n \n 2020-07-21 01:36:59 UTC\n \n 2020-07-21 01:37:49 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 933\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:36:59',4,'2020-07-21 01:37:49',4,0,NULL,NULL,NULL,'1934b675-10f8-4a35-a937-146270fc115f'),(934,'CI06d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1e','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI06d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1e\n \n \n 2020-07-21 01:38:46 UTC\n \n 2020-07-21 01:39:52 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 934\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:38:46',4,'2020-07-21 01:39:52',4,0,NULL,NULL,NULL,'71cd4a88-5f58-4d9c-8580-fee04ddc08d9'),(935,'CI08a: Adult 1st Line 1month supply 1g','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI08a: Adult 1st Line 1month supply 1g\n \n \n 2020-07-21 01:51:34 UTC\n \n 2021-07-13 10:54:56 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 935\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:51:34',4,'2021-07-13 10:54:56',4,0,NULL,NULL,NULL,'a13ddfbe-eca2-491c-acc9-504634fa6d82'),(936,'CI08b: Adult 1st Line 3 months supply 1g','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI08b: Adult 1st Line 3 months supply 1g\n \n \n 2020-07-21 01:53:02 UTC\n \n 2020-07-21 01:53:51 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 936\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:53:02',4,'2020-07-21 01:53:51',4,0,NULL,NULL,NULL,'70995f20-ec52-4069-a33e-0c8dd9e98ab9'),(937,'CI08c: Adult 1st Line 6 months supply 1g','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI08c: Adult 1st Line 6 months supply 1g\n \n \n 2020-07-21 01:54:19 UTC\n \n 2020-07-21 01:55:25 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 937\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:54:19',4,'2020-07-21 01:55:25',4,0,NULL,NULL,NULL,'183b513c-124d-4e45-9a79-3051d09e2cc4'),(938,'CI08d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1g','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI08d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1g\n \n \n 2020-07-21 01:57:00 UTC\n \n 2020-07-21 01:58:00 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 938\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 01:57:00',4,'2020-07-21 01:58:00',4,0,NULL,NULL,NULL,'dcdbd00a-5102-4e52-af19-04ff1d36d0c7'),(939,'CI09a: Adult 1st Line 1month supply 1h','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI09a: Adult 1st Line 1month supply 1h\n \n \n 2020-07-21 02:25:29 UTC\n \n 2021-07-13 10:55:41 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 939\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:25:29',4,'2021-07-13 10:55:41',4,0,NULL,NULL,NULL,'616f1562-8733-4c9e-b6e2-87a17106acaf'),(940,'CI09b: Adult 1st Line 3 months supply 1h','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI09b: Adult 1st Line 3 months supply 1h\n \n \n 2020-07-21 02:26:56 UTC\n \n 2020-07-21 02:27:40 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 940\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:26:56',4,'2020-07-21 02:27:40',4,0,NULL,NULL,NULL,'06dbe648-2a96-4fe4-aff3-575e84f4315b'),(941,'CI09c: Adult 1st Line 6 months supply 1h','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI09c: Adult 1st Line 6 months supply 1h\n \n \n 2020-07-21 02:28:15 UTC\n \n 2020-07-21 02:28:58 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 941\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:28:15',4,'2020-07-21 02:28:58',4,0,NULL,NULL,NULL,'c581e381-1a36-4591-9dc2-a8f978b9ae49'),(942,'CI09d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1h','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI09d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1h\n \n \n 2020-07-21 02:29:36 UTC\n \n 2020-07-21 02:30:16 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 942\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:29:36',4,'2020-07-21 02:30:16',4,0,NULL,NULL,NULL,'4fb604a8-0527-4eaf-bbdd-1a099d145648'),(943,'CI10a: Adult 1st Line 1month supply 1j','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI10a: Adult 1st Line 1month supply 1j\n \n \n 2020-07-21 02:34:17 UTC\n \n 2021-07-08 11:09:31 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 943\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:34:17',4,'2021-07-08 11:09:31',4,0,NULL,NULL,NULL,'1f473c7d-8597-41b4-992b-7baa77ed4aca'); INSERT INTO `serialized_object` VALUES (944,'CI10b: Adult 1st Line 3 months supply 1j','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI10b: Adult 1st Line 3 months supply 1j\n \n \n 2020-07-21 02:45:28 UTC\n \n 2020-07-21 02:46:14 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 944\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:45:28',4,'2020-07-21 02:46:14',4,0,NULL,NULL,NULL,'13a0c750-2408-4cd2-b1df-d453f45e3a00'),(945,'CI10c: Adult 1st Line 6 months supply 1j','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI10c: Adult 1st Line 6 months supply 1j\n \n \n 2020-07-21 02:46:48 UTC\n \n 2020-07-21 02:47:40 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 945\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:46:48',4,'2020-07-21 02:47:40',4,0,NULL,NULL,NULL,'26dd119e-e715-4f92-91f5-ba0f369673d9'),(946,'CI10d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1j','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI10d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1j\n \n \n 2020-07-21 02:48:29 UTC\n \n 2020-07-21 02:49:06 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 946\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:48:29',4,'2020-07-21 02:49:06',4,0,NULL,NULL,NULL,'ca557633-3e4c-49ca-9462-ca58f8010d92'),(947,'CI11a: Adult 1st Line 1month supply 1k','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI11a: Adult 1st Line 1month supply 1k\n \n \n 2020-07-21 02:51:55 UTC\n \n 2021-07-13 10:49:34 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 947\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:51:55',4,'2021-07-13 10:49:34',4,0,NULL,NULL,NULL,'dc095e0e-2c62-4c56-972b-17a67263614b'),(948,'CI11b: Adult 1st Line 3 months supply 1k','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI11b: Adult 1st Line 3 months supply 1k\n \n \n 2020-07-21 02:53:36 UTC\n \n 2020-07-21 02:54:27 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 948\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:53:36',4,'2020-07-21 02:54:27',4,0,NULL,NULL,NULL,'e32caf13-d848-4e21-97fa-e89d9563f306'),(949,'CI11c: Adult 1st Line 6 months supply 1k','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI11c: Adult 1st Line 6 months supply 1k\n \n \n 2020-07-21 02:54:50 UTC\n \n 2020-07-21 02:55:35 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 949\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:54:50',4,'2020-07-21 02:55:35',4,0,NULL,NULL,NULL,'0e12fae3-e9e2-40b2-a849-12376cb478a2'),(950,'CI11d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1k','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI11d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1k\n \n \n 2020-07-21 02:56:26 UTC\n \n 2020-07-21 02:57:11 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 950\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 02:56:26',4,'2020-07-21 02:57:11',4,0,NULL,NULL,NULL,'24257a6a-1879-4dd8-bd3d-f058279e0207'),(951,'CI12a: Adult 1st Line 1month supply 1m','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI12a: Adult 1st Line 1month supply 1m\n \n \n 2020-07-21 03:00:02 UTC\n \n 2021-07-13 10:58:00 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 951\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:00:02',4,'2021-07-13 10:58:00',4,0,NULL,NULL,NULL,'0ef6adce-502f-47eb-8795-429caf1b23ae'),(952,'CI12b: Adult 1st Line 3 months supply 1m','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI12b: Adult 1st Line 3 months supply 1m\n \n \n 2020-07-21 03:01:23 UTC\n \n 2020-07-21 03:02:10 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 952\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:01:23',4,'2020-07-21 03:02:10',4,0,NULL,NULL,NULL,'bf47b708-0b0b-43d8-a05b-273cff29afea'),(953,'CI12c: Adult 1st Line 6 months supply 1m','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI12c: Adult 1st Line 6 months supply 1m\n \n \n 2020-07-21 03:02:37 UTC\n \n 2020-07-21 03:03:20 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 953\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:02:37',4,'2020-07-21 03:03:20',4,0,NULL,NULL,NULL,'d969925a-4cbd-42c0-bf1a-cb78639c24ae'),(954,'CI12d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1m','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI12d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1m\n \n \n 2020-07-21 03:03:46 UTC\n \n 2020-07-21 03:10:58 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 954\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:03:46',4,'2020-07-21 03:10:58',4,0,NULL,NULL,NULL,'7df200bd-d206-4346-8d1f-a4afe7c120e2'),(955,'CI13a: Adult 1st Line 1month supply 1n','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI13a: Adult 1st Line 1month supply 1n\n \n \n 2020-07-21 03:05:47 UTC\n \n 2021-07-13 11:00:35 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 955\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:05:47',4,'2021-07-13 11:00:35',4,0,NULL,NULL,NULL,'32ff69f7-5a24-4515-a13a-59a4c2a0ef5c'),(956,'CI13b: Adult 1st Line 3 months supply 1n','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI13b: Adult 1st Line 3 months supply 1n\n \n \n 2020-07-21 03:07:19 UTC\n \n 2020-07-21 03:08:06 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 956\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:07:19',4,'2020-07-21 03:08:06',4,0,NULL,NULL,NULL,'1309392d-c442-4929-926d-bb5fc0e707eb'),(957,'CI13c: Adult 1st Line 6 months supply 1n','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI13c: Adult 1st Line 6 months supply 1n\n \n \n 2020-07-21 03:08:41 UTC\n \n 2020-07-21 03:09:19 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 957\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:08:41',4,'2020-07-21 03:09:19',4,0,NULL,NULL,NULL,'5af5abae-803c-43d8-9afa-04f11ee98fb0'),(958,'CI13d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1n','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI13d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1n\n \n \n 2020-07-21 03:11:12 UTC\n \n 2020-07-21 03:11:52 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 958\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:11:12',4,'2020-07-21 03:11:52',4,0,NULL,NULL,NULL,'21233a7a-d6c5-493f-a2a0-9a03f786176b'),(959,'CI14a: Adult 1st Line 1month supply 1p','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI14a: Adult 1st Line 1month supply 1p\n \n \n 2020-07-21 03:13:17 UTC\n \n 2021-07-13 11:01:47 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 959\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:13:17',4,'2021-07-13 11:01:47',4,0,NULL,NULL,NULL,'16876004-32fb-4a96-a177-2d0a96e7a208'),(960,'CI14b: Adult 1st Line 3 months supply 1p','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI14b: Adult 1st Line 3 months supply 1p\n \n \n 2020-07-21 03:15:36 UTC\n \n 2020-07-21 03:16:23 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 960\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:15:36',4,'2020-07-21 03:16:23',4,0,NULL,NULL,NULL,'e7b8e8a4-f8ee-4a2e-81cd-d97f5e7ceb8b'),(961,'CI14c: Adult 1st Line 6 months supply 1p','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI14c: Adult 1st Line 6 months supply 1p\n \n \n 2020-07-21 03:16:49 UTC\n \n 2020-07-21 03:17:52 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 961\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:16:49',4,'2020-07-21 03:17:52',4,0,NULL,NULL,NULL,'4969a61b-0fdc-4c63-b686-ba7822cfb08d'),(962,'CI14d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1p','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI14d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1p\n \n \n 2020-07-21 03:18:27 UTC\n \n 2020-07-21 03:19:04 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 962\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:18:27',4,'2020-07-21 03:19:04',4,0,NULL,NULL,NULL,'c3e318e4-0469-415f-832e-44d5b5e714f2'),(963,'CI15a: Adult 1st Line 1month supply 1q','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI15a: Adult 1st Line 1month supply 1q\n \n \n 2020-07-21 03:19:49 UTC\n \n 2021-07-13 11:03:04 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 963\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:19:49',4,'2021-07-13 11:03:04',4,0,NULL,NULL,NULL,'fb000c62-ea24-41e4-8645-8b0c6da882af'),(964,'CI15b: Adult 1st Line 3 months supply 1q','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI15b: Adult 1st Line 3 months supply 1q\n \n \n 2020-07-21 03:20:53 UTC\n \n 2020-07-21 03:21:47 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 964\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:20:53',4,'2020-07-21 03:21:47',4,0,NULL,NULL,NULL,'7463cbbb-24b0-41ba-ab49-a9113892ede3'),(965,'CI15c: Adult 1st Line 6 months supply 1q','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI15c: Adult 1st Line 6 months supply 1q\n \n \n 2020-07-21 03:22:10 UTC\n \n 2020-07-21 03:23:13 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 965\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:22:10',4,'2020-07-21 03:23:13',4,0,NULL,NULL,NULL,'ab56677f-53c2-428f-9f0b-d275436fbeac'),(966,'CI15d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1q','','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI15d: Adult 1st Line Other (2, 4, 5 or 7+) MMD supply 1q\n \n \n 2020-07-21 03:23:46 UTC\n \n 2020-07-21 03:24:21 UTC\n \n \n location\n \n org.openmrs.Location\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 966\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-07-21 03:23:46',4,'2020-07-21 03:24:21',4,0,NULL,NULL,NULL,'ee8d0792-83e6-4a75-9d29-880203b1d97f'),(967,'tests','1mnth 2c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n tests\n 1mnth 2c\n \n 2020-07-24 14:51:44 UTC\n \n 2020-07-24 14:52:23 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 967\n','2020-07-24 14:51:44',4,'2020-07-24 14:52:23',4,0,NULL,NULL,NULL,'36cc1013-4264-4c43-af7a-5c097f01d1bc'),(968,'CMP_ART Regimen 1month supply 2c','1mnth 2c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2c\n 1mnth 2c\n \n 2020-07-24 14:53:18 UTC\n \n 2020-07-24 15:00:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 968\n Clients-newly-initiated-2c OR Clients-seen-given-1-month-supply-2c\n \n \n Clients-newly-initiated-2c\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-2c\n \n \n \n \n \n \n','2020-07-24 14:53:18',4,'2020-07-24 15:00:26',4,0,NULL,NULL,NULL,'90455a27-26e1-4043-8199-8f7bda6f55da'),(969,'CMP_ART Regimen 1month supply 2d','1mnth 2d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2d\n 1mnth 2d\n \n 2020-07-24 15:01:04 UTC\n \n 2020-07-24 15:04:46 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 969\n Clients-newly-initiated-2d OR Clients-seen-given-1-month-supply-2d\n \n \n Clients-newly-initiated-2d\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-2d\n \n \n \n \n \n \n','2020-07-24 15:01:04',4,'2020-07-24 15:04:46',4,0,NULL,NULL,NULL,'4dbab0a2-b33e-4ed9-ae7d-1c4fd08fa665'),(970,'CMP_ART Regimen 1month supply 2e','1mnth 2e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2e\n 1mnth 2e\n \n 2020-07-24 15:05:29 UTC\n \n 2020-07-24 15:07:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 970\n Clients-newly-initiated-2e OR Clients-seen-given-1-month-supply-2e\n \n \n Clients-newly-initiated-2e\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-2e\n \n \n \n \n \n \n','2020-07-24 15:05:29',4,'2020-07-24 15:07:56',4,0,NULL,NULL,NULL,'c561c725-73b6-4ccf-a159-849c5fceee4d'),(971,'CMP_ART Regimen 1month supply 2f','1 mnth 2f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2f\n 1 mnth 2f\n \n 2020-07-24 15:08:32 UTC\n \n 2020-07-24 15:11:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 971\n Clients-newly-initiated-2f- OR Clients-seen-given-1-month-supply-2f\n \n \n Clients-newly-initiated-2f-\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-2f\n \n \n \n \n \n \n','2020-07-24 15:08:32',4,'2020-07-24 15:11:10',4,0,NULL,NULL,NULL,'7c9575bf-11fe-43d5-b643-6ad64139702c'),(972,'CMP_ART Regimen 1month supply 2g','1mnth 2g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2g\n 1mnth 2g\n \n 2020-07-24 15:12:42 UTC\n \n 2020-07-24 15:16:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 972\n Clients-newly-initiated-2g OR Clients-seen-given-1-month-supply-2g\n \n \n Clients-newly-initiated-2g\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-2g\n \n \n \n \n \n \n','2020-07-24 15:12:42',4,'2020-07-24 15:16:14',4,0,NULL,NULL,NULL,'f44d2ca7-dd58-414e-b2bb-0c25dfbcc2bf'),(973,'CMP_ART Regimen 1month supply 2h','1month 2h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2h\n 1month 2h\n \n 2020-07-24 15:17:06 UTC\n \n 2020-07-24 15:19:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 973\n Clients-newly-initiated-2g OR Clients-seen-given-1-month-supply-2h\n \n \n Clients-newly-initiated-2g\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-2h\n \n \n \n \n \n \n','2020-07-24 15:17:06',4,'2020-07-24 15:19:35',4,0,NULL,NULL,NULL,'c3fb524c-828b-4aa9-ad18-73c3afcd4b01'),(974,'CMP_ART Regimen 1month supply 2j','1month 2j','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2j\n 1month 2j\n \n 2020-07-24 15:20:13 UTC\n \n 2020-07-24 15:25:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 974\n Clients-newly-initiated-2j OR Clients-seen-given-1-month-supply-2j\n \n \n Clients-newly-initiated-2j\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-2j\n \n \n \n \n \n \n','2020-07-24 15:20:13',4,'2020-07-24 15:25:05',4,0,NULL,NULL,NULL,'b1ab8586-4a72-4a16-b5d7-9482e6eae2fc'),(975,'CMP_ART Regimen 1month supply 2k','1mnth 2k','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2k\n 1mnth 2k\n \n 2020-07-24 15:25:27 UTC\n \n 2020-07-24 15:30:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 975\n Clients-seen-given-1-month-supply-2k OR Clients-newly-initiated-2k\n \n \n Clients-seen-given-1-month-supply-2k\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-2k\n \n \n \n \n \n \n','2020-07-24 15:25:27',4,'2020-07-24 15:30:29',4,0,NULL,NULL,NULL,'50c6447e-caa4-4ea4-8363-2959de4a7365'),(976,'CMP_ART Regimen 1month supply 2l','1mnth 2l','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2l\n 1mnth 2l\n \n 2020-07-24 15:30:56 UTC\n \n 2020-07-24 15:32:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 976\n Clients-seen-given-1-month-supply-2l OR Clients-newly-initiated-2l\n \n \n Clients-seen-given-1-month-supply-2l\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-2l\n \n \n \n \n \n \n','2020-07-24 15:30:56',4,'2020-07-24 15:32:29',4,0,NULL,NULL,NULL,'872e6d0b-64c6-4ff1-a839-44dfc2bc7a9e'),(977,'CMP_ART Regimen 1month supply 2m','1mnth 2m','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2m\n 1mnth 2m\n \n 2020-07-26 06:13:53 UTC\n \n 2020-07-26 06:19:50 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 977\n Clients-seen-given-1-month-supply-2m OR Clients-newly-initiated-2m\n \n \n Clients-seen-given-1-month-supply-2m\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-2m\n \n \n \n \n \n \n','2020-07-26 06:13:53',4,'2020-07-26 06:19:50',4,0,NULL,NULL,NULL,'d7dd8d8a-e3a1-472c-90fc-e0c450303c18'),(978,'CMP_ART Regimen 1month supply 2n','1mnth 2n','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2n\n 1mnth 2n\n \n 2020-07-26 06:20:22 UTC\n \n 2020-07-26 06:24:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 978\n Clients-seen-given-1-month-supply-2n OR Clients-newly-initiated-2n\n \n \n Clients-seen-given-1-month-supply-2n\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-2n\n \n \n \n \n \n \n','2020-07-26 06:20:22',4,'2020-07-26 06:24:10',4,0,NULL,NULL,NULL,'7f61ff5a-9a20-4b98-aea5-db7e27f4e2d2'),(979,'CMP_ART Regimen 1month supply 2o','1mnth 2o','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2o\n 1mnth 2o\n \n 2020-07-26 07:10:30 UTC\n \n 2020-07-26 07:14:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 979\n Clients-seen-given-1-month-supply-2o OR Clients-newly-initiated-2o\n \n \n Clients-seen-given-1-month-supply-2o\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-2o\n \n \n \n \n \n \n','2020-07-26 07:10:30',4,'2020-07-26 07:14:11',4,0,NULL,NULL,NULL,'ba08340b-e00e-4de7-b5d7-8bee853471c0'),(980,'CMP_ART Regimen 1month supply 2p','1mnth 2p','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2p\n 1mnth 2p\n \n 2020-07-26 07:17:55 UTC\n \n 2020-07-26 07:36:10 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 980\n Clients-seen-given-1-month-supply-2p OR Clients-newly-initiated-2p\n \n \n Clients-seen-given-1-month-supply-2p\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-2p\n \n \n \n \n \n \n','2020-07-26 07:17:55',4,'2020-07-26 07:36:10',4,0,NULL,NULL,NULL,'06709fce-50ff-4008-aec7-900443e2c2bc'),(981,'CMP_ART Regimen 1month supply 2q','1mnth 2q','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2q\n 1mnth 2q\n \n 2020-07-26 07:39:23 UTC\n \n 2020-07-26 07:42:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 981\n Clients-seen-given-1-month-supply-2q OR Clients-newly-initiated-2q\n \n \n Clients-seen-given-1-month-supply-2q\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-2q\n \n \n \n \n \n \n','2020-07-26 07:39:23',4,'2020-07-26 07:42:14',4,0,NULL,NULL,NULL,'6d8b0fd8-70d9-4f09-8770-93a8a063bbbd'),(982,'2020_adult_arv_2ndline_regimen','new dataset adult 2nd line regimen','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_adult_arv_2ndline_regimen\n new dataset adult 2nd line regimen\n \n 2020-07-26 09:16:18 UTC\n \n 2020-07-26 09:16:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 982\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-07-26 09:16:18',4,'2020-07-26 09:16:34',4,0,NULL,NULL,NULL,'8e5b796f-0a4c-4c90-af06-b3ef89810ef2'),(983,'2020_adult_arv_2ndline_regimen Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_adult_arv_2ndline_regimen Data Set\n \n 2020-07-26 09:16:34 UTC\n \n 2020-12-03 07:35:24 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 983\n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n 2c1mnth\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n 2c3mnths\n \n \n \n \n \n \n \n \n \n 2d1mnth\n \n \n \n \n \n \n \n \n \n 2d3mnths\n \n \n \n \n \n \n \n \n \n 2e1mnth\n \n \n \n \n \n \n \n \n \n 2e3mnths\n \n \n \n \n \n \n \n \n \n 2f1mnth\n \n \n \n \n \n \n \n \n \n 2f3mnths\n \n \n \n \n \n \n \n \n \n 2g1mnth\n \n \n \n \n \n \n \n \n \n 2g3mnths\n \n \n \n \n \n \n \n \n \n 2h1mnth\n \n \n \n \n \n \n \n \n \n 2h3mnths\n \n \n \n \n \n \n \n \n \n 2i1mnth\n \n \n \n \n \n \n \n \n \n 2i3mnths\n \n \n \n \n \n \n \n \n \n 2j1mnth\n \n \n \n \n \n \n \n \n \n 2j3mnths\n \n \n \n \n \n \n \n \n \n 2k1mnth\n \n \n \n \n \n \n \n \n \n 2k3mnths\n \n \n \n \n \n \n \n \n \n 2l1mnth\n \n \n \n \n \n \n \n \n \n 2l3mnths\n \n \n \n \n \n \n \n \n \n 2m1mnth\n \n \n \n \n \n \n \n \n \n 2m3mnths\n \n \n \n \n \n \n \n \n \n 2n1mnth\n \n \n \n \n \n \n \n \n \n 2n3mnths\n \n \n \n \n \n \n \n \n \n 2o1mnth\n \n \n \n \n \n \n \n \n \n 2o3mnths\n \n \n \n \n \n \n \n \n \n 2p1mnth\n \n \n \n \n \n \n \n \n \n 2p3mnths\n \n \n \n \n \n \n \n \n \n 2q1mnth\n \n \n \n \n \n \n \n \n \n 2q3mnths\n \n \n \n \n \n \n \n \n \n 2r1mnth\n \n \n \n \n \n \n \n \n \n 2r3mnths\n \n \n \n \n \n \n \n \n \n 2s1mnth\n \n \n \n \n \n \n \n \n \n 2s3mnths\n \n \n \n \n \n \n \n \n \n','2020-07-26 09:16:34',4,'2020-12-03 07:35:24',4,0,NULL,NULL,NULL,'ef7a6344-1f91-4926-ba02-d45bbff8e6a6'),(985,'CMP_ART Regimen 1month supply 3b','1mnth 3b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 3b\n 1mnth 3b\n \n 2020-07-26 14:45:35 UTC\n \n 2020-07-30 10:21:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 985\n Clients-seen-given-1-month-supply-3b OR Clients-newly-initiated-3b\n \n \n Clients-seen-given-1-month-supply-3b\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-3b\n \n \n \n \n \n \n','2020-07-26 14:45:35',4,'2020-07-30 10:21:37',4,0,NULL,NULL,NULL,'4ac8f9b1-b672-4687-a463-74a6806e4045'),(986,'CMP_ART Regimen 1month supply 3c','1mnth 3c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 3c\n 1mnth 3c\n \n 2020-07-26 14:52:06 UTC\n \n 2020-07-30 10:25:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 986\n Clients-newly-initiated-3c OR Clients-seen-given-1-month-supply-3c\n \n \n Clients-newly-initiated-3c\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-3c\n \n \n \n \n \n \n','2020-07-26 14:52:06',4,'2020-07-30 10:25:28',4,0,NULL,NULL,NULL,'759d2eb9-1dd6-4d76-865f-7cb1d6ef75cf'),(987,'CMP_ART Regimen 1month supply 3d','1mnth 3d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 3d\n 1mnth 3d\n \n 2020-07-26 14:56:17 UTC\n \n 2020-07-30 10:27:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 987\n Clients-newly-initiated-3d OR Clients-seen-given-1-month-supply-3d\n \n \n Clients-newly-initiated-3d\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-3d\n \n \n \n \n \n \n','2020-07-26 14:56:17',4,'2020-07-30 10:27:56',4,0,NULL,NULL,NULL,'3bfa5700-82fc-4e92-a9f1-84a2a2e5d098'),(988,'CMP_ART Regimen 1month supply 3e','1mnth 3e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 3e\n 1mnth 3e\n \n 2020-07-26 14:59:13 UTC\n \n 2020-07-30 10:30:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 988\n Clients-newly-initiated-3e OR Clients-seen-given-1-month-supply-3e\n \n \n Clients-newly-initiated-3e\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-3e\n \n \n \n \n \n \n','2020-07-26 14:59:13',4,'2020-07-30 10:30:08',4,0,NULL,NULL,NULL,'1a8828f4-337f-4563-9018-82d8df61b92c'),(989,'CMP_ART Regimen 1month supply 3f','1mnth 3f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 3f\n 1mnth 3f\n \n 2020-07-26 15:02:32 UTC\n \n 2020-07-30 10:32:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 989\n Clients-newly-initiated-3f OR Clients-seen-given-1-month-supply-3f\n \n \n Clients-newly-initiated-3f\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-3f\n \n \n \n \n \n \n','2020-07-26 15:02:32',4,'2020-07-30 10:32:56',4,0,NULL,NULL,NULL,'ccceead2-c7f3-4c50-b922-0e4566dc6c5f'),(990,'CMP_ART Regimen 1month supply 3g','1mnth 3g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 3g\n 1mnth 3g\n \n 2020-07-26 15:08:27 UTC\n \n 2020-07-30 10:34:43 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 990\n Clients-newly-initiated-3g OR Clients-seen-given-1-month-supply-3g\n \n \n Clients-newly-initiated-3g\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-3g\n \n \n \n \n \n \n','2020-07-26 15:08:27',4,'2020-07-30 10:34:43',4,0,NULL,NULL,NULL,'f036add2-8f10-4f62-a371-4afac2b81e97'),(991,'CMP_ART Regimen 1month supply 3h','1mnth 3h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 3h\n 1mnth 3h\n \n 2020-07-26 15:10:27 UTC\n \n 2020-07-30 10:36:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 991\n Clients-newly-initiated-3h OR Clients-seen-given-1-month-supply-3h\n \n \n Clients-newly-initiated-3h\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-3h\n \n \n \n \n \n \n','2020-07-26 15:10:27',4,'2020-07-30 10:36:16',4,0,NULL,NULL,NULL,'761cf953-a41c-45d1-bf0a-265a97685aee'),(992,'2020_adult_arv_3rdline_regimen','new dataset 3rdline ARV','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_adult_arv_3rdline_regimen\n new dataset 3rdline ARV\n \n 2020-07-26 15:13:37 UTC\n \n 2020-07-26 19:27:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 992\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-07-26 15:13:37',4,'2020-07-26 19:27:44',4,0,NULL,NULL,NULL,'afe451d4-5080-4689-b64a-75f0211f81a3'),(993,'2020_adult_arv_2ndline_regimen Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_adult_arv_2ndline_regimen Data Set\n \n 2020-07-26 15:13:44 UTC\n \n 2020-07-26 20:13:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 993\n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n 3a1mnth\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Age\n 15+yrs\n \n \n \n \n \n 3b1mnth\n \n \n \n \n \n \n \n \n \n 3c1mnth\n \n \n \n \n \n \n \n \n \n 3d1mnth\n \n \n \n \n \n \n \n \n \n 3e1mnth\n \n \n \n \n \n \n \n \n \n 3f1mnth\n \n \n \n \n \n \n \n \n \n 3g1mnth\n \n \n \n \n \n \n \n \n \n 3h1mnth\n \n \n \n \n \n \n \n \n \n','2020-07-26 15:13:44',4,'2020-07-26 20:13:06',4,0,NULL,NULL,NULL,'01bbedc4-b494-4465-b5c8-cbaa75c5f0d5'),(994,'CMP_ART Regimen 1month supply 3a','1month 3a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 3a\n 1month 3a\n \n 2020-07-29 22:32:01 UTC\n \n 2020-07-30 09:52:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 994\n Clients-seen-given-1-month-supply-3a OR Clients-newly-initiated-3a\n \n \n Clients-seen-given-1-month-supply-3a\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-3a\n \n \n \n \n \n \n','2020-07-29 22:32:01',4,'2020-07-30 09:52:26',4,0,NULL,NULL,NULL,'a7795190-fca8-4cc7-903c-ef70798e3763'),(995,'CI33a:Enrolled in Pre ART this month','pre ART enrolled','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI33a:Enrolled in Pre ART this month\n pre ART enrolled\n \n 2020-08-04 15:01:44 UTC\n \n 2020-08-04 15:06:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 995\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-08-04 15:01:44',4,'2020-08-04 15:06:11',4,0,NULL,NULL,NULL,'ff2143b3-5c22-4373-b026-e2ad9230d145'),(997,'CI33b: Clients ever enrolled on PrE ART','ever pre art','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI33b: Clients ever enrolled on PrE ART\n ever pre art\n \n 2020-08-04 16:10:56 UTC\n \n 2020-08-04 16:16:32 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 997\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-08-04 16:10:56',4,'2020-08-04 16:16:32',4,0,NULL,NULL,NULL,'63a41dcf-c43f-4143-a703-406e75e917bb'),(998,'CI34a: ART and Pre ART seen this month','care clients seen','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI34a: ART and Pre ART seen this month\n care clients seen\n \n 2020-08-04 16:31:46 UTC\n \n 2020-08-04 16:58:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 998\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-08-04 16:31:46',4,'2020-08-04 16:58:48',4,0,NULL,NULL,NULL,'2dc3ab54-fb26-445c-a9f5-788588571414'),(999,'CI30a: ART and Pre ART screened for TB','ART and Pre ART screened for TB','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CI30a: ART and Pre ART screened for TB\n ART and Pre ART screened for TB\n \n 2020-08-04 17:01:37 UTC\n \n 2020-08-04 17:02:59 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 999\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-08-04 17:01:37',4,'2020-08-04 17:02:59',4,0,NULL,NULL,NULL,'ff11b48e-496f-4399-a9ef-f10a6f8a1fe1'),(1002,'DM_Children_Age','Children Age Groups','org.openmrs.module.reporting.indicator.dimension.Dimension','org.openmrs.module.reporting.indicator.dimension.CohortDefinitionDimension','org.openmrs.module.reporting.serializer.ReportingSerializer','\n DM_Children_Age\n Children Age Groups\n \n 2020-09-09 10:58:53 UTC\n \n 2020-09-09 11:06:02 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n 1002\n \n \n 01-04yrs\n \n \n \n \n maxAge\n 4\n \n \n minAge\n 1\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 05-09yrs\n \n \n \n \n maxAge\n 9\n \n \n minAge\n 5\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 10-14yrs\n \n \n \n \n maxAge\n 14\n \n \n minAge\n 10\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n Under 1yr\n \n \n \n \n maxAge\n 0\n \n \n minAge\n 0\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n','2020-09-09 12:58:53',4,'2020-09-09 13:06:02',4,0,NULL,NULL,NULL,'229c55ed-b8a7-4f88-b3b6-a0df413f524c'),(1004,'DM_Adults_Age','Adult Age Groups','org.openmrs.module.reporting.indicator.dimension.Dimension','org.openmrs.module.reporting.indicator.dimension.CohortDefinitionDimension','org.openmrs.module.reporting.serializer.ReportingSerializer','\n DM_Adults_Age\n Adult Age Groups\n \n 2020-09-10 16:49:59 UTC\n \n 2020-09-10 16:56:40 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n 1004\n \n \n 121-200yrs\n \n \n \n \n maxAge\n 200\n \n \n minAge\n 121\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 15-19yrs\n \n \n \n \n maxAge\n 19\n \n \n minAge\n 15\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 20-24yrs\n \n \n \n \n maxAge\n 24\n \n \n minAge\n 20\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 25-29yrs\n \n \n \n \n maxAge\n 29\n \n \n minAge\n 25\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 30-34yrs\n \n \n \n \n maxAge\n 34\n \n \n minAge\n 30\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 35-39yrs\n \n \n \n \n maxAge\n 39\n \n \n minAge\n 35\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 40-44yrs\n \n \n \n \n maxAge\n 44\n \n \n minAge\n 40\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 45-49yrs\n \n \n \n \n maxAge\n 49\n \n \n minAge\n 45\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 50-120yrs\n \n \n \n \n maxAge\n 120\n \n \n minAge\n 50\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n','2020-09-10 18:49:59',4,'2020-09-10 18:56:40',4,0,NULL,NULL,NULL,'5c344e8a-2fd0-4dff-a4b4-48516c0298e3'),(1005,'DM_Finer_Age','Finer Age Groups','org.openmrs.module.reporting.indicator.dimension.Dimension','org.openmrs.module.reporting.indicator.dimension.CohortDefinitionDimension','org.openmrs.module.reporting.serializer.ReportingSerializer','\n DM_Finer_Age\n Finer Age Groups\n \n 2020-09-10 16:59:10 UTC\n \n 2020-09-16 13:09:14 UTC\n \n \n endDate\n \n java.util.Date\n true\n \n \n 1005\n \n \n 01-04yrs\n \n \n \n \n maxAge\n 4\n \n \n minAge\n 1\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 05-09yrs\n \n \n \n \n maxAge\n 9\n \n \n minAge\n 5\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 10-14yrs\n \n \n \n \n maxAge\n 14\n \n \n minAge\n 10\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 121-200yrs\n \n \n \n \n maxAge\n 200\n \n \n minAge\n 121\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 15-19yrs\n \n \n \n \n maxAge\n 19\n \n \n minAge\n 15\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 20-24yrs\n \n \n \n \n maxAge\n 24\n \n \n minAge\n 20\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 25-29yrs\n \n \n \n \n maxAge\n 29\n \n \n minAge\n 25\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 30-34yrs\n \n \n \n \n maxAge\n 34\n \n \n minAge\n 30\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 35-39yrs\n \n \n \n \n maxAge\n 39\n \n \n minAge\n 35\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 40-44yrs\n \n \n \n \n maxAge\n 44\n \n \n minAge\n 40\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 45-49yrs\n \n \n \n \n maxAge\n 49\n \n \n minAge\n 45\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n 50Plus\n \n \n \n \n maxAge\n 120\n \n \n minAge\n 50\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n Under1yr\n \n \n \n \n maxAge\n 0\n \n \n minAge\n 0\n \n \n effectiveDate\n ${endDate}\n \n \n \n \n \n','2020-09-10 18:59:10',4,'2020-09-16 15:09:14',4,0,NULL,NULL,NULL,'47af7610-5e91-4b2d-962d-0d317ffe03fb'),(1006,'2020_ART_Current',' ART CARE - NEW AND CURRENT NUMBER OF PERSONS STARTED ON ART','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_ART_Current\n ART CARE - NEW AND CURRENT NUMBER OF PERSONS STARTED ON ART\n \n 2020-09-16 12:53:38 UTC\n \n 2020-09-30 11:59:49 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1006\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-09-16 14:53:38',4,'2020-09-30 13:59:49',4,0,NULL,NULL,NULL,'f5608fc7-5bc6-49cc-a9b0-d52917f63cd2'),(1007,'2020_ART_Current Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 2020_ART_Current Data Set\n \n 2020-09-16 12:53:44 UTC\n \n 2020-09-16 17:06:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1007\n \n \n DM_Sex\n \n \n \n \n \n \n DM_Finer_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n DefaultF1-\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n 01-04yrs\n \n \n \n \n \n DefaultF10\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n 10-14yrs\n \n \n \n \n \n DefaultF15\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n 15-19yrs\n \n \n \n \n \n DefaultF20\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n 20-24yrs\n \n \n \n \n \n DefaultF25\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n 25-29yrs\n \n \n \n \n \n DefaultF30\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n 30-34yrs\n \n \n \n \n \n DefaultF35\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n 35-39yrs\n \n \n \n \n \n DefaultF40\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n 40-44yrs\n \n \n \n \n \n DefaultF45\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n 45-49yrs\n \n \n \n \n \n DefaultF5-\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n 05-09yrs\n \n \n \n \n \n DefaultF50\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n 50Plus\n \n \n \n \n \n DefaultF<1\n \n \n \n \n DM_Sex\n Females\n \n \n DM_Finer_Age\n Under1yr\n \n \n \n \n \n DefaultM1-\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n 01-04yrs\n \n \n \n \n \n DefaultM10\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n 10-14yrs\n \n \n \n \n \n DefaultM15\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n 15-19yrs\n \n \n \n \n \n DefaultM20\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n 20-24yrs\n \n \n \n \n \n DefaultM25\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n 25-29yrs\n \n \n \n \n \n DefaultM30\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n 30-34yrs\n \n \n \n \n \n DefaultM35\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n 35-39yrs\n \n \n \n \n \n DefaultM40\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n 40-44yrs\n \n \n \n \n \n DefaultM45\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n 45-49yrs\n \n \n \n \n \n DefaultM5-\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n 05-09yrs\n \n \n \n \n \n DefaultM50\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n 50Plus\n \n \n \n \n \n DefaultM<1\n \n \n \n \n DM_Sex\n Males\n \n \n DM_Finer_Age\n Under1yr\n \n \n \n \n \n DiedClient\n \n \n \n \n \n \n \n \n \n LostToFU\n \n \n \n \n \n \n \n \n \n MMD_F1-4\n \n \n \n \n \n \n \n \n \n MMD_F10-14\n \n \n \n \n \n \n MMD_F15-19\n \n \n \n \n \n \n MMD_F20-24\n \n \n \n \n \n \n MMD_F25-29\n \n \n \n \n \n \n MMD_F30-34\n \n \n \n \n \n \n MMD_F35-39\n \n \n \n \n \n \n MMD_F40-44\n \n \n \n \n \n \n MMD_F45-49\n \n \n \n \n \n \n MMD_F5-9\n \n \n \n \n \n \n MMD_F50\n \n \n \n \n \n \n MMD_F<1\n \n \n \n \n \n \n MMD_M1-4\n \n \n \n \n \n \n MMD_M10-14\n \n \n \n \n \n \n MMD_M15-19\n \n \n \n \n \n \n MMD_M20-24\n \n \n \n \n \n \n MMD_M25-29\n \n \n \n \n \n \n MMD_M30-34\n \n \n \n \n \n \n MMD_M35-39\n \n \n \n \n \n \n MMD_M40-44\n \n \n \n \n \n \n MMD_M45-49\n \n \n \n \n \n \n MMD_M5-9\n \n \n \n \n \n \n MMD_M50\n \n \n \n \n \n \n MMD_M<1\n \n \n \n \n \n \n MissedF1-4\n \n \n \n \n \n \n \n \n \n MissedF10-\n \n \n \n \n \n \n MissedF15-\n \n \n \n \n \n \n MissedF20-\n \n \n \n \n \n \n MissedF25-\n \n \n \n \n \n \n MissedF30-\n \n \n \n \n \n \n MissedF35-\n \n \n \n \n \n \n MissedF40-\n \n \n \n \n \n \n MissedF45-\n \n \n \n \n \n \n MissedF5-9\n \n \n \n \n \n \n MissedF50\n \n \n \n \n \n \n MissedF<1\n \n \n \n \n \n \n MissedM1-4\n \n \n \n \n \n \n MissedM10-\n \n \n \n \n \n \n MissedM15-\n \n \n \n \n \n \n MissedM20-\n \n \n \n \n \n \n MissedM25-\n \n \n \n \n \n \n MissedM30-\n \n \n \n \n \n \n MissedM35-\n \n \n \n \n \n \n MissedM40-\n \n \n \n \n \n \n MissedM45-\n \n \n \n \n \n \n MissedM5-9\n \n \n \n \n \n \n MissedM50\n \n \n \n \n \n \n MissedM<1\n \n \n \n \n \n \n NewF1-4\n \n \n \n \n \n \n \n \n \n NewF10-14\n \n \n \n \n \n \n NewF15-19\n \n \n \n \n \n \n NewF20-24\n \n \n \n \n \n \n NewF25-29\n \n \n \n \n \n \n NewF30-34\n \n \n \n \n \n \n NewF35-39\n \n \n \n \n \n \n NewF40-44\n \n \n \n \n \n \n NewF45-49\n \n \n \n \n \n \n NewF5-9\n \n \n \n \n \n \n NewF50\n \n \n \n \n \n \n NewF<1\n \n \n \n \n \n \n NewM1-4\n \n \n \n \n \n \n NewM10-14\n \n \n \n \n \n \n NewM15-19\n \n \n \n \n \n \n NewM20-24\n \n \n \n \n \n \n NewM25-29\n \n \n \n \n \n \n NewM30-34\n \n \n \n \n \n \n NewM35-39\n \n \n \n \n \n \n NewM40-44\n \n \n \n \n \n \n NewM45-49\n \n \n \n \n \n \n NewM5-9\n \n \n \n \n \n \n NewM50\n \n \n \n \n \n \n NewM<1\n \n \n \n \n \n \n Restarted\n \n \n \n \n \n \n \n \n \n SeenF1-4\n \n \n \n \n \n \n \n \n \n SeenF10-14\n \n \n \n \n \n \n SeenF15-19\n \n \n \n \n \n \n SeenF20-24\n \n \n \n \n \n \n SeenF25-29\n \n \n \n \n \n \n SeenF30-34\n \n \n \n \n \n \n SeenF35-39\n \n \n \n \n \n \n SeenF40-44\n \n \n \n \n \n \n SeenF45-49\n \n \n \n \n \n \n SeenF5-9\n \n \n \n \n \n \n SeenF50\n \n \n \n \n \n \n SeenF<1\n \n \n \n \n \n \n SeenM1-4\n \n \n \n \n \n \n SeenM10-14\n \n \n \n \n \n \n SeenM15-19\n \n \n \n \n \n \n SeenM20-24\n \n \n \n \n \n \n SeenM25-29\n \n \n \n \n \n \n SeenM30-34\n \n \n \n \n \n \n SeenM35-39\n \n \n \n \n \n \n SeenM40-44\n \n \n \n \n \n \n SeenM45-49\n \n \n \n \n \n \n SeenM5-9\n \n \n \n \n \n \n SeenM50\n \n \n \n \n \n \n SeenM<1\n \n \n \n \n \n \n StoppedART\n \n \n \n \n \n \n \n \n \n TransferIn\n \n \n \n \n \n \n \n \n \n TransferOu\n \n \n \n \n \n \n \n \n \n','2020-09-16 14:53:44',4,'2020-09-16 19:06:19',4,0,NULL,NULL,NULL,'c84add35-e6ec-4ef4-81d3-53f3d0b7b38b'),(1008,'weight_query_updated','weights','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.NumericObsCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n weight_query_updated\n weights\n \n 2020-11-16 10:06:11 UTC\n \n 2020-11-17 12:17:11 UTC\n \n \n onOrAfter\n \n java.util.Date\n true\n \n \n onOrBefore\n \n java.util.Date\n true\n \n \n locationList\n \n org.openmrs.Location\n java.util.List\n true\n \n \n value1\n \n java.lang.Double\n true\n \n \n value2\n \n java.lang.Double\n true\n \n \n 1008\n LAST\n \n \n \n \n \n GREATER_EQUAL\n LESS_THAN\n','2020-11-16 10:06:11',4,'2020-11-17 12:17:11',4,0,NULL,NULL,NULL,'59e2cda8-7991-4837-b0d0-a83f0fcbd8db'),(1009,'revised_child_weight','revised weight','org.openmrs.module.reporting.indicator.dimension.Dimension','org.openmrs.module.reporting.indicator.dimension.CohortDefinitionDimension','org.openmrs.module.reporting.serializer.ReportingSerializer','\n revised_child_weight\n revised weight\n \n 2020-11-16 10:08:00 UTC\n \n 2020-11-20 10:06:34 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 1009\n \n \n 0-3.9kg\n \n \n \n \n onOrBefore\n ${endDate}\n \n \n value2\n 4.0\n \n \n value1\n 0.0\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n 10-13.9kg\n \n \n \n \n onOrBefore\n ${endDate}\n \n \n value2\n 14.0\n \n \n value1\n 10.0\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n 100+kg\n \n \n \n \n onOrBefore\n ${endDate}\n \n \n value2\n 120.0\n \n \n value1\n 100.0\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n 14-19.9kg\n \n \n \n \n onOrBefore\n ${endDate}\n \n \n value2\n 20.0\n \n \n value1\n 14.0\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n 20-24.9kg\n \n \n \n \n onOrBefore\n ${endDate}\n \n \n value2\n 25.0\n \n \n value1\n 20.0\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n 25-34.9kg\n \n \n \n \n onOrBefore\n ${endDate}\n \n \n value2\n 35.0\n \n \n value1\n 25.0\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n 35+kg\n \n \n \n \n onOrBefore\n ${endDate}\n \n \n value2\n 100.0\n \n \n value1\n 35.0\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n 35pluskg\n \n \n \n \n onOrBefore\n ${}\n \n \n value2\n 70.0\n \n \n value1\n 35.0\n \n \n onOrAfter\n ${}\n \n \n \n \n \n 4-5.9kg\n \n \n \n \n onOrBefore\n ${endDate}\n \n \n value2\n 6.0\n \n \n value1\n 4.0\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n 6-9.9kg\n \n \n \n \n onOrBefore\n ${endDate}\n \n \n value2\n 10.0\n \n \n value1\n 6.0\n \n \n onOrAfter\n ${startDate}\n \n \n \n \n \n','2020-11-16 12:08:00',4,'2020-11-20 12:06:34',4,0,NULL,NULL,NULL,'e74d2f97-2a34-41e4-9ebd-e8ed8430bd7b'),(1010,'Children ARV Regimen_1stLine','Children ARV Regimen_1stLine','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children ARV Regimen_1stLine\n Children ARV Regimen_1stLine\n \n 2020-11-16 11:27:59 UTC\n \n 2020-12-03 12:40:42 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1010\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-11-16 11:27:59',4,'2020-12-03 12:40:42',4,0,NULL,NULL,NULL,'369c2c45-a71a-48e6-bfe8-9edb1b962fe8'),(1011,'4h regimen testing Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4h regimen testing Data Set\n \n 2020-11-16 11:28:17 UTC\n \n 2021-02-04 08:45:06 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1011\n \n \n revised_child_weight\n \n \n \n \n endDate\n ${endDate}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Children_ages\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n 4L0to3.9\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n revised_child_weight\n 0-3.9kg\n \n \n Children_ages\n Children 0to14\n \n \n \n \n \n 4L10to13.9\n \n \n \n \n revised_child_weight\n 10-13.9kg\n \n \n Children_ages\n Children 0to14\n \n \n \n \n \n 4L14to19.9\n \n \n \n \n revised_child_weight\n 14-19.9kg\n \n \n Children_ages\n Children 0to14\n \n \n \n \n \n 4L20to24.9\n \n \n \n \n revised_child_weight\n 20-24.9kg\n \n \n Children_ages\n Children 0to14\n \n \n \n \n \n 4L25to34.9\n \n \n \n \n revised_child_weight\n 25-34.9kg\n \n \n Children_ages\n Children 0to14\n \n \n \n \n \n 4L35plus\n \n \n \n \n revised_child_weight\n 35pluskg\n \n \n Children_ages\n Children 0to14\n \n \n \n \n \n 4L4to5.9\n \n \n \n \n revised_child_weight\n 4-5.9kg\n \n \n Children_ages\n Children 0to14\n \n \n \n \n \n 4L6to9.9\n \n \n \n \n revised_child_weight\n 6-9.9kg\n \n \n Children_ages\n Children 0to14\n \n \n \n \n \n 4c0to3.9\n \n \n \n \n \n \n \n \n \n 4c10to13.9\n \n \n \n \n \n \n 4c14to19.9\n \n \n \n \n \n \n 4c20to24.9\n \n \n \n \n \n \n 4c25to34.9\n \n \n \n \n \n \n 4c35plus\n \n \n \n \n \n \n 4c4to5.9\n \n \n \n \n \n \n 4c6to9.9\n \n \n \n \n \n \n 4d03to3.9\n \n \n \n \n \n \n \n \n \n 4d10to13.9\n \n \n \n \n \n \n 4d14to19.9\n \n \n \n \n \n \n 4d20to24.9\n \n \n \n \n \n \n 4d25to34.9\n \n \n \n \n \n \n 4d35plus\n \n \n \n \n \n \n 4d4to5.9\n \n \n \n \n \n \n 4d6to9.9\n \n \n \n \n \n \n 4e03to3.9\n \n \n \n \n \n \n \n \n \n 4e10to13.9\n \n \n \n \n \n \n 4e14to19.9\n \n \n \n \n \n \n 4e20to24.9\n \n \n \n \n \n \n 4e25to34.9\n \n \n \n \n \n \n 4e35plus\n \n \n \n \n \n \n 4e4to5.9\n \n \n \n \n \n \n 4e6to9.9\n \n \n \n \n \n \n 4f0to3.9\n \n \n \n \n \n \n \n \n \n 4f10to13.9\n \n \n \n \n \n \n 4f14to19.9\n \n \n \n \n \n \n 4f20to24.9\n \n \n \n \n \n \n 4f25to34.9\n \n \n \n \n \n \n 4f35plus\n \n \n \n \n \n \n 4f4to5.9\n \n \n \n \n \n \n 4f6to9.9\n \n \n \n \n \n \n 4g0to3.9\n \n \n \n \n \n \n \n \n \n 4g10to13.9\n \n \n \n \n \n \n 4g14to19.9\n \n \n \n \n \n \n 4g20to24.9\n \n \n \n \n \n \n 4g25to34.9\n \n \n \n \n \n \n 4g35plus\n \n \n \n \n \n \n 4g4to5.9\n \n \n \n \n \n \n 4g6to9.9\n \n \n \n \n \n \n 4h0to3.9\n \n \n \n \n \n \n \n \n \n 4h10to13.9\n \n \n \n \n \n \n 4h14to19.9\n \n \n \n \n \n \n 4h20to24.9\n \n \n \n \n \n \n 4h25to34.9\n \n \n \n \n \n \n 4h35plus\n \n \n \n \n \n \n 4h4to5.9\n \n \n \n \n \n \n 4h6to9.9\n \n \n \n \n \n \n 4j0to3.9\n \n \n \n \n \n \n \n \n \n 4j10to13.9\n \n \n \n \n \n \n 4j14to19.9\n \n \n \n \n \n \n 4j20to24.9\n \n \n \n \n \n \n 4j25to34.9\n \n \n \n \n \n \n 4j35plus\n \n \n \n \n \n \n 4j4to5.9\n \n \n \n \n \n \n 4j6to9.9\n \n \n \n \n \n \n 4k0to3.9\n \n \n \n \n \n \n \n \n \n 4k10to13.9\n \n \n \n \n \n \n 4k14to19.9\n \n \n \n \n \n \n 4k20to24.9\n \n \n \n \n \n \n 4k25to34.9\n \n \n \n \n \n \n 4k35plus\n \n \n \n \n \n \n 4k4to5.9\n \n \n \n \n \n \n 4k6to9.9\n \n \n \n \n \n \n','2020-11-16 11:28:17',4,'2021-02-04 08:45:06',4,0,NULL,NULL,NULL,'017e9c81-7e67-4b81-b9ac-9953c2d93f4b'),(1013,'4h regimen testing Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n 4h regimen testing Data Set\n \n 2020-11-16 11:29:47 UTC\n \n 2020-11-23 16:20:12 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1013\n \n \n revised_child_weight\n \n \n \n \n endDate\n ${endDate}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n \n \n 4L0to3.9\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n revised_child_weight\n 0-3.9kg\n \n \n \n \n \n 4L10to13.9\n \n \n \n \n revised_child_weight\n 10-13.9kg\n \n \n \n \n \n 4L14to19.9\n \n \n \n \n revised_child_weight\n 14-19.9kg\n \n \n \n \n \n 4L20to24.9\n \n \n \n \n revised_child_weight\n 20-24.9kg\n \n \n \n \n \n 4L25to34.9\n \n \n \n \n revised_child_weight\n 25-34.9kg\n \n \n \n \n \n 4L35+kg\n \n \n \n \n revised_child_weight\n 35+kg\n \n \n \n \n \n 4L4to5.9\n \n \n \n \n revised_child_weight\n 4-5.9kg\n \n \n \n \n \n 4L6to9.9\n \n \n \n \n revised_child_weight\n 6-9.9kg\n \n \n \n \n \n 4c0to3.9\n \n \n \n \n \n \n \n \n \n 4c10to13.9\n \n \n \n \n \n \n 4c14to19.9\n \n \n \n \n \n \n 4c20to24.9\n \n \n \n \n \n \n 4c25to34.9\n \n \n \n \n \n \n 4c35+kg\n \n \n \n \n \n \n 4c4to5.9\n \n \n \n \n \n \n 4c6to9.9\n \n \n \n \n \n \n 4d0to3.9\n \n \n \n \n \n \n \n \n \n 4d10to13.9\n \n \n \n \n \n \n 4d14to19.9\n \n \n \n \n \n \n 4d20to24.9\n \n \n \n \n \n \n 4d25to34.9\n \n \n \n \n \n \n 4d35+kg\n \n \n \n \n \n \n 4d4to5.9\n \n \n \n \n \n \n 4d6to9.9\n \n \n \n \n \n \n 4e03to3.9\n \n \n \n \n \n \n \n \n \n 4e10to13.9\n \n \n \n \n \n \n 4e14to19.9\n \n \n \n \n \n \n 4e20to24.9\n \n \n \n \n \n \n 4e25to34.9\n \n \n \n \n \n \n 4e35+kg\n \n \n \n \n \n \n 4e4to5.9\n \n \n \n \n \n \n 4e6to9.9\n \n \n \n \n \n \n 4f0to3.9\n \n \n \n \n \n \n \n \n \n 4f10to13.9\n \n \n \n \n \n \n 4f14to19.9\n \n \n \n \n \n \n 4f20to24.9\n \n \n \n \n \n \n 4f25to34.9\n \n \n \n \n \n \n 4f35+kg\n \n \n \n \n \n \n 4f4to5.9\n \n \n \n \n \n \n 4f6to9.9\n \n \n \n \n \n \n 4g0to3.9\n \n \n \n \n \n \n \n \n \n 4g10to13.9\n \n \n \n \n \n \n 4g14to19.9\n \n \n \n \n \n \n 4g20to24.9\n \n \n \n \n \n \n 4g25to34.9\n \n \n \n \n \n \n 4g35+kg\n \n \n \n \n \n \n 4g4to5.9\n \n \n \n \n \n \n 4g6to9.9\n \n \n \n \n \n \n 4h0to3.9\n \n \n \n \n \n \n \n \n \n 4h10to13.9\n \n \n \n \n \n \n 4h14to19.9\n \n \n \n \n \n \n 4h20to24.9\n \n \n \n \n \n \n 4h25to34.9\n \n \n \n \n \n \n 4h35+kg\n \n \n \n \n \n \n 4h4to5.9\n \n \n \n \n \n \n 4h6to9.9\n \n \n \n \n \n \n 4j0to3.9\n \n \n \n \n \n \n \n \n \n 4j10to13.9\n \n \n \n \n \n \n 4j14to19.9\n \n \n \n \n \n \n 4j20to24.9\n \n \n \n \n \n \n 4j25to34.9\n \n \n \n \n \n \n 4j35+kg\n \n \n \n \n \n \n 4j4to5.9\n \n \n \n \n \n \n \n \n \n 4j6to9.9\n \n \n \n \n \n \n 4k0to3.9\n \n \n \n \n \n \n 4k10to13.9\n \n \n \n \n \n \n 4k14to19.9\n \n \n \n \n \n \n 4k20to24.9\n \n \n \n \n \n \n 4k25to34.9\n \n \n \n \n \n \n 4k35+kg\n \n \n \n \n \n \n 4k4to5.9\n \n \n \n \n \n \n 4k6to9.9\n \n \n \n \n \n \n','2020-11-16 13:29:47',4,'2020-11-23 18:20:12',4,0,NULL,NULL,NULL,'9f1d2576-51cf-452c-ab0f-b68c0cb2289f'),(1014,'adult_arv_2r_1mnth',' 1month supply of 2r','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2r_1mnth\n 1month supply of 2r\n \n 2020-11-20 11:48:38 UTC\n \n 2020-11-20 11:49:10 UTC\n \n \n location\n \n java.lang.String\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 1014\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4850 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-11-20 13:48:38',4,'2020-11-20 13:49:10',4,0,NULL,NULL,NULL,'fb71139e-a156-4964-a304-f80360ba200b'),(1015,'adult_arv_2r_3mnth','3mnths supply of 2r','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2r_3mnth\n 3mnths supply of 2r\n \n 2020-11-20 11:50:29 UTC\n \n 2020-12-02 19:51:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1015\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4850 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-11-20 11:50:29',4,'2020-12-02 19:51:13',4,0,NULL,NULL,NULL,'8f18aeea-7884-4a10-9d05-85ae3c160bd0'),(1016,'Clients given 3 months supply 2r','None','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2r\n None\n \n 2020-11-20 11:52:23 UTC\n \n 2021-07-14 08:22:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1016\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4850)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-11-20 11:52:23',4,'2021-07-14 08:22:25',4,0,NULL,NULL,NULL,'80905b89-7a28-4cda-a44b-25b0a291211d'),(1017,'Clients given 6 months supply 2r','None','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2r\n None\n \n 2020-11-20 11:55:09 UTC\n \n 2021-01-26 19:36:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1017\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4850) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 4850) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4850) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4850) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4850) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4850) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 4850 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-11-20 11:55:09',4,'2021-01-26 19:36:05',4,0,NULL,NULL,NULL,'f81d3821-0b33-4721-8548-09089e951a1e'),(1018,'Clients given Other months MMD supply 2r','None','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2r\n None\n \n 2020-11-20 11:57:01 UTC\n \n 2021-07-24 23:08:16 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1018\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4850)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-11-20 11:57:01',4,'2021-07-24 23:08:16',4,0,NULL,NULL,NULL,'ae3c1ee8-0e33-49bb-8c7f-2492ddd244da'),(1019,'Clients newly initiated 2r','None','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2r\n None\n \n 2020-11-20 12:01:14 UTC\n \n 2021-01-27 15:10:26 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1019\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4850 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-11-20 12:01:14',4,'2021-01-27 15:10:26',4,0,NULL,NULL,NULL,'14abb047-bc53-4d1f-bee5-7c4112dad68d'),(1020,'Clients seen given 1 month supply 2r','None','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2r\n None\n \n 2020-11-20 12:03:07 UTC\n \n 2021-07-13 14:24:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1020\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4850)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-11-20 12:03:07',4,'2021-07-13 14:24:13',4,0,NULL,NULL,NULL,'e4c0b8ee-d729-49d9-b05d-3af1aed9fe08'),(1021,'CMP_ART Regimen 1month supply 2r',' 1mnth 2r','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2r\n 1mnth 2r\n \n 2020-11-20 12:06:02 UTC\n \n 2020-12-03 10:49:43 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1021\n Clients-seen-given-1-month-supply-2r OR Clients-newly-initiated-2r\n \n \n Clients-seen-given-1-month-supply-2r\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-newly-initiated-2r\n \n \n \n \n \n \n','2020-11-20 12:06:02',4,'2020-12-03 10:49:43',4,0,NULL,NULL,NULL,'5dc2d400-2d6f-4d68-bbdd-58f969efdee9'),(1022,'adult_arv_2s_1mnth',' 1month supply of 2s','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2s_1mnth\n 1month supply of 2s\n \n 2020-11-23 16:01:14 UTC\n \n 2020-11-23 16:01:33 UTC\n \n \n location\n \n java.lang.String\n true\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n 1022\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4851 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4175)\n','2020-11-23 18:01:14',4,'2020-11-23 18:01:33',4,0,NULL,NULL,NULL,'41b5c235-8f68-4765-9cb7-3052079b1e52'),(1023,'adult_arv_2s_3mnth',' 3mnths supply of 2s','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2s_3mnth\n 3mnths supply of 2s\n \n 2020-11-23 16:07:24 UTC\n \n 2020-12-02 19:56:27 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1023\n select distinct o.person_id \nfrom obs o \ninner join location l on o.location_id = l.location_id \nINNER JOIN person ON person.person_id = o.person_id \nwhere (o.location_id =:location or parent_location =:location) \nAND o.voided = 0 \nand o.person_id in (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 2250 and value_coded = 4851 \n ) \nand o.person_id in \n (select o.person_id \n from obs o \n where obs_datetime BETWEEN :startDate AND :endDate \n and concept_id = 4174 and value_coded = 4177 \n)\n','2020-11-23 16:07:24',4,'2020-12-02 19:56:27',4,0,NULL,NULL,NULL,'e75199de-2b55-458d-ae92-fe19aae857bb'),(1024,'Clients given 3 months supply 2s','None','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2s\n None\n \n 2020-11-23 16:08:20 UTC\n \n 2021-07-14 08:22:56 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1024\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4851)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-11-23 16:08:20',4,'2021-07-14 08:22:56',4,0,NULL,NULL,NULL,'b83fd0d2-7016-453c-8f4d-a5ab08ec00b0'),(1025,'Clients given 6 months supply 2s','None','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2s\n None\n \n 2020-11-23 16:09:50 UTC\n \n 2021-01-26 19:35:14 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1025\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4851) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 4851) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4851) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4851) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4851) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4851) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 4851 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-11-23 16:09:50',4,'2021-01-26 19:35:14',4,0,NULL,NULL,NULL,'5de7880b-4de6-4770-923d-dc53c71bdd11'),(1026,'Clients given Other months MMD supply 2s','None','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given Other months MMD supply 2s\n None\n \n 2020-11-23 16:12:53 UTC\n \n 2021-07-24 23:11:30 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1026\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4851)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 56 AND datediff(latest_follow_up, max_observation)< 84 \n OR datediff(latest_follow_up, max_observation) >= 112 \n )as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-11-23 16:12:53',4,'2021-07-24 23:11:30',4,0,NULL,NULL,NULL,'9026be35-1eaf-4a05-aba3-c2dfffa9061e'),(1027,'Clients newly initiated 2s','None','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2s\n None\n \n 2020-11-23 16:14:46 UTC\n \n 2021-01-27 15:11:07 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1027\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 4851 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-11-23 16:14:46',4,'2021-01-27 15:11:07',4,0,NULL,NULL,NULL,'36ca3e4d-651f-4209-b140-480752765843'),(1028,'Clients seen given 1 month supply 2s','None','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2s\n None\n \n 2020-11-23 16:16:24 UTC\n \n 2021-07-13 14:24:49 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1028\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 4851)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-11-23 16:16:24',4,'2021-07-13 14:24:49',4,0,NULL,NULL,NULL,'48fdb859-4147-457e-8af6-3e2bf0ca1a0c'),(1029,'CMP_ART Regimen 1month supply 2s','1mnth 2s','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2s\n 1mnth 2s\n \n 2020-11-23 16:18:09 UTC\n \n 2020-11-23 16:34:51 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1029\n Clients-seen-given-1-month-supply-2s OR Clients-newly-initiated-2s\n \n \n Clients-newly-initiated-2s\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-2s\n \n \n \n \n \n \n','2020-11-23 18:18:09',4,'2020-11-23 18:34:51',4,0,NULL,NULL,NULL,'a6720665-3d0b-4b70-b463-fb8c9e567d64'),(1030,'Clients given 3 months supply other ','other regimen supplied','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply other \n other regimen supplied\n \n 2020-11-30 21:17:21 UTC\n \n 2021-06-30 10:45:45 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1030\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n (Select Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n AND o.person_id not in ( \n select distinct os.person_id from obs os \n where os.concept_id = 3634 \n AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n ) AS Newly_Initiated_ART_Clients) \n \nUNION \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct patient.patient_id AS Id \n from obs o \n -- CLIENTS SEEN ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND patient.voided = 0 AND o.voided = 0 \n \n ) \nAND Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2143)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-11-30 21:17:21',4,'2021-06-30 10:45:45',4,0,NULL,NULL,NULL,'c28adf82-c0fb-446c-b3c2-101d4d4f146e'),(1031,'Clients given 3 months supply 2i','3mnths of 2i regimen','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 2i\n 3mnths of 2i regimen\n \n 2020-11-30 21:18:46 UTC\n \n 2021-07-14 08:17:08 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1031\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- Picking Followup Date from Latest Followup Form \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3678)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 84 AND datediff(latest_follow_up, max_observation)< 112)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-11-30 21:18:46',4,'2021-07-14 08:17:08',4,0,NULL,NULL,NULL,'092b1af7-5dca-4b33-8a3f-98700da3548b'),(1036,'Clients given 3 months supply 3e','3mnths of 3e','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 3e\n 3mnths of 3e\n \n 2020-11-30 21:27:28 UTC\n \n 2021-01-26 17:40:25 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1036\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4707) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4707) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 4707) \n \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 4707 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-11-30 21:27:28',4,'2021-01-26 17:40:25',4,0,NULL,NULL,NULL,'b757ed79-c1de-4d4e-9d6d-c78202a81a4d'),(1037,'Clients given 3 months supply 3f','3mnths of 3f','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 3f\n 3mnths of 3f\n \n 2020-11-30 21:28:58 UTC\n \n 2021-01-26 17:42:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1037\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4708) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4708) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 4708) \n \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 4708 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-11-30 21:28:58',4,'2021-01-26 17:42:35',4,0,NULL,NULL,NULL,'34ca96df-ff64-4c2a-9ee3-6b25a5473382'),(1038,'Clients given 3 months supply 3g','3months of 3g','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 3g\n 3months of 3g\n \n 2020-11-30 21:30:47 UTC\n \n 2021-01-26 17:44:05 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1038\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4709) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4709) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 4709) \n \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 4709 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2020-11-30 21:30:47',4,'2021-01-26 17:44:05',4,0,NULL,NULL,NULL,'55dead5b-5fa0-434e-90df-16ff7a6923fb'),(1040,'Children ARV Regimen_2ndLine','2ndLine 0 to 14yrs','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children ARV Regimen_2ndLine\n 2ndLine 0 to 14yrs\n \n 2020-12-01 10:58:27 UTC\n \n 2020-12-01 12:40:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1040\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-12-01 12:58:27',4,'2020-12-01 14:40:44',4,0,NULL,NULL,NULL,'05a35dc8-35a8-4594-9194-0d4b6dd486d0'),(1041,'Children ARV Regimen_3rdLine Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children ARV Regimen_3rdLine Data Set\n \n 2020-12-01 10:58:32 UTC\n \n 2020-12-01 12:01:44 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1041\n \n \n revised_child_weight\n \n \n \n \n endDate\n ${endDate}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n 5a03to3.9\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n revised_child_weight\n 0-3.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 5a04to5.9\n \n \n \n \n revised_child_weight\n 4-5.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 5a06to9.9\n \n \n \n \n revised_child_weight\n 6-9.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 5a10to13.9\n \n \n \n \n revised_child_weight\n 10-13.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 5a14to19.9\n \n \n \n \n revised_child_weight\n 14-19.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 5a20to24.9\n \n \n \n \n revised_child_weight\n 20-24.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 5a25to34.9\n \n \n \n \n revised_child_weight\n 25-34.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 5a35Plus\n \n \n \n \n revised_child_weight\n 35pluskg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 5b03to3.9\n \n \n \n \n \n \n \n \n \n 5b04to5.9\n \n \n \n \n \n \n 5b06to9.9\n \n \n \n \n \n \n 5b10to13.9\n \n \n \n \n \n \n 5b14to19.9\n \n \n \n \n \n \n 5b20to24.9\n \n \n \n \n \n \n 5b25to34.9\n \n \n \n \n \n \n 5b35Plus\n \n \n \n \n \n \n 5c03to3.9\n \n \n \n \n \n \n \n \n \n 5c04to5.9\n \n \n \n \n \n \n 5c06to9.9\n \n \n \n \n \n \n 5c10to13.9\n \n \n \n \n \n \n 5c14to19.9\n \n \n \n \n \n \n 5c20to24.9\n \n \n \n \n \n \n 5c25to34.9\n \n \n \n \n \n \n 5cPlus\n \n \n \n \n \n \n 5d03to3.9\n \n \n \n \n \n \n \n \n \n 5d04to5.9\n \n \n \n \n \n \n 5d06to9.9\n \n \n \n \n \n \n 5d10to13.9\n \n \n \n \n \n \n 5d14to19.9\n \n \n \n \n \n \n 5d20to24.9\n \n \n \n \n \n \n 5d25to34.9\n \n \n \n \n \n \n 5d35Plus\n \n \n \n \n \n \n 5e03to3.9\n \n \n \n \n \n \n \n \n \n 5e04to5.9\n \n \n \n \n \n \n 5e06to9.9\n \n \n \n \n \n \n 5e10to13.9\n \n \n \n \n \n \n 5e14to19.9\n \n \n \n \n \n \n 5e20to24.9\n \n \n \n \n \n \n 5e25to34.9\n \n \n \n \n \n \n 5e35Plus\n \n \n \n \n \n \n 5f03to3.9\n \n \n \n \n \n \n \n \n \n 5f04to5.9\n \n \n \n \n \n \n 5f06to9.9\n \n \n \n \n \n \n 5f10to13.9\n \n \n \n \n \n \n 5f14to19.9\n \n \n \n \n \n \n 5f20to24.9\n \n \n \n \n \n \n 5f25to34.9\n \n \n \n \n \n \n 5f35Plus\n \n \n \n \n \n \n 5g00to3.9\n \n \n \n \n \n \n \n \n \n 5g04to5.9\n \n \n \n \n \n \n 5g06to9.9\n \n \n \n \n \n \n 5g10to13.9\n \n \n \n \n \n \n 5g14to19.9\n \n \n \n \n \n \n 5g20to24.9\n \n \n \n \n \n \n 5g25to34.9\n \n \n \n \n \n \n 5g35Plus\n \n \n \n \n \n \n 5h00to3.9\n \n \n \n \n \n \n \n \n \n 5h04to5.9\n \n \n \n \n \n \n 5h06to9.9\n \n \n \n \n \n \n 5h10to13.9\n \n \n \n \n \n \n 5h14to19.9\n \n \n \n \n \n \n 5h20to24.9\n \n \n \n \n \n \n 5h25to34.9\n \n \n \n \n \n \n 5h35Plus\n \n \n \n \n \n \n','2020-12-01 12:58:32',4,'2020-12-01 14:01:44',4,0,NULL,NULL,NULL,'4af0c854-1dce-4ef5-a7cd-5317a534c373'),(1042,'Children ARV Regimen_3rdLine','3rdLine 0 to 14yrs','org.openmrs.module.reporting.report.definition.ReportDefinition','org.openmrs.module.reporting.report.definition.PeriodIndicatorReportDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children ARV Regimen_3rdLine\n 3rdLine 0 to 14yrs\n \n 2020-12-01 12:42:12 UTC\n \n 2020-12-01 12:42:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1042\n \n \n defaultDataSet\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n','2020-12-01 14:42:12',4,'2020-12-01 14:42:17',4,0,NULL,NULL,NULL,'80ef520c-2d58-473a-a588-58b182a4dbcb'),(1043,'Children ARV Regimen_3rdLine Data Set',NULL,'org.openmrs.module.reporting.dataset.definition.DataSetDefinition','org.openmrs.module.reporting.dataset.definition.CohortIndicatorDataSetDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Children ARV Regimen_3rdLine Data Set\n \n 2020-12-01 12:42:17 UTC\n \n 2020-12-01 13:34:47 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1043\n \n \n revised_child_weight\n \n \n \n \n endDate\n ${endDate}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n DM_Age\n \n \n \n \n endDate\n ${endDate}\n \n \n \n \n \n \n \n 6a03to3.9\n \n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n revised_child_weight\n 0-3.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 6a04to5.9\n \n \n \n \n revised_child_weight\n 4-5.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 6a06to9.9\n \n \n \n \n revised_child_weight\n 6-9.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 6a10to13.9\n \n \n \n \n revised_child_weight\n 10-13.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 6a14to19.9\n \n \n \n \n revised_child_weight\n 14-19.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 6a20to24.9\n \n \n \n \n revised_child_weight\n 20-24.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 6a25to34.9\n \n \n \n \n revised_child_weight\n 25-34.9kg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 6a35kgPlus\n \n \n \n \n revised_child_weight\n 35pluskg\n \n \n DM_Age\n Children 0to14\n \n \n \n \n \n 6b00to3.9\n \n \n \n \n \n \n \n \n \n 6b04to5.9\n \n \n \n \n \n \n 6b06to9.9\n \n \n \n \n \n \n 6b10to13.9\n \n \n \n \n \n \n 6b14to19.9\n \n \n \n \n \n \n 6b20to24.9\n \n \n \n \n \n \n 6b25to34.9\n \n \n \n \n \n \n 6b35kgPlus\n \n \n \n \n \n \n 6c00to3.9\n \n \n \n \n \n \n \n \n \n 6c04to5.9\n \n \n \n \n \n \n 6c06to9.9\n \n \n \n \n \n \n 6c10to13.9\n \n \n \n \n \n \n 6c14to19.9\n \n \n \n \n \n \n 6c20to24.9\n \n \n \n \n \n \n 6c25to34.9\n \n \n \n \n \n \n 6c35kgPlus\n \n \n \n \n \n \n 6d00to3.9\n \n \n \n \n \n \n \n \n \n 6d04to5.9\n \n \n \n \n \n \n 6d06to9.9\n \n \n \n \n \n \n 6d10to13.9\n \n \n \n \n \n \n 6d14to19.9\n \n \n \n \n \n \n 6d20to24.9\n \n \n \n \n \n \n 6d25to34.9\n \n \n \n \n \n \n 6d35kgPlus\n \n \n \n \n \n \n 6e00to3.9\n \n \n \n \n \n \n \n \n \n 6e04to5.9\n \n \n \n \n \n \n 6e06to9.9\n \n \n \n \n \n \n 6e10to13.9\n \n \n \n \n \n \n 6e14to19.9\n \n \n \n \n \n \n 6e20to24.9\n \n \n \n \n \n \n 6e25to34.9\n \n \n \n \n \n \n 6e35kgPlus\n \n \n \n \n \n \n 6f00to3.9\n \n \n \n \n \n \n \n \n \n 6f04to5.9\n \n \n \n \n \n \n 6f06to9.9\n \n \n \n \n \n \n 6f10to13.9\n \n \n \n \n \n \n 6f14to19.9\n \n \n \n \n \n \n 6f20to24.9\n \n \n \n \n \n \n 6f25to34.9\n \n \n \n \n \n \n 6f35kgPlus\n \n \n \n \n \n \n','2020-12-01 14:42:17',4,'2020-12-01 15:34:47',4,0,NULL,NULL,NULL,'6ef48774-47bc-4e3e-af6c-6a2b8d77c151'),(1044,'adult_arv_2r_1mnth','adult_arv_2r_1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2r_1mnth\n adult_arv_2r_1mnth\n \n 2020-12-02 17:17:57 UTC\n \n 2021-07-13 14:48:20 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1044\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-12-02 17:17:57',4,'2021-07-13 14:48:20',4,0,NULL,NULL,NULL,'28807ad7-020c-4261-84e8-960017de0d3c'),(1045,'adult_arv_2s_3mnths','adult_arv_2s_3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2s_3mnths\n adult_arv_2s_3mnths\n \n 2020-12-02 17:26:50 UTC\n \n 2020-12-02 20:24:28 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1045\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-12-02 17:26:50',4,'2020-12-02 20:24:28',4,0,NULL,NULL,NULL,'9508f75e-01d6-4fac-a9ef-701b6306f4e5'),(1046,'adult_arv_2r_3mnths','adult_arv_2r_3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2r_3mnths\n adult_arv_2r_3mnths\n \n 2020-12-02 17:31:00 UTC\n \n 2020-12-02 20:20:01 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1046\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-12-02 17:31:00',4,'2020-12-02 20:20:01',4,0,NULL,NULL,NULL,'bcbafe45-287a-4341-8144-75a99f00c1e3'),(1047,'adult_arv_2s_1mnth','adult_arv_2s_1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2s_1mnth\n adult_arv_2s_1mnth\n \n 2020-12-02 20:45:08 UTC\n \n 2021-07-13 14:48:35 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1047\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-12-02 20:45:08',4,'2021-07-13 14:48:35',4,0,NULL,NULL,NULL,'2de0ce41-df04-42e8-a72d-64902cad4a98'),(1048,'CMP_ART Regimen 1month supply 2i','CMP_ART Regimen 1month supply 2i','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n CMP_ART Regimen 1month supply 2i\n CMP_ART Regimen 1month supply 2i\n \n 2020-12-02 20:46:49 UTC\n \n 2020-12-03 10:49:09 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1048\n Clients-newly-initiated-2i OR Clients-seen-given-1-month-supply-2i\n \n \n Clients-newly-initiated-2i\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n \n \n Clients-seen-given-1-month-supply-2i\n \n \n \n \n \n \n','2020-12-02 20:46:49',4,'2020-12-03 10:49:09',4,0,NULL,NULL,NULL,'591d048c-3a90-49ac-837e-e10439b8fe82'),(1049,'Clients newly initiated 2i','Clients newly initiated 2i','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients newly initiated 2i\n Clients newly initiated 2i\n \n 2020-12-02 20:51:46 UTC\n \n 2021-01-27 14:58:29 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1049\n select distinct o.person_id \nfrom obs o \n inner join location l on o.location_id = l.location_id \n INNER JOIN person ON person.person_id = o.person_id \n \nwhere (o.location_id =:location or parent_location =:location) \n AND o.concept_id = 2249 \n AND MONTH(o.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND o.voided = 0 \n \nand o.person_id in( \n select os.person_id \n from obs os \n -- All patients given x regimen during a particular period \n where os.concept_id = 2250 and os.value_coded = 3678 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \n \nand o.person_id not in ( -- remove transfer ins \n select os.person_id \n from obs os \n where os.concept_id = 3634 AND os.value_coded = 2095 \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n) \nAND person.voided = 0 \n\n','2020-12-02 20:51:46',4,'2021-01-27 14:58:29',4,0,NULL,NULL,NULL,'3c150559-79b5-49ac-890c-9d5f7a3a20fd'),(1050,'Clients seen given 1 month supply 2i','Clients seen given 1 month supply 2i','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply 2i\n Clients seen given 1 month supply 2i\n \n 2020-12-02 20:54:19 UTC\n \n 2021-07-13 14:18:04 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1050\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 3678)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2020-12-02 20:54:19',4,'2021-07-13 14:18:04',4,0,NULL,NULL,NULL,'baa39d83-3d61-46a8-9c06-28b1090d3b8f'),(1051,'adult_arv_2i_3mnths','adult_arv_2i_3mnths','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2i_3mnths\n adult_arv_2i_3mnths\n \n 2020-12-02 20:58:18 UTC\n \n 2020-12-02 21:01:13 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1051\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-12-02 20:58:18',4,'2020-12-02 21:01:13',4,0,NULL,NULL,NULL,'417c4ce0-cb54-449e-ac98-8fc8e138f03d'),(1052,'adult_arv_2i_1mnth','adult_arv_2i_1mnth','org.openmrs.module.reporting.indicator.Indicator','org.openmrs.module.reporting.indicator.CohortIndicator','org.openmrs.module.reporting.serializer.ReportingSerializer','\n adult_arv_2i_1mnth\n adult_arv_2i_1mnth\n \n 2020-12-02 21:01:50 UTC\n \n 2021-07-13 14:37:11 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1052\n COUNT\n \n \n \n \n endDate\n ${endDate}\n \n \n location\n ${location}\n \n \n startDate\n ${startDate}\n \n \n \n','2020-12-02 21:01:50',4,'2021-07-13 14:37:12',4,0,NULL,NULL,NULL,'2e956343-8dfb-46c3-94a6-c9c6f83959a6'),(1053,'Clients given 3 months supply 3a','Clients given 3 months supply 3a','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 3a\n Clients given 3 months supply 3a\n \n 2021-01-26 17:32:43 UTC\n \n 2021-01-26 17:33:19 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1053\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3683) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3683) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 3683) \n \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 3683 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2021-01-26 17:32:43',4,'2021-01-26 17:33:19',4,0,NULL,NULL,NULL,'bb3bfcea-7bf4-40ff-8e51-c02125d9ed36'),(1054,'Clients given 3 months supply 3b','3mnths 3b','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 3b\n 3mnths 3b\n \n 2021-01-26 17:35:11 UTC\n \n 2021-01-26 17:35:48 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1054\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3684) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3684) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 3684) \n \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 3684 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2021-01-26 17:35:11',4,'2021-01-26 17:35:48',4,0,NULL,NULL,NULL,'c961ad65-091a-4ef3-b3df-93795215d394'),(1055,'Clients given 3 months supply 3c','3mnths 3c','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 3c\n 3mnths 3c\n \n 2021-01-26 17:36:24 UTC\n \n 2021-01-26 17:36:53 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1055\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3685) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3685) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 3685) \n \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 3685 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2021-01-26 17:36:24',4,'2021-01-26 17:36:53',4,0,NULL,NULL,NULL,'980ee077-7ac1-4380-b636-b5d83e80e128'),(1056,'Clients given 3 months supply 3d','3mnths 3d','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 3d\n 3mnths 3d\n \n 2021-01-26 17:38:04 UTC\n \n 2021-01-26 17:38:37 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1056\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4706) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4706) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 4706) \n \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 4706 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2021-01-26 17:38:04',4,'2021-01-26 17:38:37',4,0,NULL,NULL,NULL,'a5671007-d60d-44f4-8e1c-230aeb2239ec'),(1057,'Clients given 3 months supply 3h','3 months 3h','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 3 months supply 3h\n 3 months 3h\n \n 2021-01-26 17:44:47 UTC\n \n 2021-01-26 17:45:17 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1057\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4177)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 4710) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 4710) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4177)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 4710) \n \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4177 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n )regimen \n WHERE ARV_regimen = 4710 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2021-01-26 17:44:47',4,'2021-01-26 17:45:17',4,0,NULL,NULL,NULL,'2e7c12e2-5224-464a-b8be-3b2fd231a4e1'),(1058,'Clients given 6 months supply 2i','6mnths 2i','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients given 6 months supply 2i\n 6mnths 2i\n \n 2021-01-26 19:06:43 UTC\n \n 2021-01-26 19:07:18 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1058\n select distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT person_id \nFROM( ( \n SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) as ARV_regimen \n FROM \n ( \n select distinct o.person_id,o.value_coded as current_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2250 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )currentreg \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as substitute_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 4284 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )substitutereg ON currentreg.person_id = substitutereg.person_id \n \n LEFT OUTER JOIN \n ( \n select distinct o.person_id,o.value_coded as switch_regimen \n from obs o \n \n inner join \n (select ob.person_id,cast(max(ob.obs_datetime) as date) maxdate \n from obs ob \n where ob.concept_id = 2268 \n AND cast(ob.obs_datetime as date) <= cast(:endDate as date) \n AND MONTH(ob.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(ob.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n and ob.voided = 0 \n group by ob.person_id \n )latest \n on latest.person_id = o.person_id \n \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n INNER JOIN obs os on latest.person_id = os.person_id \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND (os.concept_id = 4174 AND os.value_coded in (4247)) \n AND os.voided = 0 \n and CAST(o.obs_datetime as date) = maxdate \n and CAST(o.obs_datetime AS DATE) = CAST(os.obs_datetime AS DATE) \n and o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE oss.concept_id = 3843 AND oss.value_coded = 3841 OR oss.value_coded = 3842 \n AND MONTH(oss.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND oss.voided = 0 \n ) \n \n AND o.person_id not in ( \n select oss.person_id \n from obs oss \n -- CLIENTS NEWLY INITIATED ON ART \n WHERE (oss.concept_id = 2249 \n AND MONTH(oss.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(oss.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n AND oss.voided = 0) \n )switchreg ON currentreg.person_id = switchreg.person_id \n )regimen \n WHERE ARV_regimen = 3678) \n UNION \n \n (SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -1 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id)regimen \n WHERE ARV_regimen = 3678) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -2 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3678) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -3 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3678) \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -4 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3678) \n \n \nUNION \n \n(SELECT person_id \n FROM( \n SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n (select distinct o.person_id,o.value_coded current_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2250 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n ) \n )currentreg \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 4284 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n (select distinct o.person_id,o.value_coded as switch_regimen \n FROM obs o \n -- CAME IN PREVIOUS 1 MONTH AND WAS GIVEN (2, 3, 4, 5, 6 MONHTS SUPPLY OF DRUGS) \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND o.concept_id = 2268 \n AND o.voided = 0 \n AND o.person_id in ( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -5 MONTH)) \n AND oss.concept_id = 4174 and (oss.value_coded in (4247)) \n ) \n \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n )) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n )regimen \n WHERE ARV_regimen = 3678) \nUNION \n \n(SELECT distinct person_id \nFROM(SELECT currentreg.person_id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM(SELECT o.person_id,o.value_coded as current_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2250 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ))currentreg \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as substitute_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 4284 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n ( \n SELECT o.person_id,o.value_coded as switch_regimen \n FROM obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n AND MONTH(o.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(o.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND o.voided = 0 \n AND o.concept_id = 2268 \n AND o.person_id in( \n SELECT oss.person_id \n FROM obs oss \n WHERE MONTH(oss.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(oss.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND oss.concept_id = 4174 and oss.value_coded = 4247 \n AND oss.person_id in ( \n select distinct os.person_id from obs os \n where \n MONTH(os.obs_datetime) = MONTH(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND YEAR(os.obs_datetime) = YEAR(DATE_ADD(CAST(:endDate AS DATE), INTERVAL -6 MONTH)) \n AND os.concept_id = 3752 AND DATEDIFF(os.value_datetime, CAST(:endDate AS DATE)) BETWEEN 0 AND 28 \n ) \n ) \n \n WHERE o.person_id not in ( \n select distinct(person_id) \n from \n ( \n select os.person_id, cast(max(os.obs_datetime) as date) as latest_visit \n from obs os \n where os.concept_id=3843 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n \n ) as visit \n where CAST(o.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n AND CAST(o.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and latest_visit > CAST(o.obs_datetime AS DATE) \n and latest_visit <= CAST(:endDate AS DATE) \n ) \n )switchreg \n ON switchreg.person_id = currentreg.person_id \n \n \n )regimen \n WHERE ARV_regimen = 3678 \n) \n \n) AS ARTCurrent_PrevMonths \n \nWHERE ARTCurrent_PrevMonths.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, max(oss.value_datetime) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and oss.obs_datetime <= CAST(:endDate AS DATE) \n and oss.obs_datetime > DATE_ADD(CAST(:endDate AS DATE), INTERVAL -7 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(max(os.value_datetime), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and os.obs_datetime <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, max(os.value_datetime) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \nAND ARTCurrent_PrevMonths.person_id not in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n \n)\n','2021-01-26 19:06:43',4,'2021-01-26 19:07:18',4,0,NULL,NULL,NULL,'826fa67b-2ba1-42de-bbc9-fff95007b9fb'),(1059,'Clients seen given 1 month supply other','1 month other','org.openmrs.module.reporting.cohort.definition.CohortDefinition','org.openmrs.module.reporting.cohort.definition.SqlCohortDefinition','org.openmrs.module.reporting.serializer.ReportingSerializer','\n Clients seen given 1 month supply other\n 1 month other\n \n 2021-01-27 06:50:37 UTC\n \n 2021-07-08 14:19:54 UTC\n \n \n startDate\n \n java.util.Date\n true\n \n \n endDate\n \n java.util.Date\n true\n \n \n location\n \n org.openmrs.Location\n true\n \n \n 1059\n \nselect distinct o.person_id \nfrom obs o inner join location l on o.location_id = l.location_id \nwhere (o.location_id = :location or parent_location = :location) \nand o.person_id in \n(SELECT distinct Active_Patients.Id \nFROM \n(( \n \n(SELECT Id \nFROM ( \n \nselect distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS SEEN FOR ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND (o.concept_id = 3843 AND o.value_coded = 3841 OR o.value_coded = 3842) \n AND MONTH(o.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(o.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n AND patient.voided = 0 AND o.voided = 0 \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n) AS Clients_Seen \n \nWHERE Clients_Seen.Id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \nAND Clients_Seen.Id not in \n ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) \n and o.person_id in ( \n -- Death \n select distinct p.person_id \n from person p \n where dead = 1 \n and death_date <= CAST(:endDate AS DATE) \n ) \n ) \n) \n \nUNION \n \n(SELECT Id \n FROM \n (select distinct patient.patient_id AS Id \n \n from obs o \n -- CLIENTS NEWLY INITIATED ON ART \n INNER JOIN patient ON o.person_id = patient.patient_id \n AND o.person_id in ( \n \n select active_clients.person_id \n from \n (select B.person_id, B.obs_group_id, B.value_datetime AS latest_follow_up \n from obs B \n inner join \n (select person_id, max(obs_datetime), SUBSTRING(MAX(CONCAT(obs_datetime, obs_id)), 20) AS observation_id \n from obs where concept_id = 3753 \n and obs_datetime <= cast(:endDate as date) \n group by person_id) as A \n on A.observation_id = B.obs_group_id \n where concept_id = 3752 \n and A.observation_id = B.obs_group_id \n ) as active_clients \n where active_clients.latest_follow_up >= cast(:endDate as date) \n \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where (os.concept_id = 3843 AND os.value_coded = 3841 OR os.value_coded = 3842) \n AND MONTH(os.obs_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.obs_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct os.person_id \n from obs os \n where concept_id = 2249 \n AND MONTH(os.value_datetime) = MONTH(CAST(:endDate AS DATE)) \n AND YEAR(os.value_datetime) = YEAR(CAST(:endDate AS DATE)) \n ) \n \n and active_clients.person_id not in ( \n select distinct(o.person_id) \n from obs o \n where o.person_id in ( \n -- FOLLOW UPS \n select firstquery.person_id \n from \n ( \n select oss.person_id, SUBSTRING(MAX(CONCAT(oss.value_datetime, oss.obs_id)), 20) AS observation_id, CAST(max(oss.value_datetime) AS DATE) as latest_followup_obs \n from obs oss \n where oss.voided=0 \n and oss.concept_id=3752 \n and CAST(oss.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n and CAST(oss.obs_datetime AS DATE) >= DATE_ADD(CAST(:endDate AS DATE), INTERVAL -13 MONTH) \n group by oss.person_id) firstquery \n inner join ( \n select os.person_id,datediff(CAST(max(os.value_datetime) AS DATE), CAST(:endDate AS DATE)) as last_ap \n from obs os \n where concept_id = 3752 \n and CAST(os.obs_datetime AS DATE) <= CAST(:endDate AS DATE) \n group by os.person_id \n having last_ap < 0 \n ) secondquery \n on firstquery.person_id = secondquery.person_id \n ) and o.person_id in ( \n -- TOUTS \n select distinct(person_id) \n from \n ( \n select os.person_id, CAST(max(os.value_datetime) AS DATE) as latest_transferout \n from obs os \n where os.concept_id=2266 \n group by os.person_id \n having latest_transferout <= CAST(:endDate AS DATE) \n ) as TOUTS \n ) \n ) \n \n \n and active_clients.person_id not in ( \n select person_id \n from person \n where death_date <= cast(:endDate as date) \n and dead = 1 \n ) \n ) \n \n \n INNER JOIN person ON person.person_id = patient.patient_id AND person.voided = 0 \n INNER JOIN patient_identifier ON patient_identifier.patient_id = person.person_id AND patient_identifier.identifier_type = 3 AND patient_identifier.preferred=1 \n \n ) AS Seen_Previous_ART_Clients \n) \n \n)Active_Patients \n \nINNER JOIN \n \n(SELECT regimen.Id as Id \nFROM \n( SELECT currentreg.person_id as Id,COALESCE(switch_regimen,substitute_regimen,current_regimen) ARV_regimen \n FROM( \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS current_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2250 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as currentreg \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS substitute_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 4284 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as substitutereg \n ON substitutereg.person_id = currentreg.person_id \n \n LEFT OUTER JOIN \n \n \n (select distinct o.person_id, max(o.obs_datetime) as maxdate, SUBSTRING(MAX(CONCAT(o.obs_datetime, o.value_coded)), 20) AS switch_regimen \n from obs o \n INNER JOIN patient_identifier ON patient_identifier.patient_id = o.person_id AND patient_identifier.preferred=1 \n where o.concept_id = 2268 \n AND o.voided = 0 \n and o.obs_datetime <= cast(:endDate as date) \n group by person_id) as switchreg \n ON switchreg.person_id = currentreg.person_id \n ) \n \n )as regimen \n where regimen.ARV_regimen = 2143)Current_Reg \nON Active_Patients.Id = Current_Reg.Id \n \nINNER JOIN \n \n (select Id, latest_follow_up,max_observation \n FROM( \n select a.person_id AS Id, SUBSTRING(MAX(CONCAT(a.obs_datetime, b.value_datetime)), 20) AS latest_follow_up, Max(CAST(a.obs_datetime AS DATE)) as max_observation, \n SUBSTRING(MAX(CONCAT(a.obs_datetime, b.obs_group_id)), 20) as max_obs_group_id \n from obs a, obs b \n where a.person_id = b.person_id \n and a.concept_id = 3753 \n and b.concept_id = 3752 \n and a.obs_id = b.obs_group_id \n and a.obs_datetime <= cast(:endDate as date) \n group by a.person_id)as latest_follow_up_obs \n where datediff(latest_follow_up, max_observation) >= 10 AND datediff(latest_follow_up, max_observation)< 28 \n or datediff(latest_follow_up, max_observation) >= 28 AND datediff(latest_follow_up, max_observation)< 56)as supply_duration \n ON Active_Patients.Id = supply_duration.Id \n \n))\n','2021-01-27 06:50:37',4,'2021-07-08 14:19:54',4,0,NULL,NULL,NULL,'aba0cb73-c297-4fba-b97d-89ac9a7c8003'); @@ -79,4 +79,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-07-20 16:20:18 +-- Dump completed on 2022-07-27 6:47:46