← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11557: Add function to download lost-to-follow list as xls file.

 

------------------------------------------------------------
revno: 11557
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-08-02 11:53:58 +0700
message:
  Add function to download lost-to-follow list as xls file.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingRecords.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2013-05-28 09:04:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientService.java	2013-08-02 04:53:58 +0000
@@ -208,18 +208,19 @@
 
     void removeErollmentPrograms( Program program );
 
-    Collection<Patient> searchPatients( List<String> searchKeys, OrganisationUnit orgunit,
-       Boolean followup, Collection<PatientAttribute> patientAttributes, Integer min, Integer max );
+    Collection<Patient> searchPatients( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
+        Collection<PatientAttribute> patientAttributes, Integer min, Integer max );
 
     int countSearchPatients( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup );
 
-    Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup, Integer min,
-        Integer max );
-
-    List<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup, Integer min, Integer max );
-
-    Grid getScheduledEventsReport( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup, Integer min, Integer max,
-        I18n i18n );
+    Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
+        Integer min, Integer max );
+
+    List<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
+        Integer min, Integer max );
+
+    Grid getScheduledEventsReport( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup, Integer min,
+        Integer max, I18n i18n );
 
     Collection<Patient> getPatientsByPhone( String phoneNumber, Integer min, Integer max );
 
@@ -227,4 +228,7 @@
 
     Collection<Integer> getRegistrationOrgunitIds( Date startDate, Date endDate );
 
+    Grid getTrackingEventsReport( Program program, List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
+        I18n i18n );
+
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2013-05-28 09:04:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientStore.java	2013-08-02 04:53:58 +0000
@@ -82,10 +82,12 @@
     Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
         Collection<PatientAttribute> patientAttributes, Integer min, Integer max );
 
+    Grid getPatientEventReport( Grid grid, List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
+        Collection<PatientAttribute> patientAttributes, Collection<PatientIdentifierType> identifierTypes, Integer min,
+        Integer max );
+
     List<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Integer min, Integer max );
-
-    Grid getPatientEventReport( Grid grid, List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Integer min, Integer max );
+        Collection<PatientAttribute> patientAttributes, Collection<PatientIdentifierType> identifierTypes, Integer min,
+        Integer max );
 
 }

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2013-05-28 09:04:10 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java	2013-08-02 04:53:58 +0000
@@ -543,7 +543,7 @@
     public List<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
         Integer min, Integer max )
     {
-        return patientStore.getProgramStageInstances( searchKeys, orgunit, followup, null, min, max );
+        return patientStore.getProgramStageInstances( searchKeys, orgunit, followup, null, null, min, max );
     }
 
     @Override
@@ -593,7 +593,53 @@
         grid.addHeader( new GridHeader( i18n.getString( "program_stage" ), false, true ) );
         grid.addHeader( new GridHeader( i18n.getString( "due_date" ), false, true ) );
 
-        return patientStore.getPatientEventReport( grid, searchKeys, orgunit, followup, patientAttributes, min, max );
+        return patientStore.getPatientEventReport( grid, searchKeys, orgunit, followup, patientAttributes, null, min,
+            max );
+
+    }
+
+    @Override
+    public Grid getTrackingEventsReport( Program program, List<String> searchKeys, OrganisationUnit orgunit,
+        Boolean followup, I18n i18n )
+    {
+        String startDate = "";
+        String endDate = "";
+        for ( String searchKey : searchKeys )
+        {
+            String[] keys = searchKey.split( "_" );
+            if ( keys[0].equals( Patient.PREFIX_PROGRAM_EVENT_BY_STATUS ) )
+            {
+                startDate = keys[2];
+                endDate = keys[3];
+            }
+        }
+
+        Grid grid = new ListGrid();
+        grid.setTitle( i18n.getString( "program_tracking" ) );
+        if ( !startDate.isEmpty() && !endDate.isEmpty() )
+        {
+            grid.setSubtitle( i18n.getString( "from" ) + " " + startDate + " " + i18n.getString( "to" ) + " " + endDate );
+        }
+
+        grid.addHeader( new GridHeader( "patientid", true, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "first_name" ), true, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "middle_name" ), true, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "last_name" ), true, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "gender" ), true, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "phone_number" ), false, true ) );
+
+        Collection<PatientIdentifierType> patientIdentifierTypes = program.getPatientIdentifierTypes();
+        for ( PatientIdentifierType patientIdentifierType : patientIdentifierTypes )
+        {
+            grid.addHeader( new GridHeader( patientIdentifierType.getDisplayName(), false, true ) );
+        }
+        grid.addHeader( new GridHeader( "programstageinstanceid", true, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "program_stage" ), false, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "due_date" ), false, true ) );
+        grid.addHeader( new GridHeader( i18n.getString( "risk" ), false, true ) );
+
+        return patientStore.getPatientEventReport( grid, searchKeys, orgunit, followup, null, patientIdentifierTypes,
+            null, null );
 
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-05-29 05:24:13 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-08-02 04:53:58 +0000
@@ -49,6 +49,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.patient.Patient;
 import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientIdentifierType;
 import org.hisp.dhis.patient.PatientStore;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramInstance;
@@ -254,10 +255,10 @@
     }
 
     @Override
-    public Collection<Patient> search( List<String> searchKeys, OrganisationUnit orgunit,
-        Boolean followup, Collection<PatientAttribute> patientAttributes, Integer min, Integer max )
+    public Collection<Patient> search( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
+        Collection<PatientAttribute> patientAttributes, Integer min, Integer max )
     {
-        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, min, max );
+        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, null, min, max );
         Collection<Patient> patients = new HashSet<Patient>();
         try
         {
@@ -281,7 +282,7 @@
     public Collection<String> getPatientPhoneNumbers( List<String> searchKeys, OrganisationUnit orgunit,
         Boolean followup, Collection<PatientAttribute> patientAttributes, Integer min, Integer max )
     {
-        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, min, max );
+        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, null, min, max );
         Collection<String> phoneNumbers = new HashSet<String>();
         try
         {
@@ -304,9 +305,11 @@
 
     @Override
     public List<Integer> getProgramStageInstances( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
-        Collection<PatientAttribute> patientAttributes, Integer min, Integer max )
+        Collection<PatientAttribute> patientAttributes, Collection<PatientIdentifierType> identifierTypes, Integer min,
+        Integer max )
     {
-        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, min, max );
+        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, identifierTypes, min,
+            max );
         List<Integer> programStageInstanceIds = new ArrayList<Integer>();
         try
         {
@@ -329,19 +332,19 @@
 
     public int countSearch( List<String> searchKeys, OrganisationUnit orgunit, Boolean followup )
     {
-        String sql = searchPatientSql( true, searchKeys, orgunit, followup, null, null, null );
+        String sql = searchPatientSql( true, searchKeys, orgunit, followup, null, null, null, null );
         return jdbcTemplate.queryForObject( sql, Integer.class );
     }
 
     @Override
-    public Grid getPatientEventReport( Grid grid, List<String> searchKeys, OrganisationUnit orgunit,
-        Boolean followup, Collection<PatientAttribute> patientAttributes, Integer min, Integer max )
+    public Grid getPatientEventReport( Grid grid, List<String> searchKeys, OrganisationUnit orgunit, Boolean followup,
+        Collection<PatientAttribute> patientAttributes, Collection<PatientIdentifierType> identifierTypes, Integer min, Integer max )
     {
         // ---------------------------------------------------------------------
         // Get SQL and build grid
         // ---------------------------------------------------------------------
 
-        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, null, null );
+        String sql = searchPatientSql( false, searchKeys, orgunit, followup, patientAttributes, identifierTypes, null, null );
 
         SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
 
@@ -355,13 +358,24 @@
     // -------------------------------------------------------------------------
 
     private String searchPatientSql( boolean count, List<String> searchKeys, OrganisationUnit orgunit,
-        Boolean followup, Collection<PatientAttribute> patientAttributes, Integer min, Integer max )
+        Boolean followup, Collection<PatientAttribute> patientAttributes,
+        Collection<PatientIdentifierType> identifierTypes, Integer min, Integer max )
     {
         String selector = count ? "count(*) " : "* ";
 
         String sql = "select " + selector
             + " from ( select distinct p.patientid, p.firstname, p.middlename, p.lastname, p.gender, p.phonenumber,";
 
+        if ( identifierTypes != null )
+        {
+            for ( PatientIdentifierType identifierType : identifierTypes )
+            {
+                sql += "(select identifier from patientidentifier where patientid=p.patientid and patientidentifiertypeid="
+                    + identifierType.getId() + " ) as " + Patient.PREFIX_IDENTIFIER_TYPE + "_" + identifierType.getId()
+                    + " ,";
+            }
+        }
+        
         if ( patientAttributes != null )
         {
             for ( PatientAttribute patientAttribute : patientAttributes )
@@ -372,6 +386,7 @@
             }
         }
 
+
         String patientWhere = "";
         String patientOperator = " where ";
         String patientGroupBy = " GROUP BY  p.patientid, p.firstname, p.middlename, p.lastname, p.gender, p.phonenumber ";
@@ -649,7 +664,7 @@
         {
             sql += statementBuilder.limitRecord( min, max );
         }
-
+        System.out.println( "\n\n sql = " + sql );
         return sql;
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2013-07-16 06:53:26 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetDataRecordsAction.java	2013-08-02 04:53:58 +0000
@@ -203,6 +203,13 @@
         this.followup = followup;
     }
 
+    private Boolean trackingReport;
+
+    public void setTrackingReport( Boolean trackingReport )
+    {
+        this.trackingReport = trackingReport;
+    }
+
     // -------------------------------------------------------------------------
     // Implementation Action
     // -------------------------------------------------------------------------
@@ -226,13 +233,13 @@
                 patientAttributes = new ArrayList<PatientAttribute>(
                     patientAttributeService.getPatientAttributesByDisplayOnVisitSchedule( true ) );
 
-                Collections.sort( patientAttributes, IdentifiableObjectNameComparator.INSTANCE);
+                Collections.sort( patientAttributes, IdentifiableObjectNameComparator.INSTANCE );
 
                 total = patientService.countSearchPatients( searchTexts, orgunit, followup );
                 this.paging = createPaging( total );
 
-                List<Integer> stageInstanceIds = patientService.getProgramStageInstances( searchTexts, orgunit, followup,
-                    paging.getStartPos(), paging.getPageSize() );
+                List<Integer> stageInstanceIds = patientService.getProgramStageInstances( searchTexts, orgunit,
+                    followup, paging.getStartPos(), paging.getPageSize() );
 
                 for ( Integer stageInstanceId : stageInstanceIds )
                 {
@@ -259,6 +266,10 @@
                     }
                 }
             }
+            else if(trackingReport != null && trackingReport )
+            {
+                grid = patientService.getTrackingEventsReport( program, searchTexts, orgunit, followup, i18n );
+            }
             else
             {
                 grid = patientService.getScheduledEventsReport( searchTexts, orgunit, followup, null, null, i18n );

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js	2013-06-12 03:54:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/smsReminder.js	2013-08-02 04:53:58 +0000
@@ -1,4 +1,6 @@
 isAjax = true;
+var generateResultParams = "";
+
 function orgunitSelected( orgUnits, orgUnitNames )
 {
 	var width = jQuery('#programIdAddPatient').width();
@@ -79,10 +81,13 @@
 				+ getFieldValue('statusEvent');
 	var followup = "";
 	if( byId('followup').checked ){
-		followup = "?followup=true";
+		followup = "followup=true";
 	}
+	
+	generateResultParams = followup + "&programId=" + programId + "&searchTexts=" + searchTexts;
+	
 	showLoader();
-	jQuery('#listEventDiv').load('getSMSPatientRecords.action' + followup,
+	jQuery('#listEventDiv').load('getSMSPatientRecords.action?' + followup,
 		{
 			programId:programId,
 			listAll:false,
@@ -110,6 +115,8 @@
 	hideById('listEventDiv');
 	showLoader();
 	params += "&programId=" + getFieldValue('programIdAddPatient');
+	generateResultParams = params;
+	
 	$.ajax({
 		url: 'getSMSPatientRecords.action',
 		type:"POST",
@@ -125,6 +132,12 @@
 	});
 }
 
+function exportXlsFile()
+{
+	var url = "getActivityPlanRecords.action?type=xls&trackingReport=true&" + generateResultParams;
+	window.location.href = url;
+}
+
 // --------------------------------------------------------------------
 // program tracking form
 // --------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingRecords.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingRecords.vm	2013-06-12 03:54:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/programTrackingRecords.vm	2013-08-02 04:53:58 +0000
@@ -3,6 +3,9 @@
 	<tr>
 		<td>$i18n.getString('total_result'): </td>
 		<td id='totalTd'></td>
+		<td>
+			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:exportXlsFile();' title='$i18n.getString( "export_xls" )' ><img src='../images/excel.png' id='generateXSLBtn' ></a>
+		</td>
 	</tr>
 </table>
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm	2013-06-13 07:36:43 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm	2013-08-02 04:53:58 +0000
@@ -22,14 +22,15 @@
 		<td>
 			<select id='programIdAddPatient' name='programIdAddPatient' onchange='enableBtn();'>
 				#if($programs.size()==0)
-				<option value="">[$i18n.getString( "none_program" )]</option>
-				<script>disable('listPatientBtn')</script>
+					<option value="">[$i18n.getString( "none_program" )]</option>
+					<script>disable('listPatientBtn')</script>
 				#elseif($programs.size()>1)
-				<option value='' type='2' id='emptyProgramOption'>[$i18n.getString("please_select")]</option>
-				<script>disable('listPatientBtn')</script>
+					<option value='' type='2' id='emptyProgramOption'>[$i18n.getString("please_select")]</option>
+					<script>disable('listPatientBtn')</script>
 				#else
-				<script>enable('listPatientBtn')</script>
+					<script>enable('listPatientBtn')</script>
 				#end
+				
 				#foreach($program in $programs)
 					<option value="$program.id" type='$program.type'>$program.displayName</option>
 				#end