=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/parse/ParserType.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/parse/ParserType.java 2014-07-30 04:28:22 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sms/parse/ParserType.java 2014-12-01 02:32:57 +0000 @@ -35,5 +35,6 @@ ALERT_PARSER, UNREGISTERED_PARSER, ANONYMOUS_PROGRAM_PARSER, - TRACKED_ENTITY_REGISTRATION_PARSER + TRACKED_ENTITY_REGISTRATION_PARSER, + ADVANCE_KEY_VALUE_PARSER } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCode.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCode.java 2014-08-04 13:20:47 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCode.java 2014-12-01 02:32:57 +0000 @@ -42,6 +42,8 @@ private TrackedEntityAttribute trackedEntityAttribute; private int optionId; + + private String formula; public SMSCode( String code, DataElement dataElement, int optionId ) { @@ -110,6 +112,14 @@ { this.trackedEntityAttribute = trackedEntityAttribute; } - - + + public String getFormula() + { + return formula; + } + + public void setFormula( String formula ) + { + this.formula = formula; + } } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java 2014-09-10 04:36:51 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/smscommand/SMSCommand.java 2014-12-01 02:32:57 +0000 @@ -37,24 +37,24 @@ public class SMSCommand { - //Default message - + // Default message + public static final String WRONG_FORMAT_MESSAGE = "Wrong format for command"; - + public static final String MORE_THAN_ONE_ORGUNIT_MESSAGE = "Found more than one org unit for this number. Please specify one organisation unit"; - + public static final String NO_USER_MESSAGE = "No user associated with this phone number. Please contact your supervisor."; - + public static final String ALERT_FEEDBACK = "Your alert message sent"; - - //Completeness method code - + + // Completeness method code + public static final int RECEIVE_ALL_DATAVALUE = 1; - + public static final int RECEIVE_AT_LEAST_ONE_DATAVALUE = 2; - + public static final int DO_NOT_MARK_COMPLETE = 3; - + private int id; private String name; @@ -64,46 +64,46 @@ private ParserType parserType; private String separator; - - //Dataset + + // Dataset private DataSet dataset; private Set codes; private String codeSeparator; - - //Usergroup + + // Usergroup private UserGroup userGroup; - - //Program - + + // Program + private Program program; private Set specialCharacters; private boolean currentPeriodUsedForReporting = false; // default is prev - + private Integer completenessMethod; - - //Messages - + + // Messages + private String defaultMessage; private String receivedMessage; - + private String wrongFormatMessage; - + private String noUserMessage; - + private String moreThanOneOrgUnitMessage; - + private String successMessage; - public SMSCommand( String name, String parser, ParserType parserType, String separator, DataSet dataset, - Set codes, String codeSeparator, String defaultMessage, UserGroup userGroup, String receivedMessage, Set specialCharacters ) + Set codes, String codeSeparator, String defaultMessage, UserGroup userGroup, String receivedMessage, + Set specialCharacters ) { super(); this.name = name; === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DataValueSMSListener.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DataValueSMSListener.java 2014-08-15 07:40:20 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/sms/DataValueSMSListener.java 2014-12-01 02:32:57 +0000 @@ -47,6 +47,7 @@ import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataelement.DataElementCategoryService; +import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.dataset.CompleteDataSetRegistration; import org.hisp.dhis.dataset.CompleteDataSetRegistrationService; import org.hisp.dhis.dataset.DataSet; @@ -92,6 +93,8 @@ private IncomingSmsService incomingSmsService; + private DataElementService dataElementService; + @Transactional @Override public boolean accept( IncomingSms sms ) @@ -420,6 +423,77 @@ } } + if ( code.getFormula() != null ) + { + try + { + + // +de + String formula = code.getFormula(); + + String targetDataElementId = formula.substring( 1, formula.length() ); + String operation = String.valueOf( formula.charAt( 0 ) ); + + System.out.println( "Operation: " + operation ); + + DataElement targetDataElement = dataElementService.getDataElement( Integer + .parseInt( targetDataElementId ) ); + + if ( targetDataElement == null ) + { + return false; + } + + DataValue targetDataValue = dataValueService.getDataValue( targetDataElement, period, orgunit, + dataElementCategoryService.getDefaultDataElementCategoryOptionCombo() ); + int targetValue = 0; + boolean newTargetDataValue = false; + if ( targetDataValue == null ) + { + targetDataValue = new DataValue(); + targetDataValue.setCategoryOptionCombo( dataElementCategoryService + .getDefaultDataElementCategoryOptionCombo() ); + targetDataValue.setSource( orgunit ); + targetDataValue.setDataElement( targetDataElement ); + targetDataValue.setPeriod( period ); + targetDataValue.setComment( "" ); + newTargetDataValue = true; + } + else + { + targetValue = Integer.parseInt( targetDataValue.getValue() ); + } + + if ( operation.equals( "+" ) ) + { + targetValue = targetValue + Integer.parseInt( value ); + } + else if ( operation.equals( "-" ) ) + { + targetValue = targetValue - Integer.parseInt( value ); + } + + + targetDataValue.setValue( String.valueOf( targetValue ) ); + targetDataValue.setLastUpdated( new java.util.Date() ); + targetDataValue.setStoredBy( storedBy ); + if ( newTargetDataValue ) + { + dataValueService.addDataValue( targetDataValue ); + } + else + { + dataValueService.updateDataValue( targetDataValue ); + } + + } + catch ( Exception e ) + { + e.printStackTrace(); + return false; + } + } + return true; } @@ -586,14 +660,14 @@ } else { - if ( codesWithoutDataValues.size() > 0 ) - { - smsSender.sendMessage( reportBack + notInReport, sender ); - } - else - { - smsSender.sendMessage( reportBack, sender ); - } + // if ( codesWithoutDataValues.size() > 0 ) + // { + // smsSender.sendMessage( reportBack + notInReport, sender ); + // } + // else + // { + smsSender.sendMessage( reportBack, sender ); + // } } } @@ -711,4 +785,15 @@ { this.incomingSmsService = incomingSmsService; } + + public DataElementService getDataElementService() + { + return dataElementService; + } + + public void setDataElementService( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-11-30 10:30:06 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-12-01 02:32:57 +0000 @@ -870,6 +870,7 @@ + === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/sms/hibernate/SMSCode.hbm.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/sms/hibernate/SMSCode.hbm.xml 2014-07-30 07:07:31 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/sms/hibernate/SMSCode.hbm.xml 2014-12-01 02:32:57 +0000 @@ -12,6 +12,9 @@ + + + === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java 2014-10-23 16:38:54 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/EditSMSCommandForm.java 2014-12-01 02:32:57 +0000 @@ -56,7 +56,7 @@ // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- - + private SMSCommandService smsCommandService; public void setSmsCommandService( SMSCommandService smsCommandService ) @@ -154,6 +154,14 @@ c.setCode( x.getString( "code" ) ); c.setDataElement( dataElementService.getDataElement( x.getInt( "dataElementId" ) ) ); c.setOptionId( x.getInt( "optionId" ) ); + if ( !x.getString( "formula" ).trim().equals( "" ) ) + { + c.setFormula( x.getString( "formula" ) ); + } + else + { + c.setFormula( null ); + } codeSet.add( c ); } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/SMSCommandAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/SMSCommandAction.java 2014-10-16 06:17:19 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/java/org/hisp/dhis/mobile/action/smscommand/SMSCommandAction.java 2014-12-01 02:32:57 +0000 @@ -139,6 +139,18 @@ this.codes = codes; } + private Map formulas = new HashMap<>(); + + public Map getFormulas() + { + return formulas; + } + + public void setFormulas( Map formulas ) + { + this.formulas = formulas; + } + public ParserType[] getParserType() { return ParserType.values(); @@ -170,6 +182,11 @@ codes.put( "" + x.getDataElement().getId() + x.getOptionId(), x.getCode() ); } + if ( x.getFormula() != null ) + { + formulas.put( "" + x.getDataElement().getId() + x.getOptionId(), x.getFormula() ); + } + } } userGroupList = new ArrayList<>( userGroupService.getAllUserGroups() ); === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/command.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/command.js 2014-10-23 16:38:54 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/javascript/command.js 2014-12-01 02:32:57 +0000 @@ -50,3 +50,49 @@ { jQuery("[name=trSpecialCharacter" + rowId + "]").remove(); } + +function openFormulaForm(displayName, index) +{ + $("#displayName").html(displayName); + $("#index").val(index); + + $("#removeButton").hide(); + $('#targetDataElement option').prop('selected', false); + $('#operator option').prop('selected', false); + $("#selectedTargetDataElement").html($("#targetDataElement option:selected").text()); + + var formulaText = $("#" + "formula" + index).val(); + + if (formulaText != "") { + var operator = formulaText.substring(0,1); + var dataElementId = formulaText.substring(1,formulaText.length); + + $("#removeButton").show(); + $('#targetDataElement option[value="' + dataElementId + '"]').prop("selected", true); + $('#operator option[value="' + operator + '"]').prop("selected", true); + $("#selectedTargetDataElement").html($("#targetDataElement option:selected").text()); + } + + dialog.dialog("option", "title", "Formula Form"); + dialog.dialog("open"); +} + +function collectFormula() { + var operator = $("#operator option:selected").text(); + var deId = $("#targetDataElement option:selected").val(); + var index = $("#index").val(); + $("#addFormula" + index).val("Edit Formula"); + $("#" + "formula" + index).val(operator + "" + deId); + dialog.dialog( "close" ); +} + +function closeFormulaForm() { + dialog.dialog( "close" ); +} + +function closeAndFormulaForm() { + var index = $("#index").val(); + $("#" + "formula" + index).val(""); + $("#addFormula" + index).val("Add Formula"); + dialog.dialog( "close" ); +} === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm 2014-10-23 16:38:54 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-mobile/src/main/webapp/dhis-web-maintenance-mobile/smscommand/edit-sms-command.vm 2014-12-01 02:32:57 +0000 @@ -12,7 +12,8 @@ { selectedDataOptions += '{"dataElementId" :' + document.getElementById('codeId'+i).value.split('.')[0] + ','; selectedDataOptions += '"optionId" :' + document.getElementById('codeId'+i).value.split('.')[1] + ','; - selectedDataOptions += '"code" :"' + document.getElementById('codeValue'+i).value + '"},'; + selectedDataOptions += '"code" :"' + document.getElementById('codeValue'+i).value + '",'; + selectedDataOptions += '"formula" :"' + document.getElementById('formula'+i).value + '"},'; } selectedDataOptions += ']}'; $("#codeDataelementOption").val(selectedDataOptions); @@ -118,7 +119,15 @@ changeParserType( getFieldValue( 'parserType' ) ); validation( "updateSMSCommandForm" ); checkValueIsExist( "name", "validateSMSCommand.action", {id:"$selectedCommandID"}); + + $("#targetDataElement").change( function() { + $("#selectedTargetDataElement").html($("#targetDataElement option:selected").text()); + }); + }); + + +

$i18n.getString( "edit_command" )

@@ -235,6 +244,16 @@ + + #if($dataElement.type == "int" || $dataElement.type == "number") + #if ($formulas[$str]) + + #else + + #end + #end + + #end #else @@ -291,4 +310,46 @@ - \ No newline at end of file + + + + +
+
+ =
+
+
+
+ +
+ + + +
+
\ No newline at end of file