Skip to content

Commit

Permalink
Adding excel file exportation
Browse files Browse the repository at this point in the history
  • Loading branch information
spbogui committed Dec 18, 2018
1 parent 5ab1b77 commit bce01c5
Show file tree
Hide file tree
Showing 16 changed files with 456 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public interface PreventTransmissionService extends OpenmrsService {

List<ChildFollowupAppointment> getChildByAppointment();
List<ChildFollowupAppointment> getChildByAppointmentMissed();
List<ChildFollowupAppointment> getChildByPcrAppointment(Integer days, Integer pcrType);
List<ChildFollowupAppointment> getChildByPcrAppointment(String days, Integer pcrType);

Boolean isDead(Patient patient);
Boolean isTransfered(Patient patient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public interface PreventTransmissionDAO {

List<ChildFollowupAppointment> getChildByAppointment();
List<ChildFollowupAppointment> getChildByAppointmentMissed();
List<ChildFollowupAppointment> getChildByAppointmentPcr(Integer days, Integer pcrType);

List<ChildFollowupAppointment> getChildByAppointmentPcr(String days, Integer pcrType);

Boolean isDead(Patient patient);
Boolean isTransfered(Patient patient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,24 +889,79 @@ public List<ChildFollowupAppointment> getChildByAppointmentMissed() {
}

@Override
public List<ChildFollowupAppointment> getChildByAppointmentPcr(Integer days, Integer pcrType) {
String pcrTypeSql = "";
public List<ChildFollowupAppointment> getChildByAppointmentPcr(String pcrParams, Integer pcrType) {
/*String periodParam = "6:S|8:M";
String minAgeIn = "S";
String minAge = "0";
String maxAgeIn = "S";
String maxAge = "0";
if (!pcrParams.isEmpty()) {
String[] params = periodParam.split("|");
String[] min = params[0].split(":");
minAgeIn = min[1].equals("S") ? "7" : "30";
minAge = min[0];
if (params.length == 2) {
String[] max = params[1].split(":");
maxAgeIn = max[1].equals("S") ? "7" : "30";
maxAge = max[0];
}
}
String pcrTypeSql = "";*/

String sqlQuery = "";

if (pcrType != null) {
pcrTypeSql = " AND pcf.pcr"+ pcrType.toString() +"_sampling_date IS NULL ";
// pcrTypeSql = "AND pcf.pcr"+ pcrType.toString() +"_sampling_date IS NULL AND ";
if (pcrType == 2) {
sqlQuery = "SELECT" +
" child_followup_number AS childFollowupNumber," +
" family_name familyName," +
" given_name AS givenName," +
" pc.birth_date As lastVisitDate," +
" AppointmentDate " +
"FROM" +
" (SELECT * FROM ptme_child) pc" +
" LEFT JOIN ptme_child_followup pcf ON pc.child_id = pcf.child_followup_id" +
" LEFT JOIN (SELECT MAX(visit_date) MaxVisiteDate, child_id FROM ptme_child_followup_visit WHERE visit_date <= DATE(NOW()) AND voided = 0 GROUP BY child_id) MV" +
" ON pc.child_id = MV.child_id" +
" LEFT JOIN (SELECT child_id, visit_date, eating_type, ADDDATE(visit_date, INTERVAL 6 WEEK) AppointmentDate FROM ptme_child_followup_visit WHERE voided = 0) pcfv " +
" ON pcfv.child_id = MV.child_id AND pcfv.visit_date = MV.MaxVisiteDate " +
"WHERE " +
" pcf.pcr1_sampling_date IS NOT NULL" +
" AND pcf.pcr2_sampling_date IS NULL" +
" AND eating_type <> 1" +
" AND FLOOR(DATEDIFF(DATE(NOW()), visit_date) /7) >= 6 AND FLOOR(DATEDIFF(DATE(NOW()), visit_date) /30) < 9";
} else if (pcrType == 1) {
sqlQuery = "SELECT" +
" child_followup_number AS childFollowupNumber," +
" family_name familyName," +
" given_name AS givenName," +
" pc.birth_date As lastVisitDate," +
" AppointmentDate " +
"FROM" +
" (SELECT *, ADDDATE(birth_date, INTERVAL 6 WEEK) AppointmentDate FROM ptme_child) pc" +
" LEFT JOIN ptme_child_followup pcf ON pc.child_id = pcf.child_followup_id " +
"WHERE" +
" pcf.pcr1_sampling_date IS NULL AND FLOOR(DATEDIFF(DATE(NOW()), birth_date) /7) >= 6 AND FLOOR(DATEDIFF(DATE(NOW()), birth_date) /30) <= 8" +
" AND pcf.hiv_serology1_date IS NULL AND pcf.hiv_serology2_date IS NULL";
} else if (pcrType == 3) {
sqlQuery = "SELECT" +
" child_followup_number AS childFollowupNumber," +
" family_name familyName," +
" given_name AS givenName," +
" pc.birth_date As lastVisitDate," +
" AppointmentDate " +
"FROM" +
" (SELECT *, ADDDATE(birth_date, INTERVAL 9 MONTH) AppointmentDate FROM ptme_child) pc" +
" LEFT JOIN ptme_child_followup pcf ON pc.child_id = pcf.child_followup_id " +
"WHERE" +
" pcf.pcr1_sampling_date IS NULL AND FLOOR(DATEDIFF(DATE(NOW()), birth_date) /30) >= 9" +
" AND pcf.hiv_serology1_date IS NULL AND pcf.hiv_serology2_date IS NULL " +
" AND pcf.followup_result_date IS NULL ";
}
}
String sqlQuery = "SELECT" +
" child_followup_number AS childFollowupNumber," +
" family_name familyName," +
" given_name AS givenName," +
" pc.birth_date As lastVisitDate," +
" AppointmentDate " +
"FROM" +
" (SELECT *, ADDDATE(birth_date, INTERVAL " + days.toString() +" DAY) AppointmentDate FROM ptme_child) pc " +
" LEFT JOIN ptme_child_followup pcf ON pc.child_id = pcf.child_followup_id " +
"WHERE" +
" AppointmentDate BETWEEN DATE(CONCAT_WS('-', YEAR(NOW()), MONTH(NOW()), '01')) AND DATE(LAST_DAY(NOW())) " +
pcrTypeSql +
"ORDER BY AppointmentDate";

Query query = sessionFactory.getCurrentSession().createSQLQuery(sqlQuery)
.addScalar("childFollowupNumber", StandardBasicTypes.STRING)
// .addScalar("numberOfVisit", StandardBasicTypes.INTEGER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ public List<ChildFollowupAppointment> getChildByAppointmentMissed() {
}

@Override
public List<ChildFollowupAppointment> getChildByPcrAppointment(Integer days, Integer pcrType) {
return dao.getChildByAppointmentPcr(days, pcrType);
public List<ChildFollowupAppointment> getChildByPcrAppointment(String pcrParams, Integer pcrType) {
return dao.getChildByAppointmentPcr(pcrParams, pcrType);
}

@Override
Expand Down
Loading

0 comments on commit bce01c5

Please sign in to comment.