dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22089
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10599: delete many incoming sms, support for searching in all Organisation Unit(LWUIT), SMS notification
------------------------------------------------------------
revno: 10599
committer: Lai <lai.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-04-17 16:03:38 +0700
message:
delete many incoming sms, support for searching in all Organisation Unit(LWUIT), SMS notification
added:
dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsSender.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfiguration.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java
dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java
dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java
dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Program.java
dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java
dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java
dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/DeleteReceiveSMSAction.java
dhis-2/dhis-web/dhis-web-sms/src/main/resources/struts.xml
--
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/sms/config/SmsConfiguration.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfiguration.java 2013-01-22 08:31:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/config/SmsConfiguration.java 2013-04-17 09:03:38 +0000
@@ -126,7 +126,6 @@
return gw;
}
}
-
return null;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2013-01-16 10:29:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/DefaultMessageService.java 2013-04-17 09:03:38 +0000
@@ -90,7 +90,7 @@
log.info( "Found the following message senders: " + messageSenders );
}
-
+
// -------------------------------------------------------------------------
// MessageService implementation
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java 2013-04-03 08:06:46 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/ActivityReportingService.java 2013-04-17 09:03:38 +0000
@@ -57,10 +57,10 @@
public Patient findPatient( String name, int orgUnitId )
throws NotAllowedException;
- public String saveProgramStage( ProgramStage programStage, int orgUnitId )
+ public String saveProgramStage( ProgramStage programStage, int patientId )
throws NotAllowedException;
- public Patient enrollProgram( String enrollInfo, int orgUnitId )
+ public Patient enrollProgram( String enrollInfo )
throws NotAllowedException;
public Collection<PatientIdentifierType> getIdentifierTypes();
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java 2013-04-16 07:52:25 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java 2013-04-17 09:03:38 +0000
@@ -37,7 +37,6 @@
import org.hisp.dhis.api.mobile.model.DataStreamSerializable;
import org.hisp.dhis.api.mobile.model.PatientAttribute;
import org.hisp.dhis.api.mobile.model.PatientIdentifier;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
/**
* @author Nguyen Kim Lai
@@ -81,7 +80,7 @@
private String phoneNumber;
- private OrganisationUnit organisationUnit;
+ private String organisationUnitName;
public List<PatientIdentifier> getIdentifiers()
{
@@ -279,16 +278,6 @@
this.phoneNumber = phoneNumber;
}
- public OrganisationUnit getOrganisationUnit()
- {
- return organisationUnit;
- }
-
- public void setOrganisationUnit( OrganisationUnit organisationUnit )
- {
- this.organisationUnit = organisationUnit;
- }
-
public List<Relationship> getEnrollmentRelationships()
{
return enrollmentRelationships;
@@ -298,6 +287,16 @@
{
this.enrollmentRelationships = enrollmentRelationships;
}
+
+ public String getOrganisationUnitName()
+ {
+ return organisationUnitName;
+ }
+
+ public void setOrganisationUnitName( String organisationUnitName )
+ {
+ this.organisationUnitName = organisationUnitName;
+ }
@Override
public void serialize( DataOutputStream out )
@@ -311,6 +310,7 @@
dout.writeUTF( this.getMiddleName() );
dout.writeUTF( this.getLastName() );
dout.writeInt( this.getAge() );
+ dout.writeUTF( this.getOrganisationUnitName() );
if ( gender != null )
{
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Program.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Program.java 2013-04-15 15:12:27 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Program.java 2013-04-17 09:03:38 +0000
@@ -93,8 +93,8 @@
throws IOException
{
super.serialize( dout );
- dout.writeInt( this.status );
- dout.writeInt( this.getVersion() );
+ dout.writeInt( getStatus() );
+ dout.writeInt( getVersion() );
if( programStages == null )
{
dout.writeInt( 0 );
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java 2013-04-15 15:12:27 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java 2013-04-17 09:03:38 +0000
@@ -446,9 +446,8 @@
}
else
{
- org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( orgUnitId,
- patients.get( 0 ) );
-
+ //org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( orgUnitId, patients.get( 0 ) );
+ org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( patients.get( 0 ) );
return patientMobile;
}
}
@@ -456,7 +455,8 @@
{
Patient patient = patientService.getPatient( Integer.parseInt( keyword ) );
- org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( orgUnitId, patient );
+ //org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( orgUnitId, patient );
+ org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientMobile = getPatientModel( patient );
return patientMobile;
}
@@ -465,7 +465,7 @@
@Override
public String saveProgramStage( org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage mobileProgramStage,
- int orgUnitId )
+ int patientId )
throws NotAllowedException
{
if ( mobileProgramStage.isSingleEvent() )
@@ -496,7 +496,7 @@
programStageInstance.setCompleted( true );
- programStageInstance.setOrganisationUnit( orgUnitService.getOrganisationUnit( orgUnitId ) );
+ programStageInstance.setOrganisationUnit( patientService.getPatient( patientId ).getOrganisationUnit() );
programStageInstanceService.addProgramStageInstance( programStageInstance );
@@ -607,7 +607,7 @@
}
@Override
- public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient enrollProgram( String enrollInfo, int orgUnitId )
+ public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient enrollProgram( String enrollInfo )
throws NotAllowedException
{
String[] enrollProgramInfos = enrollInfo.split( "-" );
@@ -654,7 +654,8 @@
}
- return getPatientModel( orgUnitId, patient );
+ //return getPatientModel( orgUnitId, patient );
+ return getPatientModel( patient );
}
// -------------------------------------------------------------------------
@@ -779,7 +780,8 @@
}
// get patient model for LWUIT
- private org.hisp.dhis.api.mobile.model.LWUITmodel.Patient getPatientModel( int orgUnitId, Patient patient )
+ //private org.hisp.dhis.api.mobile.model.LWUITmodel.Patient getPatientModel( int orgUnitId, Patient patient )
+ private org.hisp.dhis.api.mobile.model.LWUITmodel.Patient getPatientModel( Patient patient )
{
org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patientModel = new org.hisp.dhis.api.mobile.model.LWUITmodel.Patient();
List<PatientAttribute> patientAtts = new ArrayList<PatientAttribute>();
@@ -793,6 +795,7 @@
Period period = new Period( new DateTime( patient.getBirthDate() ), new DateTime() );
patientModel.setAge( period.getYears() );
+ patientModel.setOrganisationUnitName( patient.getOrganisationUnit().getName() );
patientModel.setPhoneNumber( patient.getPhoneNumber() );
this.setSetting( getSettings() );
@@ -907,7 +910,7 @@
// Set available enrollment programs
List<Program> enrollmentProgramList = new ArrayList<Program>();
- enrollmentProgramList = generateEnrollmentProgramList( orgUnitId, patient );
+ enrollmentProgramList = generateEnrollmentProgramList( patient );
List<org.hisp.dhis.api.mobile.model.LWUITmodel.Program> enrollmentProgramListMobileList = new ArrayList<org.hisp.dhis.api.mobile.model.LWUITmodel.Program>();
for ( Program enrollmentProgram : enrollmentProgramList )
@@ -1084,11 +1087,12 @@
return setting;
}
- private List<Program> generateEnrollmentProgramList( int orgId, Patient patient )
+ private List<Program> generateEnrollmentProgramList( Patient patient )
{
List<Program> programs = new ArrayList<Program>();
- for ( Program program : programService.getPrograms( orgUnitService.getOrganisationUnit( orgId ) ) )
-
+
+ //for ( Program program : programService.getPrograms( orgUnitService.getOrganisationUnit( orgId ) ) )
+ for ( Program program : programService.getPrograms( patient.getOrganisationUnit()) )
{
if ( (program.isSingleEvent() && program.isRegistration()) || !program.isSingleEvent() )
{
@@ -1120,74 +1124,83 @@
org.hisp.dhis.api.mobile.model.LWUITmodel.Relationship enrollmentRelationship, int orgUnitId )
throws NotAllowedException
{
- String fullName = enrollmentRelationship.getPersonBName();
- int startIndex = fullName.indexOf( ' ' );
- int endIndex = fullName.lastIndexOf( ' ' );
-
- String firstName = fullName.toString();
- String middleName = " ";
- String lastName = " ";
-
- if ( fullName.indexOf( ' ' ) != -1 )
- {
- firstName = fullName.substring( 0, startIndex );
- if ( startIndex == endIndex )
- {
- middleName = " ";
- lastName = fullName.substring( startIndex + 1, fullName.length() );
- }
- else
- {
- middleName = " " + fullName.substring( startIndex + 1, endIndex ) + " ";
- lastName = fullName.substring( endIndex + 1, fullName.length() );
- }
- }
- List<Patient> patients = (List<Patient>) this.patientService.getPatientByFullname( firstName + middleName
- + lastName, orgUnitId );
-
- // remove the own searcher
- removeIfDuplicated( patients, enrollmentRelationship.getPersonAId() );
-
- if ( patients.size() > 1 )
- {
- String patientsInfo = new String();
-
- DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
-
- for ( Patient each : patients )
- {
- patientsInfo += each.getId() + "/" + each.getFullName() + "/" + dateFormat.format( each.getBirthDate() )
- + "$";
- }
-
- throw new NotAllowedException( patientsInfo );
- }
- else if ( patients.size() == 0 )
- {
- throw NotAllowedException.NO_BENEFICIARY_FOUND;
- }
- else
- {
- Patient patientB = patients.get( 0 );
- Patient patientA = patientService.getPatient( enrollmentRelationship.getPersonAId() );
- RelationshipType relationshipType = relationshipTypeService.getRelationshipType( enrollmentRelationship
- .getId() );
-
- Relationship relationship = new Relationship();
- relationship.setRelationshipType( relationshipType );
- if ( enrollmentRelationship.getChosenRelationship().equals( relationshipType.getaIsToB() ) )
- {
- relationship.setPatientA( patientA );
- relationship.setPatientB( patientB );
- }
- else
- {
- relationship.setPatientA( patientB );
- relationship.setPatientB( patientA );
- }
- relationshipService.saveRelationship( relationship );
- return getPatientModel( orgUnitId, patientA );
- }
+ Patient patientB;
+ if ( enrollmentRelationship.getPersonBId() != 0 )
+ {
+ patientB = patientService.getPatient( enrollmentRelationship.getPersonBId() );
+ }
+ else
+ {
+ String fullName = enrollmentRelationship.getPersonBName();
+ int startIndex = fullName.indexOf( ' ' );
+ int endIndex = fullName.lastIndexOf( ' ' );
+
+ String firstName = fullName.toString();
+ String middleName = " ";
+ String lastName = " ";
+
+ if ( fullName.indexOf( ' ' ) != -1 )
+ {
+ firstName = fullName.substring( 0, startIndex );
+ if ( startIndex == endIndex )
+ {
+ middleName = " ";
+ lastName = fullName.substring( startIndex + 1, fullName.length() );
+ }
+ else
+ {
+ middleName = " " + fullName.substring( startIndex + 1, endIndex ) + " ";
+ lastName = fullName.substring( endIndex + 1, fullName.length() );
+ }
+ }
+ List<Patient> patients = (List<Patient>) this.patientService.getPatientByFullname( firstName + middleName
+ + lastName, orgUnitId );
+
+ //remove the own searcher
+ patients = removeIfDuplicated( patients, enrollmentRelationship.getPersonAId());
+
+ if ( patients.size() > 1 )
+ {
+ String patientsInfo = new String();
+
+ DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
+
+ for ( Patient each : patients )
+ {
+ patientsInfo += each.getId() + "/" + each.getFullName() + "/" + dateFormat.format( each.getBirthDate() )
+ + "$";
+ }
+
+ throw new NotAllowedException( patientsInfo );
+ }
+ else if ( patients.size() == 0 )
+ {
+ throw NotAllowedException.NO_BENEFICIARY_FOUND;
+ }
+ else
+ {
+ patientB = patients.get( 0 );
+ }
+ }
+ Patient patientA = patientService.getPatient( enrollmentRelationship.getPersonAId() );
+ RelationshipType relationshipType = relationshipTypeService.getRelationshipType( enrollmentRelationship
+ .getId() );
+
+ Relationship relationship = new Relationship();
+ relationship.setRelationshipType( relationshipType );
+ if ( enrollmentRelationship.getChosenRelationship().equals( relationshipType.getaIsToB() ) )
+ {
+ relationship.setPatientA( patientA );
+ relationship.setPatientB( patientB );
+ }
+ else
+ {
+ relationship.setPatientA( patientB );
+ relationship.setPatientB( patientA );
+ }
+ relationshipService.saveRelationship( relationship );
+ //return getPatientModel( orgUnitId, patientA );
+ return getPatientModel( patientA );
}
@Override
@@ -1273,6 +1286,10 @@
anonymousProgramMobile.setId( anonymousProgram.getId() );
anonymousProgramMobile.setName( anonymousProgram.getName() );
+
+ anonymousProgramMobile.setVersion( anonymousProgram.getVersion() );
+
+ anonymousProgramMobile.setStatus( ProgramInstance.STATUS_ACTIVE );
ProgramStage programStage = anonymousProgram.getProgramStages().iterator().next();
@@ -1336,14 +1353,15 @@
private List<Patient> removeIfDuplicated( List<Patient> patients, int patientId )
{
- for ( Patient each : patients )
+ List<Patient> result = new ArrayList<Patient>(patients);
+ for ( int i = 0; i < patients.size(); i++ )
{
- if ( each.getId() == patientId )
+ if ( patients.get( i ).getId() == patientId )
{
- patients.remove( each );
+ result.remove( i );
}
}
- return patients;
+ return result;
}
private void saveDataValues( ActivityValue activityValue, ProgramStageInstance programStageInstance,
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java 2013-04-15 17:06:42 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java 2013-04-17 09:03:38 +0000
@@ -658,7 +658,7 @@
fullName = fullName.toLowerCase();
String sql = "SELECT patientid FROM patient where lower( " + statementBuilder.getPatientFullName() + ") "
+ "='" + fullName + "'";
- if ( orgunitId != null )
+ if ( orgunitId != null && orgunitId != 0 )
{
sql += " and organisationunitid=" + orgunitId;
}
=== added file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsSender.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsSender.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/outbound/SmsSender.java 2013-04-17 09:03:38 +0000
@@ -0,0 +1,189 @@
+/*
+ * Copyright (c) 2004-2012, 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.sms.outbound;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.message.MessageSender;
+import org.hisp.dhis.sms.SmsServiceException;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.user.UserSetting;
+import org.hisp.dhis.user.UserSettingService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Nguyen Kim Lai
+ *
+ * @version SmsSender.java 10:29:11 AM Apr 16, 2013 $
+ */
+public class SmsSender
+ implements MessageSender
+{
+ private static final Log log = LogFactory.getLog( SmsMessageSender.class );
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private CurrentUserService currentUserService;
+
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
+
+ private UserService userService;
+
+ public void setUserService( UserService userService )
+ {
+ this.userService = userService;
+ }
+
+ private OutboundSmsService outboundSmsService;
+
+ public void setOutboundSmsService( OutboundSmsService outboundSmsService )
+ {
+ this.outboundSmsService = outboundSmsService;
+ }
+
+ @Autowired
+ private OutboundSmsTransportService transportService;
+
+ @Override
+ public void sendMessage( String subject, String text, User sender, Set<User> users, boolean forceSend )
+ {
+ Set<User> toSendUserList = new HashSet<User>();
+
+ String gatewayId = transportService.getDefaultGateway();
+
+ if ( gatewayId != null || gatewayId.trim().length() != 0 )
+ {
+ boolean sendSMSNotification = false;
+ for ( User user : users )
+ {
+ if ( currentUserService.getCurrentUser() != user )
+ {
+ UserSetting userSetting = userService.getUserSetting( user, UserSettingService.KEY_MESSAGE_SMS_NOTIFICATION );
+ if ( userSetting != null )
+ {
+ sendSMSNotification = (Boolean) userSetting.getValue();
+ if ( sendSMSNotification == true )
+ {
+ toSendUserList.add( user );
+ sendSMSNotification = false;
+ }
+ }
+ }
+ }
+
+ Set<String> phoneNumbers = null;
+
+ if ( outboundSmsService != null || outboundSmsService.isEnabled() )
+ {
+ text = createMessage( subject, text, sender );
+
+ phoneNumbers = getRecipientsPhoneNumber( users );
+
+ if ( !phoneNumbers.isEmpty() && phoneNumbers.size() > 0 )
+ {
+ sendMessage( text, phoneNumbers, gatewayId );
+ }
+
+ }
+ }
+ }
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ private String createMessage( String subject, String text, User sender )
+ {
+ String name = "unknown";
+
+ if ( sender != null )
+ {
+ name = sender.getUsername();
+ }
+
+ if ( subject == null || subject.isEmpty() )
+ {
+ subject = "";
+ }
+ else
+ {
+ subject = " - " + subject;
+ }
+
+ text = "From " + name + subject + ": " + text;
+
+ // Simplistic cutoff 160 characters..
+ int length = text.length();
+
+ return (length > 160) ? text.substring( 0, 157 ) + "..." : text;
+ }
+
+ private Set<String> getRecipientsPhoneNumber( Set<User> users )
+ {
+ Set<String> recipients = new HashSet<String>();
+
+ for ( User user : users )
+ {
+ String phoneNumber = user.getPhoneNumber();
+
+ if ( phoneNumber != null && !phoneNumber.trim().isEmpty() )
+ {
+ recipients.add( phoneNumber );
+ }
+ }
+
+ return recipients;
+ }
+
+ private void sendMessage( String text, Set<String> recipients, String gateWayId )
+ {
+ OutboundSms sms = new OutboundSms();
+ sms.setMessage( text );
+ sms.setRecipients( recipients );
+
+ try
+ {
+ outboundSmsService.sendMessage( sms, gateWayId );
+ }
+ catch ( SmsServiceException e )
+ {
+ log.warn( "Unable to send message through sms: " + sms, e );
+ }
+
+ }
+
+}
=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java'
--- dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java 2013-01-22 08:31:21 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/java/org/hisp/dhis/sms/smslib/SmsLibService.java 2013-04-17 09:03:38 +0000
@@ -312,8 +312,7 @@
else if ( gatewayConfig instanceof SMPPGatewayConfig )
{
gatewayMap.put( SMPP_GATEWAY, gateway.getGatewayId() );
- // Service.getInstance().setInboundMessageNotification(
- // new InboundNotification() );
+ // Service.getInstance().setInboundMessageNotification( new InboundNotification() );
}
else
{
@@ -525,7 +524,7 @@
{
return null;
}
-
+
if ( getGatewayMap() == null )
{
return null;
@@ -553,7 +552,6 @@
{
gatewayId = gatewayMap.get( MODEM_GATEWAY );
}
-
return gatewayId;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml 2013-03-13 14:14:24 +0000
+++ dhis-2/dhis-services/dhis-service-sms/src/main/resources/META-INF/dhis/beans.xml 2013-04-17 09:03:38 +0000
@@ -39,6 +39,12 @@
<bean id="org.hisp.dhis.sms.outbound.SmsMessageSender" class="org.hisp.dhis.sms.outbound.SmsMessageSender">
<property name="outboundSmsService" ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
</bean>
+
+ <bean id="org.hisp.dhis.sms.outbound.SmsSender" class="org.hisp.dhis.sms.outbound.SmsSender">
+ <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+ <property name="userService" ref="org.hisp.dhis.user.UserService" />
+ <property name="outboundSmsService" ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
+ </bean>
<!-- Inbound SMS service -->
@@ -59,5 +65,5 @@
<property name="outboundSmsService" ref="org.hisp.dhis.sms.outbound.OutboundSmsService" />
<property name="registrationService" ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService" />
</bean>
-
+
</beans>
=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2013-04-10 10:07:56 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileOrganisationUnitController.java 2013-04-17 09:03:38 +0000
@@ -351,14 +351,12 @@
return activityReportingService.findPatient( keyword, id );
}
- @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/LWUIT/orgUnits/{id}/uploadProgramStage" )
+ @RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/LWUIT/orgUnits/{id}/uploadProgramStage/{patientId}" )
@ResponseBody
- public String saveProgramStage( @PathVariable
- int id, @RequestBody
- ProgramStage programStage )
+ public String saveProgramStage( @PathVariable int patientId, @PathVariable int id, @RequestBody ProgramStage programStage )
throws NotAllowedException
{
- return activityReportingService.saveProgramStage( programStage, id );
+ return activityReportingService.saveProgramStage( programStage, patientId );
}
@RequestMapping( method = RequestMethod.GET, value = "{clientVersion}/LWUIT/orgUnits/{id}/enrollProgram" )
@@ -368,7 +366,7 @@
String enrollInfo )
throws NotAllowedException
{
- return activityReportingService.enrollProgram( enrollInfo, id );
+ return activityReportingService.enrollProgram( enrollInfo );
}
@RequestMapping( method = RequestMethod.POST, value = "{clientVersion}/LWUIT/orgUnits/{id}/addRelationship" )
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/DeleteReceiveSMSAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/DeleteReceiveSMSAction.java 2013-03-13 10:11:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/incoming/DeleteReceiveSMSAction.java 2013-04-17 09:03:38 +0000
@@ -86,5 +86,4 @@
}
return SUCCESS;
}
-
}
=== modified file 'dhis-2/dhis-web/dhis-web-sms/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-sms/src/main/resources/struts.xml 2013-03-20 04:23:51 +0000
+++ dhis-2/dhis-web/dhis-web-sms/src/main/resources/struts.xml 2013-04-17 09:03:38 +0000
@@ -76,7 +76,6 @@
<param name="onExceptionReturn">plainTextError</param>
<param name="requiredAuthorities">F_MOBILE_SENDSMS</param>
</action>
-
<action name="searchAllFacilities" class="org.hisp.dhis.sms.action.NoAction">
<result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm
</result>