=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UploadAnonymousEventAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UploadAnonymousEventAction.java 2013-05-19 09:15:33 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/UploadAnonymousEventAction.java 2013-07-01 05:02:27 +0000 @@ -117,28 +117,22 @@ Map executionDate = (Map) input.get( "executionDate" ); - Integer programId; - Integer organisationUnitId; - - try - { - programId = Integer.parseInt( (String) executionDate.get( "programId" ) ); - organisationUnitId = Integer.parseInt( (String) executionDate.get( "organisationUnitId" ) ); - } - catch ( NumberFormatException e ) - { - message = e.getMessage(); - return ERROR; - } - Date date = format.parseDate( (String) executionDate.get( "executionDate" ) ); - if ( programId == null || date == null || organisationUnitId == null ) - { - return INPUT; - } - - Boolean completed = (Boolean) executionDate.get( "completed" ); + Boolean completed = null; + + try + { + String completeString = (String) executionDate.get( "completed" ); + + if ( completeString != null ) + { + completed = Boolean.parseBoolean( completeString ); + } + } + catch ( ClassCastException ignored ) + { + } Coordinate coordinate = null; Map coord = (Map) input.get( "coordinate" ); @@ -158,7 +152,45 @@ } - ProgramStageInstance programStageInstance = saveExecutionDate( programId, organisationUnitId, date, completed, coordinate ); + Integer programId; + Integer organisationUnitId; + Integer programStageInstanceId; + ProgramStageInstance programStageInstance; + + try + { + programStageInstanceId = Integer.parseInt( (String) executionDate.get( "programStageInstanceId" ) ); + } + catch ( NumberFormatException e ) + { + programStageInstanceId = null; + } + + if ( programStageInstanceId != null ) + { + programStageInstance = programStageInstanceService.getProgramStageInstance( programStageInstanceId ); + updateExecutionDate( programStageInstance, date, completed, coordinate ); + } + else + { + try + { + programId = Integer.parseInt( (String) executionDate.get( "programId" ) ); + organisationUnitId = Integer.parseInt( (String) executionDate.get( "organisationUnitId" ) ); + } + catch ( NumberFormatException e ) + { + message = e.getMessage(); + return ERROR; + } + + if ( date == null ) + { + return INPUT; + } + + programStageInstance = saveExecutionDate( programId, organisationUnitId, date, completed, coordinate ); + } Map values = (Map) input.get( "values" ); @@ -179,6 +211,38 @@ return SUCCESS; } + private void updateExecutionDate( ProgramStageInstance programStageInstance, Date date, Boolean completed, Coordinate coordinate ) + { + if ( date != null ) + { + programStageInstance.setDueDate( date ); + programStageInstance.setExecutionDate( date ); + } + + if ( completed != null ) + { + programStageInstance.setCompleted( completed ); + programStageInstance.setCompletedDate( new Date() ); + programStageInstance.setCompletedUser( currentUserService.getCurrentUsername() ); + } + + if ( programStageInstance.getProgramStage().getCaptureCoordinates() ) + { + if ( coordinate != null && coordinate.isValid() ) + { + programStageInstance.setCoordinates( coordinate.getCoordinateString() ); + } + else + { + programStageInstance.setCoordinates( null ); + } + } + + message = programStageInstance.getId() + ""; + + programStageInstanceService.updateProgramStageInstance( programStageInstance ); + } + private ProgramStageInstance saveExecutionDate( Integer programId, Integer organisationUnitId, Date date, Boolean completed, Coordinate coordinate ) { === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-06-18 05:51:08 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2013-07-01 05:02:27 +0000 @@ -992,7 +992,7 @@ var data = {}; data.id = programStageInstanceId; data.executionDate = createExecutionDate(programId, programStageInstanceId, executionDate, organisationUnitId); - data.executionDate.completed = false; + data.executionDate.completed = 'false'; this.set( 'dataValues', data ); }); === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js 2013-06-18 05:51:08 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js 2013-07-01 05:02:27 +0000 @@ -300,11 +300,19 @@ DAO.store.get( 'dataValues', dataValueKey ).done( function ( obj ) { if ( !obj ) { - markValue( ERROR ); - window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode ); - return; + obj = {}; + obj.executionDate = {}; + obj.executionDate.programId = $( '#programId' ).val(); + obj.executionDate.programStageInstanceId = dataValueKey; + + var orgUnitId = $( '#orgunitId' ).val(); + obj.executionDate.organisationUnitId = orgUnitId; + obj.executionDate.organisationUnit = organisationUnits[orgUnitId].n; } + obj.executionDate.executionDate = $( '#executionDate' ).val(); + obj.executionDate.completed = $( '#completed' ).val(); + if ( !obj.values ) { obj.values = {}; } @@ -606,7 +614,7 @@ return; } - obj.executionDate.completed = true; + obj.executionDate.completed = 'true'; DAO.store.set('dataValues', obj); } ); @@ -659,7 +667,7 @@ return; } - obj.executionDate.completed = false; + obj.executionDate.completed = 'false'; DAO.store.set( 'dataValues', obj ); } ); }