Skip to content

Commit

Permalink
Merge pull request #73 from emaposse/BUG-FIX-REPORT-154
Browse files Browse the repository at this point in the history
Use mysql date function to fix encounterdatetime on CCS databases.
  • Loading branch information
Guimino authored Sep 9, 2020
2 parents 983e397 + 9e65589 commit ed67013
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.List;
import org.openmrs.calculation.result.CalculationResultMap;
import org.openmrs.module.eptsreports.reporting.calculation.BooleanResult;
import org.openmrs.module.eptsreports.reporting.calculation.txcurr.TxCurrPatientsOnArtOnArvDispenseIntervalsCalculation.DisaggregationSourceTypes;
import org.openmrs.module.reporting.common.DateUtil;
import org.springframework.stereotype.Component;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,21 @@ public List<Object[]> getMaxFilaWithProximoLevantamento(EvaluationContext contex

SqlQueryBuilder qb =
new SqlQueryBuilder(
"select patient_id, last_levantamento, max(proximo_levantamento) from ( "
+ "select pickup.patient_id, pickup.last_levantamento, obs_proximo_levantamento.value_datetime proximo_levantamento from ( "
+ "select maxpkp.patient_id,e.encounter_datetime last_levantamento,e.encounter_id from ( "
+ "SELECT p.patient_id, MAX(e.encounter_datetime) last_levantamento 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 "
+ ") maxpkp "
+ "inner join encounter e on e.patient_id=maxpkp.patient_id "
+ "where e.encounter_datetime=maxpkp.last_levantamento and e.encounter_type=18 and e.location_id=:location and e.voided=0 "
+ ") pickup "
+ "inner join obs obs_proximo_levantamento on obs_proximo_levantamento.person_id = pickup.patient_id "
+ "and obs_proximo_levantamento.concept_id = 5096 and obs_proximo_levantamento.voided = 0 and pickup.encounter_id=obs_proximo_levantamento.encounter_id "
+ "order by pickup.patient_id "
+ ") plastiFila "
+ "group by patient_id ",
"select pickup.patient_id, pickup.last_levantamento, max(obs_proximo_levantamento.value_datetime) proximo_levantamento "
+ "from ( "
+ "select maxpkp.patient_id,maxpkp.last_levantamento,e.encounter_id from ( "
+ "SELECT p.patient_id, MAX(e.encounter_datetime) last_levantamento 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 date(e.encounter_datetime) <=:endDate "
+ "GROUP BY p.patient_id "
+ ") maxpkp "
+ "inner join encounter e on e.patient_id=maxpkp.patient_id "
+ "where date(e.encounter_datetime)=date(maxpkp.last_levantamento) and e.encounter_type=18 and e.location_id=:location and e.voided=0 "
+ "order by maxpkp.patient_id "
+ ") pickup "
+ "inner join obs obs_proximo_levantamento on pickup.encounter_id=obs_proximo_levantamento.encounter_id "
+ "where obs_proximo_levantamento.concept_id = 5096 and obs_proximo_levantamento.voided = 0 "
+ "group by pickup.patient_id ",
context.getParameterValues());

return Context.getRegisteredComponents(EvaluationService.class)
Expand Down

0 comments on commit ed67013

Please sign in to comment.