diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/Eri2MonthsCohortQueries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/Eri2MonthsCohortQueries.java index 6445172c51..b287d17edd 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/Eri2MonthsCohortQueries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/Eri2MonthsCohortQueries.java @@ -15,6 +15,8 @@ import org.openmrs.Location; import org.openmrs.module.eptsreports.metadata.HivMetadata; import org.openmrs.module.eptsreports.reporting.library.queries.Eri2MonthsQueries; +import org.openmrs.module.eptsreports.reporting.library.queries.Eri2MonthsQueriesInterface; +import org.openmrs.module.eptsreports.reporting.library.queries.TxNewQueries; import org.openmrs.module.eptsreports.reporting.utils.EptsReportUtils; import org.openmrs.module.reporting.cohort.definition.CohortDefinition; import org.openmrs.module.reporting.cohort.definition.CompositionCohortDefinition; @@ -32,6 +34,8 @@ public class Eri2MonthsCohortQueries { @Autowired private EriCohortQueries eriCohortQueries; + @Autowired private GenericCohortQueries genericCohorts; + /** * C * @@ -121,6 +125,11 @@ public CohortDefinition getPatientsWhoDidNotPickDrugsOnTheirSecondVisit() { return cd; } + public CohortDefinition + getPatientsStartedArtLastMonthWith2PickupsOrConsultationWithin33DaysExcludingDeadAndTransferedOutAndIn() { + return null; + } + /** * Get patients who picked up drugs on their second visit A and B and C and NOt (dead and * tarnsfers) @@ -226,6 +235,7 @@ public CohortDefinition getPatientsWhoInitiatedArtButTransferredOut() { cd.addParameter(new Parameter("cohortEndDate", "Cohort End Date", Date.class)); cd.addParameter(new Parameter("reportingEndDate", "Reporting End Date", Date.class)); cd.addParameter(new Parameter("location", "Location", Location.class)); + cd.addSearch( "initiatedArtAndNotTransferIns", EptsReportUtils.map( @@ -243,4 +253,281 @@ public CohortDefinition getPatientsWhoInitiatedArtButTransferredOut() { cd.setCompositionString("initiatedArtAndNotTransferIns AND transferredOut"); return cd; } + + public CohortDefinition getEri2MonthsCompositionCohort(final String cohortName) { + final CompositionCohortDefinition eri2MonthsCompositionCohort = + new CompositionCohortDefinition(); + + eri2MonthsCompositionCohort.setName(cohortName); + eri2MonthsCompositionCohort.addParameter(new Parameter("startDate", "Start Date", Date.class)); + eri2MonthsCompositionCohort.addParameter(new Parameter("endDate", "End Date", Date.class)); + eri2MonthsCompositionCohort.addParameter(new Parameter("location", "location", Location.class)); + + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + eri2MonthsCompositionCohort.addSearch( + "START-ART-2-MONTHS", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientEnrolledInART2Months", + Eri2MonthsQueriesInterface.QUERY.findPatientsWhoStartArtOneMonth), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "TRANSFERED-IN", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWithAProgramStateMarkedAsTransferedInInAPeriod", + TxNewQueries.QUERY.findPatientsWithAProgramStateMarkedAsTransferedInInAPeriod), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "TRANSFERED-IN-AND-IN-ART-MASTER-CARD", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWhoWhereMarkedAsTransferedInAndOnARTOnInAPeriodOnMasterCard", + TxNewQueries.QUERY + .findPatientsWhoWhereMarkedAsTransferedInAndOnARTOnInAPeriodOnMasterCard), + mappings)); + + eri2MonthsCompositionCohort.setCompositionString( + "START-ART-2-MONTHS NOT (TRANSFERED-IN OR TRANSFERED-IN-AND-IN-ART-MASTER-CARD)"); + return eri2MonthsCompositionCohort; + } + + public CohortDefinition getEri2MonthsPregnatCompositionCohort(final String cohortName) { + final CompositionCohortDefinition eri2MonthsCompositionCohort = + new CompositionCohortDefinition(); + + eri2MonthsCompositionCohort.setName(cohortName); + eri2MonthsCompositionCohort.addParameter(new Parameter("startDate", "Start Date", Date.class)); + eri2MonthsCompositionCohort.addParameter(new Parameter("endDate", "End Date", Date.class)); + eri2MonthsCompositionCohort.addParameter(new Parameter("location", "location", Location.class)); + + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + eri2MonthsCompositionCohort.addSearch( + "START-ART-2-MONTHS", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientEnrolledInART2Months", + Eri2MonthsQueriesInterface.QUERY.findPatientsWhoStartArtOneMonth), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "TRANSFERED-IN", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWithAProgramStateMarkedAsTransferedInInAPeriod", + TxNewQueries.QUERY.findPatientsWithAProgramStateMarkedAsTransferedInInAPeriod), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "TRANSFERED-IN-AND-IN-ART-MASTER-CARD", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWhoWhereMarkedAsTransferedInAndOnARTOnInAPeriodOnMasterCard", + TxNewQueries.QUERY + .findPatientsWhoWhereMarkedAsTransferedInAndOnARTOnInAPeriodOnMasterCard), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "PREGNANT", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientsThatAreFemaleAndWereMarkedAsPregnantInTheInitialConsultationOrFollowUpConsultationAndMasterCard", + Eri2MonthsQueriesInterface.QUERY + .patientsThatAreFemaleAndWereMarkedAsPregnantInTheInitialConsultationOrFollowUpConsultationAndMasterCard), + mappings)); + + eri2MonthsCompositionCohort.setCompositionString( + "START-ART-2-MONTHS AND PREGNANT NOT (TRANSFERED-IN OR TRANSFERED-IN-AND-IN-ART-MASTER-CARD)"); + + return eri2MonthsCompositionCohort; + } + + public CohortDefinition getEri2MonthsBrestfeetingCompositionCohort(final String cohortName) { + final CompositionCohortDefinition eri2MonthsCompositionCohort = + new CompositionCohortDefinition(); + + eri2MonthsCompositionCohort.setName(cohortName); + eri2MonthsCompositionCohort.addParameter(new Parameter("startDate", "Start Date", Date.class)); + eri2MonthsCompositionCohort.addParameter(new Parameter("endDate", "End Date", Date.class)); + eri2MonthsCompositionCohort.addParameter(new Parameter("location", "location", Location.class)); + + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + eri2MonthsCompositionCohort.addSearch( + "START-ART-2-MONTHS", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientEnrolledInART2Months", + Eri2MonthsQueriesInterface.QUERY.findPatientsWhoStartArtOneMonth), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "TRANSFERED-IN", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWithAProgramStateMarkedAsTransferedInInAPeriod", + TxNewQueries.QUERY.findPatientsWithAProgramStateMarkedAsTransferedInInAPeriod), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "TRANSFERED-IN-AND-IN-ART-MASTER-CARD", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWhoWhereMarkedAsTransferedInAndOnARTOnInAPeriodOnMasterCard", + TxNewQueries.QUERY + .findPatientsWhoWhereMarkedAsTransferedInAndOnARTOnInAPeriodOnMasterCard), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "BRESTFEETING", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientsThatAreFemaleAndWereMarkedAsBrestfeetingInTheInitialConsultationOrFollowUpConsultationAndMasterCard", + Eri2MonthsQueriesInterface.QUERY + .patientsThatAreFemaleAndWereMarkedAsBrestfeetingInTheInitialConsultationOrFollowUpConsultationAndMasterCard), + mappings)); + + eri2MonthsCompositionCohort.setCompositionString( + "START-ART-2-MONTHS AND BRESTFEETING NOT (TRANSFERED-IN OR TRANSFERED-IN-AND-IN-ART-MASTER-CARD)"); + + return eri2MonthsCompositionCohort; + } + + public CohortDefinition getEri2MonthsAdultCompositionCohort(final String cohortName) { + final CompositionCohortDefinition eri2MonthsCompositionCohort = + new CompositionCohortDefinition(); + + eri2MonthsCompositionCohort.setName(cohortName); + eri2MonthsCompositionCohort.addParameter(new Parameter("startDate", "Start Date", Date.class)); + eri2MonthsCompositionCohort.addParameter(new Parameter("endDate", "End Date", Date.class)); + eri2MonthsCompositionCohort.addParameter(new Parameter("location", "location", Location.class)); + + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + eri2MonthsCompositionCohort.addSearch( + "START-ART-2-MONTHS", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientEnrolledInART2Months", + Eri2MonthsQueriesInterface.QUERY.findPatientsWhoStartArtOneMonth), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "TRANSFERED-IN", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWithAProgramStateMarkedAsTransferedInInAPeriod", + TxNewQueries.QUERY.findPatientsWithAProgramStateMarkedAsTransferedInInAPeriod), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "TRANSFERED-IN-AND-IN-ART-MASTER-CARD", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWhoWhereMarkedAsTransferedInAndOnARTOnInAPeriodOnMasterCard", + TxNewQueries.QUERY + .findPatientsWhoWhereMarkedAsTransferedInAndOnARTOnInAPeriodOnMasterCard), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "BRESTFEETING", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientsThatAreFemaleAndWereMarkedAsBrestfeetingInTheInitialConsultationOrFollowUpConsultationAndMasterCard", + Eri2MonthsQueriesInterface.QUERY + .patientsThatAreFemaleAndWereMarkedAsBrestfeetingInTheInitialConsultationOrFollowUpConsultationAndMasterCard), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "PREGNANT", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientsThatAreFemaleAndWereMarkedAsPregnantInTheInitialConsultationOrFollowUpConsultationAndMasterCard", + Eri2MonthsQueriesInterface.QUERY + .patientsThatAreFemaleAndWereMarkedAsPregnantInTheInitialConsultationOrFollowUpConsultationAndMasterCard), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "ADULT", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientsThatAreAdult", Eri2MonthsQueriesInterface.QUERY.patientsThatAreAdult), + mappings)); + + eri2MonthsCompositionCohort.setCompositionString( + "START-ART-2-MONTHS AND ADULT NOT (TRANSFERED-IN OR TRANSFERED-IN-AND-IN-ART-MASTER-CARD OR PREGNANT OR BRESTFEETING)"); + + return eri2MonthsCompositionCohort; + } + + public CohortDefinition getEri2MonthsChildCompositionCohort(final String cohortName) { + final CompositionCohortDefinition eri2MonthsCompositionCohort = + new CompositionCohortDefinition(); + + eri2MonthsCompositionCohort.setName(cohortName); + eri2MonthsCompositionCohort.addParameter(new Parameter("startDate", "Start Date", Date.class)); + eri2MonthsCompositionCohort.addParameter(new Parameter("endDate", "End Date", Date.class)); + eri2MonthsCompositionCohort.addParameter(new Parameter("location", "location", Location.class)); + + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + eri2MonthsCompositionCohort.addSearch( + "START-ART-2-MONTHS", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientEnrolledInART2Months", + Eri2MonthsQueriesInterface.QUERY.findPatientsWhoStartArtOneMonth), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "TRANSFERED-IN", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWithAProgramStateMarkedAsTransferedInInAPeriod", + TxNewQueries.QUERY.findPatientsWithAProgramStateMarkedAsTransferedInInAPeriod), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "TRANSFERED-IN-AND-IN-ART-MASTER-CARD", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWhoWhereMarkedAsTransferedInAndOnARTOnInAPeriodOnMasterCard", + TxNewQueries.QUERY + .findPatientsWhoWhereMarkedAsTransferedInAndOnARTOnInAPeriodOnMasterCard), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "BRESTFEETING", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientsThatAreFemaleAndWereMarkedAsBrestfeetingInTheInitialConsultationOrFollowUpConsultationAndMasterCard", + Eri2MonthsQueriesInterface.QUERY + .patientsThatAreFemaleAndWereMarkedAsBrestfeetingInTheInitialConsultationOrFollowUpConsultationAndMasterCard), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "PREGNANT", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientsThatAreFemaleAndWereMarkedAsPregnantInTheInitialConsultationOrFollowUpConsultationAndMasterCard", + Eri2MonthsQueriesInterface.QUERY + .patientsThatAreFemaleAndWereMarkedAsPregnantInTheInitialConsultationOrFollowUpConsultationAndMasterCard), + mappings)); + + eri2MonthsCompositionCohort.addSearch( + "CHILD", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "patientsThatAreChild", Eri2MonthsQueriesInterface.QUERY.patientsThatAreChild), + mappings)); + + eri2MonthsCompositionCohort.setCompositionString( + "START-ART-2-MONTHS AND CHILD NOT (TRANSFERED-IN OR TRANSFERED-IN-AND-IN-ART-MASTER-CARD OR PREGNANT OR BRESTFEETING)"); + + return eri2MonthsCompositionCohort; + } } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/Eri2MonthsDataset.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/Eri2MonthsDataset.java index 39cf460292..fd4397fa51 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/Eri2MonthsDataset.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/Eri2MonthsDataset.java @@ -15,7 +15,7 @@ import java.util.Arrays; import java.util.List; -import org.openmrs.module.eptsreports.reporting.library.cohorts.EriCohortQueries; +import org.openmrs.module.eptsreports.reporting.library.cohorts.Eri2MonthsCohortQueries; import org.openmrs.module.eptsreports.reporting.library.dimensions.EptsCommonDimension; import org.openmrs.module.eptsreports.reporting.library.indicators.EptsGeneralIndicator; import org.openmrs.module.eptsreports.reporting.utils.EptsReportUtils; @@ -31,19 +31,18 @@ public class Eri2MonthsDataset extends BaseDataSet { @Autowired private EptsGeneralIndicator eptsGeneralIndicator; - @Autowired private EriCohortQueries eriCohortQueries; + @Autowired private Eri2MonthsCohortQueries eri2MonthsCohortQueries; public DataSetDefinition constructEri2MonthsDatset() { CohortIndicatorDataSetDefinition dsd = new CohortIndicatorDataSetDefinition(); - String mappingsInd = - "cohortStartDate=${endDate-2m+1d},cohortEndDate=${endDate-1m},reportingEndDate=${endDate},location=${location}"; + String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; dsd.setName("ERI-2months Data Set"); dsd.addParameters(getParameters()); // apply disaggregations dsd.addDimension( - "state", EptsReportUtils.map(eptsCommonDimension.getEri2MonthsDimension(), mappingsInd)); + "state", EptsReportUtils.map(eptsCommonDimension.getEri2MonthsDimension2(), mappings)); addRow( dsd, @@ -52,9 +51,12 @@ public DataSetDefinition constructEri2MonthsDatset() { EptsReportUtils.map( eptsGeneralIndicator.getIndicator( "All patients", - EptsReportUtils.map(eriCohortQueries.getAllPatientsWhoInitiatedArt(), mappingsInd)), + EptsReportUtils.map( + eri2MonthsCohortQueries.getEri2MonthsCompositionCohort("All patients"), + mappings)), mappings), get2MonthsRetentionColumns()); + addRow( dsd, "R22", @@ -62,9 +64,12 @@ public DataSetDefinition constructEri2MonthsDatset() { EptsReportUtils.map( eptsGeneralIndicator.getIndicator( "Pregnant women", - EptsReportUtils.map(eriCohortQueries.getPregnantWomenRetainedOnArt(), mappingsInd)), + EptsReportUtils.map( + eri2MonthsCohortQueries.getEri2MonthsPregnatCompositionCohort("Pregnant"), + mappings)), mappings), get2MonthsRetentionColumns()); + addRow( dsd, "R23", @@ -72,28 +77,52 @@ public DataSetDefinition constructEri2MonthsDatset() { EptsReportUtils.map( eptsGeneralIndicator.getIndicator( "Breastfeeding women", - EptsReportUtils.map(eriCohortQueries.getBreastfeedingWomenRetained(), mappingsInd)), + EptsReportUtils.map( + eri2MonthsCohortQueries.getEri2MonthsBrestfeetingCompositionCohort( + "BrestFeeting"), + mappings)), mappings), get2MonthsRetentionColumns()); + addRow( + dsd, + "R23", + "Breastfeeding women retained on ART 2 months after ART initiation", + EptsReportUtils.map( + eptsGeneralIndicator.getIndicator( + "Breastfeeding women", + EptsReportUtils.map( + eri2MonthsCohortQueries.getEri2MonthsBrestfeetingCompositionCohort( + "BrestFeeting"), + mappings)), + mappings), + get2MonthsRetentionColumns()); + addRow( dsd, "R24", - "Children (0-14, excluding pregnant and breastfeeding women) retained on ART 2 months after ART initiation", + "Children (0-14, excluding pregnant and breastfeeding women) retained on ART 2 months", EptsReportUtils.map( eptsGeneralIndicator.getIndicator( "Children", - EptsReportUtils.map(eriCohortQueries.getChildrenRetained(), mappingsInd)), + EptsReportUtils.map( + eri2MonthsCohortQueries.getEri2MonthsChildCompositionCohort("Children"), + mappings)), mappings), get2MonthsRetentionColumns()); + addRow( dsd, "R25", - "Adults (15+, excluding pregnant and breastfeeding women) retained on ART 2 months after ART initiation", + "Adults (15+, excluding pregnant and breastfeeding women) retained on ART 2 months", EptsReportUtils.map( eptsGeneralIndicator.getIndicator( - "Adults", EptsReportUtils.map(eriCohortQueries.getAdultsRetained(), mappingsInd)), + "Adult", + EptsReportUtils.map( + eri2MonthsCohortQueries.getEri2MonthsAdultCompositionCohort("Adult"), + mappings)), mappings), get2MonthsRetentionColumns()); + return dsd; } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/Eri4MonthsDataset.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/Eri4MonthsDataset.java index 7d50460e65..899769a2e2 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/Eri4MonthsDataset.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/Eri4MonthsDataset.java @@ -15,7 +15,6 @@ import java.util.Arrays; import java.util.List; - import org.openmrs.module.eptsreports.reporting.library.cohorts.Eri4MonthsCohortQueries; import org.openmrs.module.eptsreports.reporting.library.cohorts.GenericCohortQueries; import org.openmrs.module.eptsreports.reporting.library.cohorts.TxNewCohortQueries; @@ -34,138 +33,173 @@ @Component public class Eri4MonthsDataset extends BaseDataSet { - @Autowired - private EptsGeneralIndicator eptsGeneralIndicator; - - @Autowired - private Eri4MonthsDimensions eri4MonthsDimensions; - - @Autowired - private TxNewCohortQueries txNewCohortQueries; - - @Autowired - private GenericCohortQueries genericCohortQueries; - - @Autowired - private Eri4MonthsCohortQueries eri4MonthsCohortQueries; - - public DataSetDefinition constructEri4MonthsDataset() { - - final CohortIndicatorDataSetDefinition dataSetDefinition = new CohortIndicatorDataSetDefinition(); - - final String cohortPeriodMappings = "cohortStartDate=${endDate-5m+1d},cohortEndDate=${endDate-4m},location=${location}"; - - final String reportingPeriodMappings = "startDate=${startDate},endDate=${endDate},location=${location}"; - - dataSetDefinition.setName("ERI-4months Data Set"); - - dataSetDefinition.addParameters(this.getParameters()); - - dataSetDefinition.addDimension("state", - EptsReportUtils.map(this.eri4MonthsDimensions.getDimension(), cohortPeriodMappings)); - - this.addColumns(dataSetDefinition, "01", - EptsReportUtils.map( - this.eptsGeneralIndicator.getIndicator("all patients", - EptsReportUtils.map( - this.txNewCohortQueries.getTxNewCompositionCohort("patientNewlyEnrolledInART"), - "startDate=${endDate-5m+1d},endDate=${endDate-4m},location=${location}")), - reportingPeriodMappings), - this.get4MonthsRetentionColumns()); - - this.addColumns(dataSetDefinition, "02", - EptsReportUtils.map(this.eptsGeneralIndicator.getIndicator("all patients in treatment", - EptsReportUtils.map( - this.genericCohortQueries.generalSql("patientsInTreatment", - Eri4MonthsQueries - .findPatientsWhoHaveEitherClinicalConsultationOrDrugsPickupBetween61And120ForASpecificPatientType( - Eri4mType.IN_TREATMENT)), - "endDate=${endDate},location=${location}")), - reportingPeriodMappings), - this.get4MonthsRetentionColumns()); - - this.addColumns(dataSetDefinition, "03", - EptsReportUtils - .map(this.eptsGeneralIndicator.getIndicator("all patients dead", - EptsReportUtils.map( - this.genericCohortQueries.generalSql("patientsDead", - Eri4MonthsQueries - .findPatientsWhoHaveEitherClinicalConsultationOrDrugsPickupBetween61And120ForASpecificPatientType( - Eri4mType.DEAD)), - "endDate=${endDate},location=${location}")), - reportingPeriodMappings), - this.get4MonthsRetentionColumns()); - - this.addColumns(dataSetDefinition, "04", - EptsReportUtils.map( - this.eptsGeneralIndicator.getIndicator("all patients who are lost follow up", - EptsReportUtils.map(this.eri4MonthsCohortQueries.findPatientsWhoAreLostFollowUp(), - cohortPeriodMappings + ",reportingEndDate=${endDate}")), - reportingPeriodMappings), - this.get4MonthsRetentionColumns()); - - this.addColumns(dataSetDefinition, "05", - EptsReportUtils.map(this.eptsGeneralIndicator.getIndicator("all patients in tranferred out", - EptsReportUtils.map( - this.genericCohortQueries.generalSql("patientsTransferredOut", - Eri4MonthsQueries - .findPatientsWhoHaveEitherClinicalConsultationOrDrugsPickupBetween61And120ForASpecificPatientType( - Eri4mType.TRANFERED_OUT)), - "endDate=${endDate},location=${location}")), - reportingPeriodMappings), - this.get4MonthsRetentionColumns()); - - this.addColumns(dataSetDefinition, "06", - EptsReportUtils.map(this.eptsGeneralIndicator.getIndicator("all patients who stopped treatment", - EptsReportUtils.map( - this.genericCohortQueries.generalSql("patientsStoppedTreatment", - Eri4MonthsQueries - .findPatientsWhoHaveEitherClinicalConsultationOrDrugsPickupBetween61And120ForASpecificPatientType( - Eri4mType.SPTOPPED_TREATMENT)), - "endDate=${endDate},location=${location}")), - reportingPeriodMappings), - this.get4MonthsRetentionColumns()); - - this.addColumns(dataSetDefinition, "07", - EptsReportUtils.map(this.eptsGeneralIndicator.getIndicator("all patients defaulters", - EptsReportUtils.map( - this.genericCohortQueries.generalSql("patientsDefaulters", - Eri4MonthsQueries - .findPatientsWhoHaveEitherClinicalConsultationOrDrugsPickupBetween61And120ForASpecificPatientType( - Eri4mType.DEFAULTER)), - "endDate=${endDate},location=${location}")), - reportingPeriodMappings), - this.get4MonthsRetentionColumns()); - - return dataSetDefinition; - } - - private List get4MonthsRetentionColumns() { - - final ColumnParameters allPatients = new ColumnParameters("initiated ART", "Initiated ART", "", "I"); - final ColumnParameters pregnantWoman = new ColumnParameters("pregnant woman", "Pregnant Woman", - "state=PREGNANT", "I"); - final ColumnParameters brestfedding = new ColumnParameters("breastfeeding", "Breastfeeding", - "state=BREASTFEEDING", "I"); - final ColumnParameters children = new ColumnParameters("children", "Children", "state=CHILDREN", "I"); - final ColumnParameters adult = new ColumnParameters("adult", "Adult", "state=ADULT", "I"); - - return Arrays.asList(allPatients, pregnantWoman, brestfedding, children, adult); - } - - private void addColumns(final CohortIndicatorDataSetDefinition definition, final String columNumber, - final Mapped indicator, final List columns) { - - int position = 1; - - for (final ColumnParameters column : columns) { - - final String name = column.getColumn() + "" + position + "-" + columNumber; - final String label = column.getLabel() + "(" + name + ")"; - - definition.addColumn(name, label, indicator, column.getDimensions()); - - position++; - } - } + @Autowired private EptsGeneralIndicator eptsGeneralIndicator; + + @Autowired private Eri4MonthsDimensions eri4MonthsDimensions; + + @Autowired private TxNewCohortQueries txNewCohortQueries; + + @Autowired private GenericCohortQueries genericCohortQueries; + + @Autowired private Eri4MonthsCohortQueries eri4MonthsCohortQueries; + + public DataSetDefinition constructEri4MonthsDataset() { + + final CohortIndicatorDataSetDefinition dataSetDefinition = + new CohortIndicatorDataSetDefinition(); + + final String cohortPeriodMappings = + "cohortStartDate=${endDate-5m+1d},cohortEndDate=${endDate-4m},location=${location}"; + + final String reportingPeriodMappings = + "startDate=${startDate},endDate=${endDate},location=${location}"; + + dataSetDefinition.setName("ERI-4months Data Set"); + + dataSetDefinition.addParameters(this.getParameters()); + + dataSetDefinition.addDimension( + "state", + EptsReportUtils.map(this.eri4MonthsDimensions.getDimension(), cohortPeriodMappings)); + + this.addColumns( + dataSetDefinition, + "01", + EptsReportUtils.map( + this.eptsGeneralIndicator.getIndicator( + "all patients", + EptsReportUtils.map( + this.txNewCohortQueries.getTxNewCompositionCohort("patientNewlyEnrolledInART"), + "startDate=${endDate-5m+1d},endDate=${endDate-4m},location=${location}")), + reportingPeriodMappings), + this.get4MonthsRetentionColumns()); + + this.addColumns( + dataSetDefinition, + "02", + EptsReportUtils.map( + this.eptsGeneralIndicator.getIndicator( + "all patients in treatment", + EptsReportUtils.map( + this.genericCohortQueries.generalSql( + "patientsInTreatment", + Eri4MonthsQueries + .findPatientsWhoHaveEitherClinicalConsultationOrDrugsPickupBetween61And120ForASpecificPatientType( + Eri4mType.IN_TREATMENT)), + "endDate=${endDate},location=${location}")), + reportingPeriodMappings), + this.get4MonthsRetentionColumns()); + + this.addColumns( + dataSetDefinition, + "03", + EptsReportUtils.map( + this.eptsGeneralIndicator.getIndicator( + "all patients dead", + EptsReportUtils.map( + this.genericCohortQueries.generalSql( + "patientsDead", + Eri4MonthsQueries + .findPatientsWhoHaveEitherClinicalConsultationOrDrugsPickupBetween61And120ForASpecificPatientType( + Eri4mType.DEAD)), + "endDate=${endDate},location=${location}")), + reportingPeriodMappings), + this.get4MonthsRetentionColumns()); + + this.addColumns( + dataSetDefinition, + "04", + EptsReportUtils.map( + this.eptsGeneralIndicator.getIndicator( + "all patients who are lost follow up", + EptsReportUtils.map( + this.eri4MonthsCohortQueries.findPatientsWhoAreLostFollowUp(), + cohortPeriodMappings + ",reportingEndDate=${endDate}")), + reportingPeriodMappings), + this.get4MonthsRetentionColumns()); + + this.addColumns( + dataSetDefinition, + "05", + EptsReportUtils.map( + this.eptsGeneralIndicator.getIndicator( + "all patients in tranferred out", + EptsReportUtils.map( + this.genericCohortQueries.generalSql( + "patientsTransferredOut", + Eri4MonthsQueries + .findPatientsWhoHaveEitherClinicalConsultationOrDrugsPickupBetween61And120ForASpecificPatientType( + Eri4mType.TRANFERED_OUT)), + "endDate=${endDate},location=${location}")), + reportingPeriodMappings), + this.get4MonthsRetentionColumns()); + + this.addColumns( + dataSetDefinition, + "06", + EptsReportUtils.map( + this.eptsGeneralIndicator.getIndicator( + "all patients who stopped treatment", + EptsReportUtils.map( + this.genericCohortQueries.generalSql( + "patientsStoppedTreatment", + Eri4MonthsQueries + .findPatientsWhoHaveEitherClinicalConsultationOrDrugsPickupBetween61And120ForASpecificPatientType( + Eri4mType.SPTOPPED_TREATMENT)), + "endDate=${endDate},location=${location}")), + reportingPeriodMappings), + this.get4MonthsRetentionColumns()); + + this.addColumns( + dataSetDefinition, + "07", + EptsReportUtils.map( + this.eptsGeneralIndicator.getIndicator( + "all patients defaulters", + EptsReportUtils.map( + this.genericCohortQueries.generalSql( + "patientsDefaulters", + Eri4MonthsQueries + .findPatientsWhoHaveEitherClinicalConsultationOrDrugsPickupBetween61And120ForASpecificPatientType( + Eri4mType.DEFAULTER)), + "endDate=${endDate},location=${location}")), + reportingPeriodMappings), + this.get4MonthsRetentionColumns()); + + return dataSetDefinition; + } + + private List get4MonthsRetentionColumns() { + + final ColumnParameters allPatients = + new ColumnParameters("initiated ART", "Initiated ART", "", "I"); + final ColumnParameters pregnantWoman = + new ColumnParameters("pregnant woman", "Pregnant Woman", "state=PREGNANT", "I"); + final ColumnParameters brestfedding = + new ColumnParameters("breastfeeding", "Breastfeeding", "state=BREASTFEEDING", "I"); + final ColumnParameters children = + new ColumnParameters("children", "Children", "state=CHILDREN", "I"); + final ColumnParameters adult = new ColumnParameters("adult", "Adult", "state=ADULT", "I"); + + return Arrays.asList(allPatients, pregnantWoman, brestfedding, children, adult); + } + + private void addColumns( + final CohortIndicatorDataSetDefinition definition, + final String columNumber, + final Mapped indicator, + final List columns) { + + int position = 1; + + for (final ColumnParameters column : columns) { + + final String name = column.getColumn() + "" + position + "-" + columNumber; + final String label = column.getLabel() + "(" + name + ")"; + + definition.addColumn(name, label, indicator, column.getDimensions()); + + position++; + } + } } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java index accc2bfae2..cac7ffc41d 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/EptsCommonDimension.java @@ -23,6 +23,7 @@ import org.openmrs.module.eptsreports.reporting.library.cohorts.TbPrevCohortQueries; import org.openmrs.module.eptsreports.reporting.library.cohorts.TxNewCohortQueries; import org.openmrs.module.eptsreports.reporting.library.queries.BreastfeedingQueries; +import org.openmrs.module.eptsreports.reporting.library.queries.Eri2MonthsQueriesInterface; import org.openmrs.module.eptsreports.reporting.library.queries.TxCurrQueries; import org.openmrs.module.eptsreports.reporting.library.queries.TxNewQueries; import org.openmrs.module.eptsreports.reporting.utils.AgeRange; @@ -54,6 +55,8 @@ public class EptsCommonDimension { @Autowired private BreastFeedingCohortQueries breastFeedingCohortQueries; + @Autowired private GenericCohortQueries genericCohorts; + /** * Gender dimension * @@ -150,6 +153,70 @@ public CohortDefinitionDimension maternityDimension() { return dim; } + /** + * Get the dimensions based on the patient states for ERI-4 months + * + * @return CohortDefinitionDimension + */ + public CohortDefinitionDimension getEri4MonthsDimension() { + final CohortDefinitionDimension dim = new CohortDefinitionDimension(); + dim.addParameter(new Parameter("cohortStartDate", "Cohort Start Date", Date.class)); + dim.addParameter(new Parameter("cohortEndDate", "Cohort End Date", Date.class)); + dim.addParameter(new Parameter("reportingStartDate", "Report Start Date", Date.class)); + dim.addParameter(new Parameter("reportingEndDate", "Report End Date", Date.class)); + dim.addParameter(new Parameter("location", "location", Location.class)); + dim.setName("Get patient states"); + + dim.addCohortDefinition( + "IART", + EptsReportUtils.map( + this.eriCohortQueries.getAllPatientsWhoInitiatedArt(), + "cohortStartDate=${cohortStartDate},cohortEndDate=${cohortEndDate},location=${location}")); + + dim.addCohortDefinition( + "AIT", + EptsReportUtils.map( + this.eri4MonthsCohortQueries.getPatientsWhoAreAliveAndOnTreatment(), + "cohortStartDate=${cohortStartDate},cohortEndDate=${cohortEndDate},reportingEndDate=${reportingEndDate},location=${location}")); + + dim.addCohortDefinition( + "DP", + EptsReportUtils.map( + this.genericCohortQueries.getDeceasedPatients(), + "startDate=${cohortStartDate},endDate=${reportingEndDate},location=${location}")); + + dim.addCohortDefinition( + "LTFU", + EptsReportUtils.map( + this.eri4MonthsCohortQueries.getAllPatientsWhoAreLostToFollowUpDuringPeriod(), + "cohortStartDate=${cohortStartDate},cohortEndDate=${cohortEndDate},reportingEndDate=${reportingEndDate},location=${location}")); + + dim.addCohortDefinition( + "TOP", + EptsReportUtils.map( + this.genericCohortQueries.getPatientsBasedOnPatientStates( + this.hivMetadata.getARTProgram().getProgramId(), + this.hivMetadata + .getTransferredOutToAnotherHealthFacilityWorkflowState() + .getProgramWorkflowStateId()), + "startDate=${cohortStartDate},endDate=${reportingEndDate},location=${location}")); + + dim.addCohortDefinition( + "STP", + EptsReportUtils.map( + this.genericCohortQueries.getPatientsBasedOnPatientStates( + this.hivMetadata.getARTProgram().getProgramId(), + this.hivMetadata.getSuspendedTreatmentWorkflowState().getProgramWorkflowStateId()), + "startDate=${cohortStartDate},endDate=${reportingEndDate},location=${location}")); + + dim.addCohortDefinition( + "ANIT", + EptsReportUtils.map( + this.eri4MonthsCohortQueries.getPatientsWhoAreAliveAndNotOnTreatment(), + "cohortStartDate=${cohortStartDate},cohortEndDate=${cohortEndDate},reportingEndDate=${reportingEndDate},location=${location}")); + return dim; + } + /** * Get the dimensions based on the patient states for ERI-4 months * @@ -162,31 +229,37 @@ public CohortDefinitionDimension getEri2MonthsDimension() { dim.addParameter(new Parameter("reportingEndDate", "Reporting End Date", Date.class)); dim.addParameter(new Parameter("location", "location", Location.class)); dim.setName("Get patients dimensions for Eri2Months"); + dim.addCohortDefinition( "IART", EptsReportUtils.map( this.eriCohortQueries.getAllPatientsWhoInitiatedArt(), "cohortStartDate=${cohortStartDate},cohortEndDate=${cohortEndDate},location=${location}")); + dim.addCohortDefinition( "DNPUD", EptsReportUtils.map( this.eri2MonthsCohortQueries.getPatientsWhoDidNotPickDrugsOnTheirSecondVisit(), "cohortStartDate=${cohortStartDate},cohortEndDate=${cohortEndDate},reportingEndDate=${reportingEndDate},location=${location}")); + dim.addCohortDefinition( "PUD", EptsReportUtils.map( this.eri2MonthsCohortQueries.getPatientsWhoPickedUpDrugsOnTheirSecondVisit(), "cohortStartDate=${cohortStartDate},cohortEndDate=${cohortEndDate},reportingEndDate=${reportingEndDate},location=${location}")); + dim.addCohortDefinition( "DP", EptsReportUtils.map( this.eri2MonthsCohortQueries.getPatientsWhoInitiatedArtAndDead(), "cohortStartDate=${cohortStartDate},cohortEndDate=${cohortEndDate},reportingEndDate=${reportingEndDate},location=${location}")); + dim.addCohortDefinition( "TOP", EptsReportUtils.map( this.eri2MonthsCohortQueries.getPatientsWhoInitiatedArtButTransferredOut(), "cohortStartDate=${cohortStartDate},cohortEndDate=${cohortEndDate},reportingEndDate=${reportingEndDate},location=${location}")); + dim.addCohortDefinition( "STP", EptsReportUtils.map( @@ -195,6 +268,69 @@ public CohortDefinitionDimension getEri2MonthsDimension() { return dim; } + public CohortDefinitionDimension getEri2MonthsDimension2() { + final CohortDefinitionDimension dimension = new CohortDefinitionDimension(); + + dimension.setName("Get patients dimensions for Eri2Months"); + dimension.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dimension.addParameter(new Parameter("endDate", "End Date", Date.class)); + dimension.addParameter(new Parameter("location", "location", Location.class)); + + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + dimension.addCohortDefinition( + "IART", + EptsReportUtils.map( + eri2MonthsCohortQueries.getEri2MonthsCompositionCohort("IART"), mappings)); + + dimension.addCohortDefinition( + "DNPUD", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWhoStartedArtAtAPeriodAndDidNotHaveASecondPickupsOrClinicalConsultationWithin33DaysAfterArtInitiation", + Eri2MonthsQueriesInterface.QUERY + .findPatientsWhoStartedArtAtAPeriodAndDidNotHaveASecondPickupsOrClinicalConsultationWithin33DaysAfterArtInitiation), + mappings)); + + dimension.addCohortDefinition( + "PUD", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsStartedArtLastMonthWith2PickupsOrConsultationWithin33DaysExcludingDeadAndTransferedOutAndIn", + Eri2MonthsQueriesInterface.QUERY + .findPatientsStartedArtLastMonthWith2PickupsOrConsultationWithin33DaysExcludingDeadAndTransferedOutAndIn), + mappings)); + + dimension.addCohortDefinition( + "DP", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWhoStartedArtInAPeriodAndAreDeath33DaysAfterArtInitiation", + Eri2MonthsQueriesInterface.QUERY + .findPatientsWhoStartedArtInAPeriodAndAreDeath33DaysAfterArtInitiation), + mappings)); + + dimension.addCohortDefinition( + "TOP", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWhoStartedArtInAPeriodAndAreTrasferedOut33DaysAfterInitiation", + Eri2MonthsQueriesInterface.QUERY + .findPatientsWhoStartedArtInAPeriodAndAreTrasferedOut33DaysAfterInitiation), + mappings)); + + dimension.addCohortDefinition( + "STP", + EptsReportUtils.map( + this.genericCohorts.generalSql( + "findPatientsWhoStartedArtInAPeriodAndSuspendTratement33DaysAfterInitiation", + Eri2MonthsQueriesInterface.QUERY + .findPatientsWhoStartedArtInAPeriodAndSuspendTratement33DaysAfterInitiation), + mappings)); + + return dimension; + } + public CohortDefinitionDimension getArtStatusDimension() { final CohortDefinitionDimension dim = new CohortDefinitionDimension(); dim.addParameter(new Parameter("onOrAfter", "onOrAfter", Date.class)); diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/Eri2MonthsDamision.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/Eri2MonthsDamision.java new file mode 100644 index 0000000000..e5e2f08b60 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/dimensions/Eri2MonthsDamision.java @@ -0,0 +1,153 @@ +package org.openmrs.module.eptsreports.reporting.library.dimensions; + +import java.util.Date; +import org.openmrs.Location; +import org.openmrs.module.eptsreports.reporting.library.cohorts.Eri2MonthsCohortQueries; +import org.openmrs.module.eptsreports.reporting.library.cohorts.GenericCohortQueries; +import org.openmrs.module.eptsreports.reporting.library.queries.Eri2MonthsQueriesInterface; +import org.openmrs.module.eptsreports.reporting.utils.EptsReportUtils; +import org.openmrs.module.reporting.evaluation.parameter.Parameter; +import org.openmrs.module.reporting.indicator.dimension.CohortDefinitionDimension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class Eri2MonthsDamision { + + @Autowired private GenericCohortQueries genericCohortQueries; + + @Autowired private Eri2MonthsCohortQueries eri2MonthsCohortQueries; + + public CohortDefinitionDimension findPatientsWhoStartArtOneMonth() { + + final CohortDefinitionDimension dim = new CohortDefinitionDimension(); + dim.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dim.addParameter(new Parameter("endDate", "End Date", Date.class)); + dim.addParameter(new Parameter("location", "location", Location.class)); + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + dim.addCohortDefinition( + "1All", + EptsReportUtils.map( + this.eri2MonthsCohortQueries.getEri2MonthsCompositionCohort("1All"), mappings)); + + return dim; + } + + public CohortDefinitionDimension + findPatientsStartedArtLastMonthWith2PickupsOrConsultationWithin33DaysExcludingDeadAndTransferedOutAndIn() { + final CohortDefinitionDimension dimension = new CohortDefinitionDimension(); + + dimension.setName( + "PatientsStartedArtLastMonthWith2PickupsOrConsultationWithin33DaysExcludingDeadAndTransferedOutAndIn"); + dimension.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dimension.addParameter(new Parameter("endDate", "End Date", Date.class)); + dimension.addParameter(new Parameter("location", "location", Location.class)); + + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + dimension.addCohortDefinition( + "ERI2.R21-03", + EptsReportUtils.map( + this.genericCohortQueries.generalSql( + "findPatientsStartedArtLastMonthWith2PickupsOrConsultationWithin33DaysExcludingDeadAndTransferedOutAndIn", + Eri2MonthsQueriesInterface.QUERY + .findPatientsStartedArtLastMonthWith2PickupsOrConsultationWithin33DaysExcludingDeadAndTransferedOutAndIn), + mappings)); + + return dimension; + } + + public CohortDefinitionDimension + findPatientsWhoStartedArtAtAPeriodAndDidNotHaveASecondPickupsOrClinicalConsultationWithin33DaysAfterArtInitiation() { + final CohortDefinitionDimension dimension = new CohortDefinitionDimension(); + + dimension.setName( + "findPatientsWhoStartedArtAtAPeriodAndDidNotHaveASecondPickupsOrClinicalConsultationWithin33DaysAfterArtInitiation"); + dimension.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dimension.addParameter(new Parameter("endDate", "End Date", Date.class)); + dimension.addParameter(new Parameter("location", "location", Location.class)); + + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + dimension.addCohortDefinition( + "ERI2.R21-02", + EptsReportUtils.map( + this.genericCohortQueries.generalSql( + "findPatientsWhoStartedArtAtAPeriodAndDidNotHaveASecondPickupsOrClinicalConsultationWithin33DaysAfterArtInitiation", + Eri2MonthsQueriesInterface.QUERY + .findPatientsWhoStartedArtAtAPeriodAndDidNotHaveASecondPickupsOrClinicalConsultationWithin33DaysAfterArtInitiation), + mappings)); + + return dimension; + } + + public CohortDefinitionDimension + findPatientsWhoStartedArtInAPeriodAndAreDeath33DaysAfterArtInitiation() { + final CohortDefinitionDimension dimension = new CohortDefinitionDimension(); + + dimension.setName("findPatientsWhoStartedArtInAPeriodAndAreDeath33DaysAfterArtInitiation"); + dimension.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dimension.addParameter(new Parameter("endDate", "End Date", Date.class)); + dimension.addParameter(new Parameter("location", "location", Location.class)); + + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + dimension.addCohortDefinition( + "ERI2.R21-04", + EptsReportUtils.map( + this.genericCohortQueries.generalSql( + "findPatientsWhoStartedArtInAPeriodAndAreDeath33DaysAfterArtInitiation", + Eri2MonthsQueriesInterface.QUERY + .findPatientsWhoStartedArtInAPeriodAndAreDeath33DaysAfterArtInitiation), + mappings)); + + return dimension; + } + + public CohortDefinitionDimension + findPatientsWhoStartedArtInAPeriodAndSuspendTratement33DaysAfterInitiation() { + final CohortDefinitionDimension dimension = new CohortDefinitionDimension(); + + dimension.setName("findPatientsWhoStartedArtInAPeriodAndSuspendTratement33DaysAfterInitiation"); + dimension.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dimension.addParameter(new Parameter("endDate", "End Date", Date.class)); + dimension.addParameter(new Parameter("location", "location", Location.class)); + + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + dimension.addCohortDefinition( + "ERI2.R21-06", + EptsReportUtils.map( + this.genericCohortQueries.generalSql( + "findPatientsWhoStartedArtInAPeriodAndSuspendTratement33DaysAfterInitiation", + Eri2MonthsQueriesInterface.QUERY + .findPatientsWhoStartedArtInAPeriodAndSuspendTratement33DaysAfterInitiation), + mappings)); + + return dimension; + } + + public CohortDefinitionDimension + findPatientsWhoStartedArtInAPeriodAndAreTrasferedOut33DaysAfterInitiation() { + final CohortDefinitionDimension dimension = new CohortDefinitionDimension(); + + dimension.setName("findPatientsWhoStartedArtInAPeriodAndAreTrasferedOut33DaysAfterInitiation"); + dimension.addParameter(new Parameter("startDate", "Start Date", Date.class)); + dimension.addParameter(new Parameter("endDate", "End Date", Date.class)); + dimension.addParameter(new Parameter("location", "location", Location.class)); + + final String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; + + dimension.addCohortDefinition( + "ERI2.R21-03", + EptsReportUtils.map( + this.genericCohortQueries.generalSql( + "findPatientsWhoStartedArtInAPeriodAndAreTrasferedOut33DaysAfterInitiation", + Eri2MonthsQueriesInterface.QUERY + .findPatientsWhoStartedArtInAPeriodAndAreTrasferedOut33DaysAfterInitiation), + mappings)); + + return dimension; + } +} diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/Eri2MonthsQueriesInterface.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/Eri2MonthsQueriesInterface.java new file mode 100644 index 0000000000..0b4f30bc9b --- /dev/null +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/Eri2MonthsQueriesInterface.java @@ -0,0 +1,463 @@ +package org.openmrs.module.eptsreports.reporting.library.queries; + +public interface Eri2MonthsQueriesInterface { + class QUERY { + + public static final String findPatientsWhoStartArtOneMonth = + "SELECT patients.patient_id FROM (" + + "SELECT patient_id, MIN(art_start_date) art_start_date FROM( " + + "Select p.patient_id,min(e.encounter_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on o.encounter_id=e.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and e.encounter_type in (18,6,9) and o.concept_id=1255 and o.value_coded=1256 and e.encounter_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type in (18,6,9,53) and o.concept_id=1190 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union select pg.patient_id,min(date_enrolled) art_start_date from patient p inner join patient_program pg on p.patient_id=pg.patient_id " + + "where pg.voided=0 and p.voided=0 and program_id=2 and date_enrolled<=:endDate and location_id=:location group by pg.patient_id " + + "union " + + "SELECT e.patient_id, MIN(e.encounter_datetime) AS art_start_date FROM patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "WHERE p.voided=0 and e.encounter_type=18 AND e.voided=0 and e.encounter_datetime<=:endDate and e.location_id=:location GROUP BY p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type=52 and o.concept_id=23866 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id) patients_started_art " + + "GROUP BY patients_started_art.patient_id " + + "HAVING MIN(patients_started_art.art_start_date) BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH)) patients GROUP BY patients.patient_id"; + + public static final String + findPatientsStartedArtLastMonthWith2PickupsOrConsultationWithin33DaysExcludingDeadAndTransferedOutAndIn = + "SELECT patients_all.patient_id FROM( " + + "SELECT patients.patient_id, patients.art_start_date FROM ( " + + "SELECT patient_id, MIN(art_start_date) art_start_date FROM( " + + "Select p.patient_id,min(e.encounter_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on o.encounter_id=e.encounter_id where e.voided=0 and o.voided=0 and p.voided=0 and " + + "e.encounter_type in (18,6,9) and o.concept_id=1255 and o.value_coded=1256 and e.encounter_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union " + + " Select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type in (18,6,9,53) and " + + "o.concept_id=1190 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union " + + "select pg.patient_id,min(date_enrolled) art_start_date from patient p inner join patient_program pg on p.patient_id=pg.patient_id " + + "where pg.voided=0 and p.voided=0 and program_id=2 and date_enrolled<=:endDate and location_id=:location group by pg.patient_id " + + "union " + + "SELECT e.patient_id, MIN(e.encounter_datetime) AS art_start_date FROM patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "WHERE p.voided=0 and e.encounter_type=18 AND e.voided=0 and e.encounter_datetime<=:endDate and e.location_id=:location GROUP BY p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type=52 and o.concept_id=23866 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + ") patients_started_art WHERE patients_started_art.patient_id NOT IN " + + "(SELECT p.patient_id FROM patient p " + + "INNER JOIN patient_program pg ON pg.patient_id = p.patient_id " + + "INNER JOIN patient_state ps ON ps.patient_program_id = pg.patient_program_id " + + "WHERE p.voided = 0 AND pg.voided = 0 AND ps.voided = 0 AND pg.program_id = 2 AND ps.state = 29 AND ps.start_date BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) AND pg.location_id = :location GROUP BY p.patient_id " + + "union " + + "Select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs obsTrans on e.encounter_id=obsTrans.encounter_id and obsTrans.voided=0 and obsTrans.concept_id=1369 and obsTrans.value_coded=1065 " + + "inner join obs obsTarv on e.encounter_id=obsTarv.encounter_id and obsTarv.voided=0 and obsTarv.concept_id=6300 and obsTarv.value_coded=6276 " + + "where p.voided=0 and e.voided=0 and e.encounter_type=53 and obsTrans.obs_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location" + + ") GROUP BY patients_started_art.patient_id " + + "HAVING MIN(patients_started_art.art_start_date) BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH)) patients " + + "INNER JOIN (" + + "select p.patient_id, encounter_datetime from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "where p.voided=0 and e.voided=0 and " + + "e.encounter_type in (6,9,18) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) and :endDate and e.location_id=:location " + + "union " + + "Select p.patient_id,value_datetime as encounter_datetime from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type=52 and o.concept_id=23866 and o.value_datetime is not null and " + + "o.value_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) and :endDate and e.location_id=:location) lev_seg ON lev_seg.patient_id = patients.patient_id " + + "WHERE lev_seg.encounter_datetime BETWEEN patients.art_start_date AND (patients.art_start_date + INTERVAL 33 DAY) AND patients.patient_id NOT IN ( " + + "SELECT p.patient_id FROM patient p " + + "INNER JOIN patient_program pg ON pg.patient_id = p.patient_id " + + "INNER JOIN patient_state ps ON ps.patient_program_id = pg.patient_program_id " + + "WHERE p.voided = 0 AND pg.voided = 0 AND ps.voided = 0 AND pg.program_id = 2 AND ps.state IN (7, 10) AND ps.start_date BETWEEN patients.art_start_date AND :endDate AND ps.end_date IS NULL AND pg.location_id = :location GROUP BY p.patient_id " + + " union " + + " select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and " + + "e.encounter_type=53 and o.concept_id=6272 and o.value_coded in (1706,1366) and " + + "o.obs_datetime between patients.art_start_date AND :endDate and e.location_id=:location group by p.patient_id " + + "union select person_id as patient_id from person where dead=1 and death_date is not null and death_date between patients.art_start_date AND :endDate " + + "union " + + "select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs obsEncontrado on e.encounter_id=obsEncontrado.encounter_id " + + "inner join obs obsObito on e.encounter_id=obsObito.encounter_id " + + "where e.voided=0 and obsEncontrado.voided=0 and p.voided=0 and obsObito.voided=0 and " + + "e.encounter_type in (21,36,37) and e.encounter_datetime between patients.art_start_date AND :endDate and e.location_id=:location and " + + "obsEncontrado.concept_id in (2003, 6348) and obsEncontrado.value_coded=1066 and obsObito.concept_id=2031 and obsObito.value_coded=1383 group by p.patient_id " + + ") GROUP BY patients.patient_id HAVING MIN(lev_seg.encounter_datetime) < MAX(lev_seg.encounter_datetime) )patients_all GROUP BY patients_all.patient_id "; + + public static final String + findPatientsWhoStartedArtAtAPeriodAndDidNotHaveASecondPickupsOrClinicalConsultationWithin33DaysAfterArtInitiation = + "SELECT patients_all.patient_id FROM(SELECT patients.patient_id, patients.art_start_date FROM (" + + "SELECT patient_id, MIN(art_start_date) art_start_date FROM( " + + "Select p.patient_id,min(e.encounter_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on o.encounter_id=e.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and e.encounter_type in (18,6,9) and o.concept_id=1255 and o.value_coded=1256 and e.encounter_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type in (18,6,9,53) and o.concept_id=1190 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union " + + "select pg.patient_id,min(date_enrolled) art_start_date from patient p " + + "inner join patient_program pg on p.patient_id=pg.patient_id " + + "where pg.voided=0 and p.voided=0 and program_id=2 and date_enrolled<=:endDate and location_id=:location group by pg.patient_id " + + "union " + + "SELECT e.patient_id, MIN(e.encounter_datetime) AS art_start_date FROM patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "WHERE p.voided=0 and e.encounter_type=18 AND e.voided=0 and e.encounter_datetime<=:endDate and e.location_id=:location GROUP BY p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type=52 and o.concept_id=23866 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id) patients_started_art " + + "WHERE patients_started_art.patient_id NOT IN(SELECT p.patient_id FROM patient p " + + "INNER JOIN patient_program pg ON pg.patient_id = p.patient_id " + + "INNER JOIN patient_state ps ON ps.patient_program_id = pg.patient_program_id " + + "WHERE p.voided = 0 AND pg.voided = 0 AND ps.voided = 0 AND pg.program_id = 2 AND ps.state = 29 AND ps.start_date BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) AND pg.location_id = :location GROUP BY p.patient_id " + + "union Select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs obsTrans on e.encounter_id=obsTrans.encounter_id and obsTrans.voided=0 and obsTrans.concept_id=1369 and obsTrans.value_coded=1065 " + + "inner join obs obsTarv on e.encounter_id=obsTarv.encounter_id and obsTarv.voided=0 and obsTarv.concept_id=6300 and obsTarv.value_coded=6276 " + + "where p.voided=0 and e.voided=0 and e.encounter_type=53 and obsTrans.obs_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location) GROUP BY patients_started_art.patient_id " + + "HAVING MIN(patients_started_art.art_start_date) BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) " + + ") patients " + + "LEFT JOIN ( select p.patient_id,encounter_datetime from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "where p.voided=0 and e.voided=0 and e.encounter_type in (6,9,18) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) and :endDate and e.location_id=:location " + + "union " + + "Select p.patient_id,value_datetime as encounter_datetime " + + "from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type=52 and o.concept_id=23866 and o.value_datetime is not null and o.value_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) and :endDate and e.location_id=:location) lev_seg ON lev_seg.patient_id = patients.patient_id and lev_seg.encounter_datetime BETWEEN patients.art_start_date AND (patients.art_start_date + INTERVAL 33 DAY) " + + "WHERE patients.patient_id NOT IN (" + + "SELECT p.patient_id FROM patient p " + + "INNER JOIN patient_program pg ON pg.patient_id = p.patient_id " + + "INNER JOIN patient_state ps ON ps.patient_program_id = pg.patient_program_id " + + "WHERE p.voided = 0 AND pg.voided = 0 AND ps.voided = 0 AND pg.program_id = 2 AND ps.state IN (7, 10) AND ps.start_date BETWEEN patients.art_start_date AND :endDate AND ps.end_date IS NULL AND pg.location_id = :location GROUP BY p.patient_id " + + "union " + + "select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and e.encounter_type=53 and o.concept_id=6272 and o.value_coded in (1706,1366) and o.obs_datetime between patients.art_start_date AND :endDate and e.location_id=:location group by p.patient_id " + + "union " + + "select person_id as patient_id from person " + + "where dead=1 and death_date is not null and death_date between patients.art_start_date AND :endDate " + + "union select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs obsEncontrado on e.encounter_id=obsEncontrado.encounter_id " + + "inner join obs obsObito on e.encounter_id=obsObito.encounter_id " + + "where e.voided=0 and obsEncontrado.voided=0 and p.voided=0 and obsObito.voided=0 and e.encounter_type in (21,36,37) and e.encounter_datetime between patients.art_start_date AND :endDate and e.location_id=:location and obsEncontrado.concept_id in (2003, 6348) and obsEncontrado.value_coded=1066 and obsObito.concept_id=2031 and obsObito.value_coded=1383 group by p.patient_id) GROUP BY patients.patient_id " + + "HAVING MIN(lev_seg.encounter_datetime) = MAX(lev_seg.encounter_datetime) OR MIN(lev_seg.encounter_datetime) IS NULL )patients_all GROUP BY patients_all.patient_id "; + + public static final String + findPatientsWhoStartedArtInAPeriodAndAreDeath33DaysAfterArtInitiation = + "SELECT patients_all.patient_id FROM( " + + "SELECT patients.patient_id, patients.art_start_date FROM( " + + "SELECT patient_id, MIN(art_start_date) art_start_date FROM (Select p.patient_id,min(e.encounter_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on o.encounter_id=e.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and e.encounter_type in (18,6,9) and o.concept_id=1255 and o.value_coded=1256 and e.encounter_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type in (18,6,9,53) and o.concept_id=1190 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union " + + "select pg.patient_id,min(date_enrolled) art_start_date from patient p inner join patient_program pg on p.patient_id=pg.patient_id " + + "where pg.voided=0 and p.voided=0 and program_id=2 and date_enrolled<=:endDate and location_id=:location group by pg.patient_id " + + "union " + + "SELECT e.patient_id, MIN(e.encounter_datetime) AS art_start_date FROM patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "WHERE p.voided=0 and e.encounter_type=18 AND e.voided=0 and e.encounter_datetime<=:endDate and e.location_id=:location GROUP BY p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type=52 and o.concept_id=23866 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id)patients_started_art " + + "WHERE patients_started_art.patient_id NOT IN (" + + "SELECT p.patient_id FROM patient p " + + "INNER JOIN patient_program pg ON pg.patient_id = p.patient_id " + + "INNER JOIN patient_state ps ON ps.patient_program_id = pg.patient_program_id " + + "WHERE p.voided = 0 AND pg.voided = 0 AND ps.voided = 0 AND pg.program_id = 2 AND ps.state = 29 AND ps.start_date BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) AND pg.location_id = :location GROUP BY p.patient_id " + + "union " + + "Select p.patient_id from patient p inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs obsTrans on e.encounter_id=obsTrans.encounter_id and obsTrans.voided=0 and obsTrans.concept_id=1369 and obsTrans.value_coded=1065 " + + "inner join obs obsTarv on e.encounter_id=obsTarv.encounter_id and obsTarv.voided=0 and obsTarv.concept_id=6300 and obsTarv.value_coded=6276 " + + "where p.voided=0 and e.voided=0 and e.encounter_type=53 and obsTrans.obs_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location) GROUP BY patients_started_art.patient_id " + + "HAVING MIN(patients_started_art.art_start_date) BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH)) patients " + + "INNER JOIN (SELECT p.patient_id FROM patient p " + + "INNER JOIN patient_program pg ON pg.patient_id = p.patient_id " + + "INNER JOIN patient_state ps ON ps.patient_program_id = pg.patient_program_id " + + "WHERE p.voided = 0 AND pg.voided = 0 AND ps.voided = 0 AND pg.program_id = 2 AND ps.state=10 AND ps.start_date BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND :endDate AND ps.end_date IS NULL AND pg.location_id = :location GROUP BY p.patient_id " + + "union " + + "select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and e.encounter_type=53 and o.concept_id=6272 and o.value_coded=1366 and o.obs_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND :endDate and e.location_id=:location group by p.patient_id " + + "union " + + "select person_id as patient_id from person " + + "where dead=1 and death_date is not null and death_date between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND :endDate " + + "union select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs obsEncontrado on e.encounter_id=obsEncontrado.encounter_id " + + "inner join obs obsObito on e.encounter_id=obsObito.encounter_id " + + "where e.voided=0 and obsEncontrado.voided=0 and p.voided=0 and obsObito.voided=0 and e.encounter_type in (21,36,37) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND :endDate and e.location_id=:location and obsEncontrado.concept_id in (2003, 6348) and obsEncontrado.value_coded=1066 and obsObito.concept_id=2031 and obsObito.value_coded=1383 group by p.patient_id) obito ON obito.patient_id = patients.patient_id GROUP BY patients.patient_id ) patients_all " + + "GROUP BY patients_all.patient_id "; + + public static final String + findPatientsWhoStartedArtInAPeriodAndSuspendTratement33DaysAfterInitiation = + "SELECT patients_all.patient_id FROM( " + + "SELECT patients.patient_id, patients.art_start_date FROM ( " + + "SELECT patient_id, MIN(art_start_date) art_start_date FROM ( " + + "Select p.patient_id,min(e.encounter_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on o.encounter_id=e.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and e.encounter_type in (18,6,9) and o.concept_id=1255 and o.value_coded=1256 and e.encounter_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type in (18,6,9,53) and o.concept_id=1190 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union " + + "select pg.patient_id,min(date_enrolled) art_start_date from patient p inner join patient_program pg on p.patient_id=pg.patient_id " + + "where pg.voided=0 and p.voided=0 and program_id=2 and date_enrolled<=:endDate and location_id=:location group by pg.patient_id " + + "union " + + "SELECT e.patient_id, MIN(e.encounter_datetime) AS art_start_date FROM patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "WHERE p.voided=0 and e.encounter_type=18 AND e.voided=0 and e.encounter_datetime<=:endDate and e.location_id=:location GROUP BY p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type=52 and o.concept_id=23866 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id) patients_started_art " + + "WHERE patients_started_art.patient_id NOT IN(" + + "SELECT p.patient_id FROM patient p " + + "INNER JOIN patient_program pg ON pg.patient_id = p.patient_id " + + "INNER JOIN patient_state ps ON ps.patient_program_id = pg.patient_program_id " + + "WHERE p.voided = 0 AND pg.voided = 0 AND ps.voided = 0 AND pg.program_id = 2 AND ps.state = 29 AND ps.start_date BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) AND pg.location_id = :location GROUP BY p.patient_id " + + "union " + + "Select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs obsTrans on e.encounter_id=obsTrans.encounter_id and obsTrans.voided=0 and obsTrans.concept_id=1369 and obsTrans.value_coded=1065 " + + "inner join obs obsTarv on e.encounter_id=obsTarv.encounter_id and obsTarv.voided=0 and obsTarv.concept_id=6300 and obsTarv.value_coded=6276 " + + "where p.voided=0 and e.voided=0 and e.encounter_type=53 and obsTrans.obs_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location) GROUP BY patients_started_art.patient_id " + + "HAVING MIN(patients_started_art.art_start_date) BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH)) patients " + + "INNER JOIN ( " + + "SELECT p.patient_id FROM patient p " + + "INNER JOIN patient_program pg ON pg.patient_id = p.patient_id " + + "INNER JOIN patient_state ps ON ps.patient_program_id = pg.patient_program_id " + + "WHERE p.voided = 0 AND pg.voided = 0 AND ps.voided = 0 AND pg.program_id = 2 AND ps.state=8 AND ps.start_date BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND :endDate AND ps.end_date IS NULL AND pg.location_id = :location GROUP BY p.patient_id " + + "union select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and e.encounter_type=53 and o.concept_id=6272 and o.value_coded=1709 and o.obs_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND :endDate and e.location_id=:location group by p.patient_id) suspenso ON suspenso.patient_id = patients.patient_id GROUP BY patients.patient_id ) patients_all GROUP BY patients_all.patient_id "; + + public static final String + findPatientsWhoStartedArtInAPeriodAndAreTrasferedOut33DaysAfterInitiation = + "SELECT patients_all.patient_id FROM (" + + "SELECT patients.patient_id, patients.art_start_date FROM( " + + "SELECT patient_id, MIN(art_start_date) art_start_date FROM ( " + + "Select p.patient_id,min(e.encounter_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on o.encounter_id=e.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and e.encounter_type in (18,6,9) and o.concept_id=1255 and o.value_coded=1256 and e.encounter_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type in (18,6,9,53) and o.concept_id=1190 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id " + + "union " + + "select pg.patient_id,min(date_enrolled) art_start_date from patient p inner join patient_program pg on p.patient_id=pg.patient_id " + + "where pg.voided=0 and p.voided=0 and program_id=2 and date_enrolled<=:endDate and location_id=:location group by pg.patient_id " + + "union " + + "SELECT e.patient_id, MIN(e.encounter_datetime) AS art_start_date FROM patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "WHERE p.voided=0 and e.encounter_type=18 AND e.voided=0 and e.encounter_datetime<=:endDate and e.location_id=:location GROUP BY p.patient_id " + + "union select p.patient_id,min(value_datetime) art_start_date from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type=52 and o.concept_id=23866 and o.value_datetime is not null and o.value_datetime<=:endDate and e.location_id=:location group by p.patient_id) patients_started_art " + + "WHERE patients_started_art.patient_id NOT IN( " + + "SELECT p.patient_id FROM patient p " + + "INNER JOIN patient_program pg ON pg.patient_id = p.patient_id " + + "INNER JOIN patient_state ps ON ps.patient_program_id = pg.patient_program_id " + + "WHERE p.voided = 0 AND pg.voided = 0 AND ps.voided = 0 AND pg.program_id = 2 AND ps.state = 29 AND ps.start_date BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) AND pg.location_id = :location GROUP BY p.patient_id " + + "union " + + "Select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs obsTrans on e.encounter_id=obsTrans.encounter_id and obsTrans.voided=0 and obsTrans.concept_id=1369 and obsTrans.value_coded=1065 " + + "inner join obs obsTarv on e.encounter_id=obsTarv.encounter_id and obsTarv.voided=0 and obsTarv.concept_id=6300 and obsTarv.value_coded=6276 " + + "where p.voided=0 and e.voided=0 and e.encounter_type=53 and obsTrans.obs_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location) GROUP BY patients_started_art.patient_id " + + "HAVING MIN(patients_started_art.art_start_date) BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH)) patients " + + "INNER JOIN ( " + + "SELECT p.patient_id FROM patient p " + + "INNER JOIN patient_program pg ON pg.patient_id = p.patient_id " + + "INNER JOIN patient_state ps ON ps.patient_program_id = pg.patient_program_id " + + "WHERE p.voided = 0 AND pg.voided = 0 AND ps.voided = 0 AND pg.program_id = 2 AND ps.state=7 AND ps.start_date BETWEEN (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND :endDate AND ps.end_date IS NULL AND pg.location_id = :location GROUP BY p.patient_id " + + "union " + + "select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and e.encounter_type=53 and o.concept_id=6272 and o.value_coded=1706 and o.obs_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND :endDate and e.location_id=:location group by p.patient_id ) transferido ON transferido.patient_id = patients.patient_id GROUP BY patients.patient_id) patients_all GROUP BY patients_all.patient_id "; + + public static final String + patientsThatAreFemaleAndWereMarkedAsPregnantInTheInitialConsultationOrFollowUpConsultationAndMasterCard = + "select patient_id from ( " + + "Select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and concept_id=1982 and value_coded in (44,1465) and e.encounter_type in (5,6) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "Select p.patient_id from patient p inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and concept_id=1279 and e.encounter_type in (5,6) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "Select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and concept_id=1600 and e.encounter_type in (5,6) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "Select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and concept_id=6334 and value_coded=6331 and e.encounter_type in (5,6) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "select pp.patient_id from patient_program pp where pp.program_id=8 and pp.voided=0 and pp.date_enrolled between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and pp.location_id=:location " + + "union " + + "Select p.patient_id from patient p inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and o.concept_id=5272 and o.value_coded=1065 and e.encounter_type=53 and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "Select p.patient_id from patient p inner join encounter e on p.patient_id=e.patient_id inner join obs o on e.encounter_id=o.encounter_id where p.voided=0 and e.voided=0 and o.voided=0 and o.concept_id=1465 and e.encounter_type=6 and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + ") gravida inner join person p on p.person_id=gravida.patient_id where p.gender='F' "; + + public static final String + patientsThatAreFemaleAndWereMarkedAsBrestfeetingInTheInitialConsultationOrFollowUpConsultationAndMasterCard = + "select lactante_real.patient_id from ( " + + "Select p.patient_id,o.value_datetime data_parto from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and concept_id=5599 and e.encounter_type in (5,6) and o.value_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "Select p.patient_id, e.encounter_datetime data_parto from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and concept_id=6332 and value_coded=1065 and e.encounter_type in (6,53) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "Select p.patient_id, e.encounter_datetime data_parto from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and concept_id=6334 and value_coded=6332 and e.encounter_type in (5,6) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "select pg.patient_id,ps.start_date data_parto from patient p " + + "inner join patient_program pg on p.patient_id=pg.patient_id " + + "inner join patient_state ps on pg.patient_program_id=ps.patient_program_id " + + "where pg.voided=0 and ps.voided=0 and p.voided=0 and pg.program_id=8 and ps.state=27 and ps.end_date is null and ps.start_date between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and location_id=:location) lactante_real " + + "inner join person on lactante_real.patient_id=person.person_id " + + "where person.gender='F' and lactante_real.patient_id not in ( " + + "select patient_id from ( " + + "Select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and concept_id=1982 and value_coded in (44,1465) and e.encounter_type in (5,6) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "Select p.patient_id from patient p inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and concept_id=1279 and e.encounter_type in (5,6) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "Select p.patient_id from patient p inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and concept_id=1600 and e.encounter_type in (5,6) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union Select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and concept_id=6334 and value_coded=6331 and e.encounter_type in (5,6) and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "select pp.patient_id from patient_program pp " + + "where pp.program_id=8 and pp.voided=0 and pp.date_enrolled between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and pp.location_id=:location " + + "union " + + "Select p.patient_id from patient p inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and o.concept_id=5272 and o.value_coded=1065 and e.encounter_type=53 and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + "union " + + "Select p.patient_id from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and o.concept_id=1465 and e.encounter_type=6 and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location " + + ") gravida " + + "inner join person p on p.person_id=gravida.patient_id " + + "where p.gender='F') "; + + public static final String patientsThatAreAdult = + "select patient_id from ( " + + "select patient_id,min(data_inicio) data_inicio from( " + + "Select p.patient_id,min(e.encounter_datetime) data_inicio from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on o.encounter_id=e.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and e.encounter_type in (18,6,9) and o.concept_id=1255 and o.value_coded=1256 and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location group by p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) data_inicio from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type in (18,6,9,53) and o.concept_id=1190 and o.value_datetime is not null and o.value_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location group by p.patient_id " + + "union " + + "select pg.patient_id,min(date_enrolled) data_inicio from patient p " + + "inner join patient_program pg on p.patient_id=pg.patient_id " + + "where pg.voided=0 and p.voided=0 and program_id=2 and date_enrolled between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and location_id=:location group by pg.patient_id " + + "union " + + "SELECT e.patient_id, MIN(e.encounter_datetime) AS data_inicio FROM patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "WHERE p.voided=0 and e.encounter_type=18 AND e.voided=0 and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location GROUP BY p.patient_id " + + "union Select p.patient_id,min(value_datetime) data_inicio from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type=52 and o.concept_id=23866 and o.value_datetime is not null and o.value_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location group by p.patient_id) inicio group by patient_id )inicio_real " + + "inner join person pe on inicio_real.patient_id=pe.person_id " + + "where timestampdiff(year,birthdate,data_inicio)>=15 and birthdate is not null "; + + public static final String patientsThatAreChild = + "select patient_id from ( " + + "select patient_id,min(data_inicio) data_inicio from ( " + + "Select p.patient_id,min(e.encounter_datetime) data_inicio from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on o.encounter_id=e.encounter_id " + + "where e.voided=0 and o.voided=0 and p.voided=0 and e.encounter_type in (18,6,9) and o.concept_id=1255 and o.value_coded=1256 and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location group by p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) data_inicio from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type in (18,6,9,53) and o.concept_id=1190 and o.value_datetime is not null and o.value_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location group by p.patient_id " + + "union " + + "select pg.patient_id,min(date_enrolled) data_inicio from patient p inner join patient_program pg on p.patient_id=pg.patient_id " + + "where pg.voided=0 and p.voided=0 and program_id=2 and date_enrolled between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and location_id=:location group by pg.patient_id " + + "union " + + "SELECT e.patient_id, MIN(e.encounter_datetime) AS data_inicio FROM patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "WHERE p.voided=0 and e.encounter_type=18 AND e.voided=0 and e.encounter_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location GROUP BY p.patient_id " + + "union " + + "Select p.patient_id,min(value_datetime) data_inicio from patient p " + + "inner join encounter e on p.patient_id=e.patient_id " + + "inner join obs o on e.encounter_id=o.encounter_id " + + "where p.voided=0 and e.voided=0 and o.voided=0 and e.encounter_type=52 and o.concept_id=23866 and o.value_datetime is not null and o.value_datetime between (:endDate - INTERVAL 2 MONTH + INTERVAL 1 DAY) AND (:endDate - INTERVAL 1 MONTH) and e.location_id=:location group by p.patient_id) inicio group by patient_id " + + ")inicio_real inner join person pe on inicio_real.patient_id=pe.person_id where timestampdiff(year,birthdate,data_inicio)<=14 and birthdate is not null"; + } +} diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupCombinedImErReport.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupCombinedImErReport.java index 59d970804b..9944ffe2ed 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupCombinedImErReport.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupCombinedImErReport.java @@ -4,7 +4,6 @@ import java.util.Arrays; import java.util.List; import java.util.Properties; - import org.openmrs.module.eptsreports.reporting.library.cohorts.GenericCohortQueries; import org.openmrs.module.eptsreports.reporting.library.datasets.Eri2MonthsDataset; import org.openmrs.module.eptsreports.reporting.library.datasets.Eri4MonthsDataset; @@ -24,89 +23,90 @@ @Component public class SetupCombinedImErReport extends EptsDataExportManager { - @Autowired - private GenericCohortQueries genericCohortQueries; + @Autowired private GenericCohortQueries genericCohortQueries; - @Autowired - private Eri2MonthsDataset eri2MonthsDataset; + @Autowired private Eri2MonthsDataset eri2MonthsDataset; - @Autowired - private Eri4MonthsDataset eri4MonthsDataset; + @Autowired private Eri4MonthsDataset eri4MonthsDataset; - @Autowired - private TxNewDataset txNewDataset; + @Autowired private TxNewDataset txNewDataset; - @Autowired - private TxCurrDataset txCurrDataset; + @Autowired private TxCurrDataset txCurrDataset; - @Autowired - private EriDSDDataset eriDSDDataset; + @Autowired private EriDSDDataset eriDSDDataset; - @Override - public String getExcelDesignUuid() { - return "f6a597ba-5fa2-47d4-ab45-da128cabe7ac"; - } + @Override + public String getExcelDesignUuid() { + return "f6a597ba-5fa2-47d4-ab45-da128cabe7ac"; + } - @Override - public String getUuid() { - return "c6743d00-7107-4760-b19e-a9c1b4432ac0"; - } + @Override + public String getUuid() { + return "c6743d00-7107-4760-b19e-a9c1b4432ac0"; + } - @Override - public String getName() { - return "IM-ER-Report"; - } + @Override + public String getName() { + return "IM-ER-Report"; + } - @Override - public String getDescription() { - return "PEPFAR Early Retention Indicators"; - } + @Override + public String getDescription() { + return "PEPFAR Early Retention Indicators"; + } - @Override - public ReportDefinition constructReportDefinition() { - final ReportDefinition rd = new ReportDefinition(); + @Override + public ReportDefinition constructReportDefinition() { + final ReportDefinition rd = new ReportDefinition(); - rd.setUuid(this.getUuid()); - rd.setName(this.getName()); - rd.setDescription(this.getDescription()); - rd.setParameters(this.txNewDataset.getParameters()); + rd.setUuid(this.getUuid()); + rd.setName(this.getName()); + rd.setDescription(this.getDescription()); + rd.setParameters(this.txNewDataset.getParameters()); - rd.addDataSetDefinition("N", Mapped.mapStraightThrough(this.txNewDataset.constructTxNewDataset())); + rd.addDataSetDefinition( + "N", Mapped.mapStraightThrough(this.txNewDataset.constructTxNewDataset())); - rd.addDataSetDefinition("C", Mapped.mapStraightThrough(this.txCurrDataset.constructTxCurrDataset(true))); + rd.addDataSetDefinition( + "C", Mapped.mapStraightThrough(this.txCurrDataset.constructTxCurrDataset(true))); - rd.addDataSetDefinition("ERI2", Mapped.mapStraightThrough(this.eri2MonthsDataset.constructEri2MonthsDatset())); + rd.addDataSetDefinition( + "ERI2", Mapped.mapStraightThrough(this.eri2MonthsDataset.constructEri2MonthsDatset())); - rd.addDataSetDefinition("ERI4", Mapped.mapStraightThrough(this.eri4MonthsDataset.constructEri4MonthsDataset())); + rd.addDataSetDefinition( + "ERI4", Mapped.mapStraightThrough(this.eri4MonthsDataset.constructEri4MonthsDataset())); - rd.addDataSetDefinition("ERIDSD", Mapped.mapStraightThrough(this.eriDSDDataset.constructEriDSDDataset())); + rd.addDataSetDefinition( + "ERIDSD", Mapped.mapStraightThrough(this.eriDSDDataset.constructEriDSDDataset())); - rd.setBaseCohortDefinition(EptsReportUtils.map( - this.genericCohortQueries.generalSql("baseCohortQuery", BaseQueries.getBaseCohortQuery()), - "endDate=${endDate},location=${location}")); + rd.setBaseCohortDefinition( + EptsReportUtils.map( + this.genericCohortQueries.generalSql( + "baseCohortQuery", BaseQueries.getBaseCohortQuery()), + "endDate=${endDate},location=${location}")); - return rd; - } + return rd; + } - @Override - public String getVersion() { - return "1.0-SNAPSHOT"; - } + @Override + public String getVersion() { + return "1.0-SNAPSHOT"; + } - @Override - public List constructReportDesigns(final ReportDefinition reportDefinition) { - ReportDesign reportDesign = null; - try { - reportDesign = this.createXlsReportDesign(reportDefinition, "IM_ER_Report.xls", "ERI-Report", - this.getExcelDesignUuid(), null); - final Properties props = new Properties(); - props.put("sortWeight", "5000"); - reportDesign.setProperties(props); - } - catch (final IOException e) { - throw new ReportingException(e.toString()); - } + @Override + public List constructReportDesigns(final ReportDefinition reportDefinition) { + ReportDesign reportDesign = null; + try { + reportDesign = + this.createXlsReportDesign( + reportDefinition, "IM_ER_Report.xls", "ERI-Report", this.getExcelDesignUuid(), null); + final Properties props = new Properties(); + props.put("sortWeight", "5000"); + reportDesign.setProperties(props); + } catch (final IOException e) { + throw new ReportingException(e.toString()); + } - return Arrays.asList(reportDesign); - } + return Arrays.asList(reportDesign); + } } diff --git a/api/src/main/resources/IM_ER_Report.xls b/api/src/main/resources/IM_ER_Report.xls index 5330f4f5d1..dd513f0d38 100644 Binary files a/api/src/main/resources/IM_ER_Report.xls and b/api/src/main/resources/IM_ER_Report.xls differ