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 - *

  • Iniciaram TARV até o fim do período de avaliação, ou seja, com registo do Início TARV - * Excluindo todos os utentes: - *
  • Abandonos em TARV - *
  • Transferidos Para Outra US - *
  • Suspensos em TARV - *
  • Óbitos - *
  • Reinícios - * - * @return {@link String} - */ - public String getPatientsActiveOnTarv() { - return "SELECT final.patient_id, 'Activo' " - + "FROM " - + " ( " - + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() - + " ) final " - + "WHERE final.patient_id NOT IN (" - + new EptsQueriesUtil() - .unionBuilder( - listOfPatientsOnAdvancedHivIllnessQueries.getPatientsWhoAbandonedTarvQuery(false)) - .union(getB13PatientsWhoHaveTransferredOutAsPermananceState()) - .union( - listOfPatientsOnAdvancedHivIllnessQueries - .getPatientsWhoSuspendedTarvOrAreTransferredOut( - hivMetadata - .getSuspendedTreatmentWorkflowState() - .getProgramWorkflowStateId(), - hivMetadata.getSuspendedTreatmentConcept().getConceptId(), - false, - true)) - .union(listOfPatientsOnAdvancedHivIllnessQueries.getPatientsWhoDied(false)) - .buildQuery() - + " ) " - + "GROUP BY final.patient_id "; - } - - public String getB13PatientsWhoHaveTransferredOutAsPermananceState() { - - Map map = new HashMap<>(); - map.put("2", hivMetadata.getARTProgram().getProgramId()); - map.put( - "7", - hivMetadata - .getTransferredOutToAnotherHealthFacilityWorkflowState() - .getProgramWorkflowStateId()); - map.put("6", hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId()); - map.put("18", hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId()); - map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); - map.put("1369", commonMetadata.getTransferFromOtherFacilityConcept().getConceptId()); - map.put("1065", hivMetadata.getYesConcept().getConceptId()); - map.put("6300", hivMetadata.getTypeOfPatientTransferredFrom().getConceptId()); - map.put("6276", hivMetadata.getArtStatus().getConceptId()); - map.put("6273", hivMetadata.getStateOfStayOfArtPatient().getConceptId()); - map.put("6272", hivMetadata.getStateOfStayOfPreArtPatient().getConceptId()); - map.put("1706", hivMetadata.getTransferredOutConcept().getConceptId()); - map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); - map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); - map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); - map.put("5096", hivMetadata.getReturnVisitDateForArvDrugConcept().getConceptId()); - - String query = - " SELECT patient_id " - + "FROM (" - + "SELECT latest.patient_id, " - + " Max(latest.last_date) AS last_date " - + "FROM (SELECT p.patient_id, laststate.last_date AS last_date FROM patient p " - + "INNER JOIN patient_program pg " - + "ON p.patient_id = pg.patient_id " - + "INNER JOIN patient_state ps " - + "ON pg.patient_program_id = ps.patient_program_id " - + "INNER JOIN " - + " ( " - + " SELECT p.patient_id, " - + " max(ps.start_date) AS last_date " - + " FROM patient p " - + " INNER JOIN patient_program pg " - + " ON p.patient_id = pg.patient_id " - + " INNER JOIN patient_state ps " - + " ON pg.patient_program_id = ps.patient_program_id " - + " WHERE pg.voided = 0 " - + " AND ps.voided = 0 " - + " AND p.voided = 0 " - + " AND pg.program_id = ${2} " - + " AND ps.state IS NOT NULL " - + " AND ps.start_date <= :endDate " - + " AND pg.location_id = :location " - + " GROUP BY p.patient_id) laststate " - + "ON laststate.patient_id = p.patient_id WHERE pg.voided = 0 " - + "AND ps.voided = 0 " - + "AND p.voided = 0 " - + "AND pg.program_id = ${2} " - + "AND ps.state = ${7} " - + "AND ps.start_date = laststate.last_date " - + "AND pg.location_id = :location GROUP BY p.patient_id " - + "UNION " - + "SELECT p.patient_id, " - + " max_resumo_state.last_state_date AS last_date " - + "FROM patient p " - + "INNER JOIN encounter e " - + "ON e.patient_id = p.patient_id " - + "INNER JOIN obs o " - + "ON e.encounter_id = o.encounter_id " - + "INNER JOIN " - + " ( " - + " SELECT p.patient_id, " - + " max(o.obs_datetime) AS last_state_date " - + " FROM patient p " - + " INNER JOIN encounter e " - + " ON e.patient_id = p.patient_id " - + " INNER JOIN obs o " - + " ON o.encounter_id = e.encounter_id " - + " WHERE p.voided = 0 " - + " AND e.voided = 0 " - + " AND o.voided = 0 " - + " AND e.encounter_type = ${53} " - + " AND o.obs_datetime <= :endDate " - + " AND e.location_id = :location " - + " AND o.concept_id = ${6272} " - + " GROUP BY p.patient_id) max_resumo_state " - + "ON max_resumo_state.patient_id = p.patient_id " - + "WHERE p.voided = 0 " - + "AND e.voided = 0 " - + "AND o.voided = 0 " - + "AND e.encounter_type = ${53} " - + "AND o.concept_id = ${6272} " - + "AND o.value_coded = ${1706} " - + "AND o.obs_datetime = max_resumo_state.last_state_date " - + "AND e.location_id = :location " - + "GROUP BY p.patient_id " - + "UNION " - + "SELECT p.patient_id, " - + " max_state_clinical.last_state_date AS last_date " - + "FROM patient p " - + "INNER JOIN encounter e " - + "ON e.patient_id = p.patient_id " - + "INNER JOIN obs o " - + "ON o.encounter_id = e.encounter_id " - + "INNER JOIN " - + " ( " - + " SELECT p.patient_id, " - + " max(e.encounter_datetime) AS last_state_date " - + " FROM patient p " - + " INNER JOIN encounter e " - + " ON e.patient_id = p.patient_id " - + " INNER JOIN obs o " - + " ON o.encounter_id = e.encounter_id " - + " WHERE p.voided = 0 " - + " AND e.voided = 0 " - + " AND o.voided = 0 " - + " AND e.encounter_type = ${6} " - + " AND e.encounter_datetime <= :endDate " - + " AND e.location_id = :location " - + " AND o.concept_id = ${6273} " - + " GROUP BY p.patient_id) max_state_clinical " - + "ON max_state_clinical.patient_id = p.patient_id " - + "WHERE p.voided = 0 " - + "AND e.voided = 0 " - + "AND o.voided = 0 " - + "AND e.encounter_type = ${6} " - + "AND o.concept_id = ${6273} " - + "AND o.value_coded = ${1706} " - + "AND e.encounter_datetime = max_state_clinical.last_state_date " - + "AND e.location_id = :location " - + "GROUP BY p.patient_id) latest " - + "GROUP BY latest.patient_id" - + ") transferred_out " - + "WHERE transferred_out.patient_id NOT IN (SELECT p.patient_id " - + " FROM patient p " - + " INNER JOIN encounter e " - + " ON " - + " e.patient_id = p.patient_id " - + " WHERE p.voided = 0 " - + " AND e.voided = 0 " - + " AND p.patient_id = " - + " transferred_out.patient_id " - + " AND e.encounter_type = ${18} " - + " AND " - + " e.encounter_datetime > transferred_out.last_date " - + " AND " - + " e.encounter_datetime <= :endDate " - + " AND e.location_id = :location " - + " UNION " - + " SELECT p.patient_id " - + " FROM patient p " - + " INNER JOIN (SELECT " - + " last_next_pick_up.patient_id, " - + " Max(last_next_pick_up.result_value) AS " - + " max_datetame " - + " FROM " - + " (SELECT p.patient_id, " - + " Timestampadd(day, 1, o.value_datetime) AS " - + " result_value " - + " FROM patient p " - + " INNER JOIN encounter e " - + " ON p.patient_id = " - + " e.patient_id " - + " INNER JOIN obs o " - + " ON e.encounter_id = " - + " o.encounter_id " - + " INNER JOIN " - + " (SELECT p.patient_id, " - + " Max(e.encounter_datetime) " - + " AS " - + " e_datetime " - + " FROM patient p " - + " INNER JOIN encounter e " - + " ON p.patient_id = " - + " e.patient_id " - + " WHERE p.voided = 0 " - + " AND e.voided = 0 " - + " AND e.location_id = :location " - + " AND e.encounter_type = ${18} " - + " AND e.encounter_datetime " - + " <= " - + " :endDate " - + " GROUP BY p.patient_id) " - + " most_recent " - + " ON p.patient_id = " - + " most_recent.patient_id " - + " WHERE p.voided = 0 " - + " AND e.voided = 0 " - + " AND o.voided = 0 " - + " AND e.location_id = :location " - + " AND e.encounter_type = ${18} " - + " AND o.concept_id = ${5096} " - + " AND e.encounter_datetime = " - + " most_recent.e_datetime " - + " GROUP BY p.patient_id " - + " UNION " - + " SELECT p.patient_id, " - + " Timestampadd(day, 31, Max(o.value_datetime)) " - + " AS " - + " result_value " - + " FROM patient p " - + " INNER JOIN encounter e " - + " ON p.patient_id = e.patient_id " - + " INNER JOIN obs o " - + " ON e.encounter_id = o.encounter_id " - + " INNER JOIN obs o2 " - + " ON e.encounter_id = o2.encounter_id " - + " WHERE p.voided = 0 " - + " AND e.voided = 0 " - + " AND o.voided = 0 " - + " AND o2.voided = 0 " - + " AND e.location_id = :location " - + " AND e.encounter_type = ${52} " - + " AND ( o.concept_id = ${23866} " - + " AND o.value_datetime <= :endDate ) " - + " AND ( o2.concept_id = ${23865} " - + " AND o2.value_coded = ${1065} ) " - + " GROUP BY p.patient_id) AS last_next_pick_up " - + " GROUP BY last_next_pick_up.patient_id) AS " - + " last_next_scheduled_pick_up " - + " ON last_next_scheduled_pick_up.patient_id = p.patient_id " - + " WHERE last_next_scheduled_pick_up.max_datetame > :endDate ) " - + "GROUP BY transferred_out.patient_id"; - - StringSubstitutor stringSubstitutor = new StringSubstitutor(map); - return stringSubstitutor.replace(query); - } - /** * Estado de permanência no 12˚ mês de TARV- B.18 *
  • Resposta = “Abandono”, os utentes em TARV que abandonaram o tratamento @@ -5083,7 +5153,8 @@ public String getB13PatientsWhoHaveTransferredOutAsPermananceState() { * * @return {@link DataDefinition} */ - public DataDefinition getLastStateOfStayOnTarv() { + public DataDefinition getLastStateOfStayOnTarv( + int minCohortNumberOfYears, int maxCohortNumberOfYears) { SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); sqlPatientDataDefinition.setName("Get the Last State of stay "); @@ -5128,21 +5199,29 @@ public DataDefinition getLastStateOfStayOnTarv() { String query = new EptsQueriesUtil() .unionBuilder( - listOfPatientsOnAdvancedHivIllnessQueries.getPatientsWhoAbandonedTarvQuery(true)) - .union(listOfPatientsOnAdvancedHivIllnessQueries.getPatientsWhoDied(true)) + listOfPatientsWithMdsEvaluationQueries.getPatientsWhoAbandonedTarvQuery( + true, minCohortNumberOfYears, maxCohortNumberOfYears)) .union( - listOfPatientsOnAdvancedHivIllnessQueries + listOfPatientsWithMdsEvaluationQueries.getPatientsWhoDied( + true, minCohortNumberOfYears, maxCohortNumberOfYears)) + .union( + listOfPatientsWithMdsEvaluationQueries .getPatientsWhoSuspendedTarvOrAreTransferredOut( hivMetadata .getSuspendedTreatmentWorkflowState() .getProgramWorkflowStateId(), hivMetadata.getSuspendedTreatmentConcept().getConceptId(), false, - false)) + false, + minCohortNumberOfYears, + maxCohortNumberOfYears)) .union( listOfPatientsWithMdsEvaluationQueries - .getPatientsWhoHaveTransferredOutAsPermananceState()) - .union(getPatientsActiveOnTarv()) + .getPatientsWhoHaveTransferredOutAsPermananceState( + minCohortNumberOfYears, maxCohortNumberOfYears)) + .union( + listOfPatientsWithMdsEvaluationQueries.getPatientsActiveOnTarv( + minCohortNumberOfYears, maxCohortNumberOfYears)) .buildQuery(); StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -5151,4 +5230,1232 @@ public DataDefinition getLastStateOfStayOnTarv() { return sqlPatientDataDefinition; } + + public DataDefinition getActiveClinicalCondiction( + int minNumberOfMonths, + int maxNumberOfMonths, + boolean b7pedriod, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { + SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); + sqlPatientDataDefinition.setName( + "Identificação da condição clínica activa de estadio III ou IV – B7. C7 e D7"); + sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); + sqlPatientDataDefinition.addParameter(new Parameter("location", "location", Location.class)); + Map map = new HashMap<>(); + map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); + map.put("1190", hivMetadata.getARVStartDateConcept().getConceptId()); + map.put("6", hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId()); + map.put("6273", hivMetadata.getStateOfStayOfArtPatient().getConceptId()); + map.put("6272", hivMetadata.getStateOfStayOfPreArtPatient().getConceptId()); + map.put("1706", hivMetadata.getTransferredOutConcept().getConceptId()); + map.put("1369", commonMetadata.getTransferFromOtherFacilityConcept().getConceptId()); + map.put("6300", hivMetadata.getTypeOfPatientTransferredFrom().getConceptId()); + map.put("6276", hivMetadata.getArtStatus().getConceptId()); + map.put("1065", hivMetadata.getYesConcept().getConceptId()); + map.put("1066", hivMetadata.getNoConcept().getConceptId()); + map.put("165174", hivMetadata.getLastRecordOfDispensingModeConcept().getConceptId()); + map.put("165322", hivMetadata.getMdcState().getConceptId()); + map.put("1256", hivMetadata.getStartDrugs().getConceptId()); + map.put("18", hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId()); + map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); + map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); + map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("1406", hivMetadata.getOtherDiagnosis().getConceptId()); + map.put("42", tbMetadata.getPulmonaryTB().getConceptId()); + map.put("5334", hivMetadata.getCandidiaseOralConcept().getConceptId()); + map.put("1294", hivMetadata.getCryptococcalMeningitisConcept().getConceptId()); + map.put("1570", hivMetadata.getCervicalCancerConcept().getConceptId()); + map.put("5340", hivMetadata.getCandidiaseEsofagicaConcept().getConceptId()); + map.put("5344", hivMetadata.getHerpesSimplesConcept().getConceptId()); + map.put("14656", hivMetadata.getCachexiaConcept().getConceptId()); + map.put("7180", hivMetadata.getToxoplasmoseConcept().getConceptId()); + map.put("6990", hivMetadata.getHivDiseaseResultingInEncephalopathyConcept().getConceptId()); + map.put("507", commonMetadata.getKaposiSarcomaConcept().getConceptId()); + map.put("5042", tbMetadata.getExtraPulmonaryTbConcept().getConceptId()); + map.put("60", hivMetadata.getMeningitisConcept().getConceptId()); + map.put("5018", hivMetadata.getChronicDiarrheaConcept().getConceptId()); + map.put("5945", hivMetadata.getFeverConcept().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, " + + " 'Condição Clínica Activa de Estadio III ou IV' " + + "FROM patient p " + + "INNER JOIN " + + " ( " + + " SELECT e.patient_id, " + + " MAX(e.encounter_datetime) AS clinical_condiction_date" + + " FROM encounter e " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = e.patient_id " + + " INNER JOIN( " + + " SELECT p.patient_id, " + + " MIN(e.encounter_datetime) AS encounter_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs otype " + + " ON otype.encounter_id = e.encounter_id " + + " INNER JOIN obs ostate " + + " ON ostate.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT art_patient.patient_id, " + + " art_patient.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) art_patient " + + " ) art " + + " ON art.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " 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 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 " + + " GROUP BY p.patient_id ) mds " + + " ON mds.patient_id = e.patient_id " + + " WHERE e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND o.concept_id = ${1406} " + + " AND o.value_coded IN ( ${14656}, ${7180}, ${6990}, ${5344}, ${5340}, " + + " ${1294}, ${5042}, ${507}, ${1570}, ${60}, " + + " ${5018}, ${5945}, ${42} ) "; + query += + b7pedriod + ? " AND e.encounter_datetime >= mds.encounter_date " + + " AND e.encounter_datetime <= date_add( tarv.art_encounter, interval 12 month ) " + : "AND e.encounter_datetime > Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + "AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) "; + query += + "GROUP BY e.patient_id) clinical_condiction " + + "ON clinical_condiction.patient_id = p.patient_id " + + " WHERE p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) "; + + StringSubstitutor stringSubstitutor = new StringSubstitutor(map); + + sqlPatientDataDefinition.setQuery(stringSubstitutor.replace(query)); + + return sqlPatientDataDefinition; + } + + /** + * RF26.1 Recebeu uma forma de PF entre a data de inscrição no MDS e 12˚ mês de TARV? – + * B.12 + * + *

    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: + *

  • Resposta= Sim, se o utente teve registo de “Planeamento Familiar” = “Preservativo” ou + * “Contraceptivo Oral” ou “Injectável” ou ‘Implante” ou “Dispositivo Intra-uterino” ou + * “Laqueação das Trompas” ou “”Vasectomia” ou “Método Amenorreia Lactacional” ou “Outro” + * preenchido, em pelo menos uma consulta clínica (Ficha de Clínica) decorrida entre a data de + * inscrição no MDS e 12˚ mês de TARV (Data da Consulta >= “Data Inscrição MDS” e <= “Data + * Início TARV” + 12 meses) + *
  • Resposta= Não, se o utente não teve registo de “Planeamento Familiar” = “Preservativo” ou + * “Contraceptivo Oral” ou “Injectável” ou ‘Implante” ou “Dispositivo Intra-uterino” ou + * “Laqueação das Trompas” ou “”Vasectomia” ou “Método Amenorreia Lactacional” ou “Outro” + * preenchido, em pelo menos uma consulta clínica (Ficha de Clínica) decorrida entre a data de + * inscrição no MDS e 12˚ mês de TARV (Data da Consulta >= “Data Inscrição MDS” e <= “Data + * Início TARV” + 12 meses) + *
  • Resposta= N/A, se o utente não teve registo do início do MDS (Data Início MDS); + * + * @return {@link DataDefinition} + */ + public DataDefinition getPatientsWhoReceivedPf( + int minNumberOfMonths, + int maxNumberOfMonths, + boolean b12pedriod, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { + SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); + sqlPatientDataDefinition.setName( + "Identificação de utentes que receberam uma forma de PF durante o período de avaliação (B12, C12, D12)"); + sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); + sqlPatientDataDefinition.addParameter(new Parameter("location", "location", Location.class)); + Map map = new HashMap<>(); + map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); + map.put("1190", hivMetadata.getARVStartDateConcept().getConceptId()); + map.put("6", hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId()); + map.put("6273", hivMetadata.getStateOfStayOfArtPatient().getConceptId()); + map.put("6272", hivMetadata.getStateOfStayOfPreArtPatient().getConceptId()); + map.put("1706", hivMetadata.getTransferredOutConcept().getConceptId()); + map.put("1369", commonMetadata.getTransferFromOtherFacilityConcept().getConceptId()); + map.put("6300", hivMetadata.getTypeOfPatientTransferredFrom().getConceptId()); + map.put("6276", hivMetadata.getArtStatus().getConceptId()); + map.put("1065", hivMetadata.getYesConcept().getConceptId()); + map.put("1066", hivMetadata.getNoConcept().getConceptId()); + map.put("165174", hivMetadata.getLastRecordOfDispensingModeConcept().getConceptId()); + map.put("165322", hivMetadata.getMdcState().getConceptId()); + map.put("1256", hivMetadata.getStartDrugs().getConceptId()); + map.put("18", hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId()); + map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); + map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); + map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("374", commonMetadata.getMethodOfFamilyPlanningConcept().getConceptId()); + map.put("190", commonMetadata.getCondomsConcept().getConceptId()); + map.put("780", commonMetadata.getOralContraceptionConcept().getConceptId()); + map.put("5279", commonMetadata.getInjectibleContraceptiveConcept().getConceptId()); + map.put("21928", commonMetadata.getImplantConcept().getConceptId()); + map.put("5275", commonMetadata.getIntrauterineDeviceConcept().getConceptId()); + map.put("5276", commonMetadata.getFemaleSterilizationConcept().getConceptId()); + map.put("23714", commonMetadata.getVasectomyConcept().getConceptId()); + map.put("23728", commonMetadata.getOtherFamilyPlanningConcept().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, " + + " 'Sim' " + + "FROM patient p " + + "INNER JOIN " + + " ( " + + " SELECT e.patient_id, " + + " e.encounter_datetime AS clinical_date" + + " FROM encounter e " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = e.patient_id " + + " INNER JOIN( " + + " SELECT p.patient_id, " + + " MIN(e.encounter_datetime) AS encounter_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs otype " + + " ON otype.encounter_id = e.encounter_id " + + " INNER JOIN obs ostate " + + " ON ostate.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT art_patient.patient_id, " + + " art_patient.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) art_patient " + + " ) art " + + " ON art.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " 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 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 " + + " GROUP BY p.patient_id ) mds " + + " ON mds.patient_id = e.patient_id " + + " WHERE e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND o.concept_id = ${374} " + + " AND o.value_coded IN ( ${190}, ${780}, ${5279}, ${21928}, " + + " ${5275}, ${5276}, ${23714} ) " + + " OR o.concept_id = ${23728} " + + " AND o.value_text IS NOT NULL "; + query += + b12pedriod + ? " AND e.encounter_datetime >= mds.encounter_date " + + " AND e.encounter_datetime <= date_add( tarv.art_encounter, interval 12 month ) " + : "AND e.encounter_datetime > Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + "AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) "; + query += + "GROUP BY e.patient_id) planeamento_familiar " + + "ON planeamento_familiar.patient_id = p.patient_id " + + " WHERE p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + + " UNION " + + "SELECT p.patient_id, " + + " 'Não' " + + "FROM patient p " + + "INNER JOIN " + + " ( " + + " SELECT e.patient_id, " + + " e.encounter_datetime AS clinical_date" + + " FROM encounter e " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = e.patient_id " + + " INNER JOIN( " + + " SELECT p.patient_id, " + + " MIN(e.encounter_datetime) AS encounter_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs otype " + + " ON otype.encounter_id = e.encounter_id " + + " INNER JOIN obs ostate " + + " ON ostate.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT art_patient.patient_id, " + + " art_patient.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) art_patient " + + " ) art " + + " ON art.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " 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 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 " + + " GROUP BY p.patient_id ) mds " + + " ON mds.patient_id = e.patient_id " + + "WHERE e.patient_id NOT IN ( " + + " SELECT p.patient_id " + + " FROM patient p " + + " INNER JOIN encounter e ON p.patient_id = e.patient_id " + + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND ( " + + " (o.concept_id = ${374} AND o.value_coded IN (${190}, ${780}, ${5279}, ${21928}, ${5275}, ${5276}, ${23714})) " + + " OR (o.concept_id = ${23728} AND o.value_text IS NOT NULL) " + + " ) "; + query += + b12pedriod + ? " AND e.encounter_datetime >= mds.encounter_date " + + " AND e.encounter_datetime <= date_add( tarv.art_encounter, interval 12 month ) ) " + : "AND e.encounter_datetime >= Date_add(Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ), INTERVAL 1 DAY) " + + " AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) ) "; + query += + "AND e.voided = 0 " + + "GROUP BY e.patient_id ) no_pf " + + " ON no_pf.patient_id = p.patient_id " + + " WHERE p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) "; + + StringSubstitutor stringSubstitutor = new StringSubstitutor(map); + + sqlPatientDataDefinition.setQuery(stringSubstitutor.replace(query)); + + return sqlPatientDataDefinition; + } + + /** + * RF26.2 Recebeu TPT entre a data de inscrição no MDS e 12˚ mês de TARV? – B.13 (Coluna + * AN) – + * + *

    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: + *

  • Resposta= Sim, se o utente teve registo de “Profilaxia TPT” = “INH” ou “3HP” ou “1HP” ou + * “LFX”, e respectivo “Estado Profilaxia” =”Início” ou “Continua”, em pelo menos uma consulta + * clínica (“Ficha Clinica”) decorrida entre a data de inscrição no MDS e 12˚ mês de TARV + * (Data da Consulta >= “Data Inscrição MDS” e <= “Data Início TARV” + 12 meses) + *
  • Resposta= Não, se o utente não teve registo “TPT” de “Profilaxia TPT” = “INH” ou “3HP” ou + * “1HP” ou “LFX”, e respectivo “Estado Profilaxia” =”Início” ou “Continua”, em todas + * consultas clínicas (“Ficha Clinica”) decorridas entre a data de inscrição no MDS e 12˚ mês + * de TARV (Data da Consulta >= “Data Inscrição MDS” e <= “Data Início TARV” + 12 meses). Ou, + * se o utente não teve nenhuma consulta clínica entre a data de inscrição no MDS e 12˚ mês de + * TARV. + *
  • Resposta= N/A, se o utente não teve registo do início do MDS (Data Início MDS); + * + * @return {@link DataDefinition} + */ + public DataDefinition getPatientsWhoReceivedTpt( + int minNumberOfMonths, + int maxNumberOfMonths, + boolean b13pedriod, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { + SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); + sqlPatientDataDefinition.setName( + "Identificação de utentes que receberam TPT durante o período de avaliação (B13, C13, D13)"); + sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); + sqlPatientDataDefinition.addParameter(new Parameter("location", "location", Location.class)); + Map map = new HashMap<>(); + map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); + map.put("1190", hivMetadata.getARVStartDateConcept().getConceptId()); + map.put("6", hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId()); + map.put("6273", hivMetadata.getStateOfStayOfArtPatient().getConceptId()); + map.put("6272", hivMetadata.getStateOfStayOfPreArtPatient().getConceptId()); + map.put("1706", hivMetadata.getTransferredOutConcept().getConceptId()); + map.put("1369", commonMetadata.getTransferFromOtherFacilityConcept().getConceptId()); + map.put("6300", hivMetadata.getTypeOfPatientTransferredFrom().getConceptId()); + map.put("6276", hivMetadata.getArtStatus().getConceptId()); + map.put("1065", hivMetadata.getYesConcept().getConceptId()); + map.put("1066", hivMetadata.getNoConcept().getConceptId()); + map.put("165174", hivMetadata.getLastRecordOfDispensingModeConcept().getConceptId()); + map.put("165322", hivMetadata.getMdcState().getConceptId()); + map.put("18", hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId()); + map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); + map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); + map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("23985", tbMetadata.getRegimeTPTConcept().getConceptId()); + map.put("165308", tbMetadata.getDataEstadoDaProfilaxiaConcept().getConceptId()); + map.put("1256", hivMetadata.getStartDrugs().getConceptId()); + map.put("1257", hivMetadata.getContinueRegimenConcept().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, " + + " 'Sim' " + + "FROM patient p " + + "INNER JOIN " + + " ( " + + " SELECT e.patient_id, " + + " e.encounter_datetime AS clinical_date" + + " FROM encounter e " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 " + + " ON o2.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = e.patient_id " + + " INNER JOIN( " + + " SELECT p.patient_id, " + + " MIN(e.encounter_datetime) AS encounter_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs otype " + + " ON otype.encounter_id = e.encounter_id " + + " INNER JOIN obs ostate " + + " ON ostate.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT art_patient.patient_id, " + + " art_patient.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) art_patient " + + " ) art " + + " ON art.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " 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 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 " + + " GROUP BY p.patient_id ) mds " + + " ON mds.patient_id = e.patient_id " + + " WHERE e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND o.concept_id = ${23985} AND o.value_coded IS NOT NULL " + + " AND o2.concept_id = ${165308} AND o2.value_coded IN (${1256}, ${1257}) "; + query += + b13pedriod + ? " AND e.encounter_datetime >= mds.encounter_date " + + " AND e.encounter_datetime <= date_add( tarv.art_encounter, interval 12 month ) " + : "AND e.encounter_datetime > Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + "AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) "; + query += + "GROUP BY e.patient_id) received_tpt " + + "ON received_tpt.patient_id = p.patient_id " + + " WHERE p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + + " UNION " + + "SELECT p.patient_id, " + + " 'Não' " + + "FROM patient p " + + "INNER JOIN " + + " ( " + + " SELECT e.patient_id, " + + " e.encounter_datetime AS clinical_date" + + " FROM encounter e " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = e.patient_id " + + " INNER JOIN( " + + " SELECT p.patient_id, " + + " MIN(e.encounter_datetime) AS encounter_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs otype " + + " ON otype.encounter_id = e.encounter_id " + + " INNER JOIN obs ostate " + + " ON ostate.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT art_patient.patient_id, " + + " art_patient.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) art_patient " + + " ) art " + + " ON art.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " 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 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 " + + " GROUP BY p.patient_id ) mds " + + " ON mds.patient_id = e.patient_id " + + "WHERE e.patient_id NOT IN ( " + + " SELECT p.patient_id " + + " FROM patient p " + + " INNER JOIN encounter e ON p.patient_id = e.patient_id " + + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 ON o2.encounter_id = e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND o.concept_id = ${23985} AND o.value_coded IS NOT NULL " + + " AND o2.concept_id = ${165308} AND o2.value_coded IN (${1256}, ${1257}) "; + query += + b13pedriod + ? " AND e.encounter_datetime >= mds.encounter_date " + + " AND e.encounter_datetime <= date_add( tarv.art_encounter, interval 12 month ) ) " + : "AND e.encounter_datetime >= Date_add(Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ), INTERVAL 1 DAY) " + + "AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) ) "; + query += + "AND e.voided = 0 " + + "GROUP BY e.patient_id ) no_tpt " + + " ON no_tpt.patient_id = p.patient_id " + + " WHERE p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) "; + + StringSubstitutor stringSubstitutor = new StringSubstitutor(map); + + sqlPatientDataDefinition.setQuery(stringSubstitutor.replace(query)); + + return sqlPatientDataDefinition; + } + + /** + * RF27.1 - Rastreado para Tensão Arterial em todas as consultas entre a data de inscrição no + * MDS e 12 ̊ mês de TARV? – B.15 (Coluna AP
    + *
    + * + *

    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: + *
    + *
    + *

  • Resposta= Sim, se o utente foi teve registo de “Tensão Arterial” em todas as consultas + * clínicas (“Ficha Clinica”) decorridas entre a data de inscrição no MDS e 12˚ mês de TARV + * (Data da Consulta >= “Data Inscrição MDS (“Ficha Clinica”) decorridas entre a data de + * inscrição no MDS e 12˚ mês de TARV (Data da Consulta >= “Data Inscrição MDS + *
  • Resposta= Não, se o utente não teve registo de “Tensão Arterial” em todas consultas + * clínicas (“Ficha Clinica”) decorridas entre a data de inscrição no MDS e 12˚ mês de TARV + * (Data da Consulta >= “Data Incrição MDS e <= “Data Início TARV” + 12 meses). Ou, se o + * utente não teve nenhuma consulta clínica entre data de inscrição no MDS e 12˚ mês de TARV. + *
  • Resposta= N/A, se o utente não teve registo do início do MDS. + * + *

    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.
    + * + * @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 map = new HashMap<>(); + map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); + map.put("1190", hivMetadata.getARVStartDateConcept().getConceptId()); + map.put("6", hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId()); + map.put("6273", hivMetadata.getStateOfStayOfArtPatient().getConceptId()); + map.put("6272", hivMetadata.getStateOfStayOfPreArtPatient().getConceptId()); + map.put("1706", hivMetadata.getTransferredOutConcept().getConceptId()); + map.put("1369", commonMetadata.getTransferFromOtherFacilityConcept().getConceptId()); + map.put("6300", hivMetadata.getTypeOfPatientTransferredFrom().getConceptId()); + map.put("6276", hivMetadata.getArtStatus().getConceptId()); + map.put("1065", hivMetadata.getYesConcept().getConceptId()); + map.put("1066", hivMetadata.getNoConcept().getConceptId()); + map.put("165174", hivMetadata.getLastRecordOfDispensingModeConcept().getConceptId()); + map.put("165322", hivMetadata.getMdcState().getConceptId()); + map.put("1256", hivMetadata.getStartDrugs().getConceptId()); + map.put("18", hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId()); + map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); + map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); + map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("5085", commonMetadata.getSystolicBoodPressureConcept().getConceptId()); + map.put("5086", commonMetadata.getDiastolicBoodPressureConcept().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, " + + " 'Sim' " + + "FROM patient p " + + "INNER JOIN " + + " ( " + + " SELECT e.patient_id, " + + " Count(e.encounter_id) AS arterial_tension_consultations " + + " FROM encounter e " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 " + + " ON o2.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = e.patient_id " + + " INNER JOIN( " + + " SELECT p.patient_id, " + + " MIN(e.encounter_datetime) AS encounter_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs otype " + + " ON otype.encounter_id = e.encounter_id " + + " INNER JOIN obs ostate " + + " ON ostate.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT art_patient.patient_id, " + + " art_patient.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) art_patient " + + " ) art " + + " ON art.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " 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 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 " + + " GROUP BY p.patient_id ) mds " + + " ON mds.patient_id = e.patient_id " + + " WHERE e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND o.concept_id = ${5085} AND o.value_numeric IS NOT NULL" + + " AND o2.concept_id = ${5086} AND o2.value_numeric IS NOT NULL"; + query += + b15pedriod + ? " AND e.encounter_datetime >= mds.encounter_date " + + " AND e.encounter_datetime <= date_add( tarv.art_encounter, interval 12 month ) " + : " AND e.encounter_datetime > Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + " AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) "; + query += + "GROUP BY e.patient_id) arterial_consultation " + + "ON arterial_consultation.patient_id = p.patient_id " + + "INNER JOIN " + + " ( " + + " SELECT e.patient_id, " + + " count(e.encounter_id) AS nr_consultations " + + " FROM encounter e " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = e.patient_id " + + " INNER JOIN( " + + " SELECT p.patient_id, " + + " MIN(e.encounter_datetime) AS encounter_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs otype " + + " ON otype.encounter_id = e.encounter_id " + + " INNER JOIN obs ostate " + + " ON ostate.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT art_patient.patient_id, " + + " art_patient.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) art_patient " + + " ) art " + + " ON art.patient_id = e.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " 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 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 " + + " GROUP BY p.patient_id ) mds " + + " ON mds.patient_id = e.patient_id " + + " WHERE e.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location "; + query += + b15pedriod + ? " AND e.encounter_datetime >= mds.encounter_date " + + " AND e.encounter_datetime <= date_add( tarv.art_encounter, interval 12 month ) " + : " AND e.encounter_datetime > Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + " AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) "; + query += + " GROUP BY e.patient_id ) consultations " + + "ON consultations.patient_id = p.patient_id " + + "WHERE p.voided = 0 " + + " AND arterial_consultation.arterial_tension_consultations = consultations.nr_consultations " + + " AND p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + + " UNION " + + "SELECT p.patient_id, " + + " 'Não' " + + "FROM patient p " + + "INNER JOIN " + + " ( " + + " SELECT e.patient_id, " + + " Count(e.encounter_id) AS arterial_tension_consultations " + + " FROM encounter e " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 " + + " ON o2.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = e.patient_id " + + " INNER JOIN( " + + " SELECT p.patient_id, " + + " MIN(e.encounter_datetime) AS encounter_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs otype " + + " ON otype.encounter_id = e.encounter_id " + + " INNER JOIN obs ostate " + + " ON ostate.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT art_patient.patient_id, " + + " art_patient.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) art_patient " + + " ) art " + + " ON art.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " 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 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 " + + " GROUP BY p.patient_id ) mds " + + " ON mds.patient_id = e.patient_id " + + "WHERE e.patient_id NOT IN ( " + + " SELECT p.patient_id " + + " FROM patient p " + + " INNER JOIN encounter e ON p.patient_id = e.patient_id " + + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 ON o2.encounter_id = e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND o.concept_id = ${5085} AND o.value_numeric IS NOT NULL " + + " AND o2.concept_id = ${5086} AND o2.value_numeric IS NOT NULL "; + query += + b15pedriod + ? " AND e.encounter_datetime >= mds.encounter_date " + + " AND e.encounter_datetime <= date_add( tarv.art_encounter, interval 12 month ) ) " + : " AND e.encounter_datetime >= Date_add(Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ), INTERVAL 1 DAY) " + + " AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) ) "; + query += + "AND e.voided = 0 " + + "GROUP BY e.patient_id ) no_arterial_tension " + + " ON no_arterial_tension.patient_id = p.patient_id " + + " AND p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) "; + + StringSubstitutor stringSubstitutor = new StringSubstitutor(map); + + sqlPatientDataDefinition.setQuery(stringSubstitutor.replace(query)); + + return sqlPatientDataDefinition; + } + + /** + * RF29.1 Rastreado para CACUM entre o 1˚ e 12 meses de TARV? – B.18 (Coluna AS) + * + *

    O sistema irá identificar se o utente foi “Rastreado para CACUM entre o 1˚ e 12 meses de + * TARV?” com as seguintes respostas: + *

  • Resposta= Sim, se o utente é do sexo feminino e teve registo de pedido do exame “Via” + * (“Investigações – Pedidos Laboratoriais”) ou teve registo de resultado do exame “Via” ( + * “Positivo”, “Negativo” ou “Suspeita de Cancro”) em pelo menos uma consulta clínica (“Ficha + * Clinica”) decorrida entre 1˚ e 12º meses de TARV (Data da Consulta >= “Data Início TARV” e + * <= “Data Início TARV” + 12 meses) + *
  • Resposta= Não, se o utente é do sexo feminino e não teve registo de pedido do exame “Via” + * (“Investigações – Pedidos Laboratoriais”) e não teve registo de resultado do exame “Via” ( + * “Positivo”, “Negativo” ou “Suspeita de Cancro”) em todas consultas clínicas (“Ficha + * Clinica”) decorridas entre 1˚ e 12º meses de TARV (Data da Consulta >= “Data Início TARV” e + * <= “Data Início TARV” + 12 meses). Ou, se o utente não teve nenhuma consulta clínica entre + * 1˚ e 12º meses de TARV. + *
  • Resposta= N/A, se o utente não teve registo do início do MDS (Data Início MDS); + * + * @return {@link DataDefinition} + */ + public DataDefinition getPatientsWithCacumScreening( + int minNumberOfMonths, + int maxNumberOfMonths, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { + SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); + sqlPatientDataDefinition.setName( + "Identificação de utentes rastreados para CACUM durante o período de avaliação (B18, C18, D18)"); + sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); + sqlPatientDataDefinition.addParameter(new Parameter("location", "location", Location.class)); + Map map = new HashMap<>(); + map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); + map.put("1190", hivMetadata.getARVStartDateConcept().getConceptId()); + map.put("6", hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId()); + map.put("6273", hivMetadata.getStateOfStayOfArtPatient().getConceptId()); + map.put("6272", hivMetadata.getStateOfStayOfPreArtPatient().getConceptId()); + map.put("1706", hivMetadata.getTransferredOutConcept().getConceptId()); + map.put("1369", commonMetadata.getTransferFromOtherFacilityConcept().getConceptId()); + map.put("6300", hivMetadata.getTypeOfPatientTransferredFrom().getConceptId()); + map.put("6276", hivMetadata.getArtStatus().getConceptId()); + map.put("1065", hivMetadata.getYesConcept().getConceptId()); + map.put("1066", hivMetadata.getNoConcept().getConceptId()); + map.put("165174", hivMetadata.getLastRecordOfDispensingModeConcept().getConceptId()); + map.put("165322", hivMetadata.getMdcState().getConceptId()); + map.put("18", hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId()); + map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); + map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); + map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("23722", hivMetadata.getApplicationForLaboratoryResearch().getConceptId()); + map.put("2094", hivMetadata.getResultadoViaConcept().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, " + + " 'Sim' " + + "FROM patient p " + + "INNER JOIN " + + " ( " + + " SELECT p.patient_id, " + + " e.encounter_datetime AS cacum_date" + + " FROM patient p " + + " INNER JOIN person pe " + + " ON p.patient_id = pe.person_id " + + " INNER JOIN encounter e " + + " ON p.patient_id = e.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 " + + " ON o2.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND pe.gender = 'F' " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND ( (o.concept_id = ${23722} AND o.value_coded = ${2094}) " + + " OR ( o2.concept_id = ${2094} AND o2.value_coded IS NOT NULL) ) " + + "AND e.encounter_datetime > Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + "AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) " + + "GROUP BY p.patient_id) cacum " + + "ON cacum.patient_id = p.patient_id " + + " WHERE p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + + " UNION " + + "SELECT p.patient_id, " + + " 'Não' " + + "FROM patient p " + + "INNER JOIN " + + " ( " + + " SELECT p.patient_id, " + + " e.encounter_datetime AS cacum_date" + + " FROM patient p " + + " INNER JOIN person pe " + + " ON p.patient_id = pe.person_id " + + " INNER JOIN encounter e " + + " ON p.patient_id = e.patient_id " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = p.patient_id " + + "WHERE p.patient_id NOT IN ( " + + " SELECT p.patient_id " + + " FROM patient p " + + " INNER JOIN person pe ON p.patient_id = pe.person_id " + + " INNER JOIN encounter e ON p.patient_id = e.patient_id " + + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 ON o2.encounter_id = e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND pe.gender = 'F' " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND ( (o.concept_id = ${23722} AND o.value_coded = ${2094}) " + + " OR ( o2.concept_id = ${2094} AND o2.value_coded IS NOT NULL) ) " + + "AND e.encounter_datetime >= Date_add(Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ), INTERVAL 1 DAY) " + + "AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) ) " + + "AND p.voided = 0 " + + "AND e.voided = 0 " + + "AND pe.gender = 'F' " + + "GROUP BY p.patient_id ) no_cacum " + + " ON no_cacum.patient_id = p.patient_id " + + " WHERE p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) "; + + StringSubstitutor stringSubstitutor = new StringSubstitutor(map); + + sqlPatientDataDefinition.setQuery(stringSubstitutor.replace(query)); + + return sqlPatientDataDefinition; + } + + /** + * RF29.2 Resultado positivo para CACUM entre o 1˚ e 12 meses de TARV? – B.19 (Coluna AT) + * + *

    O sistema irá identificar se o utente teve “Resultado positivo para CACUM entre o 1˚ e 12 + * meses de TARV?” com as seguintes respostas: + *

  • Resposta= Sim, se o utente é do sexo feminino e teve registo de resultado do exame “Via” = + * “Positivo” em pelo menos uma consulta clínica (“Ficha Clinica”) decorrida entre 1˚ e 12 + * meses de TARV (Data da Consulta >= “Data Início TARV” e <= “Data Início TARV” + 12 meses) + *
  • Resposta= Não, se o utente é do sexo feminino e não teve registo de resultado do exame + * “Via” = “Positivo” em todas as consultas clínicas (“Ficha Clinica”) decorridas entre 1˚ e + * 12º meses de TARV (Data da Consulta >= “Data Início TARV” e <= “Data Início TARV” + 12 + * meses). Ou, se o utente não teve nenhuma consulta clínica entre 1º e 12º meses de TARV. + *
  • Resposta= N/A, se o utente não teve registo do início do MDS (Data Início MDS); + * + * @return {@link DataDefinition} + */ + public DataDefinition getPatientsWithPositiveCacum( + int minNumberOfMonths, + int maxNumberOfMonths, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { + SqlPatientDataDefinition sqlPatientDataDefinition = new SqlPatientDataDefinition(); + sqlPatientDataDefinition.setName( + "Identificação de utentes que receberam resultado positivo para CACUM durante o período de avaliação (B19, C19, D19)"); + sqlPatientDataDefinition.addParameter(new Parameter("endDate", "endDate", Date.class)); + sqlPatientDataDefinition.addParameter(new Parameter("location", "location", Location.class)); + Map map = new HashMap<>(); + map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); + map.put("1190", hivMetadata.getARVStartDateConcept().getConceptId()); + map.put("6", hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId()); + map.put("6273", hivMetadata.getStateOfStayOfArtPatient().getConceptId()); + map.put("6272", hivMetadata.getStateOfStayOfPreArtPatient().getConceptId()); + map.put("1706", hivMetadata.getTransferredOutConcept().getConceptId()); + map.put("1369", commonMetadata.getTransferFromOtherFacilityConcept().getConceptId()); + map.put("6300", hivMetadata.getTypeOfPatientTransferredFrom().getConceptId()); + map.put("6276", hivMetadata.getArtStatus().getConceptId()); + map.put("1065", hivMetadata.getYesConcept().getConceptId()); + map.put("1066", hivMetadata.getNoConcept().getConceptId()); + map.put("165174", hivMetadata.getLastRecordOfDispensingModeConcept().getConceptId()); + map.put("165322", hivMetadata.getMdcState().getConceptId()); + map.put("18", hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId()); + map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); + map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); + map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("2094", hivMetadata.getResultadoViaConcept().getConceptId()); + map.put("703", hivMetadata.getPositive().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, " + + " 'Sim' " + + "FROM patient p " + + "INNER JOIN " + + " ( " + + " SELECT p.patient_id, " + + " e.encounter_datetime AS positive_cacum_date" + + " FROM patient p " + + " INNER JOIN person pe " + + " ON p.patient_id = pe.person_id " + + " INNER JOIN encounter e " + + " ON p.patient_id = e.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND pe.gender = 'F' " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND o.concept_id = ${2094} AND o.value_coded = ${703} " + + "AND e.encounter_datetime > Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ) " + + "AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) " + + "GROUP BY p.patient_id) cacum_positive " + + "ON cacum_positive.patient_id = p.patient_id " + + " WHERE p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + + " UNION " + + "SELECT p.patient_id, " + + " 'Não' " + + "FROM patient p " + + "INNER JOIN " + + " ( " + + " SELECT p.patient_id, " + + " e.encounter_datetime AS cacum_date" + + " FROM patient p " + + " INNER JOIN person pe " + + " ON p.patient_id = pe.person_id " + + " INNER JOIN encounter e " + + " ON p.patient_id = e.patient_id " + + " INNER JOIN ( " + + " SELECT start.patient_id, " + + " start.first_pickup AS art_encounter " + + " FROM ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) start " + + ") tarv ON tarv.patient_id = p.patient_id " + + "WHERE p.patient_id IN ( " + + " SELECT p.patient_id " + + " FROM patient p " + + " INNER JOIN person pe ON p.patient_id = pe.person_id " + + " INNER JOIN encounter e ON p.patient_id = e.patient_id " + + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND pe.gender = 'F' " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND o.concept_id = ${2094} AND o.value_coded NOT IN (${703}) " + + "AND e.encounter_datetime >= Date_add(Date_add(tarv.art_encounter, INTERVAL " + + minNumberOfMonths + + " MONTH ), INTERVAL 1 DAY) " + + "AND e.encounter_datetime <= Date_add(tarv.art_encounter, INTERVAL " + + maxNumberOfMonths + + " MONTH ) ) " + + "AND p.voided = 0 " + + "AND e.voided = 0 " + + "AND pe.gender = 'F' " + + "GROUP BY p.patient_id ) no_positive_cacum " + + " ON no_positive_cacum.patient_id = p.patient_id " + + " WHERE p.patient_id IN ( " + + ListOfPatientsWithMdsEvaluationQueries.getCohortPatientsByYear( + minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) "; + + StringSubstitutor stringSubstitutor = new StringSubstitutor(map); + + sqlPatientDataDefinition.setQuery(stringSubstitutor.replace(query)); + + return sqlPatientDataDefinition; + } } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/ListOfPatientsWithMdsEvaluationCohortDataset.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/ListOfPatientsWithMdsEvaluationCohortDataset.java index db4c22fab9..79c1e22c6f 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/ListOfPatientsWithMdsEvaluationCohortDataset.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/datasets/ListOfPatientsWithMdsEvaluationCohortDataset.java @@ -18,9 +18,9 @@ public class ListOfPatientsWithMdsEvaluationCohortDataset extends BaseDataSet { private ListOfPatientsWithMdsEvaluationCohortQueries listOfPatientsWithMdsEvaluationCohortQueries; private String endDateMappings = "endDate=${evaluationYear}-06-20,location=${location}"; - private String b18Mappings = "endDate=${evaluationYear-1}-06-20,location=${location}"; - private String c18Mappings = "endDate=${evaluationYear-2}-06-20,location=${location}"; - private String d18Mappings = "endDate=${evaluationYear-3}-06-20,location=${location}"; + private String b20Mappings = "endDate=${evaluationYear-1}-06-20,location=${location}"; + private String c20Mappings = "endDate=${evaluationYear-2}-06-20,location=${location}"; + private String d20Mappings = "endDate=${evaluationYear-3}-06-20,location=${location}"; @Autowired public ListOfPatientsWithMdsEvaluationCohortDataset( @@ -131,7 +131,7 @@ public DataSetDefinition contructDataset() { // B5- Teve registo de boa adesão em TODAS consultas entre 1˚ e 3˚ mês de TARV? pdd.addColumn( "good_adherence_b", - listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithGoodAdhesion(true, 1, 3), + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithGoodAdhesion(true, 1, 3, 1, 4), // minNumberOfMonths and MaxNumberOfMonths has no effect here because the boolean b5OrC5 is // set to true endDateMappings); @@ -141,135 +141,158 @@ public DataSetDefinition contructDataset() { pdd.addColumn( "pregnant_breastfeeding_b", listOfPatientsWithMdsEvaluationCohortQueries.getPatientsPregnantBreastfeeding3MonthsTarv( - 3, 9), + 3, 9, true, 1, 4), endDateMappings); + // B7 - Condição Clínica Activa de Estadio III ou IV entre a Data Inscrição no MDS e 12º mês de + // TARV + pdd.addColumn( + "clinical_condiction_b", + listOfPatientsWithMdsEvaluationCohortQueries.getActiveClinicalCondiction(0, 12, true, 1, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + // B8- Teve TB nos 1˚s 12 meses de TARV: (coluna Q) - Resposta = Sim ou Não (RF23) pdd.addColumn( "tb_tarv_b", - listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithTbThirdToNineMonth(3, 9), + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithTbThirdToNineMonth( + 3, 9, true, 1, 4), endDateMappings); // B9- Data de inscrição no MDS: (coluna R) - Resposta = Data de Inscrição (RF24) pdd.addColumn( "mds_date", - listOfPatientsWithMdsEvaluationCohortQueries.getMdsDate(0, 12), + listOfPatientsWithMdsEvaluationCohortQueries.getMdsDate(0, 12, true, 1, 4), endDateMappings, new GeneralDateConverter()); // B10.1 -Tipo de MDS: (MDS1) Coluna S pdd.addColumn( "mds_one_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds1(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds1(12, 1, 4), endDateMappings, new DispensationTypeMdcConverter()); // B10.2 - Data Início de MDS1: Coluna T pdd.addColumn( "mds_one_start_date_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds1StartDate(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds1StartDate(12, 1, 4), endDateMappings, new GeneralDateConverter()); // B10.3 - Data Fim de MDS1: Coluna U pdd.addColumn( "mds_one_end_date_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds1EndDate(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds1EndDate(12, 1, 4), endDateMappings, new GeneralDateConverter()); // B10.4 - Tipo de MDS: (MDS2) Coluna V pdd.addColumn( "mds_two_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds2(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds2(12, 1, 4), endDateMappings, new DispensationTypeMdcConverter()); // B10.5 - Data Início de MDS2: Coluna W pdd.addColumn( "mds_two_start_date_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds2StartDate(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds2StartDate(12, 1, 4), endDateMappings, new GeneralDateConverter()); // B10.6 - Data Fim de MDS2: Coluna X pdd.addColumn( "mds_two_end_date_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds2EndDate(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds2EndDate(12, 1, 4), endDateMappings, new GeneralDateConverter()); // B10.7 - Tipo de MDS: (MDS3) Coluna Y pdd.addColumn( "mds_three_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds3(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds3(12, 1, 4), endDateMappings, new DispensationTypeMdcConverter()); // B10.8 - Data Início de MDS3: Coluna Z pdd.addColumn( "mds_three_start_date_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds3StartDate(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds3StartDate(12, 1, 4), endDateMappings, new GeneralDateConverter()); // B10.9 - Data Fim de MDS3: Coluna AA pdd.addColumn( "mds_three_end_date_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds3EndDate(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds3EndDate(12, 1, 4), endDateMappings, new GeneralDateConverter()); // B10.10 - Tipo de MDS: (MDS4) Coluna AB pdd.addColumn( "mds_four_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds4(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds4(12, 1, 4), endDateMappings, new DispensationTypeMdcConverter()); // B10.11 - Data Início de MDS4: Coluna AC pdd.addColumn( "mds_four_start_date_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds4StartDate(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds4StartDate(12, 1, 4), endDateMappings, new GeneralDateConverter()); // B10.12 - Data Fim de MDS4: Coluna AD pdd.addColumn( "mds_four_end_date_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds4EndDate(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds4EndDate(12, 1, 4), endDateMappings, new GeneralDateConverter()); // B10.13 - Tipo de MDS: (MDS5) Coluna AE pdd.addColumn( "mds_five_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds5(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds5(12, 1, 4), endDateMappings, new DispensationTypeMdcConverter()); // B10.14 - Data Início de MDS5: Coluna AF pdd.addColumn( "mds_five_start_date_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds5StartDate(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds5StartDate(12, 1, 4), endDateMappings, new GeneralDateConverter()); // B10.15 - Data Fim de MDS5: Coluna AG pdd.addColumn( "mds_five_end_date_b", - listOfPatientsWithMdsEvaluationCohortQueries.getMds5EndDate(12), + listOfPatientsWithMdsEvaluationCohortQueries.getMds5EndDate(12, 1, 4), endDateMappings, new GeneralDateConverter()); // B11 - Rastreado para TB em TODAS as consultas entre a data de inscrição no MDS e 12˚ mês de - // TARV?: Coluna AH + // TARV pdd.addColumn( "tb_screening_b", listOfPatientsWithMdsEvaluationCohortQueries.getTbScreeningSectionB(0, 12, true), endDateMappings, new NotApplicableIfNullConverter()); + // B12 - Recebeu uma forma de PF entre a data de inscrição no MDS e 12˚ mês de TARV? + pdd.addColumn( + "family_planning_b", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWhoReceivedPf(0, 12, true, 1, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + + // B13 - Recebeu TPT entre a data de inscrição no MDS e 12˚ mês de TARV? + pdd.addColumn( + "received_tpt_b", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWhoReceivedTpt(0, 12, true, 1, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + // B14 - Identificação de registo de PB/IMC em TODAS as consultas desde a inscrição no MDS até // ao 12˚ mês de TARV Coluna AK pdd.addColumn( @@ -278,28 +301,51 @@ public DataSetDefinition contructDataset() { endDateMappings, new NotApplicableIfNullConverter()); + // B15 - Rastreado para Tensão Arterial em todas as consultas entre a data de inscrição no MDS e + // 12 ̊ mês de TARV? + pdd.addColumn( + "arterial_pressure_b", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientWithArterialPressure( + 0, 12, true, 4, 1), + endDateMappings, + new NotApplicableIfNullConverter()); + // B16 - Identificação de n˚ de consultas clínicas entre 6˚ e 12˚ mês de TARV Coluna AM pdd.addColumn( "clinical_consultations_b", - listOfPatientsWithMdsEvaluationCohortQueries.getNrClinicalConsultations(6, 12), + listOfPatientsWithMdsEvaluationCohortQueries.getNrClinicalConsultations(6, 12, 1, 4), endDateMappings); // B17 - N˚ de consultas de APSS/PP entre 6˚ e 12˚ mês de TARV - Coluna AN pdd.addColumn( "apss_pp_consultations_b", - listOfPatientsWithMdsEvaluationCohortQueries.getNrApssPpConsultations(6, 12), + listOfPatientsWithMdsEvaluationCohortQueries.getNrApssPpConsultations(6, 12, 1, 4), endDateMappings); - // B18 - Estado de permanência no 12˚ mês de TARV: (coluna AO) + // B18 - Rastreado para CACUM entre o 1˚ e 12 meses de TARV? + pdd.addColumn( + "cacum_screening_b", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithCacumScreening(0, 12, 1, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + + // B19 - Resultado positivo para CACUM entre o 1˚ e 12 meses de TARV? + pdd.addColumn( + "positive_cacum_b", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithPositiveCacum(0, 12, 1, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + + // B20 - Estado de permanência no 12˚ mês de TARV: (coluna AO) pdd.addColumn( "permanence_state_b", - listOfPatientsWithMdsEvaluationCohortQueries.getLastStateOfStayOnTarv(), - b18Mappings); + listOfPatientsWithMdsEvaluationCohortQueries.getLastStateOfStayOnTarv(0, 3), + b20Mappings); // C1 - Data do pedido da CV entre 12º e 24º mês de TARV: (coluna AP) pdd.addColumn( "cv_date_c", - listOfPatientsWithMdsEvaluationCohortQueries.getLastViralLoadOnThePeriod(12, 24), + listOfPatientsWithMdsEvaluationCohortQueries.getLastViralLoadOnThePeriod(12, 24, 2, 4), endDateMappings, new GeneralDateConverter()); @@ -307,7 +353,7 @@ public DataSetDefinition contructDataset() { pdd.addColumn( "cv_result_date_c", listOfPatientsWithMdsEvaluationCohortQueries - .getLastViralLoadResultDateBetweenPeriodsInMonthsAfterTarv(12, 24), + .getLastViralLoadResultDateBetweenPeriodsInMonthsAfterTarv(12, 24, 2, 4), endDateMappings, new GeneralDateConverter()); @@ -315,20 +361,21 @@ public DataSetDefinition contructDataset() { pdd.addColumn( "cv_result_c", listOfPatientsWithMdsEvaluationCohortQueries - .getSecondViralLoadResultBetweenPeriodsOfMonthsAfterTarv(12, 24), + .getSecondViralLoadResultBetweenPeriodsOfMonthsAfterTarv(12, 24, 2, 4), endDateMappings, new ViralLoadQualitativeLabelConverter()); // C4 - Resultado do CD4 feito entre 12˚ e 24˚ mês de TARV- C.4 (Coluna AS) pdd.addColumn( "cd4_result_c", - listOfPatientsWithMdsEvaluationCohortQueries.getCd4ResultSectionC(12, 24), + listOfPatientsWithMdsEvaluationCohortQueries.getCd4ResultSectionC(12, 24, 2, 4), endDateMappings); // C5- Teve registo de boa adesão em TODAS consultas entre 12˚ e 24˚ mês de TARV? pdd.addColumn( "good_adherence_c", - listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithGoodAdhesion(false, 12, 24), + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithGoodAdhesion( + false, 12, 24, 2, 4), endDateMappings); // C6 - Esteve grávida ou foi lactante entre 12˚ e 24º mês de TARV?: (coluna AU) - Resposta = @@ -336,164 +383,208 @@ public DataSetDefinition contructDataset() { pdd.addColumn( "pregnant_breastfeeding_c", listOfPatientsWithMdsEvaluationCohortQueries.getPatientsPregnantBreastfeeding3MonthsTarv( - 12, 24), + 12, 24, false, 2, 4), + endDateMappings); + + // C7 - Condição Clínica Activa de Estadio III ou IV entre 12˚ e 24˚ mês de TARV + pdd.addColumn( + "clinical_condiction_c", + listOfPatientsWithMdsEvaluationCohortQueries.getActiveClinicalCondiction( + 12, 24, false, 2, 4), endDateMappings); // C8 - Teve TB entre 12˚ e 24 ˚ meses de TARV: (coluna AW) - Resposta = Sim ou Não (RF38) pdd.addColumn( "tb_tarv_c", - listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithTbThirdToNineMonth(12, 24), + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithTbThirdToNineMonth( + 12, 24, false, 2, 4), endDateMappings); // C9 - Data de inscrição no MDS entre 12º e 24º mês de TAV: (coluna AX) - Resposta = Data de // Inscrição (RF39) pdd.addColumn( "mds_tarv_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMdsDate(12, 24), + listOfPatientsWithMdsEvaluationCohortQueries.getMdsDate(12, 24, false, 2, 4), endDateMappings, new GeneralDateConverter()); // C10.1 -Tipo de MDS: (MDS1) Coluna AY pdd.addColumn( "mds_one_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds1(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds1(24, 2, 4), endDateMappings, new DispensationTypeMdcConverter()); // C10.2 - Data Início de MDS1: Coluna AZ pdd.addColumn( "mds_one_start_date_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds1StartDate(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds1StartDate(24, 2, 4), endDateMappings, new GeneralDateConverter()); // C10.3 - Data Fim de MDS1: Coluna BA pdd.addColumn( "mds_one_end_date_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds1EndDate(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds1EndDate(24, 2, 4), endDateMappings, new GeneralDateConverter()); // C10.4 - Tipo de MDS: (MDS2) Coluna BB pdd.addColumn( "mds_two_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds2(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds2(24, 2, 4), endDateMappings, new DispensationTypeMdcConverter()); // C10.5 - Data Início de MDS2: Coluna BC pdd.addColumn( "mds_two_start_date_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds2StartDate(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds2StartDate(24, 2, 4), endDateMappings, new GeneralDateConverter()); // C10.6 - Data Fim de MDS2: Coluna BD pdd.addColumn( "mds_two_end_date_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds2EndDate(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds2EndDate(24, 2, 4), endDateMappings, new GeneralDateConverter()); // C10.7 - Tipo de MDS: (MDS3) Coluna BE pdd.addColumn( "mds_three_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds3(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds3(24, 2, 4), endDateMappings, new DispensationTypeMdcConverter()); // C10.8 - Data Início de MDS3: Coluna BF pdd.addColumn( "mds_three_start_date_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds3StartDate(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds3StartDate(24, 2, 4), endDateMappings, new GeneralDateConverter()); // C10.9 - Data Fim de MDS3: Coluna BG pdd.addColumn( "mds_three_end_date_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds3EndDate(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds3EndDate(24, 2, 4), endDateMappings, new GeneralDateConverter()); // C10.10 - Tipo de MDS: (MDS4) Coluna BH pdd.addColumn( "mds_four_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds4(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds4(24, 2, 4), endDateMappings, new DispensationTypeMdcConverter()); // C10.11 - Data Início de MDS4: Coluna BI pdd.addColumn( "mds_four_start_date_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds4StartDate(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds4StartDate(24, 2, 4), endDateMappings, new GeneralDateConverter()); // C10.12 - Data Fim de MDS4: Coluna BJ pdd.addColumn( "mds_four_end_date_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds4EndDate(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds4EndDate(24, 2, 4), endDateMappings, new GeneralDateConverter()); // C10.13 - Tipo de MDS: (MDS5) Coluna BK pdd.addColumn( "mds_five_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds5(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds5(24, 2, 4), endDateMappings, new DispensationTypeMdcConverter()); // C10.14 - Data Início de MDS5: Coluna BL pdd.addColumn( "mds_five_start_date_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds5StartDate(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds5StartDate(24, 2, 4), endDateMappings, new GeneralDateConverter()); // C10.15 - Data Fim de MDS5: Coluna BM pdd.addColumn( "mds_five_end_date_c", - listOfPatientsWithMdsEvaluationCohortQueries.getMds5EndDate(24), + listOfPatientsWithMdsEvaluationCohortQueries.getMds5EndDate(24, 2, 4), endDateMappings, new GeneralDateConverter()); // C11 - Rastreado para TB em TODAS as consultas entre 12˚ e 24˚ mês de TARV?- C.11 (Coluna BN) pdd.addColumn( "tb_screening_c", - listOfPatientsWithMdsEvaluationCohortQueries.getTbScreeningSectionC(true, 12, 24), + listOfPatientsWithMdsEvaluationCohortQueries.getTbScreeningSectionC(true, 12, 24, 2, 4), endDateMappings); + // C12 - Recebeu uma forma de PF entre 12˚ e 24˚ mês de TARV? + pdd.addColumn( + "family_planning_c", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWhoReceivedPf(12, 24, false, 2, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + + // C13 - Recebeu TPT entre 12˚ e 24˚ mês de TARV? + pdd.addColumn( + "received_tpt_c", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWhoReceivedTpt(12, 24, false, 2, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + // C14 - PB/IMC registado em TODAS as consultas entre o 12˚ a 24º mês de TARV? (coluna BQ) - // Resposta = Sim ou Não ou N/A (RF27) pdd.addColumn( "pb_imc_c", - listOfPatientsWithMdsEvaluationCohortQueries.getTbScreeningSectionC(false, 12, 24), + listOfPatientsWithMdsEvaluationCohortQueries.getTbScreeningSectionC(false, 12, 24, 2, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + + // C15 - Rastreado para Tensão Arterial em todas as consultas entre 12˚ e 24˚ mês de TARV? + pdd.addColumn( + "arterial_pressure_c", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientWithArterialPressure( + 12, 24, false, 2, 4), endDateMappings, new NotApplicableIfNullConverter()); // C16 - Identificação de n˚ de consultas clínicas entre 6˚ e 12˚ mês de TARV Coluna AJ pdd.addColumn( "clinical_consultations_c", - listOfPatientsWithMdsEvaluationCohortQueries.getNrClinicalConsultations(12, 24), + listOfPatientsWithMdsEvaluationCohortQueries.getNrClinicalConsultations(12, 24, 2, 4), endDateMappings); // C17 - N˚ de consultas de APSS/PP tre 12˚ e 24˚ mês de TARV - Coluna BT pdd.addColumn( "apss_pp_consultations_c", - listOfPatientsWithMdsEvaluationCohortQueries.getNrApssPpConsultations(12, 24), + listOfPatientsWithMdsEvaluationCohortQueries.getNrApssPpConsultations(12, 24, 2, 4), endDateMappings); - // C18 - Estado de permanência no 24˚ mês de TARV: (coluna BU) + // C18 - Rastreado para CACUM entre 12˚ e 24˚ mês de TARV? + pdd.addColumn( + "cacum_screening_c", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithCacumScreening(12, 24, 2, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + + // C19 - Resultado positivo para CACUM entre 12˚ e 24˚ mês de TARV? + pdd.addColumn( + "positive_cacum_c", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithPositiveCacum(12, 24, 2, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + + // C20 - Estado de permanência no 24˚ mês de TARV: (coluna BU) pdd.addColumn( "permanence_state_c", - listOfPatientsWithMdsEvaluationCohortQueries.getLastStateOfStayOnTarv(), - c18Mappings); + listOfPatientsWithMdsEvaluationCohortQueries.getLastStateOfStayOnTarv(0, 2), + c20Mappings); // D.1 - Data do pedido da CV de seguimento - D.1 (coluna BV) pdd.addColumn( "cv_date_d", - listOfPatientsWithMdsEvaluationCohortQueries.getLastViralLoadOnThePeriod(24, 36), + listOfPatientsWithMdsEvaluationCohortQueries.getLastViralLoadOnThePeriod(24, 36, 3, 4), endDateMappings, new GeneralDateConverter()); @@ -501,7 +592,7 @@ public DataSetDefinition contructDataset() { pdd.addColumn( "cv_result_date_d", listOfPatientsWithMdsEvaluationCohortQueries - .getLastViralLoadResultDateBetweenPeriodsInMonthsAfterTarv(24, 36), + .getLastViralLoadResultDateBetweenPeriodsInMonthsAfterTarv(24, 36, 3, 4), endDateMappings, new GeneralDateConverter()); @@ -509,177 +600,223 @@ public DataSetDefinition contructDataset() { pdd.addColumn( "cv_result_d", listOfPatientsWithMdsEvaluationCohortQueries - .getSecondViralLoadResultBetweenPeriodsOfMonthsAfterTarv(24, 36), + .getSecondViralLoadResultBetweenPeriodsOfMonthsAfterTarv(24, 36, 3, 4), endDateMappings, new ViralLoadQualitativeLabelConverter()); // D.4 - Resultado do CD4 feito entre 24˚ e 36˚ mês de TARV- D.4 (Coluna BY) pdd.addColumn( "cd4_result_d", - listOfPatientsWithMdsEvaluationCohortQueries.getCd4ResultSectionC(24, 36), + listOfPatientsWithMdsEvaluationCohortQueries.getCd4ResultSectionC(24, 36, 3, 4), endDateMappings); // D.5- Teve registo de boa adesão em TODAS consultas entre 24˚ e 36˚ mês de TARV? pdd.addColumn( "good_adherence_d", - listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithGoodAdhesion(false, 24, 36), + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithGoodAdhesion( + false, 24, 36, 3, 4), endDateMappings); // D.6 - Esteve grávida ou foi lactante entre 24˚ e 36º mês de TARV?: (coluna CA) pdd.addColumn( "pregnant_breastfeeding_d", listOfPatientsWithMdsEvaluationCohortQueries.getPatientsPregnantBreastfeeding3MonthsTarv( - 24, 36), + 24, 36, false, 3, 4), endDateMappings); + // D7 - Condição Clínica Activa de Estadio III ou IV entre 24º e 36º mês de TARV + pdd.addColumn( + "clinical_condiction_d", + listOfPatientsWithMdsEvaluationCohortQueries.getActiveClinicalCondiction( + 24, 36, false, 3, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + // D.8 - Teve TB entre 24˚ e 36 ˚ meses de TARV: (coluna CC) pdd.addColumn( "tb_tarv_d", - listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithTbThirdToNineMonth(24, 36), + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithTbThirdToNineMonth( + 24, 36, false, 3, 4), endDateMappings); // D.9 - Data de inscrição em algum MDS entre 24º e 36º mês de TARV: (coluna CD) pdd.addColumn( "mds_tarv_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMdsDate(24, 36), + listOfPatientsWithMdsEvaluationCohortQueries.getMdsDate(24, 36, false, 3, 4), endDateMappings, new GeneralDateConverter()); // D10.1 -Tipo de MDS: (MDS1) Coluna CE pdd.addColumn( "mds_one_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds1(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds1(36, 3, 4), endDateMappings, new DispensationTypeMdcConverter()); // D10.2 - Data Início de MDS1: Coluna CF pdd.addColumn( "mds_one_start_date_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds1StartDate(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds1StartDate(36, 3, 4), endDateMappings, new GeneralDateConverter()); // D10.3 - Data Fim de MDS1: Coluna CG pdd.addColumn( "mds_one_end_date_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds1EndDate(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds1EndDate(36, 3, 4), endDateMappings, new GeneralDateConverter()); // D10.4 - Tipo de MDS: (MDS2) Coluna CH pdd.addColumn( "mds_two_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds2(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds2(36, 3, 4), endDateMappings, new DispensationTypeMdcConverter()); // D10.5 - Data Início de MDS2: Coluna CI pdd.addColumn( "mds_two_start_date_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds2StartDate(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds2StartDate(36, 3, 4), endDateMappings, new GeneralDateConverter()); // D10.6 - Data Fim de MDS2: Coluna CJ pdd.addColumn( "mds_two_end_date_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds2EndDate(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds2EndDate(36, 3, 4), endDateMappings, new GeneralDateConverter()); // D10.7 - Tipo de MDS: (MDS3) Coluna CK pdd.addColumn( "mds_three_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds3(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds3(36, 3, 4), endDateMappings, new DispensationTypeMdcConverter()); // D10.8 - Data Início de MDS3: Coluna CL pdd.addColumn( "mds_three_start_date_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds3StartDate(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds3StartDate(36, 3, 4), endDateMappings, new GeneralDateConverter()); // D10.9 - Data Fim de MDS3: Coluna CM pdd.addColumn( "mds_three_end_date_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds3EndDate(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds3EndDate(36, 3, 4), endDateMappings, new GeneralDateConverter()); // D10.10 - Tipo de MDS: (MDS4) Coluna CN pdd.addColumn( "mds_four_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds4(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds4(36, 3, 4), endDateMappings, new DispensationTypeMdcConverter()); // D10.11 - Data Início de MDS4: Coluna CO pdd.addColumn( "mds_four_start_date_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds4StartDate(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds4StartDate(36, 3, 4), endDateMappings, new GeneralDateConverter()); // D10.12 - Data Fim de MDS4: Coluna CP pdd.addColumn( "mds_four_end_date_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds4EndDate(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds4EndDate(36, 3, 4), endDateMappings, new GeneralDateConverter()); // D10.13 - Tipo de MDS: (MDS5) Coluna CQ pdd.addColumn( "mds_five_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds5(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds5(36, 3, 4), endDateMappings, new DispensationTypeMdcConverter()); // D10.14 - Data Início de MDS5: Coluna CR pdd.addColumn( "mds_five_start_date_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds5StartDate(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds5StartDate(36, 3, 4), endDateMappings, new GeneralDateConverter()); // D10.15 - Data Fim de MDS5: Coluna CS pdd.addColumn( "mds_five_end_date_d", - listOfPatientsWithMdsEvaluationCohortQueries.getMds5EndDate(36), + listOfPatientsWithMdsEvaluationCohortQueries.getMds5EndDate(36, 3, 4), endDateMappings, new GeneralDateConverter()); // D11 - Rastreado para TB em TODAS as consultas entre 24˚ e 36˚ mês de TARV?- D.11 (Coluna CT) pdd.addColumn( "tb_screening_d", - listOfPatientsWithMdsEvaluationCohortQueries.getTbScreeningSectionC(true, 24, 36), + listOfPatientsWithMdsEvaluationCohortQueries.getTbScreeningSectionC(true, 24, 36, 3, 4), endDateMappings); + // D12 - Recebeu uma forma de PF entre 24˚ e 36˚ mês de TARV? + pdd.addColumn( + "family_planning_d", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWhoReceivedPf(24, 36, false, 3, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + + // D13 - Recebeu TPT entre 24˚ e 36˚ mês de TARV? + pdd.addColumn( + "received_tpt_d", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWhoReceivedTpt(24, 36, false, 3, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + // D14 - PB/IMC registado em TODAS as consultas entre o 24˚ a 36º mês de TARV?- D.14 (Coluna CW) pdd.addColumn( "pb_imc_d", - listOfPatientsWithMdsEvaluationCohortQueries.getTbScreeningSectionC(false, 24, 36), + listOfPatientsWithMdsEvaluationCohortQueries.getTbScreeningSectionC(false, 24, 36, 4, 3), + endDateMappings, + new NotApplicableIfNullConverter()); + + // D15 - Rastreado para Tensão Arterial em todas as consultas entre 24˚ e 36˚ mês de TARV? + pdd.addColumn( + "arterial_pressure_d", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientWithArterialPressure( + 24, 36, false, 3, 4), endDateMappings, new NotApplicableIfNullConverter()); // D16 - N˚ de consultas clínicas entre 24˚ e 36˚ mês de TARV- D.16 (Coluna CY) pdd.addColumn( "clinical_consultations_d", - listOfPatientsWithMdsEvaluationCohortQueries.getNrClinicalConsultations(24, 36), + listOfPatientsWithMdsEvaluationCohortQueries.getNrClinicalConsultations(24, 36, 3, 4), endDateMappings); // D17 - N˚ de consultas de APSS/PP tre 24˚ e 36˚ mês de TARV- D.18 (Coluna CZ) pdd.addColumn( "apss_pp_consultations_d", - listOfPatientsWithMdsEvaluationCohortQueries.getNrApssPpConsultations(24, 36), + listOfPatientsWithMdsEvaluationCohortQueries.getNrApssPpConsultations(24, 36, 3, 4), endDateMappings); - // D18 - Estado de permanência no 36˚ mês de TARV: (coluna DA) + // D18 - Rastreado para CACUM entre 24˚ e 36˚ mês de TARV? + pdd.addColumn( + "cacum_screening_d", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithCacumScreening(24, 36, 3, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + + // D19 - Resultado positivo para CACUM entre 24˚ e 36˚ mês de TARV? + pdd.addColumn( + "positive_cacum_d", + listOfPatientsWithMdsEvaluationCohortQueries.getPatientsWithPositiveCacum(24, 36, 3, 4), + endDateMappings, + new NotApplicableIfNullConverter()); + + // D20 - Estado de permanência no 36˚ mês de TARV: (coluna DA) pdd.addColumn( "permanence_state_d", - listOfPatientsWithMdsEvaluationCohortQueries.getLastStateOfStayOnTarv(), - d18Mappings); + listOfPatientsWithMdsEvaluationCohortQueries.getLastStateOfStayOnTarv(0, 1), + d20Mappings); return pdd; } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/ListOfPatientsWithMdsEvaluationQueries.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/ListOfPatientsWithMdsEvaluationQueries.java index 80de4bb929..65f1194def 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/ListOfPatientsWithMdsEvaluationQueries.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/library/queries/ListOfPatientsWithMdsEvaluationQueries.java @@ -8,6 +8,7 @@ import org.openmrs.module.eptsreports.metadata.TbMetadata; import org.openmrs.module.eptsreports.reporting.library.cohorts.GenericCohortQueries; import org.openmrs.module.eptsreports.reporting.library.cohorts.ResumoMensalCohortQueries; +import org.openmrs.module.eptsreports.reporting.utils.EptsQueriesUtil; import org.springframework.stereotype.Component; @Component @@ -550,7 +551,8 @@ public static String getB1PatientsWhoAreTransferredIn( * * @return String */ - public String getPatientsWhoHaveTransferredOutAsPermananceState() { + public String getPatientsWhoHaveTransferredOutAsPermananceState( + int minCohortNumberOfYears, int maxCohortNumberOfYears) { Map map = new HashMap<>(); map.put("2", hivMetadata.getARTProgram().getProgramId()); @@ -770,6 +772,675 @@ public String getPatientsWhoHaveTransferredOutAsPermananceState() { + " last_next_scheduled_pick_up " + " ON last_next_scheduled_pick_up.patient_id = p.patient_id " + " WHERE last_next_scheduled_pick_up.max_datetame > :endDate ) " + + " AND transferred_out.patient_id IN ( " + + getCohortPatientsByYear(minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + + "GROUP BY transferred_out.patient_id"; + + StringSubstitutor stringSubstitutor = new StringSubstitutor(map); + return stringSubstitutor.replace(query); + } + + /** + * Abandonos em Tarv/ Transferidos Para + * + * @param stateOnProgram State on Program concept + * @param stateOnEncounters State on encounter types concept + * @param transferredOut transferred out flag to change the exclusion query + * @param isForCohortDefinition flag to return result based on the definition (cohort or data + * definition) + * @return {@link String} + */ + public String getPatientsWhoSuspendedTarvOrAreTransferredOut( + int stateOnProgram, + int stateOnEncounters, + boolean transferredOut, + boolean isForCohortDefinition, + int minCohortNumberOfYears, + int maxCohortNumberOfYears) { + String query = + isForCohortDefinition + ? " SELECT mostrecent.patient_id " + : " SELECT mostrecent.patient_id, 'Suspenso' "; + query += + "FROM (" + + " SELECT lastest.patient_id ,Max(lastest.last_date) as last_date " + + " FROM ( " + + " SELECT p.patient_id , MAX(ps.start_date) AS last_date " + + " FROM patient p " + + " INNER JOIN patient_program pg " + + " ON p.patient_id=pg.patient_id " + + " INNER JOIN patient_state ps " + + " ON pg.patient_program_id=ps.patient_program_id " + + " WHERE pg.voided=0 " + + " AND ps.voided=0 " + + " AND p.voided=0 " + + " AND pg.program_id= ${2} " + + " AND ps.state = " + + stateOnProgram + + " AND ps.start_date <= :endDate " + + " AND pg.location_id= :location " + + " GROUP BY p.patient_id " + + " " + + " UNION " + + " " + + " SELECT p.patient_id, Max(e.encounter_datetime) AS last_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id=p.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id=e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND o.concept_id = ${6273} " + + " AND o.value_coded = " + + stateOnEncounters + + " AND e.encounter_datetime <= :endDate " + + " AND e.location_id = :location " + + " GROUP BY p.patient_id " + + " " + + " UNION " + + " " + + " SELECT p.patient_id , Max(o.obs_datetime) AS last_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id=p.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id=e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${53} " + + " AND o.concept_id = ${6272} " + + " AND o.value_coded = " + + stateOnEncounters + + " AND o.obs_datetime <= :endDate " + + " AND e.location_id = :location " + + " GROUP BY p.patient_id " + + ") lastest " + + " WHERE lastest.patient_id NOT IN( "; + + if (transferredOut) { + 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_type = ${18} " + + " AND e.encounter_datetime > lastest.last_date " + + " AND e.encounter_datetime <= :endDate " + + " UNION " + + " SELECT final.patient_id FROM ( " + + " SELECT considered_transferred.patient_id, MAX(considered_transferred.value_datetime) as max_date " + + " FROM ( " + + " SELECT p.patient_id, " + + " TIMESTAMPADD(DAY, 1, MAX(o.value_datetime)) AS value_datetime " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id=p.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id=e.encounter_id " + + " INNER JOIN ( " + + " SELECT p.patient_id, MAX(e.encounter_datetime) AS most_recent " + + " FROM patient p " + + " INNER JOIN encounter e ON e.patient_id = p.patient_id " + + " WHERE e.encounter_type = ${18} " + + " AND e.encounter_datetime <= :endDate " + + " AND e.voided = 0 " + + " AND p.voided = 0 " + + " AND e.location_id = :location " + + " GROUP BY p.patient_id " + + " ) last_fila ON last_fila.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${18} " + + " AND o.concept_id = ${5096} " + + " AND e.encounter_datetime = last_fila.most_recent " + + " AND o.value_datetime <= :endDate " + + " AND e.location_id = :location " + + " GROUP BY p.patient_id " + + " UNION " + + " SELECT p.patient_id, " + + " TIMESTAMPADD(DAY, 31, MAX(o.value_datetime)) AS value_datetime " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id=p.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id=e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${52} " + + " AND o.concept_id = ${23866} " + + " AND o.value_datetime <= :endDate " + + " AND e.location_id = :location " + + " GROUP BY p.patient_id " + + " ) considered_transferred " + + " GROUP BY considered_transferred.patient_id " + + " HAVING max_date > :endDate " + + " ) final "; + } else { + 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_type = ${18} " + + " AND e.encounter_datetime > lastest.last_date " + + " AND e.encounter_datetime <= :endDate "; + } + query += + " ) " + + " GROUP BY lastest.patient_id )mostrecent " + + " WHERE mostrecent.patient_id IN ( " + + getCohortPatientsByYear(minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + + " GROUP BY mostrecent.patient_id"; + return query; + } + + /** + * Utentes Activos em TARV + *
  • Iniciaram TARV até o fim do período de avaliação, ou seja, com registo do Início TARV + * Excluindo todos os utentes: + *
  • Abandonos em TARV + *
  • Transferidos Para Outra US + *
  • Suspensos em TARV + *
  • Óbitos + *
  • Reinícios + * + * @return {@link String} + */ + public String getPatientsActiveOnTarv(int minCohortNumberOfYears, int maxCohortNumberOfYears) { + return "SELECT final.patient_id, 'Activo' " + + "FROM " + + " ( " + + resumoMensalCohortQueries.getPatientStartedTarvBeforeQuery() + + " ) final " + + "WHERE final.patient_id NOT IN (" + + new EptsQueriesUtil() + .unionBuilder( + getPatientsWhoAbandonedTarvQuery( + false, minCohortNumberOfYears, maxCohortNumberOfYears)) + .union( + getB13PatientsWhoHaveTransferredOutAsPermananceState( + minCohortNumberOfYears, maxCohortNumberOfYears)) + .union( + getPatientsWhoSuspendedTarvOrAreTransferredOut( + hivMetadata.getSuspendedTreatmentWorkflowState().getProgramWorkflowStateId(), + hivMetadata.getSuspendedTreatmentConcept().getConceptId(), + false, + true, + minCohortNumberOfYears, + maxCohortNumberOfYears)) + .union(getPatientsWhoDied(false, minCohortNumberOfYears, maxCohortNumberOfYears)) + .buildQuery() + + " ) " + + " AND final.patient_id IN ( " + + getCohortPatientsByYear(minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + + "GROUP BY final.patient_id "; + } + + /** + * Utentes em TARV com registo de Óbito + *
  • Utentes com registo de “Óbito” (último estado de inscrição) no programa SERVIÇO TARV + * TRATAMENTO até o fim do período de avaliação (“Data de Óbito” <= Data Fim”; ou + *
  • Utentes com registo do último estado [“Mudança Estado Permanência TARV” (Coluna 21) = “O” + * (Óbito) na Ficha Clínica com “Data da Consulta Actual” (Coluna 1, durante a qual se fez o + * registo da mudança do estado de permanência TARV) <= “Data Fim”; ou + *
  • Utentes com último registo de “Mudança Estado Permanência TARV” = “Óbito” na Ficha Resumo + * com “Data de Óbito” <= “Data Fim”; ou + * + * @return {@link String} + */ + public String getPatientsWhoDied( + boolean isForDataDefinition, int minCohortNumberOfYears, int maxCohortNumberOfYears) { + String fromSQL = + "FROM (" + + " SELECT lastest.patient_id ,Max(lastest.deceased_date) as deceased_date " + + " FROM ( " + + " " + + "SELECT p.patient_id ,ps.start_date AS deceased_date " + + " FROM patient p " + + " INNER JOIN patient_program pg " + + " ON p.patient_id=pg.patient_id " + + " INNER JOIN patient_state ps " + + " ON pg.patient_program_id=ps.patient_program_id " + + " WHERE pg.voided=0 " + + " AND ps.voided=0 " + + " AND p.voided=0 " + + " AND pg.program_id= ${2} " + + " AND ps.state = ${10} " + + " AND ps.start_date <= :endDate " + + " AND pg.location_id= :location " + + " GROUP BY p.patient_id " + + " " + + " UNION " + + " " + + " SELECT p.patient_id, Max(e.encounter_datetime) AS deceased_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id=p.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id=e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND o.concept_id = ${6273} " + + " AND o.value_coded = ${1366} " + + " AND e.encounter_datetime <= :endDate " + + " AND e.location_id = :location " + + " GROUP BY p.patient_id " + + " " + + " UNION " + + " " + + " SELECT p.patient_id , Max(o.obs_datetime) AS deceased_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id=p.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id=e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${53} " + + " AND o.concept_id = ${6272} " + + " AND o.value_coded = ${1366} " + + " AND o.obs_datetime <= :endDate " + + " AND e.location_id = :location " + + " GROUP BY p.patient_id " + + " UNION " + + " SELECT p.person_id, p.death_date AS deceased_date " + + " FROM person p " + + " WHERE p.voided = 0" + + " AND p.dead = 1 " + + " AND p.death_date <= :endDate " + + ") lastest " + + " WHERE lastest.patient_id NOT IN( " + + " SELECT p.patient_id " + + " FROM patient p " + + " JOIN encounter e " + + " ON p.patient_id = e.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND e.location_id = :location " + + " AND e.encounter_datetime > lastest.deceased_date " + + " AND e.encounter_datetime <= :endDate " + + " 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 " + + " WHERE p.voided = 0" + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${18} " + + " AND e.location_id = :location " + + " AND e.encounter_datetime > lastest.deceased_date" + + " AND e.encounter_datetime <= :endDate" + + " ) " + + " GROUP BY lastest.patient_id )mostrecent " + + " WHERE mostrecent.patient_id IN ( " + + getCohortPatientsByYear(minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + + " GROUP BY mostrecent.patient_id"; + + return isForDataDefinition + ? " SELECT mostrecent.patient_id, 'Óbito' ".concat(fromSQL) + : " SELECT mostrecent.patient_id ".concat(fromSQL); + } + + /** + * Utentes em TARV que Abandonaram o TARV Todos os utentes com a data mais recente entre + *
  • A Data do Último Levantamento registada, até o fim do período de avaliação, na “Ficha + * Recepção/Levantou ARVs?” com “Levantou ARV” = “S”, adicionando 30 dias + *
  • a Data do Último Agendamento de Levantamento registado no FILA até o fim do período de + * avaliação Esta data adicionando 60 dias é menor que a “Data Fim”; + * + *

    Excepto os utentes: + *

  • Transferidos Para Outra US + *
  • Suspensos em TARV + *
  • Óbitos + * + * @return {@link String} + */ + public String getPatientsWhoAbandonedTarvQuery( + boolean isForDataDefinition, int minCohortNumberOfYears, int maxCohortNumberOfYears) { + String fromSQL = + "FROM ( " + + " SELECT most_recent.patient_id, " + + " date_add(Max(most_recent.value_datetime), interval 60 day) final_encounter_date " + + " FROM ( " + + " SELECT p.patient_id, " + + " o.value_datetime " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " INNER JOIN ( " + + " SELECT p.patient_id, " + + " max(e.encounter_datetime) last_encounter " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${18} " + + " AND e.encounter_datetime <= :endDate " + + " AND e.location_id = :location " + + " GROUP BY p.patient_id " + + " ) last_fila ON last_fila.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${18} " + + " AND o.concept_id = ${5096} " + + " AND o.value_datetime IS NOT NULL " + + " AND e.encounter_datetime = last_fila.last_encounter " + + " AND e.location_id = :location " + + " GROUP BY p.patient_id " + + " UNION " + + " SELECT p.patient_id, " + + " date_add(max(o2.value_datetime), interval 30 day) value_datetime " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 " + + " ON o2.encounter_id = e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND e.encounter_type = ${52} " + + " AND ( " + + " o.concept_id = ${23865} " + + " AND o.value_coded = ${1065}) " + + " AND ( " + + " o2.concept_id = ${23866} " + + " AND o2.value_datetime IS NOT NULL " + + " AND o2.value_datetime <= :endDate ) " + + " AND e.location_id = :location " + + " GROUP BY p.patient_id) most_recent " + + " GROUP BY most_recent.patient_id " + + " HAVING final_encounter_date < :endDate ) final " + + "WHERE final.patient_id NOT IN ( " + + new EptsQueriesUtil() + .unionBuilder( + getPatientsWhoSuspendedTarvOrAreTransferredOut( + hivMetadata + .getTransferredOutToAnotherHealthFacilityWorkflowState() + .getProgramWorkflowStateId(), + hivMetadata.getTransferredOutConcept().getConceptId(), + true, + true, + minCohortNumberOfYears, + maxCohortNumberOfYears)) + .union( + getPatientsWhoSuspendedTarvOrAreTransferredOut( + hivMetadata + .getSuspendedTreatmentWorkflowState() + .getProgramWorkflowStateId(), + hivMetadata.getSuspendedTreatmentConcept().getConceptId(), + false, + true, + minCohortNumberOfYears, + maxCohortNumberOfYears)) + .union(getPatientsWhoDied(false, minCohortNumberOfYears, maxCohortNumberOfYears)) + .buildQuery() + + ") " + + " AND final.patient_id IN ( " + + getCohortPatientsByYear(minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + + "GROUP BY final.patient_id"; + + return isForDataDefinition + ? "SELECT final.patient_id, 'Abandono' ".concat(fromSQL) + : " SELECT final.patient_id ".concat(fromSQL); + } + + public String getB13PatientsWhoHaveTransferredOutAsPermananceState( + int minCohortNumberOfYears, int maxCohortNumberOfYears) { + + Map map = new HashMap<>(); + map.put("2", hivMetadata.getARTProgram().getProgramId()); + map.put( + "7", + hivMetadata + .getTransferredOutToAnotherHealthFacilityWorkflowState() + .getProgramWorkflowStateId()); + map.put("6", hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId()); + map.put("18", hivMetadata.getARVPharmaciaEncounterType().getEncounterTypeId()); + map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId()); + map.put("1369", commonMetadata.getTransferFromOtherFacilityConcept().getConceptId()); + map.put("1065", hivMetadata.getYesConcept().getConceptId()); + map.put("6300", hivMetadata.getTypeOfPatientTransferredFrom().getConceptId()); + map.put("6276", hivMetadata.getArtStatus().getConceptId()); + map.put("6273", hivMetadata.getStateOfStayOfArtPatient().getConceptId()); + map.put("6272", hivMetadata.getStateOfStayOfPreArtPatient().getConceptId()); + map.put("1706", hivMetadata.getTransferredOutConcept().getConceptId()); + map.put("52", hivMetadata.getMasterCardDrugPickupEncounterType().getEncounterTypeId()); + map.put("23866", hivMetadata.getArtDatePickupMasterCard().getConceptId()); + map.put("23865", hivMetadata.getArtPickupConcept().getConceptId()); + map.put("5096", hivMetadata.getReturnVisitDateForArvDrugConcept().getConceptId()); + + String query = + " SELECT patient_id " + + "FROM (" + + "SELECT latest.patient_id, " + + " Max(latest.last_date) AS last_date " + + "FROM (SELECT p.patient_id, laststate.last_date AS last_date FROM patient p " + + "INNER JOIN patient_program pg " + + "ON p.patient_id = pg.patient_id " + + "INNER JOIN patient_state ps " + + "ON pg.patient_program_id = ps.patient_program_id " + + "INNER JOIN " + + " ( " + + " SELECT p.patient_id, " + + " max(ps.start_date) AS last_date " + + " FROM patient p " + + " INNER JOIN patient_program pg " + + " ON p.patient_id = pg.patient_id " + + " INNER JOIN patient_state ps " + + " ON pg.patient_program_id = ps.patient_program_id " + + " WHERE pg.voided = 0 " + + " AND ps.voided = 0 " + + " AND p.voided = 0 " + + " AND pg.program_id = ${2} " + + " AND ps.state IS NOT NULL " + + " AND ps.start_date <= :endDate " + + " AND pg.location_id = :location " + + " GROUP BY p.patient_id) laststate " + + "ON laststate.patient_id = p.patient_id WHERE pg.voided = 0 " + + "AND ps.voided = 0 " + + "AND p.voided = 0 " + + "AND pg.program_id = ${2} " + + "AND ps.state = ${7} " + + "AND ps.start_date = laststate.last_date " + + "AND pg.location_id = :location GROUP BY p.patient_id " + + "UNION " + + "SELECT p.patient_id, " + + " max_resumo_state.last_state_date AS last_date " + + "FROM patient p " + + "INNER JOIN encounter e " + + "ON e.patient_id = p.patient_id " + + "INNER JOIN obs o " + + "ON e.encounter_id = o.encounter_id " + + "INNER JOIN " + + " ( " + + " SELECT p.patient_id, " + + " max(o.obs_datetime) AS last_state_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${53} " + + " AND o.obs_datetime <= :endDate " + + " AND e.location_id = :location " + + " AND o.concept_id = ${6272} " + + " GROUP BY p.patient_id) max_resumo_state " + + "ON max_resumo_state.patient_id = p.patient_id " + + "WHERE p.voided = 0 " + + "AND e.voided = 0 " + + "AND o.voided = 0 " + + "AND e.encounter_type = ${53} " + + "AND o.concept_id = ${6272} " + + "AND o.value_coded = ${1706} " + + "AND o.obs_datetime = max_resumo_state.last_state_date " + + "AND e.location_id = :location " + + "GROUP BY p.patient_id " + + "UNION " + + "SELECT p.patient_id, " + + " max_state_clinical.last_state_date AS last_date " + + "FROM patient p " + + "INNER JOIN encounter e " + + "ON e.patient_id = p.patient_id " + + "INNER JOIN obs o " + + "ON o.encounter_id = e.encounter_id " + + "INNER JOIN " + + " ( " + + " SELECT p.patient_id, " + + " max(e.encounter_datetime) AS last_state_date " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON e.patient_id = p.patient_id " + + " INNER JOIN obs o " + + " ON o.encounter_id = e.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.encounter_type = ${6} " + + " AND e.encounter_datetime <= :endDate " + + " AND e.location_id = :location " + + " AND o.concept_id = ${6273} " + + " GROUP BY p.patient_id) max_state_clinical " + + "ON max_state_clinical.patient_id = p.patient_id " + + "WHERE p.voided = 0 " + + "AND e.voided = 0 " + + "AND o.voided = 0 " + + "AND e.encounter_type = ${6} " + + "AND o.concept_id = ${6273} " + + "AND o.value_coded = ${1706} " + + "AND e.encounter_datetime = max_state_clinical.last_state_date " + + "AND e.location_id = :location " + + "GROUP BY p.patient_id) latest " + + "GROUP BY latest.patient_id" + + ") transferred_out " + + "WHERE transferred_out.patient_id NOT IN (SELECT p.patient_id " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON " + + " e.patient_id = p.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND p.patient_id = " + + " transferred_out.patient_id " + + " AND e.encounter_type = ${18} " + + " AND " + + " e.encounter_datetime > transferred_out.last_date " + + " AND " + + " e.encounter_datetime <= :endDate " + + " AND e.location_id = :location " + + " UNION " + + " SELECT p.patient_id " + + " FROM patient p " + + " INNER JOIN (SELECT " + + " last_next_pick_up.patient_id, " + + " Max(last_next_pick_up.result_value) AS " + + " max_datetame " + + " FROM " + + " (SELECT p.patient_id, " + + " Timestampadd(day, 1, o.value_datetime) AS " + + " result_value " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON p.patient_id = " + + " e.patient_id " + + " INNER JOIN obs o " + + " ON e.encounter_id = " + + " o.encounter_id " + + " INNER JOIN " + + " (SELECT p.patient_id, " + + " Max(e.encounter_datetime) " + + " AS " + + " e_datetime " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON p.patient_id = " + + " e.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND e.location_id = :location " + + " AND e.encounter_type = ${18} " + + " AND e.encounter_datetime " + + " <= " + + " :endDate " + + " GROUP BY p.patient_id) " + + " most_recent " + + " ON p.patient_id = " + + " most_recent.patient_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND e.location_id = :location " + + " AND e.encounter_type = ${18} " + + " AND o.concept_id = ${5096} " + + " AND e.encounter_datetime = " + + " most_recent.e_datetime " + + " GROUP BY p.patient_id " + + " UNION " + + " SELECT p.patient_id, " + + " Timestampadd(day, 31, Max(o.value_datetime)) " + + " AS " + + " result_value " + + " FROM patient p " + + " INNER JOIN encounter e " + + " ON p.patient_id = e.patient_id " + + " INNER JOIN obs o " + + " ON e.encounter_id = o.encounter_id " + + " INNER JOIN obs o2 " + + " ON e.encounter_id = o2.encounter_id " + + " WHERE p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND e.location_id = :location " + + " AND e.encounter_type = ${52} " + + " AND ( o.concept_id = ${23866} " + + " AND o.value_datetime <= :endDate ) " + + " AND ( o2.concept_id = ${23865} " + + " AND o2.value_coded = ${1065} ) " + + " GROUP BY p.patient_id) AS last_next_pick_up " + + " GROUP BY last_next_pick_up.patient_id) AS " + + " last_next_scheduled_pick_up " + + " ON last_next_scheduled_pick_up.patient_id = p.patient_id " + + " WHERE last_next_scheduled_pick_up.max_datetame > :endDate ) " + + " AND transferred_out.patient_id IN ( " + + getCohortPatientsByYear(minCohortNumberOfYears, maxCohortNumberOfYears) + + " ) " + "GROUP BY transferred_out.patient_id"; StringSubstitutor stringSubstitutor = new StringSubstitutor(map); @@ -1085,4 +1756,134 @@ public static String getFirstMdsAndDateQuery(int numberOfMonths) { + " AND otype1.obs_group_id = ostate1.obs_group_id " + " GROUP BY mds1.patient_id "; } + + public static String getCohortPatientsByYear( + int minCohortNumberOfYears, int maxCohortNumberOfYears) { + return "SELECT " + + " art_patient.patient_id " + + "FROM " + + " ( " + + " SELECT " + + " first.patient_id, " + + " MIN(first.pickup_date) first_pickup " + + " FROM " + + " ( " + + " SELECT " + + " p.patient_id, " + + " Min(e.encounter_datetime) pickup_date " + + " FROM " + + " patient p " + + " INNER JOIN encounter e ON e.patient_id = p.patient_id " + + " WHERE " + + " p.voided = 0 " + + " AND e.voided = 0 " + + " AND e.encounter_type = ${18} " + + " AND e.location_id = :location " + + " AND e.encounter_datetime <= :endDate " + + " GROUP BY " + + " p.patient_id " + + " UNION " + + " SELECT " + + " p.patient_id, " + + " Min(o2.value_datetime) pickup_date " + + " FROM " + + " patient p " + + " INNER JOIN encounter e ON e.patient_id = p.patient_id " + + " INNER JOIN obs o ON o.encounter_id = e.encounter_id " + + " INNER JOIN obs o2 ON o2.encounter_id = e.encounter_id " + + " WHERE " + + " p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND e.encounter_type = ${52} " + + " AND e.location_id = :location " + + " AND o.concept_id = ${23865} " + + " AND o.value_coded = ${1065} " + + " AND o2.concept_id = ${23866} " + + " AND o2.value_datetime <= :endDate " + + " GROUP BY " + + " p.patient_id " + + " ) first " + + " GROUP BY " + + " first.patient_id " + + " ) art_patient " + + "WHERE " + + " art_patient.first_pickup >= DATE_SUB( " + + " :endDate, INTERVAL " + + maxCohortNumberOfYears + + " YEAR ) " + + " AND art_patient.first_pickup <= DATE_SUB( " + + " :endDate, INTERVAL " + + minCohortNumberOfYears + + " YEAR ) " + + " AND art_patient.patient_id NOT IN ( " + + " SELECT " + + " patient_id " + + " FROM " + + " ( " + + " SELECT " + + " p.patient_id, " + + " ps.start_date AS data_transferido " + + " FROM " + + " patient p " + + " INNER JOIN patient_program pg ON p.patient_id = pg.patient_id " + + " INNER JOIN patient_state ps ON pg.patient_program_id = ps.patient_program_id " + + " INNER JOIN( " + + " SELECT " + + " p.patient_id, " + + " MIN(ps.start_date) AS data_transferido " + + " FROM " + + " patient p " + + " INNER JOIN patient_program pg ON p.patient_id = pg.patient_id " + + " INNER JOIN patient_state ps ON pg.patient_program_id = ps.patient_program_id " + + " WHERE " + + " pg.voided = 0 " + + " AND ps.voided = 0 " + + " AND p.voided = 0 " + + " AND pg.program_id = ${2} " + + " AND pg.location_id = :location " + + " AND ps.start_date <= DATE_SUB( " + + " :endDate, INTERVAL " + + minCohortNumberOfYears + + " YEAR ) " + + " GROUP BY " + + " p.patient_id " + + " ) pgEnrollment ON pgEnrollment.patient_id = p.patient_id " + + " where " + + " ps.start_date = pgEnrollment.data_transferido " + + " AND pg.program_id = ${2} " + + " AND ps.state = ${29} " + + " AND pg.location_id = :location " + + " AND ps.voided = 0 " + + " AND pg.voided = 0 " + + " AND p.voided = 0 " + + " UNION " + + " SELECT " + + " p.patient_id, " + + " o2.obs_datetime AS data_transferido " + + " FROM " + + " patient p " + + " INNER JOIN encounter e ON p.patient_id = e.patient_id " + + " INNER JOIN obs o ON e.encounter_id = o.encounter_id " + + " INNER JOIN obs o2 ON e.encounter_id = o2.encounter_id " + + " WHERE " + + " p.voided = 0 " + + " AND e.voided = 0 " + + " AND o.voided = 0 " + + " AND o2.voided = 0 " + + " AND e.location_id = :location " + + " AND e.encounter_type = ${53} " + + " AND o.concept_id = ${1369} " + + " AND o.value_coded = ${1065} " + + " AND o2.concept_id = ${23891} " + + " AND o2.value_datetime <= DATE_SUB( " + + " :endDate, INTERVAL " + + minCohortNumberOfYears + + " YEAR ) " + + " GROUP BY " + + " p.patient_id " + + " ) transferido_de " + + ")"; + } } diff --git a/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupListOfPatientsWithMdsEvaluation.java b/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupListOfPatientsWithMdsEvaluation.java index cf323a8c14..46c3de5cdb 100644 --- a/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupListOfPatientsWithMdsEvaluation.java +++ b/api/src/main/java/org/openmrs/module/eptsreports/reporting/reports/SetupListOfPatientsWithMdsEvaluation.java @@ -3,9 +3,7 @@ import java.io.IOException; import java.util.*; import org.openmrs.Location; -import org.openmrs.module.eptsreports.reporting.library.datasets.DatimCodeDatasetDefinition; -import org.openmrs.module.eptsreports.reporting.library.datasets.ListOfPatientsWithMdsEvaluationCohortDataset; -import org.openmrs.module.eptsreports.reporting.library.datasets.SismaCodeDatasetDefinition; +import org.openmrs.module.eptsreports.reporting.library.datasets.*; import org.openmrs.module.eptsreports.reporting.reports.manager.EptsDataExportManager; import org.openmrs.module.reporting.ReportingException; import org.openmrs.module.reporting.evaluation.parameter.Mapped; @@ -61,6 +59,7 @@ public ReportDefinition constructReportDefinition() { rd.addParameters(getParameters()); rd.addDataSetDefinition("DT", Mapped.mapStraightThrough(new DatimCodeDatasetDefinition())); rd.addDataSetDefinition("SM", Mapped.mapStraightThrough(new SismaCodeDatasetDefinition())); + rd.addDataSetDefinition("HF", Mapped.mapStraightThrough(new LocationDataSetDefinition())); rd.addDataSetDefinition( "MDS", Mapped.mapStraightThrough(listOfPatientsWithMdsEvaluationCohortDataset.contructDataset())); @@ -75,7 +74,7 @@ public List constructReportDesigns(ReportDefinition reportDefiniti reportDesign = createXlsReportDesign( reportDefinition, - "Template_MDS_v2.0.1.xls", + "MISAU_SESP_MASC_MDS_v3.1.xls", "Relatório de Avaliação de MDS", getExcelDesignUuid(), null); diff --git a/api/src/main/resources/MISAU_SESP_MASC_MDS_v3.1.xls b/api/src/main/resources/MISAU_SESP_MASC_MDS_v3.1.xls new file mode 100644 index 0000000000..2c47f8a2de Binary files /dev/null and b/api/src/main/resources/MISAU_SESP_MASC_MDS_v3.1.xls differ diff --git a/api/src/main/resources/Template_MDS_v2.0.1.xls b/api/src/main/resources/Template_MDS_v2.0.1.xls deleted file mode 100644 index f22a0b221b..0000000000 Binary files a/api/src/main/resources/Template_MDS_v2.0.1.xls and /dev/null differ diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index 9a771b6017..b7f8c5b88d 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -4293,4 +4293,93 @@ + + eptsreports.methodOfFamilyPlanningUuid + e1d1a6d8-1d5f-11e0-b929-000c29ad1d07 + + METHOD OF FAMILY PLANNING Concept + + + + + eptsreports.condomsConceptUuid + e1cff2ac-1d5f-11e0-b929-000c29ad1d07 + + CONDOMS Concept + + + + + eptsreports.oralContraceptionConceptUuid + e1d5c786-1d5f-11e0-b929-000c29ad1d07 + + ORAL CONTRACEPTION Concept + + + + + eptsreports.injectibleContraceptiveConceptUuid + e1e492ca-1d5f-11e0-b929-000c29ad1d07 + + INJECTABLE CONTRACEPTIVES Concept + + + + + + eptsreports.implantConceptUuid + b69a31ae-ef74-4daa-b7fe-5a153948a2cd + + Implant Concept + + + + + eptsreports.intrauterineDeviceConceptUuid + e1e485fa-1d5f-11e0-b929-000c29ad1d07 + + INTRAUTERINE DEVICE Concept + + + + + eptsreports.femaleSterilizationConceptUuid + e1e486f4-1d5f-11e0-b929-000c29ad1d07 + + FEMALE STERILIZATION Concept + + + + + eptsreports.vasectomyConceptUuid + 0b9a8904-3c82-4b9a-9f15-50a2509cacf9 + + VASECTOMY Concept + + + + + eptsreports.otherFamilyPlanningConceptUuid + 20ba316b-ef66-4f39-a1af-1e978aa02d18 + + OTHER FAMILY PLANNING Concept + + + + + eptsreports.systolicBoodPressureConceptUuid + 5085AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + + Systolic blood pressure Concept + + + + + eptsreports.diastolicBoodPressureConceptUuid + 5086AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + + Diastolic blood pressure Concept + + + \ No newline at end of file