dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09473
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2520: Mobile Report for Received SMS from Users
------------------------------------------------------------
revno: 2520
committer: Neeraj <neeraj.hisp@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-01-11 17:40:34 +0530
message:
Mobile Report for Received SMS from Users
added:
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile/
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile/action/
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile/action/GenerateMobileReportAnalyserFormAction.java
local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile/action/GenerateMobileReportAnalyserResultAction.java
local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForMobileReport.vm
local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/mobileReportAnalysisFront.vm
modified:
local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml
local/in/dhis-web-reports-national/src/main/resources/struts.xml
local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menu.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
=== added directory 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile'
=== added directory 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile/action'
=== added file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile/action/GenerateMobileReportAnalyserFormAction.java'
--- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile/action/GenerateMobileReportAnalyserFormAction.java 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile/action/GenerateMobileReportAnalyserFormAction.java 2011-01-11 12:10:34 +0000
@@ -0,0 +1,32 @@
+package org.hisp.dhis.reports.mobile.action;
+
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+
+import com.opensymphony.xwork2.Action;
+
+public class GenerateMobileReportAnalyserFormAction
+implements Action
+{
+ //--------------------------------------------------------------------------
+ //Dependencies
+ //--------------------------------------------------------------------------
+
+ private OrganisationUnitService organisationUnitService;
+
+ public OrganisationUnitService getOrganisationUnitService()
+ {
+ return organisationUnitService;
+ }
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ public String execute()
+ {
+
+ return SUCCESS;
+ }
+
+}
=== added file 'local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile/action/GenerateMobileReportAnalyserResultAction.java'
--- local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile/action/GenerateMobileReportAnalyserResultAction.java 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/java/org/hisp/dhis/reports/mobile/action/GenerateMobileReportAnalyserResultAction.java 2011-01-11 12:10:34 +0000
@@ -0,0 +1,309 @@
+package org.hisp.dhis.reports.mobile.action;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+import jxl.Workbook;
+import jxl.format.Alignment;
+import jxl.format.Border;
+import jxl.format.BorderLineStyle;
+import jxl.format.Colour;
+import jxl.write.Label;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+
+import org.amplecode.quick.StatementManager;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.reports.ReportService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserService;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
+
+import com.opensymphony.xwork2.Action;
+
+public class GenerateMobileReportAnalyserResultAction
+implements Action
+{
+
+ //--------------------------------------------------------------------------
+ //Dependencies
+ //--------------------------------------------------------------------------
+
+ private OrganisationUnitService organisationunitService;
+
+ public OrganisationUnitService getOrganisationunitService()
+ {
+ return organisationunitService;
+ }
+
+ public void setOrganisationunitService( OrganisationUnitService organisationunitService )
+ {
+ this.organisationunitService = organisationunitService;
+ }
+
+ private StatementManager statementManager;
+
+ public void setStatementManager( StatementManager statementManager )
+ {
+ this.statementManager = statementManager;
+ }
+
+ private ReportService reportService;
+
+ public void setReportService( ReportService reportService )
+ {
+ this.reportService = reportService;
+ }
+
+ private I18nFormat format;
+
+ public void setFormat( I18nFormat format )
+ {
+ this.format = format;
+ }
+
+ private JdbcTemplate jdbcTemplate;
+
+ public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+ {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
+ private UserService userService;
+
+ public void setUserService( UserService userService )
+ {
+ this.userService = userService;
+ }
+
+ //--------------------------------------------------------------------------
+ //Input/Output
+ //--------------------------------------------------------------------------
+ private String startDate;
+
+ public void setStartDate( String startDate )
+ {
+ this.startDate = startDate;
+ }
+
+ private String endDate;
+
+ public void setEndDate( String endDate )
+ {
+ this.endDate = endDate;
+ }
+
+ private String fileName;
+
+ public String getFileName()
+ {
+ return fileName;
+ }
+
+ private InputStream inputStream;
+
+ public InputStream getInputStream()
+ {
+ return inputStream;
+ }
+
+ private String raFolderName;
+
+ private Date sDate;
+
+ private Date eDate;
+
+
+ //--------------------------------------------------------------------------
+ //Action Implementation
+ //--------------------------------------------------------------------------
+
+ public String execute()
+ throws Exception
+ {
+ statementManager.initialise();
+
+ raFolderName = reportService.getRAFolderName();
+
+ System.out.println( "Report Generation Start Time is : \t" + new Date() );
+ generateMobileReport();
+ statementManager.destroy();
+ System.out.println( "Report Generation End Time is : \t" + new Date() );
+
+ return SUCCESS;
+ }
+
+ public void generateMobileReport()
+ throws Exception
+ {
+ String outputReportPath = System.getenv( "DHIS2_HOME" ) + File.separator + raFolderName + File.separator
+ + "output" + File.separator + UUID.randomUUID().toString() + ".xls";
+ WritableWorkbook outputReportWorkbook = Workbook.createWorkbook( new File( outputReportPath ) );
+
+ WritableSheet sheet0 = outputReportWorkbook.createSheet( "MobileReport", 0 );
+
+ // Cell Format
+ WritableCellFormat wCellformat = new WritableCellFormat();
+ wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN );
+ wCellformat.setWrap( true );
+ wCellformat.setAlignment( Alignment.CENTRE );
+
+ int rowStart = 0;
+ int colStart = 0;
+
+ sheet0.addCell( new Label( colStart, rowStart, "Date And Time", getCellFormat1() ) );
+ sheet0.addCell( new Label( colStart + 1, rowStart, "Phone Number", getCellFormat1() ) );
+ sheet0.addCell( new Label( colStart + 2, rowStart, "ANM Name", getCellFormat1() ) );
+ sheet0.addCell( new Label( colStart + 3, rowStart, "Query", getCellFormat1() ) );
+ sheet0.addCell( new Label( colStart + 4, rowStart, "SubCentre", getCellFormat1() ) );
+ sheet0.addCell( new Label( colStart + 5, rowStart, "Block", getCellFormat1() ) );
+ sheet0.addCell( new Label( colStart + 6, rowStart, "District", getCellFormat1() ) );
+
+ rowStart++;
+
+
+ //----------------------------------------------------------------------
+ //Coding for Printing Data
+ //----------------------------------------------------------------------
+
+ sDate = format.parseDate( startDate );
+
+ eDate = format.parseDate( endDate );
+
+ List<Date> dateList = new ArrayList<Date> ( getDatesBetweenDates( sDate, eDate ) );
+
+ for ( Date date : dateList )
+ {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+
+ String query = "select receiverInfo,smscontent from receivesms where receiverInfo like '%_" + simpleDateFormat.format( date ) + "_%'";
+
+ SqlRowSet rs1 = jdbcTemplate.queryForRowSet( query );
+
+ if ( rs1 != null )
+ {
+ while ( rs1.next() )
+ {
+ String senderInfo = rs1.getString( 1 );
+ String receivedSMS = rs1.getString( 2 );
+ String mobileNo = senderInfo.split( "_" )[0];
+ String sentDate = senderInfo.split( "_" )[1];
+ String sentTime = senderInfo.split( "_" )[2];
+
+ sentTime = sentTime.replaceAll( ".xml", "" );
+ sentTime = sentTime.replaceAll( "-", ":" );
+
+ if ( mobileNo != null)
+ {
+ List<User> userList = new ArrayList<User> ( userService.getUsersByPhoneNumber( mobileNo ) );
+ if ( userList != null && userList.size() != 0)
+ {
+ User user = userList.get( 0 );
+ List<OrganisationUnit> orgUnitList = new ArrayList<OrganisationUnit> ( user.getOrganisationUnits() );
+ if ( orgUnitList != null && orgUnitList.size() != 0 )
+ {
+ OrganisationUnit orgUnit = orgUnitList.get( 0 );
+
+ String anmName = orgUnit.getComment();
+
+ sheet0.addCell( new Label( colStart, rowStart, sentDate + "_" + sentTime, wCellformat ) );
+ sheet0.addCell( new Label( colStart + 1, rowStart, mobileNo, wCellformat ) );
+ sheet0.addCell( new Label( colStart + 2, rowStart, anmName, wCellformat ) );
+ sheet0.addCell( new Label( colStart + 3, rowStart, receivedSMS, wCellformat ) );
+ if ( orgUnit.getParent() != null )
+ {
+ sheet0.addCell( new Label( colStart + 4, rowStart, orgUnit.getParent().getName(), wCellformat ) );
+ if ( orgUnit.getParent().getParent() != null )
+ {
+ sheet0.addCell( new Label( colStart + 5, rowStart, orgUnit.getParent().getParent().getName(), wCellformat ) );
+
+ if ( orgUnit.getParent().getParent().getParent() != null )
+ {
+ sheet0.addCell( new Label( colStart + 6, rowStart, orgUnit.getParent().getParent().getParent().getName(), wCellformat ) );
+ }
+ else
+ {
+ sheet0.addCell( new Label( colStart + 6, rowStart, " ", wCellformat ) );
+ }
+ }
+ else
+ {
+ sheet0.addCell( new Label( colStart + 5, rowStart, " ", wCellformat ) );
+ sheet0.addCell( new Label( colStart + 6, rowStart, " ", wCellformat ) );
+ }
+ }
+ else
+ {
+ sheet0.addCell( new Label( colStart + 4, rowStart, " ", wCellformat ) );
+ sheet0.addCell( new Label( colStart + 5, rowStart, " ", wCellformat ) );
+ sheet0.addCell( new Label( colStart + 6, rowStart, " ", wCellformat ) );
+ }
+
+ rowStart++;
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ outputReportWorkbook.write();
+
+ outputReportWorkbook.close();
+
+ fileName = "MobileReport.xls";
+ File outputReportFile = new File( outputReportPath );
+ inputStream = new BufferedInputStream( new FileInputStream( outputReportFile ) );
+
+ outputReportFile.deleteOnExit();
+
+ }
+
+ private List<Date> getDatesBetweenDates( Date startDate, Date endDate )
+ {
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ Calendar startDateCal = Calendar.getInstance();
+ startDateCal.setTime( startDate );
+ List<Date> dateList = new ArrayList<Date>();
+ dateList.add( startDateCal.getTime() );
+
+ while( !simpleDateFormat.format( startDateCal.getTime() ).equalsIgnoreCase( simpleDateFormat.format( endDate ) ) )
+ {
+
+ startDateCal.add( Calendar.DAY_OF_YEAR, 1 );
+
+ dateList.add( startDateCal.getTime() );
+ System.out.println(startDateCal.getTime() + "---" + endDate);
+ }
+
+ System.out.println("DateListSize:"+dateList.size() );
+
+ return dateList;
+ }
+
+ public WritableCellFormat getCellFormat1()
+ throws Exception
+ {
+ WritableCellFormat wCellformat = new WritableCellFormat();
+
+ wCellformat.setBorder( Border.ALL, BorderLineStyle.THIN );
+ wCellformat.setAlignment( Alignment.LEFT );
+ wCellformat.setBackground( Colour.GRAY_25 );
+ wCellformat.setWrap( true );
+ return wCellformat;
+ } // end getCellFormat1() function
+
+}
=== modified file 'local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml 2011-01-08 05:58:26 +0000
+++ local/in/dhis-web-reports-national/src/main/resources/META-INF/dhis/beans.xml 2011-01-11 12:10:34 +0000
@@ -954,6 +954,39 @@
</bean>
+ <!--Mobile Reports-->
+
+ <bean
+ id="org.hisp.dhis.reports.mobile.action.GenerateMobileReportAnalyserFormAction"
+ class="org.hisp.dhis.reports.mobile.action.GenerateMobileReportAnalyserFormAction"
+ scope="prototype">
+
+ <property name="organisationUnitService">
+ <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+ </property>
+
+ </bean>
+
+ <bean
+ id="org.hisp.dhis.reports.mobile.action.GenerateMobileReportAnalyserResultAction"
+ class="org.hisp.dhis.reports.mobile.action.GenerateMobileReportAnalyserResultAction"
+ scope="prototype">
+
+ <property name="organisationunitService">
+ <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
+ </property>
+ <property name="statementManager" ref="statementManager"/>
+ <property name="reportService">
+ <ref bean="org.hisp.dhis.reports.ReportService"/>
+ </property>
+ <property name="jdbcTemplate" ref="jdbcTemplate"/>
+ <property name="userService">
+ <ref bean="org.hisp.dhis.user.UserService"/>
+ </property>
+
+
+ </bean>
+
<!-- Report Service -->
<bean id="org.hisp.dhis.reports.util.ReportService"
class="org.hisp.dhis.reports.util.ReportService" scope="prototype">
@@ -1321,7 +1354,4 @@
</bean>
<!-- CS Review Reports End 09/08/2010-->
-
-
-
</beans>
=== modified file 'local/in/dhis-web-reports-national/src/main/resources/struts.xml'
--- local/in/dhis-web-reports-national/src/main/resources/struts.xml 2010-12-31 07:16:18 +0000
+++ local/in/dhis-web-reports-national/src/main/resources/struts.xml 2011-01-11 12:10:34 +0000
@@ -1052,6 +1052,28 @@
</result>
</action>
+ <!--Mobile Report-->
+ <action name="mobileReportAnalyser"
+ class="org.hisp.dhis.reports.mobile.action.GenerateMobileReportAnalyserFormAction">
+ <result name="success" type="velocity">/main.vm</result>
+ <param name="page">
+ /dhis-web-reports/mobileReportAnalysisFront.vm</param>
+ <param name="menu">
+ /dhis-web-reports/menuWithTreeForMobileReport.vm</param>
+ <param name="javascripts">../dhis-web-commons/ouwt/ouwt.js,../dhis-web-commons/lists/lists.js,javascript/datasetLockReport.js,javascript/reportManagement.js,javascript/hashtable.js</param>
+ <param name="stylesheets">css/StylesForTags.css</param>
+ <interceptor-ref name="organisationUnitTreeStack"/>
+ </action>
+
+ <action name="generateMobileReport"
+ class="org.hisp.dhis.reports.mobile.action.GenerateMobileReportAnalyserResultAction">
+ <result name="success" type="stream">
+ <param name="contentType">application/vnd.ms-excel</param>
+ <param name="inputName">inputStream</param>
+ <param name="contentDisposition">filename="${fileName}"</param>
+ <param name="bufferSize">1024</param>S </result>
+ </action>
+
<!-- CS Review Reports Start -->
<action name="csReviewReportForm"
class="org.hisp.dhis.reports.csreview.action.GenerateCSReviewReportFormAction">
=== modified file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menu.vm'
--- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menu.vm 2010-12-31 07:16:18 +0000
+++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menu.vm 2011-01-11 12:10:34 +0000
@@ -46,6 +46,9 @@
#if( $auth.hasAccess( "dhis-web-reports", "quarterlyPhysicalReport") )
<li><a href = "quarterlyPhysicalReport.action ">Quarterly Physical Output Reports</a></li>
#end
+ #if( $auth.hasAccess( "dhis-web-reports", "mobileReportAnalyser") )
+ <li><a href = "mobileReportAnalyser.action">Mobile Reports</a></li>
+ #end
#if( $auth.hasAccess( "dhis-web-reports", "csReviewReportForm") )
<li><a href = "csReviewReportForm.action">CS Review Reports</a></li>
#end
=== added file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForMobileReport.vm'
--- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForMobileReport.vm 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/menuWithTreeForMobileReport.vm 2011-01-11 12:10:34 +0000
@@ -0,0 +1,32 @@
+<h2>Report Analyser</h2>
+<ul>
+ <li>Report Analysis</li>
+ <ul>
+ <li>
+ Mobile Reports
+ </li>
+ </ul>
+</ul>
+<div style=" float:right; font-size:6pt; cursor:pointer; margin-top:-15px; ">
+ <a href="index.action">
+ <img src="images/goback.png" width="36" height="30" alt="$i18n.getString( "go_back" )"></a>
+</div>
+#parse( "/dhis-web-commons/ouwt/orgunittreesearch.vm" )
+
+<!-- The script that registeres selctions in the orgunit tree -->
+<script type="text/javascript">
+
+function orgUnitHasBeenSelected( orgUnitIds )
+{
+ document.reportForm.ouIDTB.value = orgUnitIds;
+
+ if(orgUnitIds != null && orgUnitIds != "" )
+ {
+ getSelectedOrgUnit( orgUnitIds );
+ }
+}
+
+selection.setListenerFunction( orgUnitHasBeenSelected );
+
+</script>
+
=== added file 'local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/mobileReportAnalysisFront.vm'
--- local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/mobileReportAnalysisFront.vm 1970-01-01 00:00:00 +0000
+++ local/in/dhis-web-reports-national/src/main/webapp/dhis-web-reports/mobileReportAnalysisFront.vm 2011-01-11 12:10:34 +0000
@@ -0,0 +1,93 @@
+<script>
+ // OrganisationUnit ids and its Names
+ /*
+ var orgUnits = new HashTable();
+ #foreach($orgUnit in $organisationUnits)
+ var orgUnitId = ""+$orgUnit.getId();
+ orgUnits.put(orgUnitId,"$orgUnit.getShortName()");
+ #end
+ function formValidations()
+ {
+
+
+ var startDateValue = document.reportForm.startDate.value;
+ var endDateValue = document.reportForm.endDate.value;
+ var ouIdTb = document.getElementById("ouIDTB");
+ var orgunitIdValue = ouIdTb.value;
+
+ if(startDateValue == null || startDateValue== "" || endDateValue == null || endDateValue=="") {alert("Please Select Period"); return false;}
+ else if(startDateValue > endDateValue) {alert("Start Date is Greater than End Date"); return false;}
+ else if(orgunitIdValue == null || orgunitIdValue=="" || orgunitIdValue==" ") {alert("Please Select OrganisationUnit"); return false;}
+ document.forms['reportForm'].submit();
+ }
+
+ //-----------------------------------------------------------------------
+ //init jQuery validation for reportForm
+ //@added validation for all fields and additional rules alphanumericwithbasicpuncspaces, date and url.
+ //-----------------------------------------------------------------------
+ jQuery(document).ready(
+ function()
+ {
+ jQuery("#reportForm").validate({
+ meta:"validate"
+ ,errorElement:"td"
+ ,submitHandler: function(form)
+ {
+ formValidations();
+ }
+ });
+ ///jQuery.validator.loadLocaled( jQuery("#curLocaleCode").val() );
+ jQuery("#name").focus();
+ }
+ );
+
+</script>
+<h1>Mobile Report</h1><hr /><br />
+
+ <form id="reportForm" name="reportForm" action="generateMobileReport.action" method="post" target="_blank">
+
+ <table align="center" style=" border-collapse: collapse; margin-top: 0;" cellpadding="0" cellspacing="0" width="730" border=0>
+ <tr>
+ <td class="NormalB">
+ <label for="startDate">$i18n.getString( 'start_date' ) ($i18n.getString( "format.date.label" ))</label><br/>
+ <input type="text" id="startDate" name="startDate" onchange="if(!checkStartDate( this.value )) this.value='';" style="width:15em" class="{validate:{required:true,dateISO:true}}">
+
+ </td>
+ <td class="NormalB">
+ <label for="endDate">$i18n.getString( 'end_date' ) ($i18n.getString( "format.date.label" ))</label><br />
+ <input type="text" id="endDate" name="endDate" onchange="if(!checkEndDate( this.value )) this.value='';" style="width:15em" class="{validate:{required:true,dateISO:true}}">
+
+ </td>
+ </tr>
+
+ <tr>
+ <td> </td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td> </td>
+ </tr>
+
+ <tr>
+ <td class="NormalB">
+ OrganisationUnit : <br />
+ <input type="text" name="ouNameTB" id="ouNameTB" size="20" disabled>
+ </td>
+
+ <td>
+ <input type="submit" name="generate" value="Generate Report"/>
+ <input type="hidden" name="ouIDTB" id="ouIDTB">
+ </td>
+ </tr>
+ </table>
+
+ </form>
+
+
+ <script type="text/javascript">
+ jQuery( function(){
+ datePickerInRange( "startDate", "endDate", false, false );
+ });
+
+ </script>
\ No newline at end of file