=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java 2010-12-23 11:56:44 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java 2011-05-07 22:48:54 +0000 @@ -94,6 +94,15 @@ * @return htmlCode. */ String prepareDataEntryFormCode( String preparedCode ); + + /** + * Prepares the data entry form code by injecting the dataElement name and + * and title for each entry field. + * + * @param htmlCode HTML code of the data entry form. + * @return HTML code for the data entry form injected with data element names. + */ + String prepareDataEntryFormForEdit( String htmlCode ); Collection listDisctinctDataEntryFormByProgramStageIds( List programStageIds ); === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java 2010-12-23 11:56:44 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java 2011-05-07 22:48:54 +0000 @@ -32,6 +32,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +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.system.util.Filter; import org.hisp.dhis.system.util.FilterUtils; import org.springframework.transaction.annotation.Transactional; @@ -44,6 +48,8 @@ public class DefaultDataEntryFormService implements DataEntryFormService { + private static final Pattern IDENTIFIER_PATTERN = Pattern.compile( "value\\[(.*)\\].value:value\\[(.*)\\].value" ); + // ------------------------------------------------------------------------ // Dependencies // ------------------------------------------------------------------------ @@ -55,6 +61,20 @@ this.dataEntryFormStore = dataEntryFormStore; } + private DataElementCategoryService categoryService; + + public void setCategoryService( DataElementCategoryService categoryService ) + { + this.categoryService = categoryService; + } + + private DataElementService dataElementService; + + public void setDataElementService( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + // ------------------------------------------------------------------------ // Implemented Methods // ------------------------------------------------------------------------ @@ -164,6 +184,124 @@ return sb.toString(); } + public String prepareDataEntryFormForEdit( String htmlCode ) + { + // --------------------------------------------------------------------- + // Buffer to contain the final result. + // --------------------------------------------------------------------- + + StringBuffer sb = new StringBuffer(); + + // --------------------------------------------------------------------- + // Pattern to match data elements in the HTML code. + // --------------------------------------------------------------------- + + Pattern patDataElement = Pattern.compile( "(" ); + Matcher matDataElement = patDataElement.matcher( htmlCode ); + + // --------------------------------------------------------------------- + // Iterate through all matching data element fields. + // --------------------------------------------------------------------- + + while ( matDataElement.find() ) + { + // ----------------------------------------------------------------- + // Get input HTML code + // ----------------------------------------------------------------- + + String dataElementCode = matDataElement.group( 1 ); + + // ----------------------------------------------------------------- + // Pattern to extract data element ID from data element field + // ----------------------------------------------------------------- + + Matcher dataElementMatcher = IDENTIFIER_PATTERN.matcher( dataElementCode ); + + if ( dataElementMatcher.find() && dataElementMatcher.groupCount() > 0 ) + { + // ------------------------------------------------------------- + // Get data element id,name, optionCombo id,name of data element + // ------------------------------------------------------------- + + int dataElementId = Integer.parseInt( dataElementMatcher.group( 1 ) ); + DataElement dataElement = dataElementService.getDataElement( dataElementId ); + + int optionComboId = Integer.parseInt( dataElementMatcher.group( 2 ) ); + DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo( optionComboId ); + String optionComboName = optionCombo != null ? optionCombo.getName() : ""; + + // ------------------------------------------------------------- + // Insert name of data element in output code + // ------------------------------------------------------------- + + String displayValue = "Data element does not exist"; + + if ( dataElement != null ) + { + displayValue = dataElement.getShortName() + " " + optionComboName; + + if ( dataElementCode.contains( "value=\"\"" ) ) + { + dataElementCode = dataElementCode.replace( "value=\"\"", "value=\"[ " + displayValue + " ]\"" ); + } + else + { + dataElementCode += " value=\"[ " + displayValue + " ]\""; + } + + StringBuilder title = new StringBuilder( "title=\"" ).append( dataElement.getId() ).append( " - " ). + append( dataElement.getName() ).append( " - " ).append( optionComboId ).append( " - " ). + append( optionComboName ).append( " - " ).append( dataElement.getType() ).append( "\"" ); + + if ( dataElementCode.contains( "title=\"\"" ) ) + { + dataElementCode = dataElementCode.replace( "title=\"\"", title ); + } + else + { + dataElementCode += " " + title; + } + } + else + { + if ( dataElementCode.contains( "value=\"\"" ) ) + { + dataElementCode = dataElementCode.replace( "value=\"\"", "value=\"[ " + displayValue + " ]\"" ); + } + else + { + dataElementCode += " value=\"[ " + displayValue + " ]\""; + } + + if ( dataElementCode.contains( "title=\"\"" ) ) + { + dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"" + displayValue + "\"" ); + } + else + { + dataElementCode += " title=\"" + displayValue + "\""; + } + } + + // ------------------------------------------------------------- + // Appends dataElementCode + // ------------------------------------------------------------- + + String appendCode = dataElementCode; + appendCode += "/>"; + matDataElement.appendReplacement( sb, appendCode ); + } + } + + // --------------------------------------------------------------------- + // Add remaining code (after the last match), and return formatted code + // --------------------------------------------------------------------- + + matDataElement.appendTail( sb ); + + return sb.toString(); + } + public Collection listDisctinctDataEntryFormByProgramStageIds( List programStageIds ) { if ( programStageIds == null || programStageIds.isEmpty() ) === 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 2011-04-23 18:52:44 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2011-05-07 22:48:54 +0000 @@ -308,8 +308,9 @@ - + + + === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java 2011-05-07 22:34:06 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/ViewDataEntryFormAction.java 2011-05-07 22:48:54 +0000 @@ -30,16 +30,12 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataelement.DataElementCategoryService; import org.hisp.dhis.dataelement.DataElementOperand; -import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.dataelement.comparator.DataElementOperandNameComparator; import org.hisp.dhis.dataentryform.DataEntryForm; +import org.hisp.dhis.dataentryform.DataEntryFormService; import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.user.UserSettingService; @@ -53,8 +49,6 @@ public class ViewDataEntryFormAction implements Action { - private static final Pattern IDENTIFIER_PATTERN = Pattern.compile( "value\\[(.*)\\].value:value\\[(.*)\\].value" ); - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -66,13 +60,6 @@ this.dataSetService = dataSetService; } - private DataElementService dataElementService; - - public void setDataElementService( DataElementService dataElementService ) - { - this.dataElementService = dataElementService; - } - private DataElementCategoryService dataElementCategoryService; public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService ) @@ -86,6 +73,13 @@ { this.userSettingService = userSettingService; } + + private DataEntryFormService dataEntryFormService; + + public void setDataEntryFormService( DataEntryFormService dataEntryFormService ) + { + this.dataEntryFormService = dataEntryFormService; + } // ------------------------------------------------------------------------- // Getters & Setters @@ -144,7 +138,7 @@ dataEntryForm = dataSet.getDataEntryForm(); - dataEntryValue = dataEntryForm != null ? prepareDataEntryFormForEdit( dataEntryForm.getHtmlCode() ) : ""; + dataEntryValue = dataEntryForm != null ? dataEntryFormService.prepareDataEntryFormForEdit( dataEntryForm.getHtmlCode() ) : ""; autoSave = (Boolean) userSettingService.getUserSetting( UserSettingService.AUTO_SAVE_DATA_ENTRY_FORM, false ); @@ -154,129 +148,4 @@ return SUCCESS; } - - /** - * Prepares the data entry form code by injecting the dataElement name and - * and title for each entry field. - * - * @param htmlCode HTML code of the data entry form. - * @return HTML code for the data entry form injected with data element names. - */ - private String prepareDataEntryFormForEdit( String htmlCode ) - { - // --------------------------------------------------------------------- - // Buffer to contain the final result. - // --------------------------------------------------------------------- - - StringBuffer sb = new StringBuffer(); - - // --------------------------------------------------------------------- - // Pattern to match data elements in the HTML code. - // --------------------------------------------------------------------- - - Pattern patDataElement = Pattern.compile( "(" ); - Matcher matDataElement = patDataElement.matcher( htmlCode ); - - // --------------------------------------------------------------------- - // Iterate through all matching data element fields. - // --------------------------------------------------------------------- - - while ( matDataElement.find() ) - { - // ----------------------------------------------------------------- - // Get input HTML code - // ----------------------------------------------------------------- - - String dataElementCode = matDataElement.group( 1 ); - - // ----------------------------------------------------------------- - // Pattern to extract data element ID from data element field - // ----------------------------------------------------------------- - - Matcher dataElementMatcher = IDENTIFIER_PATTERN.matcher( dataElementCode ); - - if ( dataElementMatcher.find() && dataElementMatcher.groupCount() > 0 ) - { - // ------------------------------------------------------------- - // Get data element id,name, optionCombo id,name of data element - // ------------------------------------------------------------- - - int dataElementId = Integer.parseInt( dataElementMatcher.group( 1 ) ); - DataElement dataElement = dataElementService.getDataElement( dataElementId ); - - int optionComboId = Integer.parseInt( dataElementMatcher.group( 2 ) ); - DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo( optionComboId ); - String optionComboName = optionCombo != null ? optionCombo.getName() : ""; - - // ------------------------------------------------------------- - // Insert name of data element in output code - // ------------------------------------------------------------- - - String displayValue = "Data element does not exist"; - - if ( dataElement != null ) - { - displayValue = dataElement.getShortName() + " " + optionComboName; - - if ( dataElementCode.contains( "value=\"\"" ) ) - { - dataElementCode = dataElementCode.replace( "value=\"\"", "value=\"[ " + displayValue + " ]\"" ); - } - else - { - dataElementCode += " value=\"[ " + displayValue + " ]\""; - } - - StringBuilder title = new StringBuilder( "title=\"" ).append( dataElement.getId() ).append( " - " ). - append( dataElement.getName() ).append( " - " ).append( optionComboId ).append( " - " ). - append( optionComboName ).append( " - " ).append( dataElement.getType() ).append( "\"" ); - - if ( dataElementCode.contains( "title=\"\"" ) ) - { - dataElementCode = dataElementCode.replace( "title=\"\"", title ); - } - else - { - dataElementCode += " " + title; - } - } - else - { - if ( dataElementCode.contains( "value=\"\"" ) ) - { - dataElementCode = dataElementCode.replace( "value=\"\"", "value=\"[ " + displayValue + " ]\"" ); - } - else - { - dataElementCode += " value=\"[ " + displayValue + " ]\""; - } - - if ( dataElementCode.contains( "title=\"\"" ) ) - { - dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"" + displayValue + "\"" ); - } - else - { - dataElementCode += " title=\"" + displayValue + "\""; - } - } - - // ------------------------------------------------------------- - // Appends dataElementCode - // ------------------------------------------------------------- - - String appendCode = dataElementCode; - appendCode += "/>"; - matDataElement.appendReplacement( sb, appendCode ); - } - } - - // --------------------------------------------------------------------- - // Add remaining code (after the last match), and return formatted code - // --------------------------------------------------------------------- - - matDataElement.appendTail( sb ); - - return sb.toString(); - } } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml 2011-04-27 16:07:05 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/resources/META-INF/dhis/beans.xml 2011-05-07 22:48:54 +0000 @@ -304,15 +304,15 @@ - - - + + +