← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11966: Allow to send sms for program in Dashboard.

 

------------------------------------------------------------
revno: 11966
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-09-08 04:25:35 +0700
message:
  Allow to send sms for program in Dashboard.
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SendSmsAction.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/webapp/dhis-web-caseentry/javascript/commons.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/visitSchedule.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-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SendSmsAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SendSmsAction.java	2013-09-04 10:01:16 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SendSmsAction.java	2013-09-07 21:25:35 +0000
@@ -35,6 +35,8 @@
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.patient.PatientReminder;
 import org.hisp.dhis.patient.PatientReminderService;
+import org.hisp.dhis.program.ProgramInstance;
+import org.hisp.dhis.program.ProgramInstanceService;
 import org.hisp.dhis.program.ProgramStageInstance;
 import org.hisp.dhis.program.ProgramStageInstanceService;
 import org.hisp.dhis.sms.SmsSender;
@@ -84,6 +86,13 @@
         this.patientReminderService = patientReminderService;
     }
 
+    private ProgramInstanceService programInstanceService;
+
+    public void setProgramInstanceService( ProgramInstanceService programInstanceService )
+    {
+        this.programInstanceService = programInstanceService;
+    }
+
     private I18n i18n;
 
     public void setI18n( I18n i18n )
@@ -102,6 +111,13 @@
         this.programStageInstanceId = programStageInstanceId;
     }
 
+    private Integer programInstanceId;
+
+    public void setProgramInstanceId( Integer programInstanceId )
+    {
+        this.programInstanceId = programInstanceId;
+    }
+
     private String msg;
 
     public void setMsg( String msg )
@@ -131,6 +147,24 @@
     public String execute()
         throws Exception
     {
+        if ( programStageInstanceId != null )
+        {
+            sendSMSToEvent();
+        }
+        else if ( programInstanceId != null )
+        {
+            sendSMSToProgram();
+        }
+
+        return SUCCESS;
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private String sendSMSToEvent()
+    {
         ProgramStageInstance programStageInstance = programStageInstanceService
             .getProgramStageInstance( programStageInstanceId );
 
@@ -155,19 +189,57 @@
                 outboundSmsList = new ArrayList<OutboundSms>();
             }
             outboundSmsList.add( outboundSms );
+
             programStageInstance.setOutboundSms( outboundSmsList );
             programStageInstanceService.updateProgramStageInstance( programStageInstance );
-
-            message = i18n.getString( "message_is_sent" );
-        }
-        catch ( SmsServiceException e )
-        {
-            message = e.getMessage();
-
-            return ERROR;
-        }
-
-        return SUCCESS;
-    }
-
+            message = i18n.getString( "message_is_sent" + " " + phoneNumbers );
+            return ERROR;
+        }
+        catch ( SmsServiceException e )
+        {
+            message = e.getMessage();
+
+            return ERROR;
+        }
+    }
+
+    private String sendSMSToProgram()
+    {
+        ProgramInstance programInstance = programInstanceService
+            .getProgramInstance( programInstanceId );
+
+        PatientReminder patientReminder = new PatientReminder();
+        patientReminder.setTemplateMessage( msg );
+        patientReminder.setSendTo( sendTo );
+
+        Set<String> phoneNumbers = patientReminderService.getPhonenumbers( patientReminder, programInstance.getPatient() );
+
+        try
+        {
+            OutboundSms outboundSms = new OutboundSms();
+            outboundSms.setMessage( msg );
+            outboundSms.setRecipients( phoneNumbers );
+            outboundSms.setSender( currentUserService.getCurrentUsername() );
+            smsSender.sendMessage( outboundSms, null );
+
+            List<OutboundSms> outboundSmsList = programInstance.getOutboundSms();
+            if ( outboundSmsList == null )
+            {
+                outboundSmsList = new ArrayList<OutboundSms>();
+            }
+            outboundSmsList.add( outboundSms );
+
+            programInstance.setOutboundSms( outboundSmsList );
+            programInstanceService.updateProgramInstance( programInstance );
+            message = i18n.getString( "message_is_sent" + " " + phoneNumbers );
+
+            return SUCCESS;
+        }
+        catch ( SmsServiceException e )
+        {
+            message = e.getMessage();
+
+            return ERROR;
+        }
+    }
 }

=== 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-09-06 15:53:07 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2013-09-07 21:25:35 +0000
@@ -1090,6 +1090,8 @@
 			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
 		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
 		<property name="patientReminderService" ref="org.hisp.dhis.patient.PatientReminderService" />
+		<property name="programInstanceService"
+			ref="org.hisp.dhis.program.ProgramInstanceService" />
 	</bean>
 
 	<bean id="org.hisp.dhis.caseentry.action.reminder.SendSmsToListAction"

=== 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-09-07 12:32:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-09-07 21:25:35 +0000
@@ -680,4 +680,5 @@
 incomplete_confirm_message = Are you sure this event is incompleted?
 non_value = No value
 update_comment = Update comment
-update_success = Update successfully
\ No newline at end of file
+update_success = Update successfully
+send_message = Send message
\ No newline at end of file

=== 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-09-07 12:37:59 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-09-07 21:25:35 +0000
@@ -1888,7 +1888,7 @@
 		});
 }
 
-function sendSmsOnePatient( field, programStageInstanceId )
+function sendSmsOnePatient( field, id )
 {
 	if(field.value==""){
 		field.style.backgroundColor = ERROR_COLOR;
@@ -1896,10 +1896,17 @@
 		return;
 	}
 	
+	var url = 'sendSMS.action?';
+	if(getFieldValue('sendFromEvent')=="true"){
+		url += "programStageInstanceId=" + id;
+	}
+	else{
+		url += "programInstanceId=" + getFieldValue('programInstanceId');
+	}
+	
 	field.style.backgroundColor = SAVING_COLOR;
-	jQuery.postUTF8( 'sendSMS.action',
+	jQuery.postUTF8( url,
 		{
-			programStageInstanceId: programStageInstanceId,
 			msg: field.value,
 			sendTo: getFieldValue('sendTo')
 		}, function ( json )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm	2013-09-07 14:38:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/selectPatient.vm	2013-09-07 21:25:35 +0000
@@ -153,7 +153,7 @@
 				}
 			  }
 			});
-			window.history.pushState('patient', null, './#patient');
+			window.history.pushState('patient.action#patient', null, './patient.action#patient');
 	}
 	
 	$( "#orgUnitTree" ).one( "ouwtLoaded", function () {

=== 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-09-07 14:57:19 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/visitSchedule.vm	2013-09-07 21:25:35 +0000
@@ -88,8 +88,9 @@
 		#end
 		</td>
 		
-		<td valign="top">
+		<td valign="top" colspan='4'>
 			<input type="button" id='updateCommentBtn' name='updateCommentBtn' #if($!programStageInstance.patientComment) value="$i18n.getString( 'update_comment' )" #else value="$i18n.getString( 'save_comment' )" #end style="width:130px" onclick="saveComment($programInstance.id);">
+			<input type="button" id='sendProgramSMSBtn' name='sendProgramSMSBtn' value="$i18n.getString( 'send_message' )" style="width:130px" onclick="setFieldValue('sendFromEvent','false');sendSmsOnePatientForm();">
 		</td>
 	</tr>
 
@@ -187,7 +188,7 @@
 					|| $!programInstance.patient.healthWorker.phoneNumber 
 					|| $!programInstance.patient.healthWorker.organisationUnit.phoneNumber 
 					|| $hasUsers ))
-				<img src="images/send_sms.png" class='img-button' title="$i18n.getString( 'send_message' )" onclick="setFieldValue( 'programStageInstanceId',$programStageInstance.id);sendSmsOnePatientForm();"/>
+				<img src="images/send_sms.png" class='img-button' title="$i18n.getString( 'send_message' )" onclick="setFieldValue('sendFromEvent','true');setFieldValue( 'programStageInstanceId',$programStageInstance.id);sendSmsOnePatientForm();"/>
 				#end
 				#if( $auth.hasAccess( "dhis-web-caseentry", "removeCurrentEncounter" ) )
 					<a href="javascript:removeEvent($programStageInstance.id, false)" link="javascript:removeEvent($programStageInstance.id, false)" title='$i18n.getString( "remove" )'><img src="../images/delete.png" id='del_$programStageInstance.id' name='del_$programStageInstance.id' alt='$i18n.getString( "remove" )' #if( $status==1 ) class='hidden' #end></a>
@@ -200,6 +201,7 @@
 	</table>
 	
 	<div id='smsDiv' name="smsDiv" class='hidden'>
+		<input type='hidden' id='sendFromEvent' name='sendFromEvent' value='true'>
 		<table>
 			<tr>
 				<td>$i18n.getString("send_to")</td>
@@ -230,7 +232,7 @@
 			<tr>
 				<td></td>
 				<td>
-					<input type='button' value="$i18n.getString('send')" onclick="sendSmsOnePatient(byId('smsField'),getFieldValue('programStageInstanceId') );">
+					<input type='button' value="$i18n.getString('send')" onclick="var id=getFieldValue('programStageInstanceId');if(getFieldValue('sendFromEvent')=='false'){id=$programInstance.id};sendSmsOnePatient(byId('smsField'),id );">
 					<input type='button' value="$i18n.getString('cancel')" onclick="jQuery('#smsDiv').dialog('close');">
 				</td>
 			</tr>