=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java 2011-05-30 04:34:47 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryService.java 2011-07-14 09:31:24 +0000 @@ -30,6 +30,7 @@ import java.util.Collection; import java.util.regex.Pattern; +import org.hisp.dhis.dataentryform.DataEntryForm; import org.hisp.dhis.i18n.I18n; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.patientdatavalue.PatientDataValue; @@ -42,16 +43,16 @@ public interface ProgramDataEntryService { final Pattern INPUT_PATTERN = Pattern.compile( "(", Pattern.DOTALL ); - final Pattern SELECT_PATTERN = Pattern.compile( "(", Pattern.DOTALL ); - final Pattern IDENTIFIER_PATTERN_TEXTBOX = Pattern.compile( "\"value\\[([\\p{Digit}.]*)\\].value:value\\[([\\p{Digit}.]*)\\].value:value\\[([\\p{Digit}.]*)\\].value\"" ); - final Pattern IDENTIFIER_PATTERN_BOOLEAN = Pattern.compile( "value\\[(.*)\\].boolean:value\\[(.*)\\].boolean" ); - final Pattern IDENTIFIER_PATTERN_COMBO = Pattern.compile( "\"value\\[([\\p{Digit}.]*)\\].combo:value\\[([\\p{Digit}.]*)\\].combo\"" ); - final Pattern IDENTIFIER_PATTERN_DATE = Pattern.compile( "\"value\\[([\\p{Digit}.]*)\\].date:value\\[([\\p{Digit}.]*)\\].date\"" ); - + + final Pattern IDENTIFIER_PATTERN_TEXTBOX = Pattern.compile( "id=\"(\\d+)-(\\d+)-(\\d+)-val\"" ); + final Pattern IDENTIFIER_PATTERN_OTHERS = Pattern.compile( "id=\"(\\d+)-(\\d+)-val\"" ); + //-------------------------------------------------------------------------- // ProgramDataEntryService //-------------------------------------------------------------------------- + Collection getProgramDataEntryForms(); + String prepareDataEntryFormForEntry( String htmlCode, Collection dataValues, String disabled, I18n i18n, ProgramStage programStage, ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit ); === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryStore.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramDataEntryStore.java 2011-07-14 09:31:24 +0000 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2004-2009, 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.program; + +import java.util.Collection; + +import org.hisp.dhis.dataentryform.DataEntryForm; + +/** + * @author Chau Thu Tran + * @version $ ProgramDataEntryService.java May 26, 2011 3:56:03 PM $ + * + */ +public interface ProgramDataEntryStore +{ + Collection get(); +} === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormUpgrader.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormUpgrader.java 2011-07-11 10:22:45 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormUpgrader.java 2011-07-14 09:31:24 +0000 @@ -1,61 +1,196 @@ package org.hisp.dhis.dataentryform; +import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.hisp.dhis.program.ProgramDataEntryService; import org.hisp.dhis.system.startup.AbstractStartupRoutine; import org.springframework.transaction.annotation.Transactional; /** - * Upgrades the format of the input field identifiers from the legacy "value[12].value:value[34].value" - * to the new "12-34-val" + * Upgrades the format of the input field identifiers from the legacy + * "value[12].value:value[34].value" to the new "12-34-val" */ public class DataEntryFormUpgrader extends AbstractStartupRoutine { private static final Log log = LogFactory.getLog( DataEntryFormUpgrader.class ); - + private final static String ID_EXPRESSION = "id=\"value\\[(\\d+)\\]\\.value:value\\[(\\d+)\\]\\.value\""; + private final static Pattern ID_PATTERN = Pattern.compile( ID_EXPRESSION ); - + + private final Pattern SELECT_PATTERN = Pattern.compile( "(", Pattern.DOTALL ); + + private final Pattern ID_PROGRAM_ENTRY_TEXTBOX = Pattern + .compile( "id=\"value\\[(\\d+)\\].value:value\\[(\\d+)\\].value:value\\[(\\d+)\\].value\"" ); + + private final Pattern ID_PROGRAM_ENTRY_OPTION = Pattern + .compile( "id=\"value\\[(\\d+)\\].(combo|boolean){1}:value\\[(\\d+)\\].(combo|boolean){1}\"" ); + + private final Pattern ID_PROGRAM_ENTRY_DATE = Pattern + .compile( "id=\"value\\[(\\d+)\\].date:value\\[(\\d+)\\].date\"" ); + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + private DataEntryFormService dataEntryFormService; public void setDataEntryFormService( DataEntryFormService dataEntryFormService ) { this.dataEntryFormService = dataEntryFormService; } - + + private ProgramDataEntryService programDataEntryService; + + public void setProgramDataEntryService( ProgramDataEntryService programDataEntryService ) + { + this.programDataEntryService = programDataEntryService; + } + + // ------------------------------------------------------------------------- + // Implementation method + // ------------------------------------------------------------------------- + @Transactional @Override public void execute() { + Collection dataEntryForms = dataEntryFormService.getAllDataEntryForms(); + + Collection programDataEntryForms = programDataEntryService.getProgramDataEntryForms(); + + dataEntryForms.removeAll( programDataEntryForms ); + + upgradeDataEntryForm( dataEntryForms ); + + upgradeProgramDataEntryForm( programDataEntryForms ); + } + + // ------------------------------------------------------------------------- + // Supportive methods + // ------------------------------------------------------------------------- + + private void upgradeDataEntryForm( Collection dataEntryForms ) + { int i = 0; - + for ( DataEntryForm form : dataEntryFormService.getAllDataEntryForms() ) { - Matcher matcher = ID_PATTERN.matcher( form.getHtmlCode() ); + Matcher matcher = ID_PATTERN.matcher( form.getHtmlCode() ); StringBuffer out = new StringBuffer(); - + while ( matcher.find() ) { - String upgradedId = "id=\"" + matcher.group(1) + "-" + matcher.group(2) + "-val\""; - + String upgradedId = "id=\"" + matcher.group( 1 ) + "-" + matcher.group( 2 ) + "-val\""; + matcher.appendReplacement( out, upgradedId ); - + i++; } matcher.appendTail( out ); - + form.setHtmlCode( out.toString() ); form.setHtmlCode( form.getHtmlCode().replaceAll( "view=\"@@deshortname@@\"", "" ) ); - + dataEntryFormService.updateDataEntryForm( form ); } - + log.info( "Upgraded custom data entry form identifiers: " + i ); } -} + + private void upgradeProgramDataEntryForm( Collection programDataEntryForms ) + { + int i = 0; + + for ( DataEntryForm programDataEntryForm : programDataEntryForms ) + { + String customForm = upgradeProgramDataEntryFormForTextBox( programDataEntryForm.getHtmlCode() ); + + customForm = upgradeProgramDataEntryFormForDate( customForm ); + + customForm = upgradeProgramDataEntryFormForOption( customForm ); + + programDataEntryForm.setHtmlCode( customForm ); + + dataEntryFormService.updateDataEntryForm( programDataEntryForm ); + + i++; + } + + log.info( "Upgraded custom case entry form identifiers: " + i ); + } + + private String upgradeProgramDataEntryFormForTextBox( String htmlCode ) + { + int i = 0; + + Matcher matcher = ID_PROGRAM_ENTRY_TEXTBOX.matcher( htmlCode ); + + StringBuffer out = new StringBuffer(); + + while ( matcher.find() ) + { + String upgradedId = "id=\"" + matcher.group( 1 ) + "-" + matcher.group( 2 ) + "-" + matcher.group( 3 ) + + "-val\""; + + matcher.appendReplacement( out, upgradedId ); + + i++; + } + + matcher.appendTail( out ); + + return out.toString().replaceAll( "view=\"@@deshortname@@\"", "" ); + } + + private String upgradeProgramDataEntryFormForOption( String htmlCode ) + { + StringBuffer out = new StringBuffer(); + Matcher inputMatcher = SELECT_PATTERN.matcher( htmlCode ); + + while ( inputMatcher.find() ) + { + String inputHtml = inputMatcher.group(); + + Matcher matcher = ID_PROGRAM_ENTRY_OPTION.matcher( inputHtml ); + + if ( matcher.find() ) + { + String upgradedId = matcher.group( 1 ) + "-" + matcher.group( 3 ) + "-val"; + + inputHtml = ""; + } + + inputMatcher.appendReplacement( out, inputHtml ); + } + + inputMatcher.appendTail( out ); + + return out.toString().replaceAll( "view=\"@@deshortname@@\"", "" ); + } + + private String upgradeProgramDataEntryFormForDate( String htmlCode ) + { + Matcher matcher = ID_PROGRAM_ENTRY_DATE.matcher( htmlCode ); + + StringBuffer out = new StringBuffer(); + + while ( matcher.find() ) + { + String upgradedId = "id=\"" + matcher.group( 1 ) + "-" + matcher.group( 2 ) + "-val\" "; + + matcher.appendReplacement( out, upgradedId ); + } + + matcher.appendTail( out ); + + return out.toString().replaceAll( "view=\"@@deshortname@@\"", "" ); + } +} \ No newline at end of file === 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-07-11 10:22:45 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2011-07-14 09:31:24 +0000 @@ -997,6 +997,7 @@ + === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java 2011-07-13 02:28:39 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java 2011-07-14 09:31:24 +0000 @@ -439,7 +439,7 @@ { condition = getConditionForProgramProperty( orgunitId, startDate, endDate ) + info[1]; } - else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM ) ) + else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM ) ) { condition = getConditionForProgram( info[1], orgunitId, startDate, endDate ); } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java 2011-07-06 08:04:17 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java 2011-07-14 09:31:24 +0000 @@ -38,6 +38,7 @@ import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataelement.DataElementCategoryService; import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.dataentryform.DataEntryForm; import org.hisp.dhis.i18n.I18n; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.patientdatavalue.PatientDataValue; @@ -67,6 +68,13 @@ // Dependencies // ------------------------------------------------------------------------- + private ProgramDataEntryStore programDataEntryStore; + + public void setProgramDataEntryStore( ProgramDataEntryStore programDataEntryStore ) + { + this.programDataEntryStore = programDataEntryStore; + } + private PatientDataValueService patientDataValueService; public void setPatientDataValueService( PatientDataValueService patientDataValueService ) @@ -114,6 +122,12 @@ // ------------------------------------------------------------------------- @Override + public Collection getProgramDataEntryForms() + { + return programDataEntryStore.get(); + } + + @Override public String prepareDataEntryFormForEntry( String htmlCode, Collection dataValues, String disabled, I18n i18n, ProgramStage programStage, ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit ) @@ -125,13 +139,13 @@ result = populateCustomDataEntryForTextBox( htmlCode, dataValues, disabled, i18n, programStage, programStageInstance, organisationUnit, mapDataValue ); + result = populateCustomDataEntryForDate( result, dataValues, disabled, i18n, programStage, + programStageInstance, organisationUnit, mapDataValue ); + result = populateCustomDataEntryForBoolean( result, dataValues, disabled, i18n, programStage, programStageInstance, organisationUnit, mapDataValue ); - result = populateCustomDataEntryForMutiDimentionalString( result, dataValues, disabled, i18n, programStage, - programStageInstance, organisationUnit, mapDataValue ); - - result = populateCustomDataEntryForDate( result, dataValues, disabled, i18n, programStage, + result = populateCustomDataEntryForCombo( result, dataValues, disabled, i18n, programStage, programStageInstance, organisationUnit, mapDataValue ); result = populateI18nStrings( result, i18n ); @@ -143,12 +157,10 @@ { String result = populateCustomDataEntryForTextBox( htmlCode ); - result = populateCustomDataEntryForCombo( result ); - - result = populateCustomDataEntryForBoolean( result ); - result = populateCustomDataEntryForDate( result ); + result = populateCustomDataEntryForOption( result ); + return result; } @@ -207,139 +219,77 @@ inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, displayValue ) : inputHTML + " " + displayValue; - String displayTitle = (dataElement == null || optionCombo == null) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\"" - : "title=\"-- ID:" + dataElement.getId() + " - Name:" + dataElement.getShortName() + " - " - + optionComboId + " - " + optionCombo.getName() + " - Type:" + dataElement.getType() + "\""; - inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle ) - : inputHTML + " " + displayTitle; - - inputHTML = inputHTML + ">"; - - inputMatcher.appendReplacement( sb, inputHTML ); - } - } - - inputMatcher.appendTail( sb ); - - return (sb.toString().isEmpty()) ? htmlCode : sb.toString(); - } - - private String populateCustomDataEntryForBoolean( String htmlCode ) - { - // --------------------------------------------------------------------- - // Metadata code to add to HTML before outputting - // --------------------------------------------------------------------- - - StringBuffer sb = new StringBuffer(); - - // --------------------------------------------------------------------- - // Pattern to match data elements in the HTML code - // --------------------------------------------------------------------- - - Matcher inputMatcher = SELECT_PATTERN.matcher( htmlCode ); - - // --------------------------------------------------------------------- - // Iterate through all matching data element fields - // --------------------------------------------------------------------- - - while ( inputMatcher.find() ) - { - String inputHTML = inputMatcher.group(); - inputHTML = inputHTML.replace( ">", "" ); - - // ----------------------------------------------------------------- - // Get HTML input field code - // ----------------------------------------------------------------- - - String dataElementCode = inputMatcher.group( 1 ); - - Matcher identifierMatcher = IDENTIFIER_PATTERN_BOOLEAN.matcher( dataElementCode ); - - if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 ) - { - // ------------------------------------------------------------- - // Get data element ID of data element - // ------------------------------------------------------------- - - int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) ); - DataElement dataElement = dataElementService.getDataElement( dataElementId ); - - String displayValue = (dataElement == null) ? "value=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\"" - : "value=\"[ " + dataElement.getName() + " ]\""; - inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, displayValue ) - : inputHTML + " " + displayValue; - - String displayTitle = (dataElement == null) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\"" : "title=\"-- ID:" - + dataElement.getId() + " - Name:" + dataElement.getShortName() + " - Type:" - + dataElement.getType() + "\""; - inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle ) - : inputHTML + " " + displayTitle; - - inputHTML = inputHTML + ">"; - - inputMatcher.appendReplacement( sb, inputHTML ); - } - } - - inputMatcher.appendTail( sb ); - - return (sb.toString().isEmpty()) ? htmlCode : sb.toString(); - } - - private String populateCustomDataEntryForCombo( String htmlCode ) - { - // --------------------------------------------------------------------- - // Metadata code to add to HTML before outputting - // --------------------------------------------------------------------- - - StringBuffer sb = new StringBuffer(); - - // --------------------------------------------------------------------- - // Pattern to match data elements in the HTML code - // --------------------------------------------------------------------- - - Matcher inputMatcher = SELECT_PATTERN.matcher( htmlCode ); - - // --------------------------------------------------------------------- - // Iterate through all matching data element fields - // --------------------------------------------------------------------- - - while ( inputMatcher.find() ) - { - String inputHTML = inputMatcher.group(); - - inputHTML = inputHTML.replace( ">", "" ); - - // ----------------------------------------------------------------- - // Get HTML input field code - // ----------------------------------------------------------------- - - String dataElementCode = inputMatcher.group( 1 ); - - Matcher identifierMatcher = IDENTIFIER_PATTERN_COMBO.matcher( dataElementCode ); - - if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 ) - { - // ------------------------------------------------------------- - // Get data element ID of data element - // ------------------------------------------------------------- - - int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) ); - DataElement dataElement = dataElementService.getDataElement( dataElementId ); - - String displayValue = (dataElement == null) ? "value=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\"" - : "value=\"[ " + dataElement.getName() + " ]\""; - inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, displayValue ) - : inputHTML + " " + displayValue; - - String displayTitle = (dataElement == null) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\"" : "title=\"-- ID:" - + dataElement.getId() + " - Name:" + dataElement.getShortName() + " - Type:" - + dataElement.getType() + "\""; - inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle ) - : inputHTML + " " + displayTitle; - - inputHTML = inputHTML + ">"; - + String displayTitle = (dataElement == null || optionCombo == null) ? "title=\"" + + DATA_ELEMENT_DOES_NOT_EXIST + "\"" : "title=\"" + dataElement.getId() + "." + + dataElement.getName() + "-" + optionComboId + "." + optionCombo.getName() + "-" + + dataElement.getDetailedNumberType() + "\" "; + inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle ) + : inputHTML + " " + displayTitle; + + inputHTML = inputHTML + ">"; + + inputMatcher.appendReplacement( sb, inputHTML ); + } + } + + inputMatcher.appendTail( sb ); + + return (sb.toString().isEmpty()) ? htmlCode : sb.toString(); + } + + private String populateCustomDataEntryForOption( String htmlCode ) + { + // --------------------------------------------------------------------- + // Metadata code to add to HTML before outputting + // --------------------------------------------------------------------- + + StringBuffer sb = new StringBuffer(); + + // --------------------------------------------------------------------- + // Pattern to match data elements in the HTML code + // --------------------------------------------------------------------- + + Matcher inputMatcher = INPUT_PATTERN.matcher( htmlCode ); + + // --------------------------------------------------------------------- + // Iterate through all matching data element fields + // --------------------------------------------------------------------- + + while ( inputMatcher.find() ) + { + String inputHTML = inputMatcher.group(); + inputHTML = inputHTML.replace( ">", "" ); + + // ----------------------------------------------------------------- + // Get HTML input field code + // ----------------------------------------------------------------- + + String dataElementCode = inputMatcher.group( 1 ); + + Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode ); + + if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 ) + { + // ------------------------------------------------------------- + // Get data element ID of data element + // ------------------------------------------------------------- + + int dataElementId = Integer.parseInt( identifierMatcher.group( 2 ) ); + DataElement dataElement = dataElementService.getDataElement( dataElementId ); + + String displayValue = (dataElement == null) ? "value=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\"" + : "value=\"[ " + dataElement.getName() + " ]\""; + inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, displayValue ) + : inputHTML + " " + displayValue; + + String displayTitle = (dataElement == null) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\"" + : "title=\"" + dataElement.getId() + "." + dataElement.getName() + "-" + + dataElement.getDetailedNumberType() + "\" "; + inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle ) + : inputHTML + " " + displayTitle; + + inputHTML = inputHTML + ">"; + inputMatcher.appendReplacement( sb, inputHTML ); } } @@ -370,16 +320,16 @@ while ( inputMatcher.find() ) { String inputHTML = inputMatcher.group(); - + inputHTML = inputHTML.replace( ">", "" ); - + // ----------------------------------------------------------------- // Get HTML input field code // ----------------------------------------------------------------- String dataElementCode = inputMatcher.group( 1 ); - Matcher identifierMatcher = IDENTIFIER_PATTERN_DATE.matcher( dataElementCode ); + Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode ); if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 ) { @@ -395,14 +345,14 @@ inputHTML = inputHTML.contains( EMPTY_VALUE_TAG ) ? inputHTML.replace( EMPTY_VALUE_TAG, displayValue ) : inputHTML + " " + displayValue; - String displayTitle = (dataElement == null ) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\"" - : "title=\"-- ID:" + dataElement.getId() + " - Name:" + dataElement.getShortName() + " - " - + " - Type:" + dataElement.getType() + "\""; + String displayTitle = (dataElement == null) ? "title=\"" + DATA_ELEMENT_DOES_NOT_EXIST + "\"" + : "title=\"" + dataElement.getId() + "." + dataElement.getName() + "-" + + dataElement.getDetailedNumberType() + "\" "; inputHTML = inputHTML.contains( EMPTY_TITLE_TAG ) ? inputHTML.replace( EMPTY_TITLE_TAG, displayTitle ) : inputHTML + " " + displayTitle; - + inputHTML = inputHTML + ">"; - + inputMatcher.appendReplacement( sb, inputHTML ); } } @@ -421,11 +371,7 @@ // Inline Javascript to add to HTML before outputting // --------------------------------------------------------------------- - final String jsCodeForInputs = " $DISABLED onchange=\"saveValueCustom( this )\" data=\"{compulsory:$COMPULSORY, optionComboId:$OPTIONCOMBOID, dataElementId:$DATAELEMENTID, dataElementName:'$DATAELEMENTNAME', dataElementType:'$DATAELEMENTTYPE', programStageId:$PROGRAMSTAGEID, programStageName: '$PROGRAMSTAGENAME', orgUnitName:'$ORGUNITNAME'}\" onkeypress=\"return keyPress(event, this)\" "; - - // --------------------------------------------------------------------- - // Metadata code to add to HTML before outputting - // --------------------------------------------------------------------- + final String jsCodeForInputs = " $DISABLED onchange=\"saveVal( $DATAELEMENTID, $OPTIONCOMBOID )\" data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', deType:'$DATAELEMENTTYPE'}\" onkeypress=\"return keyPress(event, this)\" style=\" text-align:center;\" "; StringBuffer sb = new StringBuffer(); @@ -493,13 +439,13 @@ { continue; } - + if ( !DataElement.VALUE_TYPE_INT.equals( dataElement.getType() ) && !DataElement.VALUE_TYPE_STRING.equals( dataElement.getType() ) ) { continue; } - + // ------------------------------------------------------------- // Find type of data element // ------------------------------------------------------------- @@ -550,13 +496,25 @@ { dataElementCode += "value=\"" + dataElementValue + "\""; } - - // ------------------------------------------------------------- - // Remove placeholder view attribute from input field - // ------------------------------------------------------------- - - dataElementCode = dataElementCode.replaceAll( "view=\".*?\"", "" ); - + + // ------------------------------------------------------------- + // Insert title information - Data element id, name, type, min, + // max + // ------------------------------------------------------------- + DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo( optionComboId ); + + if ( dataElementCode.contains( "title=\"\"" ) ) + { + dataElementCode = dataElementCode.replace( "title=\"\"", "title=\"" + dataElement.getId() + + "." + dataElement.getName() +"-" + + optionComboId + optionCombo.getName() + "-" + dataElementType + "\" " ); + } + else + { + dataElementCode += "title=\"" + dataElement.getId() + "." + dataElement.getName() + +"-" + optionComboId + optionCombo.getName() + "-" + dataElementType + "\" "; + } + // ------------------------------------------------------------- // Append Javascript code and meta data (type/min/max) for // persisting to output code, and insert value and type for @@ -568,7 +526,7 @@ appendCode += jsCodeForInputs; appendCode += " />"; - + // ----------------------------------------------------------- // Check if this dataElement is from another programStage then // disable @@ -583,7 +541,6 @@ // ----------------------------------------------------------- appendCode = addProvidedByOtherFacilityCheckbox( appendCode, patientDataValue ); - } else { @@ -637,21 +594,15 @@ // Inline Javascript to add to HTML before outputting // --------------------------------------------------------------------- - final String jsCodeForBoolean = " name=\"entryselect\" data=\"{compulsory:$COMPULSORY, dataElementId:$DATAELEMENTID, dataElementName:'$DATAELEMENTNAME', dataElementType:'$DATAELEMENTTYPE', programStageId:$PROGRAMSTAGEID, programStageName: '$PROGRAMSTAGENAME', orgUnitName:'$ORGUNITNAME'}\" $DISABLED onchange=\"saveChoiceCustom( $PROGRAMSTAGEID, $DATAELEMENTID,this)\""; - - // --------------------------------------------------------------------- - // Metadata code to add to HTML before outputting - // --------------------------------------------------------------------- - - final String metaDataCode = "$DATAELEMENTNAME" - + "$DATAELEMENTTYPE"; + final String jsCodeForBoolean = " name=\"entryselect\" $DISABLED data=\"{compulsory:$COMPULSORY}\" onchange=\"saveOpt( $DATAELEMENTID )\" style=\" text-align:center;\" "; + StringBuffer sb = new StringBuffer(); // --------------------------------------------------------------------- // Pattern to match data elements in the HTML code // --------------------------------------------------------------------- - Matcher dataElementMatcher = SELECT_PATTERN.matcher( dataEntryFormCode ); + Matcher dataElementMatcher = INPUT_PATTERN.matcher( dataEntryFormCode ); // --------------------------------------------------------------------- // Iterate through all matching data element fields @@ -667,7 +618,7 @@ String compulsory = "null"; String dataElementCode = dataElementMatcher.group( 1 ); - Matcher identifierMatcher = IDENTIFIER_PATTERN_BOOLEAN.matcher( dataElementCode ); + Matcher identifierMatcher = IDENTIFIER_PATTERN_OTHERS.matcher( dataElementCode ); if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 ) { // ------------------------------------------------------------- @@ -716,7 +667,7 @@ // Find type of data element // ------------------------------------------------------------- - String dataElementType = dataElement.getType(); + String dataElementType = dataElement.getDetailedNumberType(); // ------------------------------------------------------------- // Find existing value of data element in data set @@ -754,16 +705,35 @@ } } - String appendCode = dataElementCode; + String appendCode = dataElementCode.replaceFirst( "input", "select" ); appendCode = appendCode.replace( "name=\"entryselect\"", jsCodeForBoolean ); + + // ------------------------------------------------------------- + // Add title + // ------------------------------------------------------------- + if ( dataElementCode.contains( "title=\"\"" ) ) + { + appendCode = appendCode.replace( "title=\"\"", "title=\"" + dataElement.getId() + + "." + dataElement.getName() + "-" + dataElementType + "\" " ); + } + else + { + appendCode += "title=\"" + dataElement.getId() + "." + dataElement.getName() + + "-" + dataElementType + "\" "; + } + + appendCode += ">"; + appendCode += ""; + appendCode += ""; + appendCode += ""; + // ------------------------------------------------------------- // Insert value of data element in output code // ------------------------------------------------------------- if ( patientDataValue != null ) { - if ( dataElementValue.equalsIgnoreCase( "true" ) ) { appendCode = appendCode.replace( "