diff --git a/api/src/main/java/org/openmrs/module/eptsreports/metadata/HivMetadata.java b/api/src/main/java/org/openmrs/module/eptsreports/metadata/HivMetadata.java index 6fe01aee5d..aad5015c20 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/metadata/HivMetadata.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/metadata/HivMetadata.java @@ -49,6 +49,7 @@ public Concept getReturnVisitDateForArvDrugConcept() { .getGlobalProperty("eptsreports.returnVisitDateForArvDrugConceptUuid"); return getConcept(uuid); } + // concept_id=6123 public Concept getDateOfHivDiagnosisConcept() { String uuid = @@ -98,6 +99,7 @@ public Concept getAzt3tcAbcEfvConcept() { .getGlobalProperty("eptsreports.AZT_3TC_ABC_EFV_ConceptUuid"); return getConcept(uuid); } + // 6327 public Concept getD4t3tcAbcEfvConcept() { String uuid = @@ -105,6 +107,7 @@ public Concept getD4t3tcAbcEfvConcept() { .getGlobalProperty("eptsreports.D4T_3TC_ABC_EFV_ConceptUuid"); return getConcept(uuid); } + // 6326 public Concept getAzt3tcAbcLpvConcept() { String uuid = @@ -112,6 +115,7 @@ public Concept getAzt3tcAbcLpvConcept() { .getGlobalProperty("eptsreports.AZT_3TC_ABC_LPV_ConceptUuid"); return getConcept(uuid); } + // 6325 public Concept getD4t3tcAbcLpvConcept() { String uuid = @@ -119,48 +123,56 @@ public Concept getD4t3tcAbcLpvConcept() { .getGlobalProperty("eptsreports.D4T_3TC_ABC_LPV_ConceptUuid"); return getConcept(uuid); } + // 6109 public Concept getAztDdiLpvConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.AZT_DDI_LPV_ConceptUuid"); return getConcept(uuid); } + // 1315 public Concept getTdf3tcEfvConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.TDF_3TC_EFV_ConceptUuid"); return getConcept(uuid); } + // 1314 public Concept getAzt3tcLpvConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.AZT_3TC_LPV_ConceptUuid"); return getConcept(uuid); } + // 1313 public Concept getAbc3tcEfvConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.ABC_3TC_EFV_ConceptUuid"); return getConcept(uuid); } + // 1312 public Concept getAbc3tcNvpConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.ABC_3TC_NVP_ConceptUuid"); return getConcept(uuid); } + // 1311 public Concept getAbc3tcLpvConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.ABC_3TC_LPV_ConceptUuid"); return getConcept(uuid); } + // public Concept getTdf3tcLpvConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.TDF_3TC_LPV_ConceptUuid"); return getConcept(uuid); } + // concept id 6306 public Concept getAcceptContactConcept() { String uuid = @@ -195,6 +207,7 @@ public Concept getIsoniazidUsageConcept() { Context.getAdministrationService().getGlobalProperty("eptsreports.isoniazidUseConceptUuid"); return getConcept(uuid); } + // concept_id=1695 public Concept getCD4AbsoluteOBSConcept() { String uuid = @@ -216,6 +229,7 @@ public Concept getcurrentWhoHivStageConcept() { Context.getAdministrationService().getGlobalProperty("eptsreports.currentWhoHivStageUuid"); return getConcept(uuid); } + // concept_id=1205 public Concept getWho2AdultStageConcept() { String uuid = @@ -229,6 +243,7 @@ public Concept getWho3AdultStageConcept() { Context.getAdministrationService().getGlobalProperty("eptsreports.who3AdultStageUuid"); return getConcept(uuid); } + // concept_id=1207 public Concept getWho4AdultStageConcept() { String uuid = @@ -268,46 +283,54 @@ public Concept getBuscaConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.busca"); return getConcept(uuid); } + // concept_id = 6254 public Concept getSecondAttemptConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.secondAttempt"); return getConcept(uuid); } + // concept_id = 6255 public Concept getThirdAttemptConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.thirdAttempt"); return getConcept(uuid); } + // concept_id = 2016 public Concept getDefaultingMotiveConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.defaultingMotive"); return getConcept(uuid); } + // concept_id = 2158 public Concept getReportOfVisitSupportConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.reportOfVisitSupport"); return getConcept(uuid); } + // concept_id = 2157 public Concept getPatientHadDifficultyConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.patientHadDifficulty"); return getConcept(uuid); } + // concept_id = 1272 public Concept getPatientFoundForwardedConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.patientFoundForwarded"); return getConcept(uuid); } + // concept_id = 2037 public Concept getWhoGaveInformationConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.whoGaveInformation"); return getConcept(uuid); } + // concept_id = 2180 public Concept getCardDeliveryDateConcept() { String uuid = @@ -377,145 +400,171 @@ public Concept getAdherenceCoucelingConcept() { Context.getAdministrationService().getGlobalProperty("eptsreports.adherenceCounselingUuid"); return getConcept(uuid); } + // concept_id=5497 public Concept getCD4AbsoluteConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.cd4AbsolutoUuid"); return getConcept(uuid); } + // concept_id=730 public Concept getCD4PercentConcept() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.cd4PercentUuid"); return getConcept(uuid); } + // concept_id=1714 public Concept getAdherence() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.poorAdherenceUuid"); return getConcept(uuid); } + // concept_id=2015 public Concept getAdverseReaction() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.adverseReactionUuid"); return getConcept(uuid); } + // Concept 6292 public Concept getNeutropenia() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.neutropenia"); return getConcept(uuid); } + // Concept 6293 public Concept getPancreatitis() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.pancreatitis"); return getConcept(uuid); } + // Concept 6294 public Concept getHepatotoxicity() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.hepatotoxicity"); return getConcept(uuid); } + // Concept 6295 public Concept getPsychologicalChanges() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.psychologicalChanges"); return getConcept(uuid); } + // Concept 6296 public Concept getMyopathy() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.myopathy"); return getConcept(uuid); } + // Concept 6297 public Concept getSkinAllergy() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.skinAllergy"); return getConcept(uuid); } + // Concept 6298 public Concept getLipodystrophy() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.lipodystrophy"); return getConcept(uuid); } + // Concept 6299 public Concept getLacticAcidosis() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.lacticAcidosis"); return getConcept(uuid); } + // Concept 821 public Concept getPeripheralNeuropathy() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.peripheralNeuropathy"); return getConcept(uuid); } + // Concept 16 public Concept getDiarrhea() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.diarrhea"); return getConcept(uuid); } + // Concept 1406 public Concept getOtherDiagnosis() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.otherDiagnosis"); return getConcept(uuid); } + // Concept 23724 GAAC public Concept getGaac() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.gaac"); return getConcept(uuid); } + // Concept 23725 AF public Concept getFamilyApproach() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.familyApproach"); return getConcept(uuid); } + // Concept 23726 CA public Concept getAccessionClubs() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.accessionClubs"); return getConcept(uuid); } + // Concept 23727 PU public Concept getSingleStop() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.singleStop"); return getConcept(uuid); } + // Concept 23729 FR public Concept getRapidFlow() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.rapidFlow"); return getConcept(uuid); } + // Concept 23730 DT public Concept getQuarterlyDispensation() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.quarterlyDispensation"); return getConcept(uuid); } + // Concept 23731 DC public Concept getCommunityDispensation() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.communityDispensation"); return getConcept(uuid); } + // Concept 23732 Other Model public Concept getAnotherModel() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.anotherModel"); return getConcept(uuid); } + // Concept 1256 Start Drugs public Concept getStartDrugs() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.startDrugs"); return getConcept(uuid); } + // Concept 1257 Continue Regimen public Concept getContinueRegimen() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.continueRegimen"); return getConcept(uuid); } + // Concept 23808 Pre-ART Start Date public Concept getPreArtStartDate() { String uuid = @@ -552,8 +601,15 @@ public Concept getReasonPatientNotFound() { return getConcept(uuid); } - // Concept 2027 PATIENT IS DEAD + // Concept 1383 PATIENT IS DEAD - Incorrect public Concept getPatientIsDead() { + String uuid = + Context.getAdministrationService().getGlobalProperty("eptsreports.patientIsdeadIncorrect"); + return getConcept(uuid); + } + + // Concept 2027 PATIENT IS DEAD + public Concept getPatientIsDeadCorrect() { String uuid = Context.getAdministrationService().getGlobalProperty("eptsreports.patientIsdead"); return getConcept(uuid); } @@ -571,6 +627,21 @@ public Concept getTransferredOutConcept() { .getGlobalProperty("eptsreports.transferOutToAnotherFacilityConceptUuid"); return getConcept(uuid); } + + // Concept 23722 APPLICATION FOR LABORATORY RESEARCH + public Concept getApplicationForLaboratoryResearch() { + String uuid = + Context.getAdministrationService() + .getGlobalProperty("eptsreports.applicationForLaboratoryResearch"); + return getConcept(uuid); + } + // Concept 1305 HIV VIRAL LOAD, QUALITATIVE + public Concept getHivViralLoadQualitative() { + String uuid = + Context.getAdministrationService() + .getGlobalProperty("eptsreports.viralLoadQualitativeConceptUuid"); + return getConcept(uuid); + } // Encounter types // encounterType_id = 6 public EncounterType getAdultoSeguimentoEncounterType() { @@ -626,6 +697,7 @@ public EncounterType getEvaluationAndPrepForARTEncounterType() { .getGlobalProperty("eptsreports.evaluationAndPrepForARTEncounterTypeUuid"); return getEncounterType(uuid); } + // encounter_type 13 public EncounterType getMisauLaboratorioEncounterType() { String uuid = @@ -754,7 +826,8 @@ public ProgramWorkflowState getTransferredOutToAnotherHealthFacilityWorkflowStat } public ProgramWorkflowState getTransferredFromOtherHealthFacilityWorkflowState() { - // TODO Refactor this method, use #getTransferredFromOtherHealthFacilityWorkflowState(Program, + // TODO Refactor this method, use + // #getTransferredFromOtherHealthFacilityWorkflowState(Program, // ProgramWorkflow) String artProgramUuid = Context.getAdministrationService().getGlobalProperty(gpArtProgramUuid); String transferFromOtherUuid = diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/ResumoMensalCohortQueries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/ResumoMensalCohortQueries.java index 603b0177f1..2268d04c29 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/ResumoMensalCohortQueries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/ResumoMensalCohortQueries.java @@ -18,6 +18,7 @@ import static org.openmrs.module.reporting.evaluation.parameter.Mapped.mapStraightThrough; import java.util.Date; +import org.openmrs.Concept; import org.openmrs.Location; import org.openmrs.api.context.Context; import org.openmrs.module.eptsreports.metadata.HivMetadata; @@ -43,11 +44,14 @@ public class ResumoMensalCohortQueries { private HivMetadata hivMetadata; private TbMetadata tbMetadata; + private GenericCohortQueries genericCohortQueries; @Autowired - public ResumoMensalCohortQueries(HivMetadata hivMetadata, TbMetadata tbMetadata) { + public ResumoMensalCohortQueries( + HivMetadata hivMetadata, TbMetadata tbMetadata, GenericCohortQueries genericCohortQueries) { this.hivMetadata = hivMetadata; this.tbMetadata = tbMetadata; + this.genericCohortQueries = genericCohortQueries; } /** A1 Number of patients who initiated Pre-TARV at this HF by end of previous month */ @@ -479,4 +483,357 @@ private DateObsCohortDefinition getLastArvPickupDateCohort() { cd.setTimeModifier(BaseObsCohortDefinition.TimeModifier.LAST); return cd; } + + /** + * E1: Number of active patients in ART at the end of current month who performed Viral Load Test + * (Annual Notification) B12 OR (B1 OR B2 OR B3) AND NOT (B5 OR B6 OR B7 OR B8) + * + * @return CohortDefinition + */ + public CohortDefinition getNumberOfActivePatientsInArtAtEndOfCurrentMonthWithVlPerformed() { + CompositionCohortDefinition cd = new CompositionCohortDefinition(); + cd.setName( + "Number of active patients in ART at the end of current month who performed Viral Load Test (Annual Notification)"); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + + cd.addSearch( + "common", + map( + getStandardDefinitionForEcolumns(), + "startDate=${startDate},endDate=${endDate},location=${location}")); + + cd.addSearch( + "F", + map( + getPatientsWithCodedObsAndAnswers( + hivMetadata.getApplicationForLaboratoryResearch(), + hivMetadata.getHivViralLoadConcept()), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.addSearch( + "E1x", + map( + genericCohortQueries.generalSql( + "E1x", + ResumoMensalQueries.getE1ExclusionCriteria( + hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId(), + hivMetadata.getApplicationForLaboratoryResearch().getConceptId(), + hivMetadata.getHivViralLoadConcept().getConceptId())), + "startDate=${startDate},endDate=${endDate},location=${location}")); + + cd.setCompositionString("(common AND F) AND NOT E1x"); + return cd; + } + + public CohortDefinition getStandardDefinitionForEcolumns() { + CompositionCohortDefinition cd = new CompositionCohortDefinition(); + cd.setName("Standard columns for E1, E2 and E3"); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + + cd.addSearch( + "B12", + map( + getPatientsWhoInitiatedPreTarvDuringCurrentMonthAndScreenedTB(), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.addSearch( + "B1", + map( + getPatientsWhoInitiatedTarvAtThisFacilityDuringCurrentMonthB1(), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.addSearch( + "B2", + map( + getNumberOfPatientsTransferredInFromOtherHealthFacilitiesDuringCurrentMonthB2(), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.addSearch( + "B3", + map( + getPatientsWithStartDrugs(), + "onOrAfter=${startDate},onOrBefore=${endDate},locationList=${location}")); + cd.addSearch( + "B5", + map( + getPatientsTransferredOut(), + "onOrAfter=${startDate},onOrBefore=${endDate},locationList=${location}")); + cd.addSearch( + "B6", + map( + getPatientsWhoSuspendedTreatment(), + "onOrAfter=${startDate},onOrBefore=${endDate},locationList=${location}")); + cd.addSearch( + "B7", + map( + getNumberOfPatientsWhoAbandonedArtDuringCurrentMonthB7(), + "onOrBefore=${endDate},locationList=${location},value1=${endDate-90d},value2=${endDate}")); + cd.addSearch( + "B8", + map( + getPatientsWhoDied(), + "onOrAfter=${startDate},onOrBefore=${endDate},locationList=${location}")); + cd.setCompositionString("(B12 OR (B1 OR B2 OR B3)) AND NOT (B5 OR B6 OR B7 OR B8)"); + return cd; + } + + /** Filter only those patients */ + private CohortDefinition getPatientsWithCodedObsAndAnswers(Concept question, Concept answer) { + SqlCohortDefinition cd = new SqlCohortDefinition(); + cd.setName( + "Patients with lab request having question and answer - encounter date within boundaries"); + cd.addParameter(new Parameter("startDate", "After Date", Date.class)); + cd.addParameter(new Parameter("endDate", "Before Date", Date.class)); + cd.addParameter(new Parameter("location", "location", Location.class)); + cd.setQuery( + ResumoMensalQueries.getPatientsWithCodedObsAndAnswers( + hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId(), + question.getConceptId(), + answer.getConceptId())); + return cd; + } + + /** + * get patients who have viral load test done + * + * @return CohortDefinition + */ + private CohortDefinition getViralLoadTestDone() { + SqlCohortDefinition cd = new SqlCohortDefinition(); + cd.setName("Viral load test"); + cd.addParameter(new Parameter("startDate", "After Date", Date.class)); + cd.addParameter(new Parameter("endDate", "Before Date", Date.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + cd.setQuery( + ResumoMensalQueries.getPatientsHavingViralLoadResults( + hivMetadata.getHivViralLoadConcept().getConceptId(), + hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId())); + return cd; + } + + /** + * Get patients with coded observation + * + * @param question + * @return + */ + private CohortDefinition gePatientsWithCodedObs(Concept question) { + SqlCohortDefinition cd = new SqlCohortDefinition(); + cd.setName("Patients with Viral load qualitative done"); + cd.addParameter(new Parameter("startDate", "After Date", Date.class)); + cd.addParameter(new Parameter("endDate", "Before Date", Date.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + cd.setQuery( + ResumoMensalQueries.gePatientsWithCodedObs( + hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId(), + question.getConceptId())); + return cd; + } + + /** + * Combine the viral load and viral load qualitative + * + * @return CohortDefinition + */ + private CohortDefinition getViralLoadOrQualitative() { + CompositionCohortDefinition cd = new CompositionCohortDefinition(); + cd.setName("Combined viral load and its qualitative patients"); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + cd.addSearch( + "VL", + map( + getViralLoadTestDone(), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.addSearch( + "VLQ", + map( + gePatientsWithCodedObs(hivMetadata.getHivViralLoadQualitative()), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.setCompositionString("VL OR VLQ"); + return cd; + } + + /** + * E2 Get the combinations together E2: Number of active patients in ART at the end of current + * month who received a Viral Load Test Result (Annual Notification + * + * @return CohortDefinition + */ + public CohortDefinition + getNumberOfActivePatientsInArtAtTheEndOfTheCurrentMonthHavingVlTestResults() { + CompositionCohortDefinition cd = new CompositionCohortDefinition(); + cd.setName( + "E2: Number of active patients in ART at the end of current month who received a Viral Load Test Result (Annual Notification"); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + cd.addSearch( + "C", + map( + getStandardDefinitionForEcolumns(), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.addSearch( + "VL", + map( + getViralLoadOrQualitative(), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.addSearch( + "Ex2", + map( + genericCohortQueries.generalSql( + "Ex2", + ResumoMensalQueries.getE2ExclusionCriteria( + hivMetadata.getHivViralLoadConcept().getConceptId(), + hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId(), + hivMetadata.getHivViralLoadQualitative().getConceptId())), + "startDate=${startDate},endDate=${endDate},location=${location}")); + + cd.setCompositionString("(C AND VL) AND NOT Ex2"); + return cd; + } + + /** + * E3: Number of active patients in ART at the end of current month who received supressed Viral + * Load Result (Annual Notification) + * + * @return CohortDefinition + */ + public CohortDefinition getActivePatientsOnArtWhoRecievedVldSuppressionResults() { + CompositionCohortDefinition cd = new CompositionCohortDefinition(); + cd.setName( + "Number of active patients in ART at the end of current month who received supressed Viral Load Result (Annual Notification)"); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + cd.addSearch( + "C", + map( + getStandardDefinitionForEcolumns(), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.addSearch( + "SUPP", + map( + getViralLoadSuppression(), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.addSearch( + "QUAL", + map( + gePatientsWithCodedObs(hivMetadata.getHivViralLoadQualitative()), + "startDate=${startDate},endDate=${endDate},location=${location}")); + + cd.addSearch( + "Ex3", + map( + genericCohortQueries.generalSql( + "Ex3", + ResumoMensalQueries.getE3ExclusionCriteria( + hivMetadata.getHivViralLoadConcept().getConceptId(), + hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId(), + hivMetadata.getHivViralLoadQualitative().getConceptId())), + "startDate=${startDate},endDate=${endDate},location=${location}")); + + cd.setCompositionString("(C AND (SUPP OR QUAL)) AND NOT Ex3"); + return cd; + } + + private CohortDefinition getViralLoadSuppression() { + SqlCohortDefinition cd = new SqlCohortDefinition(); + cd.setName("Viral load suppression"); + cd.addParameter(new Parameter("startDate", "After Date", Date.class)); + cd.addParameter(new Parameter("endDate", "Before Date", Date.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + cd.setQuery( + ResumoMensalQueries.getPatientsHavingViralLoadSuppression( + hivMetadata.getHivViralLoadConcept().getConceptId(), + hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId())); + return cd; + } + + /** + * F1: Number of patients who had clinical appointment during the reporting month + * + * @return CohortDefinition + */ + public CohortDefinition getNumberOfPatientsWhoHadClinicalAppointmentDuringTheReportingMonth() { + SqlCohortDefinition cd = new SqlCohortDefinition(); + cd.setName("F1: Number of patients who had clinical appointment during the reporting month"); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + cd.setQuery( + ResumoMensalQueries.getPatientsWithGivenEncounterType( + hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId())); + return cd; + } + + /** + * F2: Number of patients who had clinical appointment during the reporting month and were + * screened for TB + * + * @return CohortDefinition + */ + public CohortDefinition + getNumberOfPatientsWhoHadClinicalAppointmentDuringTheReportingMonthAndScreenedFoTb() { + SqlCohortDefinition sqlCohortDefinition = new SqlCohortDefinition(); + sqlCohortDefinition.setName("Exclusions"); + sqlCohortDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class)); + sqlCohortDefinition.addParameter(new Parameter("endDate", "End Date", Date.class)); + sqlCohortDefinition.addParameter(new Parameter("location", "Location", Location.class)); + sqlCohortDefinition.setQuery( + ResumoMensalQueries.getPatientsForF2ForExclusionFromMainQuery( + hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId(), + tbMetadata.getHasTbSymptomsConcept().getConceptId(), + hivMetadata.getYesConcept().getConceptId(), + tbMetadata.getTBTreatmentPlanConcept().getConceptId())); + + CompositionCohortDefinition cd = new CompositionCohortDefinition(); + cd.setName( + "Number of patients who had clinical appointment during the reporting month and were screened for TB"); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + cd.addSearch( + "F2F", + map( + getPatientsWithCodedObsAndAnswers( + tbMetadata.getHasTbSymptomsConcept(), hivMetadata.getYesConcept()), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.addSearch( + "F2x", + map(sqlCohortDefinition, "startDate=${startDate},endDate=${endDate},location=${location}")); + + cd.setCompositionString("F2F AND NOT F2x"); + return cd; + } + + /** + * F3: Number of patients who had at least one clinical appointment during the year + * + * @return CohortDefinition + */ + public CohortDefinition getNumberOfPatientsWithAtLeastOneClinicalAppointmentDuringTheYear() { + CompositionCohortDefinition cd = new CompositionCohortDefinition(); + cd.setName("Number of patients who had at least one clinical appointment during the year"); + cd.addParameter(new Parameter("startDate", "Start Date", Date.class)); + cd.addParameter(new Parameter("endDate", "End Date", Date.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + + cd.addSearch( + "F1", + map( + getNumberOfPatientsWhoHadClinicalAppointmentDuringTheReportingMonth(), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.addSearch( + "Fx3", + map( + genericCohortQueries.generalSql( + "Fx3", + ResumoMensalQueries.getF3Exclusion( + hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId())), + "startDate=${startDate},endDate=${endDate},location=${location}")); + cd.setCompositionString("F1 AND NOT Fx3"); + return cd; + } } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/TxMlCohortQueries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/TxMlCohortQueries.java index 81c34a3a3e..77f46dea1a 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/TxMlCohortQueries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/TxMlCohortQueries.java @@ -276,14 +276,14 @@ public CohortDefinition getPatientsWhoMissedNextAppointmentAndNotTransferredOutA getPatientsWhoMissedNextAppointmentAndNotTransferredOut(), "startDate=${startDate},endDate=${endDate},location=${location}")); cd.addSearch( - "withVisitCard", + "withoutVisitCard", EptsReportUtils.map( - getPatientsWithVisitCardRegisteredBtwnLastAppointmentOrDrugPickupAndEnddate(), + getPatientsWithoutVisitCardRegisteredBtwnLastAppointmentOrDrugPickupAndEnddate(), "startDate=${startDate},endDate=${endDate},location=${location}")); cd.addSearch( - "withVisitCardandWithoutObs", + "withVisitCardandWithObs", EptsReportUtils.map( - getPatientsWithVisitCardAndWithoutObs(), + getPatientsWithVisitCardAndWithObs(), "startDate=${startDate},endDate=${endDate},location=${location}")); cd.addSearch( "dead", @@ -297,15 +297,15 @@ public CohortDefinition getPatientsWhoMissedNextAppointmentAndNotTransferredOutA "startDate=${startDate},endDate=${endDate},location=${location}")); cd.setCompositionString( - "missedAppointmentLessTransfers AND (NOT withVisitCard OR withVisitCardandWithoutObs) AND NOT (dead OR homeVisitCardDead)"); + "missedAppointmentLessTransfers AND (withoutVisitCard OR NOT withVisitCardandWithObs) AND NOT (dead OR homeVisitCardDead)"); return cd; } /* - * Untraced Patients Criteria 2 Patients with a set of observations + * Untraced Patients Criteria 2 Patients with a visit card of type busca with certain set of observations */ - public CohortDefinition getPatientsWithVisitCardAndWithoutObs() { + public CohortDefinition getPatientsWithVisitCardAndWithObs() { SqlCohortDefinition sqlCohortDefinition = new SqlCohortDefinition(); sqlCohortDefinition.setName("Get patients without Visit Card but with a set of observations"); @@ -314,7 +314,7 @@ public CohortDefinition getPatientsWithVisitCardAndWithoutObs() { sqlCohortDefinition.addParameter(new Parameter("location", "Location", Location.class)); sqlCohortDefinition.setQuery( - TxMlQueries.getPatientsWithVisitCardAndWithoutObs( + TxMlQueries.getPatientsWithVisitCardAndWithObs( hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId(), hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId(), hivMetadata.getARVPediatriaSeguimentoEncounterType().getEncounterTypeId(), @@ -345,7 +345,7 @@ public CohortDefinition getPatientsWithVisitCardAndWithoutObs() { * reporting end date and the reporting end date */ public CohortDefinition - getPatientsWithVisitCardRegisteredBtwnLastAppointmentOrDrugPickupAndEnddate() { + getPatientsWithoutVisitCardRegisteredBtwnLastAppointmentOrDrugPickupAndEnddate() { SqlCohortDefinition sqlCohortDefinition = new SqlCohortDefinition(); sqlCohortDefinition.setName( @@ -355,7 +355,7 @@ public CohortDefinition getPatientsWithVisitCardAndWithoutObs() { sqlCohortDefinition.addParameter(new Parameter("location", "Location", Location.class)); sqlCohortDefinition.setQuery( - TxMlQueries.getPatientsWithVisitCardRegisteredBtwnLastAppointmentOrDrugPickupAndEnddate( + TxMlQueries.getPatientsWithoutVisitCardRegisteredBtwnLastAppointmentOrDrugPickupAndEnddate( hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId(), hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId(), hivMetadata.getARVPediatriaSeguimentoEncounterType().getEncounterTypeId(), diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec14PatientListDataset.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec14PatientListDataset.java index 26df13c12c..7ce34389a9 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec14PatientListDataset.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec14PatientListDataset.java @@ -17,6 +17,7 @@ import org.openmrs.module.eptsreports.metadata.HivMetadata; import org.openmrs.module.eptsreports.reporting.library.datasets.BaseDataSet; import org.openmrs.module.eptsreports.reporting.library.queries.data.quality.Ec14Queries; +import org.openmrs.module.eptsreports.reporting.utils.EptsReportConstants; import org.openmrs.module.reporting.dataset.definition.DataSetDefinition; import org.openmrs.module.reporting.dataset.definition.SqlDataSetDefinition; import org.openmrs.module.reporting.evaluation.parameter.Parameter; @@ -39,7 +40,10 @@ public DataSetDefinition ec14PatientListDataset(List parameterList) { dsd.setName("EC14"); dsd.addParameters(parameterList); dsd.setSqlQuery( - Ec14Queries.getEc14CombinedQuery(hivMetadata.getARTProgram().getProgramId(), 100)); + Ec14Queries.getEc14CombinedQuery( + hivMetadata.getARTProgram().getProgramId(), + 100, + EptsReportConstants.getProgramWorkflowStateIds(hivMetadata.getARTProgram()))); return dsd; } } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec15PatientListDataset.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec15PatientListDataset.java index f34898a00d..52f1239194 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec15PatientListDataset.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec15PatientListDataset.java @@ -17,6 +17,7 @@ import org.openmrs.module.eptsreports.metadata.HivMetadata; import org.openmrs.module.eptsreports.reporting.library.datasets.BaseDataSet; import org.openmrs.module.eptsreports.reporting.library.queries.data.quality.Ec15Queries; +import org.openmrs.module.eptsreports.reporting.utils.EptsReportConstants; import org.openmrs.module.reporting.dataset.definition.DataSetDefinition; import org.openmrs.module.reporting.dataset.definition.SqlDataSetDefinition; import org.openmrs.module.reporting.evaluation.parameter.Parameter; @@ -44,7 +45,8 @@ public DataSetDefinition ec15PatientListDataset(List parameterList) { dsd.setSqlQuery( Ec15Queries.getEc15CombinedQuery( hivMetadata.getARTProgram().getProgramId(), - hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId())); + hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId(), + EptsReportConstants.getProgramWorkflowStateIds(hivMetadata.getARTProgram()))); return dsd; } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec3PatientListDataset.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec3PatientListDataset.java index 90f413f0d3..77d4a34e08 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec3PatientListDataset.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec3PatientListDataset.java @@ -17,6 +17,7 @@ import org.openmrs.module.eptsreports.metadata.HivMetadata; import org.openmrs.module.eptsreports.reporting.library.datasets.BaseDataSet; import org.openmrs.module.eptsreports.reporting.library.queries.data.quality.Ec3Queries; +import org.openmrs.module.eptsreports.reporting.utils.EptsReportConstants; import org.openmrs.module.reporting.dataset.definition.DataSetDefinition; import org.openmrs.module.reporting.dataset.definition.SqlDataSetDefinition; import org.openmrs.module.reporting.evaluation.parameter.Parameter; @@ -42,7 +43,8 @@ public DataSetDefinition ec3PatientListDataset(List parameterList) { Ec3Queries.getEc3CombinedQuery( hivMetadata.getARTProgram().getProgramId(), hivMetadata.getArtDeadWorkflowState().getProgramWorkflowStateId(), - hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId())); + hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId(), + EptsReportConstants.getProgramWorkflowStateIds(hivMetadata.getARTProgram()))); return dsd; } } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec4PatientListDataset.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec4PatientListDataset.java index 8ae362b764..ddd469f56b 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec4PatientListDataset.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/data/quality/Ec4PatientListDataset.java @@ -17,6 +17,7 @@ import org.openmrs.module.eptsreports.metadata.HivMetadata; import org.openmrs.module.eptsreports.reporting.library.datasets.BaseDataSet; import org.openmrs.module.eptsreports.reporting.library.queries.data.quality.Ec4Queries; +import org.openmrs.module.eptsreports.reporting.utils.EptsReportConstants; import org.openmrs.module.reporting.dataset.definition.DataSetDefinition; import org.openmrs.module.reporting.dataset.definition.SqlDataSetDefinition; import org.openmrs.module.reporting.evaluation.parameter.Parameter; @@ -42,7 +43,8 @@ public DataSetDefinition ec4PatientListDataset(List parameterList) { hivMetadata.getARTProgram().getProgramId(), hivMetadata.getArtDeadWorkflowState().getProgramWorkflowStateId(), hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId(), - hivMetadata.getARVPediatriaSeguimentoEncounterType().getEncounterTypeId())); + hivMetadata.getARVPediatriaSeguimentoEncounterType().getEncounterTypeId(), + EptsReportConstants.getProgramWorkflowStateIds(hivMetadata.getARTProgram()))); return dsd; } } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/resumo/ResumoMensalDataSetDefinition.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/resumo/ResumoMensalDataSetDefinition.java index e7c8d065ea..d01576555e 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/resumo/ResumoMensalDataSetDefinition.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/resumo/ResumoMensalDataSetDefinition.java @@ -60,6 +60,7 @@ public ResumoMensalDataSetDefinition( public DataSetDefinition constructResumoMensalDataset() { CohortIndicatorDataSetDefinition dsd = new CohortIndicatorDataSetDefinition(); + String mappings = "startDate=${startDate},endDate=${endDate},location=${location}"; dsd.setName("Resumo Mensal Data set B"); dsd.addParameters(getParameters()); @@ -410,6 +411,91 @@ public DataSetDefinition constructResumoMensalDataset() { getPatientsWhoInitiatedPreTarvDuringCurrentMonthAndDiagnosedForActiveTB(), ""); + // E1 indicators + + addRow( + dsd, + "E1", + "Annual Notification", + map( + eptsGeneralIndicator.getIndicator( + "E1", + map( + resumoMensalCohortQueries + .getNumberOfActivePatientsInArtAtEndOfCurrentMonthWithVlPerformed(), + mappings)), + mappings), + resumoMensalAandBdisaggregations.disAggForE()); + // E2 + addRow( + dsd, + "E2", + "Annual Notification", + map( + eptsGeneralIndicator.getIndicator( + "E2", + map( + resumoMensalCohortQueries + .getNumberOfActivePatientsInArtAtTheEndOfTheCurrentMonthHavingVlTestResults(), + mappings)), + mappings), + resumoMensalAandBdisaggregations.disAggForE()); + + // E3 + addRow( + dsd, + "E3", + "Annual Notification", + map( + eptsGeneralIndicator.getIndicator( + "E3", + map( + resumoMensalCohortQueries + .getActivePatientsOnArtWhoRecievedVldSuppressionResults(), + mappings)), + mappings), + resumoMensalAandBdisaggregations.disAggForE()); + + // F1 + dsd.addColumn( + "F1", + "Number of patients who had clinical appointment during the reporting month", + map( + eptsGeneralIndicator.getIndicator( + "F1", + map( + resumoMensalCohortQueries + .getNumberOfPatientsWhoHadClinicalAppointmentDuringTheReportingMonth(), + mappings)), + mappings), + ""); + // F2 + dsd.addColumn( + "F2", + "Number of patients who had clinical appointment during the reporting month and were screened for TB", + map( + eptsGeneralIndicator.getIndicator( + "F2", + map( + resumoMensalCohortQueries + .getNumberOfPatientsWhoHadClinicalAppointmentDuringTheReportingMonthAndScreenedFoTb(), + mappings)), + mappings), + ""); + // F3 + dsd.addColumn( + "F3", + "Number of patients who had at least one clinical appointment during the year", + map( + eptsGeneralIndicator.getIndicator( + "F3", + map( + resumoMensalCohortQueries + .getNumberOfPatientsWithAtLeastOneClinicalAppointmentDuringTheYear(), + mappings)), + mappings), + ""); + return dsd; } 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 bee802aa84..2084b3e3e6 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 @@ -75,6 +75,9 @@ public CohortDefinitionDimension age(AgeDimensionCohortInterface ageDimensionCoh dim.addCohortDefinition( "0-4", ageDimensionCohort.createXtoYAgeCohort("patients with age between 0 and 4 years", 0, 4)); + dim.addCohortDefinition( + "0-14", + ageDimensionCohort.createXtoYAgeCohort("patients with age between 0 and 14 years", 0, 14)); dim.addCohortDefinition( "0-15", ageDimensionCohort.createXtoYAgeCohort("patients with age between 0 and 15 years", 0, 15)); diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/disaggregations/ResumoMensalAandBdisaggregations.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/disaggregations/ResumoMensalAandBdisaggregations.java index 9859824dd4..7a49f529b6 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/disaggregations/ResumoMensalAandBdisaggregations.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/disaggregations/ResumoMensalAandBdisaggregations.java @@ -28,13 +28,13 @@ public List getUnder14YearsColumns() { new ColumnParameters("fiveTo9years", "5 to 9 years patients", "age=5-9", "02"); ColumnParameters tenTo14yearsMale = new ColumnParameters( - "tenTo14yearsMale", "10 to 14 years male patients", "gender=M|age=10-15", "03"); + "tenTo14yearsMale", "10 to 14 years male patients", "gender=M|age=10-14", "03"); ColumnParameters tenTo14yearsFemale = new ColumnParameters( - "tenTo14yearsFemale", "10 to 14 years female patients", "gender=F|age=10-15", "04"); + "tenTo14yearsFemale", "10 to 14 years female patients", "gender=F|age=10-14", "04"); ColumnParameters under14yearsTotal = new ColumnParameters( - "under14yearsTotal", "Under 15 years patients - Totals", "age=0-15", "05"); + "under14yearsTotal", "Under 15 years patients - Totals", "age=0-14", "05"); return Arrays.asList( under4years, fiveTo9years, tenTo14yearsMale, tenTo14yearsFemale, under14yearsTotal); @@ -62,9 +62,9 @@ public List getAdultPatients() { public List getAdolescentesColumns() { ColumnParameters tenTo14Male = - new ColumnParameters("tenTo14Male", "10 to 14 years male", "gender=M|age=10-15", "01"); + new ColumnParameters("tenTo14Male", "10 to 14 years male", "gender=M|age=10-14", "01"); ColumnParameters tenTo14Female = - new ColumnParameters("tenTo14Female", "10 to 14 years female", "gender=F|age=10-15", "02"); + new ColumnParameters("tenTo14Female", "10 to 14 years female", "gender=F|age=10-14", "02"); ColumnParameters fifteenTo19Female = new ColumnParameters( "fifteenTo19Female", "15 to 19 years female", "gender=F|age=15-19", "03"); @@ -76,4 +76,16 @@ public List getAdolescentesColumns() { return Arrays.asList( tenTo14Male, tenTo14Female, fifteenTo19Female, fifteenTo19Male, adolescentTotals); } + + /** + * Get teh disaggregations for the patients under 14 years and those above 14 yeara + * + * @return List of ColumnParameters + */ + public List disAggForE() { + ColumnParameters under14Years = + new ColumnParameters("under14", "Under 14 years", "age=0-14", "01"); + ColumnParameters over14Years = new ColumnParameters("over14", "15+ years", "age=15+", "02"); + return Arrays.asList(under14Years, over14Years); + } } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/ResumoMensalQueries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/ResumoMensalQueries.java index b1d8fee206..a47cfca282 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/ResumoMensalQueries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/ResumoMensalQueries.java @@ -120,4 +120,243 @@ public static String getPatientsTransferredFromAnotherHealthFacilityByEndOfPrevi typeOfPantientConcept, tarvConcept); } + + public static String getPatientsForF2ForExclusionFromMainQuery( + int encounterType, int tbSymptomsConcept, int yesConcept, int tbTreatmentPlanConcept) { + String query = + "SELECT p.patient_id " + + "FROM patient p " + + " JOIN encounter e " + + " ON p.patient_id = e.patient_id " + + " JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " JOIN (SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM encounter enc JOIN patient pat ON pat.patient_id=enc.patient_id " + + " JOIN obs ob ON enc.encounter_id=ob.encounter_id WHERE pat.voided = 0 AND enc.voided = 0 AND ob.voided = 0 " + + " AND enc.location_id = :location AND enc.encounter_datetime BETWEEN :startDate AND :endDate " + + " AND enc.encounter_type= %d AND ob.concept_id=%d AND ob.value_coded=%d) ed " + + " ON p.patient_id=ed.patient_id" + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND e.encounter_type = %d " + + " AND e.location_id = :location " + + " AND e.encounter_datetime = ed.endDate " + + " AND o.voided = 0 " + + " AND o.concept_id = %d "; + return String.format( + query, encounterType, tbSymptomsConcept, yesConcept, encounterType, tbTreatmentPlanConcept); + } + + /** + * Get patients with encounters within start and end date F1: Number of patients who had clinical + * appointment during the reporting month + * + * @return String + */ + public static String getPatientsWithGivenEncounterType(int encounterType) { + String query = + "SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id " + + " WHERE e.encounter_type=%d AND e.location_id=:location " + + " AND e.encounter_datetime BETWEEN :startDate AND :endDate AND p.voided=0 AND e.voided=0 "; + return String.format(query, encounterType); + } + + /** + * Get patients with viral load suppression + * + * @return String + */ + public static String getPatientsHavingViralLoadSuppression( + int viralLoadConcept, int encounterType) { + String query = + "SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id " + + " WHERE p.voided=0 AND e.voided=0 AND o.voided=0 AND e.location_id=:location " + + " AND e.encounter_datetime BETWEEN :startDate AND :endDate " + + " AND o.value_numeric IS NOT NULL " + + " AND o.concept_id=%d " + + " AND e.encounter_type=%d " + + " AND o.value_numeric < 1000"; + return String.format(query, viralLoadConcept, encounterType); + } + + /** + * getPatientsWithCodedObsAndAnswers + * + * @return String + */ + public static String getPatientsWithCodedObsAndAnswers( + int encounterType, int questionConceptId, int answerConceptId) { + String query = + "SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id " + + " WHERE p.voided = 0 AND e.voided = 0 AND o.voided = 0 " + + " AND e.location_id = :location AND e.encounter_datetime BETWEEN :startDate AND :endDate AND e.encounter_type=%d " + + " AND o.concept_id=%d AND o.value_coded=%d"; + return String.format(query, encounterType, questionConceptId, answerConceptId); + } + + /** + * Get patients with viral load suppression + * + * @return String + */ + public static String getPatientsHavingViralLoadResults(int viralLoadConcept, int encounterType) { + String query = + "SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id " + + " WHERE p.voided=0 AND e.voided=0 AND o.voided=0 AND e.location_id=:location " + + " AND e.encounter_datetime BETWEEN :startDate AND :endDate " + + " AND o.value_numeric IS NOT NULL " + + " AND o.concept_id=%d " + + " AND e.encounter_type=%d "; + return String.format(query, viralLoadConcept, encounterType); + } + + /** + * Get patients with any coded obs value + * + * @return String + */ + public static String gePatientsWithCodedObs(int encounterType, int conceptId) { + String query = + "SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id " + + " WHERE p.voided = 0 AND e.voided = 0 AND o.voided = 0 " + + " AND e.location_id = :location AND e.encounter_datetime BETWEEN :startDate AND :endDate AND e.encounter_type=%d " + + " AND o.concept_id=%d "; + return String.format(query, encounterType, conceptId); + } + + /** + * E1 exclusions + * + * @return String + */ + public static String getE1ExclusionCriteria( + int encounterType, int questionConceptId, int answerConceptId) { + String query = + "SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id " + + " JOIN (SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM patient pat " + + " JOIN encounter enc ON pat.patient_id=enc.patient_id JOIN obs ob ON enc.encounter_id=ob.encounter_id " + + " WHERE pat.voided = 0 AND enc.voided = 0 AND ob.voided = 0 AND enc.location_id = :location " + + " AND enc.encounter_datetime BETWEEN :startDate AND :endDate AND enc.encounter_type=%d AND " + + " ob.concept_id=%d AND ob.value_coded=%d) ed " + + " ON p.patient_id=ed.patient_id " + + " WHERE p.voided = 0 AND e.voided = 0 AND o.voided = 0 " + + " AND e.location_id = :location AND e.encounter_datetime BETWEEN " + + " IF(MONTH(:startDate) = 12 && DAY(:startDate) = 21, :startDate, CONCAT(YEAR(:startDate)-1, '-12','-21')) " + + " AND ed.endDate AND e.encounter_type=%d " + + " AND o.concept_id=%d AND o.value_coded=%d"; + return String.format( + query, + encounterType, + questionConceptId, + answerConceptId, + encounterType, + questionConceptId, + answerConceptId); + } + + /** + * E2 exclusions + * + * @param viralLoadConcept + * @param encounterType + * @param qualitativeConcept + * @return String + */ + public static String getE2ExclusionCriteria( + int viralLoadConcept, int encounterType, int qualitativeConcept) { + + String query = + "SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id " + + "JOIN (SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM patient pat JOIN encounter enc ON pat.patient_id=enc.patient_id JOIN obs ob " + + " ON enc.encounter_id=ob.encounter_id " + + " WHERE pat.voided=0 AND enc.voided=0 AND ob.voided=0 AND enc.location_id=:location AND enc.encounter_datetime " + + " BETWEEN :startDate AND :endDate AND ob.concept_id IN(%d, %d) AND enc.encounter_type=%d) ed " + + " ON p.patient_id=ed.patient_id " + + " WHERE p.voided=0 AND e.voided=0 AND o.voided=0 AND e.location_id=:location " + + " AND e.encounter_datetime BETWEEN " + + " IF(MONTH(:startDate) = 12 && DAY(:startDate) = 21, :startDate, CONCAT(YEAR(:startDate)-1, '-12','-21')) " + + " AND ed.endDate " + + " AND o.concept_id IN (%d, %d)" + + " AND e.encounter_type=%d "; + return String.format( + query, + viralLoadConcept, + qualitativeConcept, + encounterType, + viralLoadConcept, + qualitativeConcept, + encounterType); + } + + /** + * E3 exclusion + * + * @param viralLoadConcept + * @param encounterType + * @param qualitativeConcept + * @return + */ + public static String getE3ExclusionCriteria( + int viralLoadConcept, int encounterType, int qualitativeConcept) { + String query = + "SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id " + + " JOIN (SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM patient pat " + + " JOIN encounter enc ON pat.patient_id=enc.patient_id JOIN obs ob ON enc.encounter_id=ob.encounter_id " + + " WHERE pat.voided=0 AND enc.voided=0 AND ob.voided=0 AND enc.location_id=:location " + + " AND enc.encounter_datetime BETWEEN :startDate AND :endDate AND ob.value_numeric IS NOT NULL " + + " AND ob.concept_id=%d AND enc.encounter_type=%d AND ob.value_numeric < 1000) ed " + + " ON p.patient_id=ed.patient_id" + + " WHERE p.voided=0 AND e.voided=0 AND o.voided=0 AND e.location_id=:location " + + " AND e.encounter_datetime BETWEEN " + + " IF(MONTH(:startDate) = 12 && DAY(:startDate) = 21, :startDate, CONCAT(YEAR(:startDate)-1, '-12','-21')) " + + " AND ed.endDate " + + " AND o.value_numeric IS NOT NULL " + + " AND o.concept_id=%d " + + " AND e.encounter_type=%d " + + " AND o.value_numeric < 1000" + + " UNION " + + " SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN obs o ON e.encounter_id=o.encounter_id " + + " JOIN (SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM patient pat " + + " JOIN encounter enc ON pat.patient_id=enc.patient_id JOIN obs ob ON enc.encounter_id=ob.encounter_id " + + " WHERE pat.voided = 0 AND enc.voided = 0 AND ob.voided = 0 AND enc.location_id = :location AND " + + " enc.encounter_datetime BETWEEN :startDate AND :endDate AND enc.encounter_type=%d AND ob.concept_id=%d) ed " + + " ON p.patient_id=ed.patient_id " + + " WHERE p.voided = 0 AND e.voided = 0 AND o.voided = 0 " + + " AND e.location_id = :location AND e.encounter_datetime BETWEEN " + + " IF(MONTH(:startDate) = 12 && DAY(:startDate) = 21, :startDate, CONCAT(YEAR(:startDate)-1, '-12','-21')) " + + " AND ed.endDate " + + " AND e.encounter_type=%d " + + " AND o.concept_id=%d "; + + return String.format( + query, + viralLoadConcept, + encounterType, + viralLoadConcept, + encounterType, + encounterType, + qualitativeConcept, + encounterType, + qualitativeConcept); + } + + /** + * F3 exclusions + * + * @param encounterType + * @return + */ + public static String getF3Exclusion(int encounterType) { + String query = + " SELECT p.patient_id FROM patient p JOIN encounter e ON p.patient_id=e.patient_id JOIN ( " + + " SELECT pat.patient_id AS patient_id, enc.encounter_datetime AS endDate FROM encounter enc JOIN patient pat " + + " ON enc.patient_id=pat.patient_id WHERE enc.encounter_type=%d AND enc.location_id=:location " + + " AND enc.encounter_datetime BETWEEN :startDate AND :endDate AND pat.voided=0 AND enc.voided=0) ed " + + " ON p.patient_id=ed.patient_id" + + " WHERE e.encounter_type=%d AND e.location_id=:location " + + " AND e.encounter_datetime BETWEEN " + + " IF(MONTH(:startDate) = 12 && DAY(:startDate) = 21, :startDate, CONCAT(YEAR(:startDate)-1, '-12','-21')) " + + " AND ed.endDate " + + "AND p.voided=0 AND e.voided=0 "; + return String.format(query, encounterType, encounterType); + } } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/TxMlQueries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/TxMlQueries.java index f979f30a2a..3eac034360 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/TxMlQueries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/TxMlQueries.java @@ -82,7 +82,7 @@ public static String getPatientsMarkedDeadInHomeVisitCard( + "ON pa.patient_id=e.patient_id " + "INNER JOIN obs o " + "ON pa.patient_id=o.person_id " - + "WHERE e.encounter_type IN (%d) " + + "WHERE e.encounter_type IN (%d, %d, %d) " + "AND o.concept_id= %d " + "AND o.value_coded = %d " + "AND e.location_id=:location " @@ -99,9 +99,9 @@ public static String getPatientsMarkedDeadInHomeVisitCard( /* Untraced Patients Criteria 2 - Patients without Patient Visit Card without a set of observations + Patients without Patient Visit Card of type busca and with a set of observations */ - public static String getPatientsWithVisitCardAndWithoutObs( + public static String getPatientsWithVisitCardAndWithObs( int pharmacyEncounterTypeId, int adultoSequimentoEncounterTypeId, int arvPediatriaSeguimentoEncounterTypeId, @@ -125,34 +125,33 @@ public static String getPatientsWithVisitCardAndWithoutObs( String query = "SELECT pa.patient_id " + "FROM patient pa " - + " INNER JOIN (" - + " SELECT pa.patient_id,e.encounter_id FROM patient pa " - + " INNER JOIN encounter e ON pa.patient_id=e.patient_id " - + " INNER JOIN obs o ON pa.patient_id=o.person_id " - + " INNER JOIN (" - + " SELECT p.patient_id,MAX(e.encounter_datetime) return_date FROM patient p " - + " INNER JOIN encounter e ON e.patient_id = p.patient_id AND e.encounter_datetime <=:endDate AND e.location_id=:location " - + " INNER JOIN obs o ON o.encounter_id = e.encounter_id AND o.location_id=:location " - + " WHERE p.voided = 0 AND e.voided = 0 AND o.voided=0 " - + " AND e.encounter_type IN (%d,%d,%d) " - + " AND o.concept_id IN (%d, %d) " - + " AND e.location_id = :location " - + " GROUP BY p.patient_id)lp ON pa.patient_id=lp.patient_id " - + " WHERE e.encounter_datetime >= lp.return_date AND e.encounter_datetime<=:endDate " - + " AND e.encounter_type IN (%d, %d, %d) " - + " AND e.location_id=:location " - + " GROUP BY pa.patient_id) visitCard on visitCard.patient_id = pa.patient_id " - + " LEFT JOIN obs visitType ON " - + " visitType.encounter_id = visitCard.encounter_id AND " - + " visitType.concept_id = %d AND " - + " visitType.value_coded = %d AND " - + " visitType.obs_datetime <= :endDate " - + " LEFT JOIN obs o ON " - + " o.encounter_id = visitCard.encounter_id AND " - + " o.concept_id IN (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d) AND " - + " o.obs_datetime <= :endDate " - + " WHERE o.obs_id IS NULL OR visitType.obs_id IS NULL " - + "GROUP BY pa.patient_id "; + + "INNER JOIN (" + + " SELECT p.patient_id,MAX(e.encounter_datetime) return_date FROM patient p " + + " INNER JOIN encounter e ON e.patient_id = p.patient_id AND e.encounter_datetime <=:endDate AND e.location_id=:location " + + " INNER JOIN obs o ON o.encounter_id = e.encounter_id AND o.location_id=:location " + + " WHERE p.voided = 0 AND e.voided = 0 AND o.voided=0 " + + " AND e.encounter_type IN (%d,%d,%d) " + + " AND o.concept_id IN (%d, %d) " + + " AND e.location_id = :location " + + " GROUP BY p.patient_id)lp ON pa.patient_id=lp.patient_id " + + "INNER JOIN encounter e ON " + + " pa.patient_id=e.patient_id AND " + + " e.encounter_datetime >= lp.return_date AND " + + " e.encounter_datetime <= :endDate AND " + + " e.encounter_type IN (%d, %d, %d) AND " + + " e.location_id=:location " + + "INNER JOIN obs visitType ON " + + " pa.patient_id=visitType.person_id AND " + + " visitType.encounter_id = e.encounter_id AND " + + " visitType.concept_id = %d AND " + + " visitType.value_coded = %d AND " + + " visitType.obs_datetime <= :endDate " + + "INNER JOIN obs o ON " + + " pa.patient_id=o.person_id AND " + + " o.encounter_id = e.encounter_id AND " + + " o.concept_id IN (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d) AND " + + " o.obs_datetime <= :endDate " + + "GROUP BY pa.patient_id "; return String.format( query, @@ -182,18 +181,22 @@ public static String getPatientsWithVisitCardAndWithoutObs( ◦ the last scheduled appointment or drugs pick up (the most recent one) by reporting end date and ◦ the reporting end date */ - public static String getPatientsWithVisitCardRegisteredBtwnLastAppointmentOrDrugPickupAndEnddate( - int pharmacyEncounterTypeId, - int adultoSequimentoEncounterTypeId, - int arvPediatriaSeguimentoEncounterTypeId, - int returnVisitDateForDrugsConcept, - int returnVisitDateConcept, - int homeVisitCardEncounterTypeId, - int apoioReintegracaoParteAEncounterTypeId, - int apoioReintegracaoParteBEncounterTypeId) { + public static String + getPatientsWithoutVisitCardRegisteredBtwnLastAppointmentOrDrugPickupAndEnddate( + int pharmacyEncounterTypeId, + int adultoSequimentoEncounterTypeId, + int arvPediatriaSeguimentoEncounterTypeId, + int returnVisitDateForDrugsConcept, + int returnVisitDateConcept, + int homeVisitCardEncounterTypeId, + int apoioReintegracaoParteAEncounterTypeId, + int apoioReintegracaoParteBEncounterTypeId) { String query = " SELECT pa.patient_id FROM patient pa " + + " WHERE pa.patient_id NOT IN (" + + " SELECT pa.patient_id " + + " FROM patient pa" + " INNER JOIN encounter e ON pa.patient_id=e.patient_id " + " INNER JOIN obs o ON pa.patient_id=o.person_id " + " INNER JOIN (" @@ -208,7 +211,9 @@ public static String getPatientsWithVisitCardRegisteredBtwnLastAppointmentOrDrug + " WHERE e.encounter_datetime >= lp.return_date AND e.encounter_datetime<=:endDate" + " AND e.encounter_type IN (%d, %d, %d) " + " AND e.location_id=:location " - + " GROUP BY pa.patient_id"; + + " GROUP BY pa.patient_id" + + ") " + + " GROUP BY pa.patient_id"; return String.format( query, diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec14Queries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec14Queries.java index db04099b64..14bde502ad 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec14Queries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec14Queries.java @@ -13,6 +13,8 @@ */ package org.openmrs.module.eptsreports.reporting.library.queries.data.quality; +import java.util.List; + public class Ec14Queries { /** @@ -20,7 +22,9 @@ public class Ec14Queries { * * @return String */ - public static String getEc14CombinedQuery(int programId, int years) { + public static String getEc14CombinedQuery(int programId, int years, List statesList) { + String states = (String.valueOf(statesList).replaceAll("\\[", "")).replaceAll("]", ""); + String query = "SELECT DISTINCT(pa.patient_id), pi.identifier AS NID, CONCAT(pn.given_name, ' ', pn.family_name ) AS Name, DATE_FORMAT(pe.birthdate, '%d-%m-%Y') AS birthdate, IF(pe.birthdate_estimated = 1, 'Yes','No') AS Estimated_dob, pe.gender AS Sex, DATE_FORMAT(pa.date_created, '%d-%m-%Y %H:%i:%s') AS First_entry_date, DATE_FORMAT(pa.date_changed, '%d-%m-%Y %H:%i:%s') AS Last_updated, DATE_FORMAT(pg.date_enrolled, '%d-%m-%Y') AS date_enrolled, case when ps.state = 9 then 'DROPPED FROM TREATMENT' when ps.state = 6 then 'ACTIVE ON PROGRAM' when ps.state = 10 then 'PATIENT HAS DIED' when ps.state = 8 then 'SUSPENDED TREATMENT' when ps.state = 7 then 'TRANSFERED OUT TO ANOTHER FACILITY' when ps.state = 29 then 'TRANSFERRED FROM OTHER FACILTY' end AS state, l.name AS location_name FROM patient pa " + " INNER JOIN patient_identifier pi ON pa.patient_id=pi.patient_id" @@ -35,6 +39,9 @@ public static String getEc14CombinedQuery(int programId, int years) { + programId + " AND ps.start_date IS NOT NULL AND ps.end_date IS NULL " + " AND pe.birthdate IS NOT NULL " + + " AND ps.state IN(" + + states + + ") " + " AND TIMESTAMPDIFF(YEAR, pe.birthdate, :endDate) >" + years; return query; diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec15Queries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec15Queries.java index f725696d67..e40d8fda90 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec15Queries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec15Queries.java @@ -13,6 +13,8 @@ */ package org.openmrs.module.eptsreports.reporting.library.queries.data.quality; +import java.util.List; + public class Ec15Queries { /** @@ -20,10 +22,12 @@ public class Ec15Queries { * * @return String */ - public static String getEc15CombinedQuery(int programId, int encounterType) { + public static String getEc15CombinedQuery( + int programId, int encounterType, List statesList) { + String states = (String.valueOf(statesList).replaceAll("\\[", "")).replaceAll("]", ""); String query = "SELECT patient_id, NID, Name, birthdate, Estimated_dob, Sex, First_entry_date, Last_updated, date_enrolled, MIN(encounter_date) AS encounter_date, encounter_date_created, state, location_name FROM(" - + " SELECT pa.patient_id, pi.identifier AS NID, CONCAT(pn.given_name, ' ', pn.family_name ) AS Name, DATE_FORMAT(pe.birthdate, '%d-%m-%Y') AS birthdate, IF(pe.birthdate_estimated = 1, 'Yes','No') AS Estimated_dob, pe.gender AS Sex, DATE_FORMAT(pa.date_created, '%d-%m-%Y %H:%i:%s') AS First_entry_date, DATE_FORMAT(pa.date_changed, '%d-%m-%Y %H:%i:%s') AS Last_updated, DATE_FORMAT(pg.date_enrolled, '%d-%m-%Y %H:%i:%s') AS date_enrolled, DATE_FORMAT(e.encounter_datetime, '%d-%m-%Y %H:%i:%s') AS encounter_date, DATE_FORMAT(e.date_created, '%d-%m-%Y %H:%i:%s') AS encounter_date_created,case when ps.state = 9 then 'DROPPED FROM TREATMENT' when ps.state = 6 then 'ACTIVE ON PROGRAM' when ps.state = 10 then 'PATIENT HAS DIED' when ps.state = 8 then 'SUSPENDED TREATMENT' when ps.state = 7 then 'TRANSFERED OUT TO ANOTHER FACILITY' when ps.state = 29 then 'TRANSFERRED FROM OTHER FACILTY' end AS state, l.name AS location_name FROM patient pa " + + " SELECT pa.patient_id, pi.identifier AS NID, CONCAT(pn.given_name, ' ', pn.family_name ) AS Name, DATE_FORMAT(pe.birthdate, '%d-%m-%Y') AS birthdate, IF(pe.birthdate_estimated = 1, 'Yes','No') AS Estimated_dob, pe.gender AS Sex, DATE_FORMAT(pa.date_created, '%d-%m-%Y %H:%i:%s') AS First_entry_date, DATE_FORMAT(pa.date_changed, '%d-%m-%Y %H:%i:%s') AS Last_updated, DATE_FORMAT(pg.date_enrolled, '%d-%m-%Y') AS date_enrolled, DATE_FORMAT(e.encounter_datetime, '%d-%m-%Y %H:%i:%s') AS encounter_date, DATE_FORMAT(e.date_created, '%d-%m-%Y %H:%i:%s') AS encounter_date_created,case when ps.state = 9 then 'DROPPED FROM TREATMENT' when ps.state = 6 then 'ACTIVE ON PROGRAM' when ps.state = 10 then 'PATIENT HAS DIED' when ps.state = 8 then 'SUSPENDED TREATMENT' when ps.state = 7 then 'TRANSFERED OUT TO ANOTHER FACILITY' when ps.state = 29 then 'TRANSFERRED FROM OTHER FACILTY' end AS state, l.name AS location_name FROM patient pa " + " INNER JOIN patient_identifier pi ON pa.patient_id=pi.patient_id" + " INNER JOIN person pe ON pa.patient_id=pe.person_id" + " INNER JOIN person_name pn ON pa.patient_id=pn.person_id " @@ -39,7 +43,10 @@ public static String getEc15CombinedQuery(int programId, int encounterType) { + encounterType + " AND pe.birthdate IS NOT NULL" + " AND e.location_id IN(:location) AND pa.voided = 0 and e.voided=0 " - + " AND pe.birthdate > e.encounter_datetime" + + " AND pe.birthdate > e.encounter_datetime " + + " AND ps.state IN(" + + states + + ") " + ")f_ec15 GROUP BY f_ec15.patient_id"; return query; } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec3Queries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec3Queries.java index 665a046bdd..c35d1291e1 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec3Queries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec3Queries.java @@ -13,6 +13,8 @@ */ package org.openmrs.module.eptsreports.reporting.library.queries.data.quality; +import java.util.List; + public class Ec3Queries { /** @@ -20,7 +22,9 @@ public class Ec3Queries { * * @return String */ - public static String getEc3CombinedQuery(int programId, int stateId, int encounterType) { + public static String getEc3CombinedQuery( + int programId, int stateId, int encounterType, List stateIds) { + String states = (String.valueOf(stateIds).replaceAll("\\[", "")).replaceAll("]", ""); String query = "SELECT dd.patient_id As patient_id, pi.identifier AS NID, CONCAT(pn.given_name, ' ', pn.family_name ) AS Name, DATE_FORMAT(pe.birthdate, '%d-%m-%Y') AS birthdate, IF(pe.birthdate_estimated = 1, 'Yes','No') AS Estimated_dob, pe.gender AS Sex, DATE_FORMAT(pe.date_created, '%d-%m-%Y %H:%i:%s') AS First_entry_date, DATE_FORMAT(pe.date_changed, '%d-%m-%Y %H:%i:%s') AS Last_updated, DATE_FORMAT(pg.date_enrolled, '%d-%m-%Y') AS date_enrolled, case when ps.state = 9 then 'DROPPED FROM TREATMENT' when ps.state = 6 then 'ACTIVE ON PROGRAM' when ps.state = 10 then 'PATIENT HAS DIED' when ps.state = 8 then 'SUSPENDED TREATMENT' when ps.state = 7 then 'TRANSFERED OUT TO ANOTHER FACILITY' when ps.state = 29 then 'TRANSFERRED FROM OTHER FACILTY' end AS state, DATE_FORMAT(ps.start_date, '%d-%m-%Y') AS state_date, DATE_FORMAT(pe.death_date,'%d-%m-%Y') As death_date, MIN(DATE_FORMAT(e.encounter_datetime, '%d-%m-%Y')) AS encounter_date, DATE_FORMAT(e.date_created, '%d-%m-%Y %H:%i:%s') AS encounter_date_created, dd.location_name AS location_name FROM (" + " SELECT pg.patient_id AS patient_id, ps.start_date As death_date, l.name AS location_name " @@ -67,6 +71,9 @@ public static String getEc3CombinedQuery(int programId, int stateId, int encount + encounterType + " AND pg.location_id IN(:location)" + " AND ps.start_date IS NOT NULL AND ps.end_date IS NULL " + + " AND ps.state IN(" + + states + + ") " + " AND e.encounter_datetime >= dd.death_date " + " GROUP BY dd.patient_id"; return query; diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec4Queries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec4Queries.java index fe305f75ca..718979fe98 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec4Queries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/data/quality/Ec4Queries.java @@ -13,6 +13,8 @@ */ package org.openmrs.module.eptsreports.reporting.library.queries.data.quality; +import java.util.List; + public class Ec4Queries { /** @@ -21,7 +23,8 @@ public class Ec4Queries { * @return String */ public static String getEc4CombinedQuery( - int programId, int stateId, int adultFollowUp, int childFollowUp) { + int programId, int stateId, int adultFollowUp, int childFollowUp, List stateIds) { + String states = (String.valueOf(stateIds).replaceAll("\\[", "")).replaceAll("]", ""); String query = "SELECT dd.patient_id As patient_id, pi.identifier AS NID, CONCAT(pn.given_name, ' ', pn.family_name ) AS Name, DATE_FORMAT(pe.birthdate, '%d-%m-%Y') AS birthdate, IF(pe.birthdate_estimated = 1, 'Yes','No') AS Estimated_dob, pe.gender AS Sex, DATE_FORMAT(pe.date_created, '%d-%m-%Y %H:%i:%s') AS First_entry_date, DATE_FORMAT(pe.date_changed, '%d-%m-%Y %H:%i:%s') AS Last_updated, DATE_FORMAT(pg.date_enrolled, '%d-%m-%Y') AS date_enrolled, case when ps.state = 9 then 'DROPPED FROM TREATMENT' when ps.state = 6 then 'ACTIVE ON PROGRAM' when ps.state = 10 then 'PATIENT HAS DIED' when ps.state = 8 then 'SUSPENDED TREATMENT' when ps.state = 7 then 'TRANSFERED OUT TO ANOTHER FACILITY' when ps.state = 29 then 'TRANSFERRED FROM OTHER FACILTY' end AS state, DATE_FORMAT(ps.start_date, '%d-%m-%Y') AS state_date, DATE_FORMAT(pe.death_date,'%d-%m-%Y') As death_date, MIN(DATE_FORMAT(e.encounter_datetime, '%d-%m-%Y')) AS encounter_date, DATE_FORMAT(e.date_created, '%d-%m-%Y %H:%i:%s') AS encounter_date_created, dd.location_name AS location_name FROM (" + " SELECT pg.patient_id AS patient_id, ps.start_date As death_date, l.name AS location_name " @@ -77,6 +80,9 @@ public static String getEc4CombinedQuery( + ") " + " AND pg.location_id IN(:location)" + " AND ps.start_date IS NOT NULL AND ps.end_date IS NULL " + + " AND ps.state IN(" + + states + + ") " + " AND e.encounter_datetime >= dd.death_date " + " GROUP BY dd.patient_id"; return query; diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupEc20DataQualityReport.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupEc20DataQualityReport.java index 84688b0f4c..79fcc7c4ab 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupEc20DataQualityReport.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupEc20DataQualityReport.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +@Deprecated @Component public class SetupEc20DataQualityReport extends EptsDataExportManager { diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/utils/EptsReportConstants.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/utils/EptsReportConstants.java index 39a96d9398..f473a7b579 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/utils/EptsReportConstants.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/utils/EptsReportConstants.java @@ -12,6 +12,11 @@ package org.openmrs.module.eptsreports.reporting.utils; +import java.util.ArrayList; +import java.util.List; +import org.openmrs.Program; +import org.openmrs.ProgramWorkflowState; + public final class EptsReportConstants { // Enumeration @@ -24,4 +29,12 @@ public enum PregnantOrBreastfeedingWomen { PREGNANTWOMEN, BREASTFEEDINGWOMEN } + + public static List getProgramWorkflowStateIds(Program program) { + List defaultStateIds = new ArrayList<>(); + for (ProgramWorkflowState p : program.getAllWorkflows().iterator().next().getStates()) { + defaultStateIds.add(p.getProgramWorkflowStateId()); + } + return defaultStateIds; + } } diff --git a/api/src/main/resources/Data_Quality_Report.xls b/api/src/main/resources/Data_Quality_Report.xls index 6faa6c5807..9cb3479d81 100644 Binary files a/api/src/main/resources/Data_Quality_Report.xls and b/api/src/main/resources/Data_Quality_Report.xls differ diff --git a/api/src/main/resources/Relatorio_Mensal.xls b/api/src/main/resources/Relatorio_Mensal.xls index d6c5de3135..f52377214c 100644 Binary files a/api/src/main/resources/Relatorio_Mensal.xls and b/api/src/main/resources/Relatorio_Mensal.xls differ diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index e3e511f39e..5d92c2f446 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -424,6 +424,14 @@ + + @MODULE_ID@.patientIsdeadIncorrect + e1dac772-1d5f-11e0-b929-000c29ad1d07 + + UUID for the PATIENT IS DEAD concept - Incorrectly used + + + @MODULE_ID@.typeOfVisit e1e055a2-1d5f-11e0-b929-000c29ad1d07 @@ -1349,6 +1357,24 @@ + + + eptsreports.applicationForLaboratoryResearch + 92653c45-9eb2-486d-90c0-3e00569e99c0 + + UUID for the APPLICATION FOR LABORATORY RESEARCH concept + + + + + + eptsreports.viralLoadQualitativeConceptUuid + e1da2704-1d5f-11e0-b929-000c29ad1d07 + + UUID for the Viral load qualitative concept + + +