← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11241: Allow to select the person/orgunit/users in orgunit or health worker to send message in Person Da...

 

------------------------------------------------------------
revno: 11241
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-06-20 15:49:00 +0700
message:
  Allow to select the person/orgunit/users in orgunit or health worker to send message in Person 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/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/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	2012-09-24 05:50:08 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SendSmsAction.java	2013-06-20 08:49:00 +0000
@@ -28,9 +28,12 @@
 package org.hisp.dhis.caseentry.action.reminder;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.patient.PatientReminder;
 import org.hisp.dhis.program.ProgramStageInstance;
 import org.hisp.dhis.program.ProgramStageInstanceService;
 import org.hisp.dhis.sms.SmsServiceException;
@@ -98,6 +101,13 @@
         this.msg = msg;
     }
 
+    private int sendTo;
+
+    public void setSendTo( int sendTo )
+    {
+        this.sendTo = sendTo;
+    }
+
     private String message = "";
 
     public String getMessage()
@@ -116,40 +126,53 @@
         ProgramStageInstance programStageInstance = programStageInstanceService
             .getProgramStageInstance( programStageInstanceId );
 
-        String phoneNumber = programStageInstance.getProgramInstance().getPatient().getPhoneNumber();
-
-        if ( phoneNumber != null && !phoneNumber.isEmpty() )
-        {
-            try
-            {
-                OutboundSms outboundSms = new OutboundSms( msg, phoneNumber );
-                outboundSms.setSender( currentUserService.getCurrentUsername() );
-                outboundSmsService.sendMessage( outboundSms, null );
-
-                List<OutboundSms> outboundSmsList = programStageInstance.getOutboundSms();
-                if ( outboundSmsList == null )
-                {
-                    outboundSmsList = new ArrayList<OutboundSms>();
-                }
-                outboundSmsList.add( outboundSms );
-                programStageInstance.setOutboundSms( outboundSmsList );
-                programStageInstanceService.updateProgramStageInstance( programStageInstance );
-
-                message = i18n.getString( "sent_message_to" ) + " " + phoneNumber;
-
-                return SUCCESS;
-            }
-            catch ( SmsServiceException e )
-            {
-                message = e.getMessage();
-
-                return ERROR;
-            }
-        }
-
-        message = i18n.getString( "patient_did_not_register_a_phone_number" );
-        
-        return INPUT;
+        Set<String> phoneNumbers = new HashSet<String>();
+
+        switch ( sendTo )
+        {
+        case PatientReminder.SEND_TO_PATIENT:
+            phoneNumbers.add( programStageInstance.getProgramInstance().getPatient().getPhoneNumber() );
+            break;
+        case PatientReminder.SEND_TO_HEALTH_WORKER:
+            phoneNumbers
+                .add( programStageInstance.getProgramInstance().getPatient().getHealthWorker().getPhoneNumber() );
+            break;
+        case PatientReminder.SEND_TO_ORGUGNIT_REGISTERED:
+            phoneNumbers.add( programStageInstance.getProgramInstance().getPatient().getOrganisationUnit()
+                .getPhoneNumber() );
+            break;
+        default:
+            phoneNumbers.add( programStageInstance.getProgramInstance().getPatient().getPhoneNumber() );
+            break;
+        }
+
+        try
+        {
+            OutboundSms outboundSms = new OutboundSms();
+            outboundSms.setMessage( msg );
+            outboundSms.setRecipients( phoneNumbers );
+            outboundSms.setSender( currentUserService.getCurrentUsername() );
+            outboundSmsService.sendMessage( outboundSms, null );
+
+            List<OutboundSms> outboundSmsList = programStageInstance.getOutboundSms();
+            if ( outboundSmsList == null )
+            {
+                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;
     }
 
 }

=== 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-06-20 04:38:07 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-06-20 08:49:00 +0000
@@ -657,4 +657,5 @@
 use_data_element_form_names = Use data element form names
 section = Section
 orgunit_registered = Organisation registered
-users_in_orgunit_registered = Users in organisation registered
\ No newline at end of file
+users_in_orgunit_registered = Users in organisation registered
+message_is_sent = Message is sent.
\ 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-05-29 14:28:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-06-20 08:49:00 +0000
@@ -1777,6 +1777,20 @@
 // Comment && Message
 // --------------------------------------------------------------------
 
+function sendSmsOnePatientForm()
+{
+	jQuery('#smsDiv').dialog(
+		{
+			title:i18n_send_message,
+			maximize:true, 
+			closable:true,
+			modal:true,
+			overlay:{background:'#000000', opacity:0.1},
+			width:400,
+			height:200
+		});
+}
+
 function sendSmsOnePatient( field, programStageInstanceId )
 {
 	setInnerHTML('smsError', '');
@@ -1790,7 +1804,8 @@
 	jQuery.postUTF8( 'sendSMS.action',
 		{
 			programStageInstanceId: programStageInstanceId,
-			msg: field.value
+			msg: field.value,
+			sendTo: getFieldValue('sendTo')
 		}, function ( json )
 		{
 			if ( json.response == "success" ) {

=== 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-06-04 05:14:05 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/visitSchedule.vm	2013-06-20 08:49:00 +0000
@@ -1,5 +1,10 @@
 #set($programStageInstances = $programInstance.programStageInstances)
-
+#set($hasUsers = false)
+#foreach($user in $!programInstance.patient.healthWorker.organisationUnit.users)
+	#if($!user.phoneNumber!='') 
+		#set($hasUsers = true)
+	#end
+#end
 <table>
 	<colgroup>
        <col/>
@@ -177,20 +182,62 @@
 			</td>
 			<td>
 				<img src='images/post_comment.png' class='img-button' title='$i18n.getString("post_comment")' onclick="addComment(byId('message_$programStageInstance.id'),'$programStageInstance.id')">
-				#if($!programInstance.patient.phoneNumber && $!programInstance.patient.phoneNumber!='')
-				<img src="images/send_sms.png" class='img-button' title="$i18n.getString( 'send_message' )" onclick="setFieldValue( 'programStageInstanceId',$programStageInstance.id);sendSmsOnePatient(byId('message_$programStageInstance.id'),'$programStageInstance.id');"/>
-				#end
 			</td>
-			#if( $auth.hasAccess( "dhis-web-caseentry", "removeCurrentEncounter" ) )
 			<td>
-				<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>
+				#if(($auth.hasAccess( "dhis-web-caseentry", "sendSMS" ) ) 
+					&& ($!programInstance.patient.phoneNumber 
+					|| $!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();"/>
+				#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>
+				#end
 			</td>
-			#end
 		</tr>
 		#set( $mark = !$mark  )
 	#end
 	</tbody>
 	</table>
+	
+	<div id='smsDiv' class='hidden'>
+		<table>
+			<tr>
+				<td>$i18n.getString("send_to")</td>
+				<td>
+					<select id='sendTo' name='sendTo' style='width:260px;'>
+						#if($!programInstance.patient.phoneNumber)
+						<option value='1'>$i18n.getString('patient')</option>
+						#end
+						
+						#if($!programInstance.patient.healthWorker.phoneNumber)
+						<option value='2'>$i18n.getString('health_worker')</option>
+						#end
+						
+						#if($!programInstance.patient.healthWorker.organisationUnit.phoneNumber)
+						<option value='3'>$i18n.getString('orgunit_registered')</option>
+						#end
+						
+						#if($hasUsers)
+						<option value='4'>$i18n.getString('users_in_orgunit_registered')</option>
+						#end
+					</select>
+				</td>
+			</tr>
+			<tr>
+				<td>$i18n.getString("message")</td>
+				<td><input type='text' id='smsField' name='smsField' style='width:260px;height:50px;'></td>
+			</tr>
+			<tr>
+				<td></td>
+				<td>
+					<input type='button' value="$i18n.getString('send')" onclick="sendSmsOnePatient(byId('smsField'),getFieldValue('programStageInstanceId') );">
+					<input type='button' value="$i18n.getString('cancel')" onclick="jQuery('#smsDiv').dialog('close');">
+				</td>
+			</tr>
+		</table>
+	</div>
 #end
 
 <script>
@@ -204,4 +251,5 @@
 	#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" ) , "'")';
+	var i18n_send_message = '$encoder.jsEscape( $i18n.getString( "send_message" ) , "'")';
 </script>