------------------------------------------------------------ revno: 10252 committer: Tran Chau <tran.hispviet...@gmail.com> branch nick: dhis2 timestamp: Fri 2013-03-15 21:43:16 +0700 message: Add function to delete program which no stages with data. added: dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveProgramInstanceAction.java modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 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/javascript/commons.js dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/visitSchedule.vm dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties
-- 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/ProgramInstanceService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java 2013-03-08 08:47:35 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java 2013-03-15 14:43:16 +0000 @@ -98,5 +98,7 @@ Date endDate ); int countUnenrollment( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate ); + + void removeProgramEnrollment( ProgramInstance programInstance ); } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java 2013-03-08 08:47:35 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java 2013-03-15 14:43:16 +0000 @@ -78,5 +78,6 @@ Collection<ProgramInstance> getUnenrollment( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate ); int countUnenrollment( Program program, Collection<Integer> orgunitIds, Date startDate, Date endDate ); - + + void removeProgramEnrollment( ProgramInstance programInstance ); } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2013-03-08 08:47:35 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2013-03-15 14:43:16 +0000 @@ -361,6 +361,11 @@ return programInstanceStore.countUnenrollment( program, orgunitIds, startDate, endDate ); } + public void removeProgramEnrollment( ProgramInstance programInstance ) + { + programInstanceStore.removeProgramEnrollment( programInstance ); + } + // ------------------------------------------------------------------------- // due-date && report-date // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java 2013-03-12 03:33:20 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java 2013-03-15 14:43:16 +0000 @@ -40,6 +40,7 @@ import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramInstance; import org.hisp.dhis.program.ProgramInstanceStore; +import org.springframework.jdbc.core.JdbcTemplate; /** * @author Abyot Asalefew @@ -49,6 +50,21 @@ extends HibernateGenericStore<ProgramInstance> implements ProgramInstanceStore { + // ------------------------------------------------------------------------- + // Dependency + // ------------------------------------------------------------------------- + + private JdbcTemplate jdbcTemplate; + + public void setJdbcTemplate( JdbcTemplate jdbcTemplate ) + { + this.jdbcTemplate = jdbcTemplate; + } + + // ------------------------------------------------------------------------- + // Implemented methods + // ------------------------------------------------------------------------- + @SuppressWarnings( "unchecked" ) public Collection<ProgramInstance> get( boolean completed ) { @@ -204,4 +220,13 @@ return rs != null ? rs.intValue() : 0; } + public void removeProgramEnrollment( ProgramInstance programInstance ) + { + String sql = "delete from programstageinstance where programinstanceid=" + programInstance.getId(); + jdbcTemplate.execute( sql ); + + sql = "delete from programinstance where programinstanceid=" + programInstance.getId(); + jdbcTemplate.execute( sql ); + } + } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-03-12 03:33:20 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-03-15 14:43:16 +0000 @@ -45,6 +45,7 @@ class="org.hisp.dhis.program.hibernate.HibernateProgramInstanceStore"> <property name="clazz" value="org.hisp.dhis.program.ProgramInstance" /> <property name="sessionFactory" ref="sessionFactory" /> + <property name="jdbcTemplate" ref="jdbcTemplate" /> </bean> <bean id="org.hisp.dhis.program.ProgramStageStore" === added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveProgramInstanceAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveProgramInstanceAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveProgramInstanceAction.java 2013-03-15 14:43:16 +0000 @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2004-2009, 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.program.ProgramInstance; +import org.hisp.dhis.program.ProgramInstanceService; + +import com.opensymphony.xwork2.Action; + +/** + * @author Chau Thu Tran + * + * @version RemoveProgramInstanceAction.java 8:52:52 PM Mar 15, 2013 $ + */ +public class RemoveProgramInstanceAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private ProgramInstanceService programInstanceService; + + public void setProgramInstanceService( ProgramInstanceService programInstanceService ) + { + this.programInstanceService = programInstanceService; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private Integer id; + + public void setId( Integer id ) + { + this.id = id; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + { + ProgramInstance programInstance = programInstanceService.getProgramInstance( id ); + + programInstanceService.removeProgramEnrollment( programInstance ); + + 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 2013-03-11 06:04:54 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2013-03-15 14:43:16 +0000 @@ -1068,6 +1068,14 @@ <property name="patientAuditService" ref="org.hisp.dhis.patient.PatientAuditService" /> <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" /> </bean> + + <bean + id="org.hisp.dhis.caseentry.action.caseentry.RemoveProgramInstanceAction" + class="org.hisp.dhis.caseentry.action.caseentry.RemoveProgramInstanceAction" + scope="prototype"> + <property name="programInstanceService" + ref="org.hisp.dhis.program.ProgramInstanceService" /> + </bean> <!-- Comment --> === 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 2013-03-15 13:36:01 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties 2013-03-15 14:43:16 +0000 @@ -600,4 +600,5 @@ aggregate_successfully = Aggregate successfully complete_quit = Complete/Quit re_enrol = Re-enrol -overwrite = Overwrite \ No newline at end of file +overwrite = Overwrite +remove_confirm_message=Are you sure you want to delete program? \ 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 2013-03-15 05:48:16 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2013-03-15 14:43:16 +0000 @@ -1037,6 +1037,17 @@ <param name="requiredAuthorities">F_PATIENT_DASHBOARD</param> </action> + <action name="removeProgramInstance" + class="org.hisp.dhis.caseentry.action.caseentry.RemoveProgramInstanceAction"> + <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> + <param name="requiredAuthorities">F_PROGRAM_INSTANCE_DELETE</param> + </action> + <!-- Comment --> <action name="addPatientComment" === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js 2013-03-15 04:29:23 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js 2013-03-15 14:43:16 +0000 @@ -1497,6 +1497,22 @@ } +function removeProgramInstance( programInstanceId ) +{ + if( confirm(i18n_remove_confirm_message) ) + { + $.postJSON( 'removeProgramInstance.action', + { + id: programInstanceId + }, function( json ) + { + jQuery('#activeTB [id=tr1_' + programInstanceId + ']').remove(); + jQuery('#activeTB [id=tr2_' + programInstanceId + ']').remove(); + hideById('programEnrollmentDiv'); + }); + } +} + // ---------------------------------------------------------------- // Identifiers && Attributes for selected program // ---------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/visitSchedule.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/visitSchedule.vm 2013-03-15 04:20:33 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/visitSchedule.vm 2013-03-15 14:43:16 +0000 @@ -1,26 +1,40 @@ +#set($programStageInstances = $programInstance.programStageInstances) <fieldset> <legend>$i18n.getString("program")</legend> <table> <tr> <td class='text-column'>$programInstance.program.dateOfEnrollmentDescription:</td> - <td><input name="enrollmentDate" id="enrollmentDate" readonly value="$!format.formatDate( $programInstance.enrollmentDate )" style="width:330px;"></td> + <td><input name="enrollmentDate" id="enrollmentDate" readonly value="$!format.formatDate( $programInstance.enrollmentDate )" style="width:270px;"></td> </tr> <tr> <td class='text-column'>$programInstance.program.dateOfIncidentDescription:</td> - <td><input name="dateOfIncident" id="dateOfIncident" readonly value="$!format.formatDate( $programInstance.dateOfIncident )" style="width:330px;"></td> + <td><input name="dateOfIncident" id="dateOfIncident" readonly value="$!format.formatDate( $programInstance.dateOfIncident )" style="width:270px;"></td> </tr> <tr> <td></td> <td> - <input type="button" class='large-button' value="$i18n.getString( 'update' )" onclick='updateEnrollment($programInstance.patient.id, $programInstance.program.id, $programInstance.id, "$programInstance.program.displayName")'/> + <input type="button" style='width:80px' value="$i18n.getString( 'update' )" onclick='updateEnrollment($programInstance.patient.id, $programInstance.program.id, $programInstance.id, "$programInstance.program.displayName")'/> <input type="button" class='large-button' id='completeProgram' value="$i18n.getString( 'complete_quit' )" onclick='unenrollmentForm($programInstance.id)' /> - <input type="button" class='large-button' id='incompleteProgram' value="$i18n.getString( 're_enrol' )" onclick='reenrollmentForm($programInstance.id)' /> + <input type="button" style='width:80px' id='incompleteProgram' value="$i18n.getString( 're_enrol' )" onclick='reenrollmentForm($programInstance.id)' /> + #set($allowRemove = 'true') + #foreach( $programStageInstance in $programStageInstances ) + #if( $programStageInstance.executionDate ) + #set($allowRemove = 'false') + #end + #end + #if($allowRemove == 'true') + <input type="button" style='width:80px' id='removeProgram' value="$i18n.getString( 'remove' )" onclick='removeProgramInstance($programInstance.id)' /> + <script> + jQuery('#enrollmentDate').width('355'); + jQuery('#dateOfIncident').width('355'); + </script> + #end </td> </tr> </table> </fieldset> <br> -#set($programStageInstances = $programInstance.programStageInstances) + #if( $programStageInstances.size() > 0 ) <table class='mainPageTable listTable' id='progarmStageListDiv' name='progarmStageListDiv' > <colgroup> @@ -112,4 +126,5 @@ $('[id=tab-3]').find('img').parent().removeAttr("href"); #end var i18n_insert_a_due_date = '$encoder.jsEscape( $i18n.getString( "insert_a_due_date" ) , "'")'; + var i18n_remove_confirm_message = '$encoder.jsEscape( $i18n.getString( "remove_confirm_message" ) , "'")'; </script> \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2013-03-14 04:50:21 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/org/hisp/dhis/user/i18n_module.properties 2013-03-15 14:43:16 +0000 @@ -151,6 +151,7 @@ F_SEARCH_PATIENT_IN_ALL_FACILITIES = Search Person In All Facilities F_ADD_PATIENT_REGISTRATION_FORM=Add Person Registration Form F_PROGRAM_INSTANCE_MANAGEMENT = Program Event Management +F_PROGRAM_INSTANCE_DELETE = Delete Program Enrollment F_PROGRAM_TRACKING_MANAGEMENT = Program Tracking Management F_PROGRAM_PUBLIC_ADD=Add Public Program F_PROGRAM_PRIVATE_ADD=Add Private Program
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp