diff --git a/api/src/main/java/org/openmrs/module/eptsreports/metadata/CommonMetadata.java b/api/src/main/java/org/openmrs/module/eptsreports/metadata/CommonMetadata.java index c304032028..fc08f7d84a 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/metadata/CommonMetadata.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/metadata/CommonMetadata.java @@ -1084,4 +1084,182 @@ public Concept getFollowingtSampleBetween9To17MonthsConcept() { .getGlobalProperty("eptsreports.followingSampleBetween9To17MonthsConceptUuid"); return getConcept(uuid); } + + /** + * concept_id = 374 + * + *
Name: METHOD OF FAMILY PLANNING + * + *
Description: + * + * @return {@link Concept} + */ + public Concept getMethodOfFamilyPlanningConcept() { + String uuid = + Context.getAdministrationService() + .getGlobalProperty("eptsreports.methodOfFamilyPlanningUuid"); + return getConcept(uuid); + } + + /** + * concept_id = 190 + * + *
Name: CONDOMS + * + *
Description: Methods for preventing pregnancy. + * + * @return {@link Concept} + */ + public Concept getCondomsConcept() { + String uuid = + Context.getAdministrationService().getGlobalProperty("eptsreports.condomsConceptUuid"); + return getConcept(uuid); + } + + /** + * concept_id = 780 + * + *
Name: ORAL CONTRACEPTION + * + *
Description: Female contraception method. Ultimately will make a good MedSet. + * + * @return {@link Concept} + */ + public Concept getOralContraceptionConcept() { + String uuid = + Context.getAdministrationService() + .getGlobalProperty("eptsreports.oralContraceptionConceptUuid"); + return getConcept(uuid); + } + + /** + * concept_id = 5279 + * + *
Name: INJECTABLE CONTRACEPTIVES + * + *
Description: Injectable medicines which enable deliberate prevention of conception or + * impregnation. + * + * @return {@link Concept} + */ + public Concept getInjectibleContraceptiveConcept() { + String uuid = + Context.getAdministrationService() + .getGlobalProperty("eptsreports.injectibleContraceptiveConceptUuid"); + return getConcept(uuid); + } + + /** + * concept_id = 21928 + * + *
Name: Implant + * + *
Description: Is a small flexible plastic rod that is placed under the skin in upper + * arm + * + * @return {@link Concept} + */ + public Concept getImplantConcept() { + String uuid = + Context.getAdministrationService().getGlobalProperty("eptsreports.implantConceptUuid"); + return getConcept(uuid); + } + + /** + * concept_id = 5275 + * + *
Name: INTRAUTERINE DEVICE + * + *
Description: A device (as a spiral of plastic or a ring of stainless steel) inserted + * and left in the uterus to prevent effective conception. + * + * @return {@link Concept} + */ + public Concept getIntrauterineDeviceConcept() { + String uuid = + Context.getAdministrationService() + .getGlobalProperty("eptsreports.intrauterineDeviceConceptUuid"); + return getConcept(uuid); + } + + /** + * concept_id = 5276 + * + *
Name: FEMALE STERILIZATION + * + *
Description: Surgical removal of the uterus. + * + * @return {@link Concept} + */ + public Concept getFemaleSterilizationConcept() { + String uuid = + Context.getAdministrationService() + .getGlobalProperty("eptsreports.femaleSterilizationConceptUuid"); + return getConcept(uuid); + } + + /** + * concept_id = 23714 + * + *
Name: VASECTOMY + * + *
Description: anti-conceptive method + * + * @return {@link Concept} + */ + public Concept getVasectomyConcept() { + String uuid = + Context.getAdministrationService().getGlobalProperty("eptsreports.vasectomyConceptUuid"); + return getConcept(uuid); + } + + /** + * concept_id = 23728 + * + *
Name: OTHER FAMILY PLANNING + * + *
Description: other family planning + * + * @return {@link Concept} + */ + public Concept getOtherFamilyPlanningConcept() { + String uuid = + Context.getAdministrationService() + .getGlobalProperty("eptsreports.otherFamilyPlanningConceptUuid"); + return getConcept(uuid); + } + + /** + * concept_id = 5085 + * + *
Name: Systolic blood pressure + * + *
Description: A patient's systolic blood pressure measurement (taken with a manual + * cuff in either a sitting or standing position) + * + * @return {@link Concept} + */ + public Concept getSystolicBoodPressureConcept() { + String uuid = + Context.getAdministrationService() + .getGlobalProperty("eptsreports.systolicBoodPressureConceptUuid"); + return getConcept(uuid); + } + + /** + * concept_id = 5086 + * + *
Name: Diastolic blood pressure + * + *
Description: A patient's diastolic blood pressure measurement (taken with a manual + * cuff in either a sitting or standing position) + * + * @return {@link Concept} + */ + public Concept getDiastolicBoodPressureConcept() { + String uuid = + Context.getAdministrationService() + .getGlobalProperty("eptsreports.diastolicBoodPressureConceptUuid"); + return getConcept(uuid); + } } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/ListOfPatientsWithMdsEvaluationCohortQueries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/ListOfPatientsWithMdsEvaluationCohortQueries.java index 79e7f4737a..66d84a5eaa 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/ListOfPatientsWithMdsEvaluationCohortQueries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/ListOfPatientsWithMdsEvaluationCohortQueries.java @@ -9,7 +9,6 @@ import org.openmrs.module.eptsreports.metadata.HivMetadata; import org.openmrs.module.eptsreports.metadata.TbMetadata; import org.openmrs.module.eptsreports.reporting.library.queries.ListOfPatientsWithMdsEvaluationQueries; -import org.openmrs.module.eptsreports.reporting.library.queries.advancedhivillness.ListOfPatientsOnAdvancedHivIllnessQueries; import org.openmrs.module.eptsreports.reporting.utils.EptsQueriesUtil; import org.openmrs.module.eptsreports.reporting.utils.queries.UnionBuilder; import org.openmrs.module.reporting.cohort.definition.CohortDefinition; @@ -35,22 +34,18 @@ public class ListOfPatientsWithMdsEvaluationCohortQueries { private final ListOfPatientsWithMdsEvaluationQueries listOfPatientsWithMdsEvaluationQueries; - private final ListOfPatientsOnAdvancedHivIllnessQueries listOfPatientsOnAdvancedHivIllnessQueries; - @Autowired public ListOfPatientsWithMdsEvaluationCohortQueries( HivMetadata hivMetadata, TbMetadata tbMetadata, CommonMetadata commonMetadata, ResumoMensalCohortQueries resumoMensalCohortQueries, - ListOfPatientsWithMdsEvaluationQueries listOfPatientsWithMdsEvaluationQueries, - ListOfPatientsOnAdvancedHivIllnessQueries listOfPatientsOnAdvancedHivIllnessQueries) { + ListOfPatientsWithMdsEvaluationQueries listOfPatientsWithMdsEvaluationQueries) { this.hivMetadata = hivMetadata; this.tbMetadata = tbMetadata; this.commonMetadata = commonMetadata; this.resumoMensalCohortQueries = resumoMensalCohortQueries; this.listOfPatientsWithMdsEvaluationQueries = listOfPatientsWithMdsEvaluationQueries; - this.listOfPatientsOnAdvancedHivIllnessQueries = listOfPatientsOnAdvancedHivIllnessQueries; } /** @@ -97,6 +92,38 @@ public CohortDefinition getCoort12Or24Or36() { return cd; } + public CohortDefinition getCoort24Or36month() { + CompositionCohortDefinition cd = new CompositionCohortDefinition(); + cd.setName("Patients who initiated the ART between the cohort period"); + cd.addParameter(new Parameter("evaluationYear", "evaluationYear", Integer.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + + CohortDefinition twentyFourMonths = getCoort(3, 2, false); + CohortDefinition thirtySixMonths = getCoort(4, 3, false); + + cd.addSearch("twentyFourMonths", Mapped.mapStraightThrough(twentyFourMonths)); + cd.addSearch("thirtySixMonths", Mapped.mapStraightThrough(thirtySixMonths)); + + cd.setCompositionString("twentyFourMonths OR thirtySixMonths"); + + return cd; + } + + public CohortDefinition getCoort36month() { + CompositionCohortDefinition cd = new CompositionCohortDefinition(); + cd.setName("Patients who initiated the ART between the cohort period"); + cd.addParameter(new Parameter("evaluationYear", "evaluationYear", Integer.class)); + cd.addParameter(new Parameter("location", "Location", Location.class)); + + CohortDefinition thirtySixMonths = getCoort(4, 3, false); + + cd.addSearch("thirtySixMonths", Mapped.mapStraightThrough(thirtySixMonths)); + + cd.setCompositionString("thirtySixMonths"); + + return cd; + } + private String getCoort12Or24Or36Query( int numberOfYearsStartDate, int numberOfYearsEndDate, boolean coortName) { @@ -359,7 +386,7 @@ public DataDefinition getTptInitiationDate() { map.put("165307", tbMetadata.getDT3HPConcept().getConceptId()); String query = - " SELECT min.patient_id, min.encounter_date " + " SELECT min.patient_id, MIN(min.encounter_date) AS tpt_start " + " FROM ( " + " SELECT p.patient_id, " + " MIN(e.encounter_datetime) AS encounter_date " @@ -805,7 +832,11 @@ public DataDefinition getLastViralLoadRequestOnTheFirst12MonthsOfTarv() { * * @return {DataDefinition} */ - public DataDefinition getLastViralLoadOnThePeriod(int minNumberOfMonths, int maxNumberOfMonths) { + public DataDefinition getLastViralLoadOnThePeriod( + int minNumberOfMonths, + int maxNumberOfMonths, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("Data do pedido da CV de entre 12º e 24º mês de TARV"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -830,6 +861,9 @@ public DataDefinition getLastViralLoadOnThePeriod(int minNumberOfMonths, int max map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); map.put("1305", hivMetadata.getHivViralLoadQualitative().getConceptId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT p.patient_id, " @@ -858,6 +892,10 @@ public DataDefinition getLastViralLoadOnThePeriod(int minNumberOfMonths, int max + " MONTH ) " + " AND o.concept_id = ${23722} " + " AND o.value_coded = ${856} " + + " AND p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY p.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -967,7 +1005,10 @@ private String getLastVlDateOn1st12MonthsOfTarv() { * @return {DataDefinition} */ public DataDefinition getLastViralLoadResultDateBetweenPeriodsInMonthsAfterTarv( - int minNumberOfMonths, int maxNumberOfMonths) { + int minNumberOfMonths, + int maxNumberOfMonths, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName( "C2 - Data de registo do resultado da entre 12º e 24º mês do TARV"); @@ -982,8 +1023,15 @@ public DataDefinition getLastViralLoadResultDateBetweenPeriodsInMonthsAfterTarv( map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); map.put("1065", hivMetadata.getYesConcept().getConceptId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); + map.put("1369", commonMetadata.getTransferFromOtherFacilityConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); - String query = getLastVlDateBetweenPeriods(minNumberOfMonths, maxNumberOfMonths); + String query = + getLastVlDateBetweenPeriods( + minNumberOfMonths, maxNumberOfMonths, minCohortNumberOfYears, maxCohortNumberOfYears); StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -992,7 +1040,11 @@ public DataDefinition getLastViralLoadResultDateBetweenPeriodsInMonthsAfterTarv( return sqlPatientDataDefinition; } - private String getLastVlDateBetweenPeriods(int minNumberOfMonths, int maxNumberOfMonths) { + private String getLastVlDateBetweenPeriods( + int minNumberOfMonths, + int maxNumberOfMonths, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { return " SELECT p.patient_id, " + " MAX(e.encounter_datetime) AS last_vl_date " + "FROM patient p " @@ -1024,6 +1076,10 @@ private String getLastVlDateBetweenPeriods(int minNumberOfMonths, int maxNumberO + " OR ( " + " o.concept_id = ${1305} " + " AND o.value_coded IS NOT NULL)) " + + " AND p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + "GROUP BY p.patient_id"; } @@ -1111,7 +1167,7 @@ public DataDefinition getLastViralLoadResultOnThe1st12MonthsOfTarv() { * @return {DataDefinition} */ public DataDefinition getSecondViralLoadResultBetweenPeriodsOfMonthsAfterTarv( - int firstMonth, int lastMonth) { + int firstMonth, int lastMonth, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("C3- Resultado da CV entre 12º e 24º mês do TARV "); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -1125,6 +1181,11 @@ public DataDefinition getSecondViralLoadResultBetweenPeriodsOfMonthsAfterTarv( map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); map.put("1065", hivMetadata.getYesConcept().getConceptId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); + map.put("1369", commonMetadata.getTransferFromOtherFacilityConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = "SELECT p.patient_id, " @@ -1136,7 +1197,7 @@ public DataDefinition getSecondViralLoadResultBetweenPeriodsOfMonthsAfterTarv( + "ON o.encounter_id = e.encounter_id " + "INNER JOIN " + " ( " - + getLastVlDateBetweenPeriods(firstMonth, lastMonth) + + getLastVlDateBetweenPeriods(firstMonth, lastMonth, 2, 4) + " ) last_vl ON last_vl.patient_id = p.patient_id " + " WHERE p.voided = 0 " + " AND e.voided = 0 " @@ -1153,6 +1214,10 @@ public DataDefinition getSecondViralLoadResultBetweenPeriodsOfMonthsAfterTarv( + "AND p.voided = 0 " + "AND e.voided = 0 " + "AND o.voided = 0 " + + " AND p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + "GROUP BY p.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -1265,7 +1330,11 @@ public DataDefinition getSecondCd4Result() { * * @return {DataDefinition} */ - public DataDefinition getCd4ResultSectionC(int minNumberOfMonths, int maxNumberOfMonths) { + public DataDefinition getCd4ResultSectionC( + int minNumberOfMonths, + int maxNumberOfMonths, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("Resultado do CD4 feito entre 12˚ e 24˚ mês de TARV"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -1287,6 +1356,9 @@ public DataDefinition getCd4ResultSectionC(int minNumberOfMonths, int maxNumberO map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT cd4.patient_id, " @@ -1320,7 +1392,7 @@ public DataDefinition getCd4ResultSectionC(int minNumberOfMonths, int maxNumberO + " AND enc.location_id = :location " + " AND obs.concept_id = ${1695} " + " AND obs.value_numeric IS NOT NULL " - + " AND enc.encounter_datetime >= DATE_ADD(art.art_encounter, INTERVAL " + + " AND enc.encounter_datetime > DATE_ADD(art.art_encounter, INTERVAL " + minNumberOfMonths + " MONTH ) " + " AND enc.encounter_datetime <= DATE_ADD(art.art_encounter, INTERVAL " @@ -1335,6 +1407,10 @@ public DataDefinition getCd4ResultSectionC(int minNumberOfMonths, int maxNumberO + " AND enc.encounter_datetime = most_recent_cd4.encounter_date " + " AND obs.concept_id = ${1695} " + " AND obs.value_numeric IS NOT NULL " + + " AND cd4.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY cd4.patient_id "; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -1377,7 +1453,11 @@ public DataDefinition getCd4ResultSectionC(int minNumberOfMonths, int maxNumberO * @return {DataDefinition} */ public DataDefinition getPatientsWithGoodAdhesion( - boolean b5Orc5, int minNumberOfMonths, int maxNumberOfMonths) { + boolean b5Orc5, + int minNumberOfMonths, + int maxNumberOfMonths, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName( "Teve registo de boa adesão em TODAS consultas entre 1˚ e 3˚ mês de TARV?; (coluna N) – Resposta = Sim ou Não"); @@ -1403,6 +1483,9 @@ public DataDefinition getPatientsWithGoodAdhesion( map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = "SELECT p.patient_id, " @@ -1432,7 +1515,7 @@ public DataDefinition getPatientsWithGoodAdhesion( b5Orc5 ? " AND e.encounter_datetime >= DATE_ADD( tarv.art_encounter, INTERVAL 33 DAY) " + " AND e.encounter_datetime <= DATE_ADD( tarv.art_encounter, INTERVAL 3 MONTH) " - : " AND e.encounter_datetime >= DATE_ADD( tarv.art_encounter, INTERVAL " + : " AND e.encounter_datetime > DATE_ADD( tarv.art_encounter, INTERVAL " + minNumberOfMonths + " MONTH ) " + " AND e.encounter_datetime <= DATE_ADD( tarv.art_encounter, INTERVAL " @@ -1488,7 +1571,11 @@ public DataDefinition getPatientsWithGoodAdhesion( + " ${1385} ) " + " GROUP BY e.patient_id) bad_consultations " + " ON bad_consultations.patient_id = p.patient_id " - + "WHERE p.voided = 0"; + + "WHERE p.voided = 0" + + " AND p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) "; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -1526,7 +1613,11 @@ public DataDefinition getPatientsWithGoodAdhesion( * @return {DataDefinition} */ public DataDefinition getPatientsPregnantBreastfeeding3MonthsTarv( - int minNumberOfMonths, int maxNumberOfMonths) { + int minNumberOfMonths, + int maxNumberOfMonths, + boolean b6Period, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName( "B6- Esteve grávida ou foi lactante entre 3˚ e 9º mês de TARV?: (coluna M)- Resposta = Sim ou Não"); @@ -1549,6 +1640,9 @@ public DataDefinition getPatientsPregnantBreastfeeding3MonthsTarv( map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = "SELECT final_query.person_id, " @@ -1576,16 +1670,31 @@ public DataDefinition getPatientsPregnantBreastfeeding3MonthsTarv( + " AND p.gender = 'F' " + " AND Timestampdiff(year, p.birthdate, art.art_encounter) > 9 " + " AND o.concept_id IN ( ${1982}, ${6332} ) " - + " AND o.value_coded = ( ${1065} ) " - + " AND e.encounter_datetime BETWEEN " - + " Date_add(art.art_encounter, INTERVAL " - + minNumberOfMonths - + " MONTH ) " - + " AND " - + " Date_add(art.art_encounter, INTERVAL " - + maxNumberOfMonths - + " MONTH ) " - + " GROUP BY p.person_id) final_query " + + " AND o.value_coded = ( ${1065} ) "; + query += + b6Period + ? " AND e.encounter_datetime >= " + + " Date_add(art.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + " AND e.encounter_datetime <= " + + " Date_add(art.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) " + : " AND e.encounter_datetime > " + + " Date_add(art.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + " AND e.encounter_datetime <= " + + " Date_add(art.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) "; + query += + " GROUP BY p.person_id) final_query " + + " WHERE final_query.person_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " UNION " + "SELECT final_query.person_id, " + " 'Não' " @@ -1612,16 +1721,31 @@ public DataDefinition getPatientsPregnantBreastfeeding3MonthsTarv( + " AND p.gender = 'F' " + " AND Timestampdiff(year, p.birthdate, art.art_encounter) > 9 " + " AND o.concept_id IN ( ${1982}, ${6332} ) " - + " AND o.value_coded = ( ${1065} ) " - + " AND e.encounter_datetime NOT BETWEEN " - + " Date_add(art.art_encounter, INTERVAL " - + minNumberOfMonths - + " MONTH ) " - + " AND " - + " Date_add(art.art_encounter, INTERVAL " - + maxNumberOfMonths - + " MONTH ) " - + " GROUP BY p.person_id) final_query "; + + " AND o.value_coded != ( ${1065} ) "; + query += + b6Period + ? " AND e.encounter_datetime BETWEEN " + + " Date_add(art.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + " AND " + + " Date_add(art.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) " + : " AND e.encounter_datetime BETWEEN " + + " Date_add(Date_add(art.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ), INTERVAL 1 DAY) " + + " AND " + + " Date_add(art.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) "; + query += + " GROUP BY p.person_id) final_query " + + " WHERE final_query.person_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) "; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -1667,7 +1791,11 @@ public DataDefinition getPatientsPregnantBreastfeeding3MonthsTarv( * @return {DataDefinition} */ public DataDefinition getPatientsWithTbThirdToNineMonth( - int minNumberOfMonths, int maxNumberOfMonths) { + int minNumberOfMonths, + int maxNumberOfMonths, + boolean b8Period, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName( "B8-Teve TB nos 1˚s 12 meses de TARV: (coluna Q) - Resposta = Sim ou Não (RF23)"); @@ -1694,6 +1822,9 @@ public DataDefinition getPatientsWithTbThirdToNineMonth( map.put("1256", hivMetadata.getStartDrugs().getConceptId()); map.put("1257", hivMetadata.getContinueRegimenConcept().getConceptId()); map.put("1267", hivMetadata.getCompletedConcept().getConceptId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = "SELECT final_query.patient_id, " @@ -1720,16 +1851,27 @@ public DataDefinition getPatientsWithTbThirdToNineMonth( + " AND o.voided = 0 " + " AND o2.voided = 0 " + " AND e.encounter_type = ${6} " - + " AND e.location_id = :location " - + " AND e.encounter_datetime BETWEEN " - + " date_add( art.art_encounter, INTERVAL " - + minNumberOfMonths - + " MONTH ) " - + " AND " - + " date_add( art.art_encounter, INTERVAL " - + maxNumberOfMonths - + " MONTH ) " - + " AND ( ( o.concept_id = ${23761} " + + " AND e.location_id = :location "; + query += + b8Period + ? " AND e.encounter_datetime >= " + + " date_add( art.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + " AND e.encounter_datetime <= " + + " date_add( art.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) " + : " AND e.encounter_datetime > " + + " date_add( art.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + " AND e.encounter_datetime <= " + + " date_add( art.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) "; + query += + " AND ( ( o.concept_id = ${23761} " + " AND o.value_coded IN ( ${1065} ) ) " + " OR ( o2.concept_id = ${1268} " + " AND o2.value_coded IN ( ${1256}, ${1257} ) ) ) " @@ -1759,20 +1901,35 @@ public DataDefinition getPatientsWithTbThirdToNineMonth( + " AND o.voided = 0 " + " AND o2.voided = 0 " + " AND e.encounter_type = ${6} " - + " AND e.location_id = :location " - + " AND e.encounter_datetime NOT BETWEEN " - + " date_add( art.art_encounter, INTERVAL " - + minNumberOfMonths - + " MONTH ) " - + " AND " - + " date_add( art.art_encounter, INTERVAL " - + maxNumberOfMonths - + " MONTH ) " - + " AND ( ( o.concept_id = ${23761} " + + " AND e.location_id = :location "; + query += + b8Period + ? " AND e.encounter_datetime NOT BETWEEN " + + " Date_add(art.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + " AND " + + " Date_add(art.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) " + : " AND e.encounter_datetime NOT BETWEEN " + + " Date_add(Date_add(art.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ), INTERVAL 1 DAY) " + + " AND " + + " Date_add(art.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) "; + query += + " AND ( ( o.concept_id = ${23761} " + " AND o.value_coded NOT IN ( ${1065} ) ) " + " OR ( o2.concept_id = ${1268} " + " AND o2.value_coded NOT IN ( ${1256}, ${1257} ) ) ) " - + " GROUP BY p.patient_id ) AS final_query "; + + " GROUP BY p.patient_id ) AS final_query " + + " WHERE final_query.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) "; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -1808,7 +1965,12 @@ public DataDefinition getPatientsWithTbThirdToNineMonth( * * @return {@link DataDefinition} */ - public DataDefinition getMdsDate(int minNumberOfMonths, int maxNumberOfMonths) { + public DataDefinition getMdsDate( + int minNumberOfMonths, + int maxNumberOfMonths, + boolean b9period, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName( "D9- Data de inscrição no MDS: (coluna CD) - Resposta = Data de Inscrição (RF54)"); @@ -1835,6 +1997,9 @@ public DataDefinition getMdsDate(int minNumberOfMonths, int maxNumberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT p.patient_id, MIN(e.encounter_datetime) AS encounter_date " @@ -1858,18 +2023,31 @@ public DataDefinition getMdsDate(int minNumberOfMonths, int maxNumberOfMonths) { + " AND otype.voided = 0 " + " AND ostate.voided = 0 " + " AND e.encounter_type = ${6} " - + " AND e.location_id = :location " - + " AND e.encounter_datetime >= date_add( art.art_encounter, INTERVAL " - + minNumberOfMonths - + " MONTH ) " - + " AND e.encounter_datetime <= date_add( art.art_encounter, INTERVAL " - + maxNumberOfMonths - + " MONTH ) " - + " AND ( ( otype.concept_id = ${165174} " + + " AND e.location_id = :location "; + query += + b9period + ? " AND e.encounter_datetime >= date_add( art.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + " AND e.encounter_datetime <= date_add( art.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) " + : " AND e.encounter_datetime > date_add( art.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + " AND e.encounter_datetime <= date_add( art.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) "; + query += + " AND ( ( otype.concept_id = ${165174} " + " AND otype.value_coded IS NOT NULL ) " + " AND ( ostate.concept_id = ${165322} " + " AND ostate.value_coded IN (${1256}) ) ) " + " AND otype.obs_group_id = ostate.obs_group_id " + + " AND p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY p.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -1886,7 +2064,8 @@ public DataDefinition getMdsDate(int minNumberOfMonths, int maxNumberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds1(int numberOfMonths) { + public DataDefinition getMds1( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B10- Tipo de MDS - (MDS1) Coluna S"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -1911,6 +2090,9 @@ public DataDefinition getMds1(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds1.patient_id, " @@ -1969,6 +2151,10 @@ public DataDefinition getMds1(int numberOfMonths) { + " AND ( ostate1.concept_id = ${165322} " + " AND ostate1.value_coded IN (${1256}) ) ) " + " AND otype1.obs_group_id = ostate1.obs_group_id " + + " AND mds1.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds1.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -1985,7 +2171,8 @@ public DataDefinition getMds1(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds1StartDate(int numberOfYears) { + public DataDefinition getMds1StartDate( + int numberOfYears, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("Data Início de MDS1: Coluna T"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -2010,6 +2197,9 @@ public DataDefinition getMds1StartDate(int numberOfYears) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT p.patient_id, " @@ -2044,6 +2234,10 @@ public DataDefinition getMds1StartDate(int numberOfYears) { + " AND ( ostate.concept_id = ${165322} " + " AND ostate.value_coded IN (${1256}) ) ) " + " AND otype.obs_group_id = ostate.obs_group_id " + + " AND p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY p.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -2060,7 +2254,8 @@ public DataDefinition getMds1StartDate(int numberOfYears) { * * @return {@link DataDefinition} */ - public DataDefinition getMds2StartDate(int numberOfMonths) { + public DataDefinition getMds2StartDate( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("Data Início de MDS2: Coluna W"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -2085,6 +2280,9 @@ public DataDefinition getMds2StartDate(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds2.patient_id, " @@ -2156,6 +2354,10 @@ public DataDefinition getMds2StartDate(int numberOfMonths) { + " AND ( ostate2.concept_id = ${165322} " + " AND ostate2.value_coded = ${1256} ) ) " + " AND otype2.obs_group_id = ostate2.obs_group_id " + + " AND mds2.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds2.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -2172,7 +2374,8 @@ public DataDefinition getMds2StartDate(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds2EndDate(int numberOfMonths) { + public DataDefinition getMds2EndDate( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("Data Fim de MDS2: Coluna X"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -2198,6 +2401,9 @@ public DataDefinition getMds2EndDate(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds2_end.patient_id, " @@ -2306,6 +2512,10 @@ public DataDefinition getMds2EndDate(int numberOfMonths) { + " AND ( os22.concept_id = ${165322} " + " AND os22.value_coded = ${1267} ) ) " + " AND ot22.obs_group_id = os22.obs_group_id " + + " AND mds2_end.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds2_end.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -2322,7 +2532,8 @@ public DataDefinition getMds2EndDate(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds1EndDate(int numberOfMonths) { + public DataDefinition getMds1EndDate( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("Data Fim de MDS1: Coluna U"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -2348,6 +2559,9 @@ public DataDefinition getMds1EndDate(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds1_end.patient_id, " @@ -2386,6 +2600,10 @@ public DataDefinition getMds1EndDate(int numberOfMonths) { + " AND ( os.concept_id = ${165322} " + " AND os.value_coded IN (${1267}) ) ) " + " AND ot.obs_group_id = os.obs_group_id " + + " AND mds1_end.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds1_end.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -2402,7 +2620,8 @@ public DataDefinition getMds1EndDate(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds2(int numberOfMonths) { + public DataDefinition getMds2( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B10- Tipo de MDS: (MDS2) Coluna V"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -2427,6 +2646,9 @@ public DataDefinition getMds2(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds2.patient_id, " @@ -2498,6 +2720,10 @@ public DataDefinition getMds2(int numberOfMonths) { + " AND ( ostate2.concept_id = ${165322} " + " AND ostate2.value_coded = ${1256} ) ) " + " AND otype2.obs_group_id = ostate2.obs_group_id " + + " AND mds2.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds2.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -2514,7 +2740,8 @@ public DataDefinition getMds2(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds3(int numberOfMonths) { + public DataDefinition getMds3( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B10- Tipo de MDS: (MDS3) Coluna Y"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -2539,6 +2766,9 @@ public DataDefinition getMds3(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds3.patient_id, " @@ -2647,6 +2877,10 @@ public DataDefinition getMds3(int numberOfMonths) { + " AND ( ostate3.concept_id = ${165322} " + " AND ostate3.value_coded = ${1256} ) ) " + " AND otype3.obs_group_id = ostate3.obs_group_id " + + " AND mds3.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds3.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -2663,7 +2897,8 @@ public DataDefinition getMds3(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds3StartDate(int numberOfMonths) { + public DataDefinition getMds3StartDate( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B10- Data Início de MDS3: Coluna Z"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -2688,6 +2923,9 @@ public DataDefinition getMds3StartDate(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds3.patient_id, " @@ -2796,6 +3034,10 @@ public DataDefinition getMds3StartDate(int numberOfMonths) { + " AND ( ostate3.concept_id = ${165322} " + " AND ostate3.value_coded = ${1256} ) ) " + " AND otype3.obs_group_id = ostate3.obs_group_id " + + " AND mds3.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds3.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -2812,7 +3054,8 @@ public DataDefinition getMds3StartDate(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds3EndDate(int numberOfMonths) { + public DataDefinition getMds3EndDate( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B10- Data Fim de MDS3: Coluna AA"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -2834,6 +3077,9 @@ public DataDefinition getMds3EndDate(int numberOfMonths) { map.put("165322", hivMetadata.getMdcState().getConceptId()); map.put("1256", hivMetadata.getStartDrugs().getConceptId()); map.put("1267", hivMetadata.getCompletedConcept().getConceptId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); map.put("18", hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId()); map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); @@ -2982,6 +3228,10 @@ public DataDefinition getMds3EndDate(int numberOfMonths) { + " AND ( os33.concept_id = ${165322} " + " AND os33.value_coded = ${1267} ) ) " + " AND ot33.obs_group_id = os33.obs_group_id " + + " AND mds3_end.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds3_end.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -2998,7 +3248,8 @@ public DataDefinition getMds3EndDate(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds4(int numberOfMonths) { + public DataDefinition getMds4( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B10- Tipo de MDS: (MDS4) Coluna AB"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -3023,6 +3274,9 @@ public DataDefinition getMds4(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds4.patient_id, " @@ -3168,6 +3422,10 @@ public DataDefinition getMds4(int numberOfMonths) { + " AND ( ostate4.concept_id = ${165322} " + " AND ostate4.value_coded = ${1256} ) ) " + " AND otype4.obs_group_id = ostate4.obs_group_id " + + " AND mds4.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds4.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -3184,7 +3442,8 @@ public DataDefinition getMds4(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds4StartDate(int numberOfMonths) { + public DataDefinition getMds4StartDate( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B10- Data Início de MDS4: Coluna AC"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -3209,6 +3468,9 @@ public DataDefinition getMds4StartDate(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds4.patient_id, " @@ -3354,6 +3616,10 @@ public DataDefinition getMds4StartDate(int numberOfMonths) { + " AND ( ostate4.concept_id = ${165322} " + " AND ostate4.value_coded = ${1256} ) ) " + " AND otype4.obs_group_id = ostate4.obs_group_id " + + " AND mds4.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds4.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -3370,7 +3636,8 @@ public DataDefinition getMds4StartDate(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds4EndDate(int numberOfMonths) { + public DataDefinition getMds4EndDate( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B10- Data Fim de MDS4: Coluna AD"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -3396,6 +3663,9 @@ public DataDefinition getMds4EndDate(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds4_end.patient_id, " @@ -3577,6 +3847,10 @@ public DataDefinition getMds4EndDate(int numberOfMonths) { + " AND ( os44.concept_id = ${165322} " + " AND os44.value_coded = ${1267} ) ) " + " AND ot44.obs_group_id = os44.obs_group_id " + + " AND mds4_end.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds4_end.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -3593,7 +3867,8 @@ public DataDefinition getMds4EndDate(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds5(int numberOfMonths) { + public DataDefinition getMds5( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B10- Tipo de MDS: (MDS5) Coluna AE"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -3618,6 +3893,9 @@ public DataDefinition getMds5(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds5.patient_id, " @@ -3800,6 +4078,10 @@ public DataDefinition getMds5(int numberOfMonths) { + " AND ( ostate5.concept_id = ${165322} " + " AND ostate5.value_coded = ${1256} ) ) " + " AND otype5.obs_group_id = ostate5.obs_group_id " + + " AND mds5.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds5.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -3816,7 +4098,8 @@ public DataDefinition getMds5(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds5StartDate(int numberOfMonths) { + public DataDefinition getMds5StartDate( + int numberOfMonths, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B10- Data Início de MDS5: Coluna AF"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -3841,6 +4124,9 @@ public DataDefinition getMds5StartDate(int numberOfMonths) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds5.patient_id, " @@ -4023,6 +4309,10 @@ public DataDefinition getMds5StartDate(int numberOfMonths) { + " AND ( ostate5.concept_id = ${165322} " + " AND ostate5.value_coded = ${1256} ) ) " + " AND otype5.obs_group_id = ostate5.obs_group_id " + + " AND mds5.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds5.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -4039,7 +4329,8 @@ public DataDefinition getMds5StartDate(int numberOfMonths) { * * @return {@link DataDefinition} */ - public DataDefinition getMds5EndDate(int numberOfMonthss) { + public DataDefinition getMds5EndDate( + int numberOfMonthss, int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B10- Data Fim de MDS5: Coluna AG"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -4065,6 +4356,9 @@ public DataDefinition getMds5EndDate(int numberOfMonthss) { map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT mds5_end.patient_id, " @@ -4284,6 +4578,10 @@ public DataDefinition getMds5EndDate(int numberOfMonthss) { + " AND ( os55.concept_id = ${165322} " + " AND os55.value_coded = ${1267} ) ) " + " AND ot55.obs_group_id = os55.obs_group_id " + + " AND mds5_end.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY mds5_end.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -4564,7 +4862,11 @@ public DataDefinition getTbScreeningSectionB( } public DataDefinition getTbScreeningSectionC( - boolean tbScreeningOrPbImc, int minNumberOfMonths, int maxNumberOfMonths) { + boolean tbScreeningOrPbImc, + int minNumberOfMonths, + int maxNumberOfMonths, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName( "B11 - Identificação de Utente Rastreado para TB em TODAS as consultas entre a data de inscrição no MDS e 12˚ mês de TARV"); @@ -4592,6 +4894,9 @@ public DataDefinition getTbScreeningSectionC( map.put("23758", hivMetadata.getTBSymptomsConcept().getConceptId()); map.put("1343", commonMetadata.getMidUpperArmCircumferenceConcept().getConceptId()); map.put("1342", commonMetadata.getBodyMassIndexConcept().getConceptId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT p.patient_id, " @@ -4650,7 +4955,7 @@ public DataDefinition getTbScreeningSectionC( + "WHERE e.voided = 0 " + "AND e.encounter_type = ${6} " + "AND e.location_id = :location " - + "AND e.encounter_datetime >= Date_add(tarv.art_encounter, INTERVAL " + + "AND e.encounter_datetime > Date_add(tarv.art_encounter, INTERVAL " + minNumberOfMonths + " MONTH ) " + "AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " @@ -4658,7 +4963,11 @@ public DataDefinition getTbScreeningSectionC( + " MONTH ) " + "GROUP BY e.patient_id) consultations " + "ON consultations.patient_id = p.patient_id " - + "WHERE p.voided = 0"; + + "WHERE p.voided = 0" + + " AND p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) "; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -4682,7 +4991,11 @@ public DataDefinition getTbScreeningSectionC( * * @return {DataDefinition} */ - public DataDefinition getNrClinicalConsultations(int minNumberOfMonths, int maxNumberOfMonths) { + public DataDefinition getNrClinicalConsultations( + int minNumberOfMonths, + int maxNumberOfMonths, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B16- Identificação de n˚ de consultas clínicas"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -4704,6 +5017,10 @@ public DataDefinition getNrClinicalConsultations(int minNumberOfMonths, int maxN map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT p.patient_id, " @@ -4729,6 +5046,10 @@ public DataDefinition getNrClinicalConsultations(int minNumberOfMonths, int maxN + " AND e.encounter_datetime <= date_add( art.art_encounter, INTERVAL " + maxNumberOfMonths + " MONTH ) " + + " AND p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY p.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -4753,7 +5074,11 @@ public DataDefinition getNrClinicalConsultations(int minNumberOfMonths, int maxN * * @return {DataDefinition} */ - public DataDefinition getNrApssPpConsultations(int minNumberOfMonths, int maxNumberOfMonths) { + public DataDefinition getNrApssPpConsultations( + int minNumberOfMonths, + int maxNumberOfMonths, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("B17- Identificação de n˚ de consultas apss/pp"); sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); @@ -4776,6 +5101,10 @@ public DataDefinition getNrApssPpConsultations(int minNumberOfMonths, int maxNum map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put("29", hivMetadata.getHepatitisConcept().getConceptId()); + map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); + map.put("23891", hivMetadata.getDateOfMasterCardFileOpeningConcept().getConceptId()); String query = " SELECT p.patient_id, " @@ -4801,6 +5130,10 @@ public DataDefinition getNrApssPpConsultations(int minNumberOfMonths, int maxNum + " AND e.encounter_datetime <= date_add( art.art_encounter, INTERVAL " + maxNumberOfMonths + " MONTH ) " + + " AND p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + " GROUP BY p.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -4810,269 +5143,6 @@ public DataDefinition getNrApssPpConsultations(int minNumberOfMonths, int maxNum return sqlPatientDataDefinition; } - /** - * Utentes Activos em TARV - *
O sistema irá identificar se o utente “Recebeu uma forma de PF entre a data de inscrição no + * MDS e 12˚ mês de TARV?” com as seguintes respostas: + *
O sistema irá identificar se o utente “Recebeu TPT entre a data de inscrição no MDS e 12˚ + * mês de TARV?” com as seguintes respostas: + *
O sistema irá identificar se o utente foi “Rastreado para Tensão Arterial em todas as
+ * consultas entre a data de inscrição no MDS e 12 ̊ mês de TARV?” com as seguintes respostas:
+ *
+ *
+ *
Nota 1: A “Data Início TARV” é definida no RF61
+ *
+ *
+ *
Nota 2: A “Data Início MDS” (RF24) é a data mais antiga (primeira) entre as “Data Início + * 1º MDS”, “Data Início 2º MDS”, “Data Início 3º MDS”, “Data Início 4º MDS”, “Data Início 5º + * MDS”.. + * + *
Nota 3: O utente a ser considerado nesta definição iniciou TARV ou na coorte de 12 meses
+ * ou na coorte de 24 meses ou na coorte de 36 meses, conforme definido no RF4. O sistema irá identificar se o utente foi “Rastreado para CACUM entre o 1˚ e 12 meses de
+ * TARV?” com as seguintes respostas:
+ * O sistema irá identificar se o utente teve “Resultado positivo para CACUM entre o 1˚ e 12
+ * meses de TARV?” com as seguintes respostas:
+ * Excepto os utentes:
+ *
+ *
+ * @return {@link CohortDefinition}
+ */
+ public DataDefinition getPatientWithArterialPressure(
+ int minNumberOfMonths,
+ int maxNumberOfMonths,
+ boolean b15pedriod,
+ int minCohortNumberOfYears,
+ int maxCohortNumberOfYears) {
+ SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition();
+ sqlPatientDataDefinition.setName(
+ "Identificação de utentes rastreados para TA em todas as consultas durante o período de avaliação (B15, C15, D15)");
+ sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class));
+ sqlPatientDataDefinition.addParameter(new Parameter("location", "location", Location.class));
+ Map