Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MEPTS - 1609 | MQ Cat 15 Diff CCS DB #1295

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7674,7 +7674,7 @@
hivMetadata.getSemiannualDispensation(),
hivMetadata.getAnnualArvDispensationConcept()));

CohortDefinition transferOut = getTranferredOutPatients();
CohortDefinition transferOut = getTranferredOutPatientDuringRevisionPeriod();

Check warning on line 7677 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L7677

Added line #L7677 was not covered by tests

CohortDefinition dead = getDeadPatientsComposition();

Expand Down Expand Up @@ -7756,7 +7756,7 @@
resumoMensalCohortQueries.getPatientsWhoWereActiveByEndOfMonthB13(),
"endDate=${revisionEndDate},location=${location}"));

comp.addSearch("F", EptsReportUtils.map(transferOut, MAPPING1));
comp.addSearch("F", EptsReportUtils.map(transferOut, MAPPING3));

Check warning on line 7759 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L7759

Added line #L7759 was not covered by tests

comp.addSearch(
"dead", EptsReportUtils.map(dead, "endDate=${revisionEndDate},location=${location}"));
Expand Down Expand Up @@ -7895,7 +7895,7 @@
break;
case 9:
comp.setName(
"% de Crianças (2-9 anos) inscritas 12 meses em algum MDS (DT) que receberam pelo menos um resultado de CV");
"% de Crianças (2-9 anos) activas em TARV e inscritos 24 meses em algum MDS (DT) que receberam o segundo resultado de CV");
break;
case 10:
comp.setName(
Expand Down Expand Up @@ -8223,6 +8223,9 @@
CohortDefinition nextPickupBetween173And187 =
QualityImprovement2020Queries.getPatientsWithPickupOnFilaBetween(173, 187);

CohortDefinition nextPickupBetween335And395 =
QualityImprovement2020Queries.getPatientsWithPickupOnFilaBetween(335, 395);

Check warning on line 8227 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L8226-L8227

Added lines #L8226 - L8227 were not covered by tests

compositionCohortDefinition.addSearch(
"MDS",
EptsReportUtils.map(
Expand All @@ -8245,7 +8248,13 @@
nextPickupBetween173And187,
"startDate=${startDate},endDate=${endDate},location=${location}"));

compositionCohortDefinition.setCompositionString("MDS OR DSDT OR FILA83 OR FILA173");
compositionCohortDefinition.addSearch(

Check warning on line 8251 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L8251

Added line #L8251 was not covered by tests
"FILA335",
EptsReportUtils.map(

Check warning on line 8253 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L8253

Added line #L8253 was not covered by tests
nextPickupBetween335And395,
"startDate=${startDate},endDate=${endDate},location=${location}"));

compositionCohortDefinition.setCompositionString("MDS OR DSDT OR FILA83 OR FILA173 OR FILA335");

Check warning on line 8257 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L8257

Added line #L8257 was not covered by tests

return compositionCohortDefinition;
}
Expand Down Expand Up @@ -9456,6 +9465,7 @@
ageCohortQueries.createXtoYAgeCohort("Ages", 2, 200), "effectiveDate=${endDate}"));

cd.setCompositionString("MQ15DenMDS AND MDS AND AGE");

return cd;
}

Expand Down Expand Up @@ -11962,7 +11972,7 @@
+ " AND e.voided = 0 "
+ " AND o.voided = 0) vl_result "
+ " ON two_dispensations.patient_id = vl_result.patient_id "
+ "WHERE vl_result.vl_date > two_dispensations.second_date AND vl_result.vl_date <= :revisionEndDate";
+ "WHERE vl_result.vl_date >= two_dispensations.second_date AND vl_result.vl_date <= :revisionEndDate";

StringSubstitutor sb = new StringSubstitutor(map);

Expand Down Expand Up @@ -12116,7 +12126,7 @@
+ " AND p.voided = 0 "
+ " AND e.voided = 0 "
+ " AND o.voided = 0) vl_result ON two_dispensations.patient_id = vl_result.patient_id "
+ "WHERE vl_result.vl_date > two_dispensations.second_date "
+ "WHERE vl_result.vl_date >= two_dispensations.second_date "
+ " AND vl_result.vl_date <= :revisionEndDate";

StringSubstitutor sb = new StringSubstitutor(map);
Expand Down Expand Up @@ -13700,6 +13710,7 @@
+ " AND o.voided = 0 "
+ " AND e.encounter_type = ${6} "
+ " AND e.location_id = :location "
+ " AND e.encounter_datetime <= :revisionEndDate "
+ " AND o.concept_id = ${1268} "
+ " AND o.value_coded = ${1267} "
+ " GROUP BY p.patient_id) tb_end "
Expand Down Expand Up @@ -15753,4 +15764,123 @@

return compositionCohortDefinition;
}

/**
* <b>Utentes Transferidos Para Outra US</b>
*
* <p>O sistema irá identificar utentes “Transferido Para” outras US em TARV durante o período de
* revisão seleccionando os utentes registados como:
* <li>último registo de [“Mudança Estado Permanência TARV” (Coluna 21) = “T” (Transferido Para)
* 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) durante o período de revisão (>= “Data Início
* Revisão” e <= “Data Fim Revisão) ou
* <li>registados como “Mudança Estado Permanência TARV” = “Transferido Para”, último estado
* registado na “Ficha Resumo” com “Data da Transferência”) durante o período de revisão (>=
* “Data Início Revisão” e <= “Data Fim Revisão;
*
* @return {@link CohortDefinition}
*/
public CohortDefinition getTranferredOutPatientDuringRevisionPeriod() {

SqlCohortDefinition sqlCohortDefinition = new SqlCohortDefinition();
sqlCohortDefinition.setName("Utentes Transferidos Para Outra US");
sqlCohortDefinition.addParameter(new Parameter("startDate", "Start Date", Date.class));
sqlCohortDefinition.addParameter(new Parameter("endDate", "End Date", Date.class));
sqlCohortDefinition.addParameter(new Parameter("location", "location", Location.class));

Check warning on line 15789 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L15785-L15789

Added lines #L15785 - L15789 were not covered by tests

Map<String, Integer> map = new HashMap<>();
map.put("6", hivMetadata.getAdultoSeguimentoEncounterType().getEncounterTypeId());
map.put("53", hivMetadata.getMasterCardEncounterType().getEncounterTypeId());
map.put("6272", hivMetadata.getStateOfStayOfPreArtPatient().getConceptId());
map.put("6273", hivMetadata.getStateOfStayOfArtPatient().getConceptId());
map.put("1706", hivMetadata.getTransferredOutConcept().getConceptId());

Check warning on line 15796 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L15791-L15796

Added lines #L15791 - L15796 were not covered by tests

String query =

Check warning on line 15798 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L15798

Added line #L15798 was not covered by tests
"SELECT max_transferout.patient_id "
+ "FROM patient p "
+ " JOIN encounter e "
+ " ON p.patient_id = e.patient_id "
+ " JOIN obs o "
+ " ON e.encounter_id = o.encounter_id "
+ " "
+ " JOIN ( "
+ getLastPatientStateOfStayFromSources()

Check warning on line 15807 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L15807

Added line #L15807 was not covered by tests
+ " ) max_transferout ON max_transferout.patient_id = p.patient_id "
+ "WHERE p.voided = 0 "
+ " AND e.voided = 0 "
+ " AND e.location_id = :location "
+ " AND e.encounter_type = ${6} "
+ " AND e.encounter_datetime = max_transferout.transferout_date "
+ " AND o.voided = 0 "
+ " AND o.concept_id = ${6273} "
+ " AND o.value_coded = ${1706} "
+ "GROUP BY p.patient_id "
+ "UNION "
+ "SELECT max_transferout.patient_id "
+ "FROM patient p "
+ " JOIN encounter e "
+ " ON p.patient_id = e.patient_id "
+ " JOIN obs o "
+ " ON e.encounter_id = o.encounter_id "
+ " "
+ " JOIN ( "
+ getLastPatientStateOfStayFromSources()

Check warning on line 15827 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L15827

Added line #L15827 was not covered by tests
+ ") max_transferout ON max_transferout.patient_id = p.patient_id "
+ "WHERE p.voided = 0 "
+ " AND e.voided = 0 "
+ " AND e.location_id = :location "
+ " AND e.encounter_type = ${53} "
+ " AND o.obs_datetime = max_transferout.transferout_date "
+ " AND o.voided = 0 "
+ " AND o.concept_id = ${6272} "
+ " AND o.value_coded = ${1706} "
+ "GROUP BY p.patient_id";

StringSubstitutor stringSubstitutor = new StringSubstitutor(map);

Check warning on line 15839 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L15839

Added line #L15839 was not covered by tests

sqlCohortDefinition.setQuery(stringSubstitutor.replace(query));

Check warning on line 15841 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L15841

Added line #L15841 was not covered by tests

return sqlCohortDefinition;

Check warning on line 15843 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L15843

Added line #L15843 was not covered by tests
}

private static String getLastPatientStateOfStayFromSources() {
return " SELECT transferout.patient_id, "

Check warning on line 15847 in api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/openmrs/module/eptsreports/reporting/library/cohorts/QualityImprovement2020CohortQueries.java#L15847

Added line #L15847 was not covered by tests
+ " Max(transferout.transferout_date) transferout_date "
+ " FROM (SELECT p.patient_id, "
+ " Max(e.encounter_datetime) AS transferout_date "
+ " 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 e.location_id = :location "
+ " AND e.encounter_type = ${6} "
+ " AND e.encounter_datetime >= :startDate "
+ " AND e.encounter_datetime <= :endDate "
+ " AND o.voided = 0 "
+ " AND o.concept_id = ${6273} "
+ " AND o.value_coded IS NOT NULL "
+ " GROUP BY p.patient_id "
+ " UNION "
+ " SELECT p.patient_id, "
+ " Max(o.obs_datetime) AS transferout_date "
+ " 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 e.location_id = :location "
+ " AND e.encounter_type = ${53} "
+ " AND o.obs_datetime >= :startDate "
+ " AND o.obs_datetime <= :endDate "
+ " AND o.voided = 0 "
+ " AND o.concept_id = ${6272} "
+ " AND o.value_coded IS NOT NULL "
+ " GROUP BY p.patient_id) transferout "
+ " GROUP BY transferout.patient_id ";
}
}