dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24265
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11859: require program, orgUnit, startDate, endDate in export of events. Minor additions to service laye...
------------------------------------------------------------
revno: 11859
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-09-02 12:37:36 +0200
message:
require program, orgUnit, startDate, endDate in export of events. Minor additions to service layer for programs.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java
dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/eventExportForm.vm
dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataValueForm.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/program/ProgramStageInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2013-08-26 13:01:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstanceService.java 2013-09-02 10:37:36 +0000
@@ -66,6 +66,8 @@
Collection<ProgramStageInstance> getProgramStageInstances( ProgramStage programStage, OrganisationUnit organisationUnit);
+ Collection<ProgramStageInstance> getProgramStageInstances( ProgramStage programStage, OrganisationUnit organisationUnit, Date start, Date end);
+
Collection<ProgramStageInstance> getProgramStageInstances( Collection<ProgramInstance> programInstances );
Collection<ProgramStageInstance> getProgramStageInstances( Date dueDate );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java 2013-08-26 13:01:59 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/BaseEventService.java 2013-09-02 10:37:36 +0000
@@ -354,18 +354,29 @@
ProgramStage programStage = program.getProgramStageByStage( 1 );
- List<ProgramStageInstance> programStageInstances = null;
-
- if ( organisationUnit != null )
- {
- programStageInstances = new ArrayList<ProgramStageInstance>(
- programStageInstanceService.getProgramStageInstances( programStage, organisationUnit ) );
- }
- else
- {
- programStageInstances = new ArrayList<ProgramStageInstance>(
- programStageInstanceService.getProgramStageInstances( programStage ) );
- }
+ List<ProgramStageInstance> programStageInstances;
+
+ programStageInstances = new ArrayList<ProgramStageInstance>(
+ programStageInstanceService.getProgramStageInstances( programStage, organisationUnit ) );
+
+ List<Event> convertedEvents = convertProgramStageInstances( programStageInstances );
+
+ events.setEvents( convertedEvents );
+
+ return events;
+ }
+
+ @Override
+ public Events getEvents( Program program, OrganisationUnit organisationUnit, Date start, Date end )
+ {
+ Events events = new Events();
+
+ ProgramStage programStage = program.getProgramStageByStage( 1 );
+
+ List<ProgramStageInstance> programStageInstances;
+
+ programStageInstances = new ArrayList<ProgramStageInstance>(
+ programStageInstanceService.getProgramStageInstances( programStage, organisationUnit, start, end ) );
List<Event> convertedEvents = convertProgramStageInstances( programStageInstances );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java 2013-08-26 13:01:59 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/EventService.java 2013-09-02 10:37:36 +0000
@@ -36,6 +36,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.Date;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -54,6 +55,8 @@
Events getEvents( Program program, OrganisationUnit organisationUnit );
+ Events getEvents( Program program, OrganisationUnit organisationUnit, Date start, Date end );
+
Event getEvent( String uid );
Event getEvent( ProgramStageInstance programStageInstance );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/Options.java 2013-09-02 10:37:36 +0000
@@ -53,7 +53,7 @@
return str;
}
- protected static Date stringAsDate( String str )
+ public static Date stringAsDate( String str )
{
if ( str == null )
{
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java 2013-08-27 03:31:40 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramStageInstanceService.java 2013-09-02 10:37:36 +0000
@@ -166,6 +166,12 @@
return programStageInstanceStore.get( programStage, organisationUnit );
}
+ @Override
+ public Collection<ProgramStageInstance> getProgramStageInstances( ProgramStage programStage, OrganisationUnit organisationUnit, Date start, Date end )
+ {
+ return programStageInstanceStore.get( programStage, organisationUnit, start, end, 0, Integer.MAX_VALUE );
+ }
+
public void updateProgramStageInstance( ProgramStageInstance programStageInstance )
{
programStageInstance.setAutoFields();
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java 2013-08-26 13:01:59 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java 2013-09-02 10:37:36 +0000
@@ -41,6 +41,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
@@ -55,13 +56,14 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.util.Date;
import java.util.Map;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@Controller
-@RequestMapping(value = EventController.RESOURCE_PATH)
+@RequestMapping( value = EventController.RESOURCE_PATH )
public class EventController
{
public static final String RESOURCE_PATH = "/events";
@@ -81,27 +83,39 @@
// -------------------------------------------------------------------------
@RequestMapping( value = "", method = RequestMethod.GET )
- public String getEvents( @RequestParam( "program" ) String programUid, @RequestParam( value = "orgUnit", required = false ) String orgUnitUid,
+ public String getEvents(
+ @RequestParam( "program" ) String programUid,
+ @RequestParam( value = "orgUnit" ) String orgUnitUid,
+ @RequestParam @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date startDate,
+ @RequestParam @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
@RequestParam Map<String, String> parameters, Model model, HttpServletRequest request,
HttpServletResponse response ) throws Exception
{
WebOptions options = new WebOptions( parameters );
Program program = manager.get( Program.class, programUid );
- OrganisationUnit organisationUnit = null;
+ OrganisationUnit organisationUnit;
if ( program == null )
{
throw new NotFoundException( "Program", programUid );
}
- if ( orgUnitUid != null )
- {
- organisationUnit = manager.get( OrganisationUnit.class, orgUnitUid );
-
- if ( organisationUnit == null )
- {
- throw new NotFoundException( "OrganisationUnit", programUid );
- }
+ organisationUnit = manager.get( OrganisationUnit.class, orgUnitUid );
+
+ if ( organisationUnit == null )
+ {
+ try
+ {
+ organisationUnit = manager.get( OrganisationUnit.class, Integer.parseInt( orgUnitUid ) );
+ }
+ catch ( NumberFormatException ignored )
+ {
+ }
+ }
+
+ if ( organisationUnit == null )
+ {
+ throw new NotFoundException( "OrganisationUnit", programUid );
}
if ( program.isRegistration() || !program.isSingleEvent() )
@@ -109,7 +123,7 @@
throw new HttpClientErrorException( HttpStatus.BAD_REQUEST, "Only single event with no registration is currently supported." );
}
- Events events = eventService.getEvents( program, organisationUnit );
+ Events events = eventService.getEvents( program, organisationUnit, startDate, endDate );
if ( options.hasLinks() )
{
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/eventExportForm.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/eventExportForm.vm 2013-09-02 08:27:33 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/eventExportForm.vm 2013-09-02 10:37:36 +0000
@@ -1,14 +1,40 @@
+<script type="text/javascript" src="../dhis-web-commons/oust/oust.js"></script>
+<script type="text/javascript" src="../dhis-web-commons/oust/selectionTreeSelect.js"></script>
<script>
$( function() {
+ datePickerInRange( 'startDate' , 'endDate' );
+
$( '#submit' ).on( 'click', function() {
var format = $( '#format' ).val();
var program = $( '#programs' ).val();
var url = '../api/events' + format + "?program=" + program;
+ if( program.length == 0 ) {
+ setHeaderDelayMessage( "No program selected." );
+ return false;
+ }
+
+ if( !selectionTreeSelection.isSelected() ) {
+ setHeaderDelayMessage( "No organisation unit selected." );
+ return false;
+ }
+
+ url += "&orgUnit=" + selectedOrganisationUnit[0];
+
+ var startDate = $('#startDate' ).val();
+ var endDate = $('#endDate' ).val();
+
+ url += "&startDate=" + startDate;
+ url += "&endDate=" + endDate;
+
window.location = url;
console.log(url);
});
+ selectionTreeSelection.setMultipleSelectionAllowed( false );
+ selectionTree.clearSelectedOrganisationUnits();
+ selectionTree.buildSelectionTree();
+
$.ajax({
url: '../api/programs.json',
data: {
@@ -36,11 +62,20 @@
<h3>$i18n.getString( "event_data_export" )</h3>
-<div id="inputCriteria" class="inputCriteria" style="width: 480px;">
+<div id="inputCriteria" class="inputCriteria" style="width: 730px;">
<form id="importForm" name="importForm" method="post" enctype="multipart/form-data" action="importMetaData.action">
<table>
<col width="140">
<col>
+
+<tr>
+ <td colspan="2">$i18n.getString( "organisation_unit" )</td>
+</tr>
+
+<tr>
+ <td colspan="2"><div id="selectionTree" style="width:700px; height:220px"></div></td>
+</tr>
+
<tr>
<td>$i18n.getString( "programs" )</td>
<td><select disabled="disabled" style="width: 300px;" id="programs" name="programs">
@@ -50,6 +85,16 @@
</tr>
<tr>
+ <td>$i18n.getString("start_date")</td>
+ <td><input type="text" id="startDate" name="startDate" value="$!startDate" style="width:300px"></td>
+</tr>
+
+<tr>
+ <td>$i18n.getString("end_date")</td>
+ <td><input type="text" id="endDate" name="endDate" value="$!endDate" style="width:300px"></td>
+</tr>
+
+<tr>
<td>$i18n.getString( "compression" )</td>
<td>
<select disabled="disabled" id="compression" style="width: 300px;">
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataValueForm.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataValueForm.vm 2012-04-14 18:32:00 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/exportDataValueForm.vm 2013-09-02 10:37:36 +0000
@@ -5,7 +5,7 @@
selectionTreeSelection.setMultipleSelectionAllowed( true );
selectionTree.clearSelectedOrganisationUnits();
selectionTree.buildSelectionTree();
-
+
jQuery("#availableDataSets").dhisAjaxSelect({
source: "../api/dataSets.json?links=false&paging=false",
iterator: "dataSets",