dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15237
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5426: Add Create-new-event and Delete-current-event buttons for anonymous data entry.
------------------------------------------------------------
revno: 5426
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-12-15 13:47:36 +0700
message:
Add Create-new-event and Delete-current-event buttons for anonymous data entry.
added:
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveCurrentEncounterAction.java
modified:
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueDeletionHandler.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm
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/entry.js
--
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-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueDeletionHandler.java 2011-11-30 06:38:30 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientdatavalue/PatientDataValueDeletionHandler.java 2011-12-15 06:47:36 +0000
@@ -28,6 +28,7 @@
package org.hisp.dhis.patientdatavalue;
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.program.ProgramInstance;
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.system.deletion.DeletionHandler;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -79,4 +80,15 @@
return jdbcTemplate.queryForInt( sql ) == 0 ? null : ERROR;
}
+
+ @Override
+ public void deleteProgramInstance( ProgramInstance programInstance )
+ {
+ String sql = "DELETE FROM patientdatavalue " +
+ "WHERE programstageinstanceid in " +
+ "( SELECT programstageinstanceid FROM programstageinstance " +
+ "WHERE programinstanceid = " + programInstance.getId() + ")";
+
+ jdbcTemplate.execute( sql );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.java 2011-11-30 08:34:01 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.java 2011-12-15 06:47:36 +0000
@@ -66,6 +66,14 @@
String sql = "SELECT COUNT(*) " + "FROM programstageinstance " + "WHERE programstageid=" + programStage.getId();
return jdbcTemplate.queryForInt( sql ) == 0 ? null : ERROR;
+ }
+
+ @Override
+ public void deleteProgramInstance( ProgramInstance programInstance )
+ {
+ String sql = "DELETE FROM programstageinstance " +
+ "WHERE programinstanceid = " + programInstance.getId();
+ jdbcTemplate.execute( sql );
}
}
=== added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveCurrentEncounterAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveCurrentEncounterAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveCurrentEncounterAction.java 2011-12-15 06:47:36 +0000
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.hisp.dhis.caseentry.action.caseentry;
+
+import org.hisp.dhis.common.DeleteNotAllowedException;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramInstanceService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $Id: RemoveCurrentEncounterAction.java Dec 15, 2011 12:53:34 PM $
+ */
+public class RemoveCurrentEncounterAction
+ implements Action
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private ProgramInstanceService programInstanceService;
+
+ public void setProgramInstanceService( ProgramInstanceService programInstanceService )
+ {
+ this.programInstanceService = programInstanceService;
+ }
+
+ // --------------------------------------------------------------------------
+ // Input
+ // -------------------------------------------------------------------------
+
+ private int programInstanceId;
+
+ public void setProgramInstanceId( int programInstanceId )
+ {
+ this.programInstanceId = programInstanceId;
+ }
+
+ private I18n i18n;
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
+ // -------------------------------------------------------------------------
+ // Output
+ // -------------------------------------------------------------------------
+
+ private String message;
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ public String execute()
+ throws Exception
+ {
+ try
+ {
+ ProgramInstance programInstance = programInstanceService.getProgramInstance( programInstanceId );
+
+ programInstanceService.deleteProgramInstance( programInstance );
+ }
+ catch ( DeleteNotAllowedException ex )
+ {
+ if ( ex.getErrorCode().equals( DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS ) )
+ {
+ message = i18n.getString( "object_not_deleted_associated_by_objects" ) + " " + ex.getMessage();
+
+ return ERROR;
+ }
+ }
+ return SUCCESS;
+ }
+
+}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2011-12-14 07:33:18 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2011-12-15 06:47:36 +0000
@@ -381,6 +381,12 @@
<property name="programService"
ref="org.hisp.dhis.program.ProgramService" />
</bean>
+
+ <bean id="org.hisp.dhis.caseentry.action.caseentry.RemoveCurrentEncounterAction"
+ class="org.hisp.dhis.caseentry.action.caseentry.RemoveCurrentEncounterAction" scope="prototype">
+ <property name="programInstanceService"
+ ref="org.hisp.dhis.program.ProgramInstanceService" />
+ </bean>
<!-- Patient chart -->
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties 2011-12-15 04:13:03 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties 2011-12-15 06:47:36 +0000
@@ -447,4 +447,8 @@
date_of_edit=Date of edit
can_not_enrol_into_the_program_because=Could not enroll into the program because
event_registration=Event registration
-intro_event_registration=Register anonymous events. The data to register is defined by a single event anonymous program.
\ No newline at end of file
+intro_event_registration=Register anonymous events. The data to register is defined by a single event anonymous program.
+create_new_event=Create new event
+delete_current_event = Delete current event
+delete_current_event_success=Delete current event successfully
+please_enter_report_date = Please enter report date
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2011-12-15 04:13:03 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2011-12-15 06:47:36 +0000
@@ -440,6 +440,14 @@
/dhis-web-commons/ajax/jsonPrograms.vm</result>
</action>
+ <action name="removeCurrentEncounter"
+ class="org.hisp.dhis.caseentry.action.caseentry.RemoveCurrentEncounterAction">
+ <result name="success" type="velocity-json">
+ /dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+ <result name="error" type="velocity-json">
+ /dhis-web-commons/ajax/jsonResponseError.vm</result>
+ </action>
+
<!-- Patient-Program Enrollment -->
<action name="showProgramEnrollmentForm"
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm 2011-12-15 04:13:03 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/anonymousRegistration.vm 2011-12-15 06:47:36 +0000
@@ -2,13 +2,13 @@
<div id="actions">
+ <input type="button" id="createEventBtn" value="$i18n.getString('create_new_event')" onClick="javascript: createNewEvent();" style="width:12em " disabled="disabled">
+ <input type="button" id="deleteCurrentEventBtn" value="$i18n.getString('delete_current_event')" onClick="javascript: deleteCurrentEvent();" style="width:12em " disabled="disabled" >
<input type="button" id="validationBtn" value="$i18n.getString('run_validation')" onClick="javascript: runValidation();" style="width:12em " disabled="disabled" >
</div>
<div id="dataRecordingSelectDiv" class="inputCriteria" style="width:420px;height:80px;">
-
<input type='hidden' id="programStageId">
-
<table>
<tr>
<td>$i18n.getString('program')</td>
@@ -54,4 +54,7 @@
var i18n_date_is_greater_then_or_equals_due_date = '$encoder.jsEscape( $i18n.getString( "date_is_greater_then_or_equals_due_date" ) , "'")';
var i18n_violate_validation = '$encoder.jsEscape( $i18n.getString( "violate_validation" ) , "'")';
+
+ var i18n_delete_current_event_success = '$encoder.jsEscape( $i18n.getString( "delete_current_event_success" ) , "'")';
+ var i18n_please_enter_report_date = '$encoder.jsEscape( $i18n.getString( "please_enter_report_date" ) , "'")';
</script>
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm 2011-11-21 12:44:20 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm 2011-12-15 06:47:36 +0000
@@ -22,6 +22,7 @@
<input type='hidden' id='incidentDate' value='$!format.formatDate($programStageInstance.programInstance.dateOfIncident)'>
<input type='hidden' name='programStageInstanceId' id='programStageInstanceId' value='$!programStageInstance.id'>
+<input type='hidden' name='programInstanceId' id='programInstanceId' value='$!programStageInstance.programInstance.id'>
<input type='hidden' name='irregular' id='irregular' value='$!programStageInstance.programStage.irregular'>
<input type='hidden' name='completed' id='completed' value='$!programStageInstance.completed'>
=== 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 2011-12-15 04:13:03 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/anonymousRegistration.js 2011-12-15 06:47:36 +0000
@@ -3,6 +3,11 @@
{
disable('executionDate');
setFieldValue('executionDate', '');
+ $('#executionDate').unbind('change');
+
+ disable('createEventBtn');
+ disable('deleteCurrentEventBtn');
+
$.postJSON( 'loadAnonymousPrograms.action',{}
, function( json )
@@ -23,10 +28,10 @@
function showEventForm()
{
+ setFieldValue('executionDate', '');
+
if( getFieldValue('programId') == '' )
{
- disable('executionDate');
- setFieldValue('executionDate', '');
hideById('dataEntryFormDiv');
return;
}
@@ -55,5 +60,59 @@
enable('executionDate');
hideById('loaderDiv');
showById('dataEntryFormDiv');
+
+ var programStageInstanceId = getFieldValue('programStageInstanceId');
+
+ if( programStageInstanceId == '' )
+ {
+ $('#executionDate').unbind('change');
+ disable('deleteCurrentEventBtn');
+ enable('createEventBtn');
+ }
+ else
+ {
+ disable('createEventBtn');
+ enable('deleteCurrentEventBtn');
+ }
+
} );
+}
+
+function createNewEvent()
+{
+ saveExecutionDate( getFieldValue('programStageId'), getFieldValue('executionDate') );
+ loadEventRegistrationForm();
+
+ disable('createEventBtn');
+ enable('deleteCurrentEventBtn');
+
+ $('#executionDate').change(function() {
+ saveExecutionDate( getFieldValue('programStageId'), getFieldValue('executionDate') );
+ });
+}
+
+function deleteCurrentEvent()
+{
+ jQuery.postJSON( "removeCurrentEncounter.action",
+ {
+ programInstanceId: getFieldValue('programInstanceId')
+ },
+ function( json )
+ {
+ var type = json.response;
+
+ if( type == 'success' )
+ {
+ showSuccessMessage( i18n_delete_current_event_success );
+ hideById('dataEntryFormDiv');
+ setFieldValue('executionDate','');
+ $('#executionDate').unbind('change');
+ disable('deleteCurrentEventBtn');
+ enable('createEventBtn');
+ }
+ else if( type == 'input' )
+ {
+ showWarningMessage( json.message );
+ }
+ });
}
\ No newline at end of file
=== 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 2011-11-21 12:44:20 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js 2011-12-15 06:47:36 +0000
@@ -655,11 +655,12 @@
if( executionDate != "")
{
markValue( ERROR );
- window.alert( i18n_invalid_date );
+ showWarningMessage( i18n_invalid_date );
}
else
{
- markValue( resultColor );
+ markValue( ERROR );
+ showWarningMessage( i18n_please_enter_report_date );
}
hideById('dataEntryFormDiv');
}