dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #11988
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3538: Merged DataEntryScreenManager into DataEntryFormService in service layer
------------------------------------------------------------
revno: 3538
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-05-08 01:05:00 +0200
message:
Merged DataEntryScreenManager into DataEntryFormService in service layer
removed:
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DataEntryScreenManager.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/FormAction.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.java
--
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/dataentryform/DataEntryFormService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java 2011-05-07 22:48:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java 2011-05-07 23:05:00 +0000
@@ -29,6 +29,12 @@
import java.util.Collection;
import java.util.List;
+import java.util.Map;
+
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.minmax.MinMaxDataElement;
/**
* @author Bharath Kumar
@@ -89,21 +95,37 @@
Collection<DataEntryForm> getDataEntryForms( final Collection<Integer> identifiers );
/**
- * Prepare DataEntryForm code
+ * Prepare DataEntryForm code.
*
- * @return htmlCode.
+ * @return htmlCode the HTML code of the data entry form.
*/
- String prepareDataEntryFormCode( String preparedCode );
+ String prepareDataEntryFormCode( String htmlCode );
/**
- * Prepares the data entry form code by injecting the dataElement name and
+ * Prepares the data entry form code by injecting the data element name and
* and title for each entry field.
*
- * @param htmlCode HTML code of the data entry form.
+ * @param htmlCode the HTML code of the data entry form.
* @return HTML code for the data entry form injected with data element names.
*/
String prepareDataEntryFormForEdit( String htmlCode );
+ /**
+ * Prepares the data entry form for data entry by injecting required javascripts
+ * and drop down lists.
+ *
+ * @param htmlCode the HTML code of the data entry form.
+ * @param dataValues the data values which are registered for this form.
+ * @param minMaxMap a map with data element operand identifier as key and
+ * corresponding min max data element as value.
+ * @param disabled whether this form is disabled for entry.
+ * @param i18n the i18n object.
+ * @param dataSet the data set associated with this form.
+ * @return HTML code for the form.
+ */
+ String prepareDataEntryFormForEntry( String htmlCode,
+ Collection<DataValue> dataValues, Map<String, MinMaxDataElement> minMaxMap, String disabled, I18n i18n, DataSet dataSet );
+
Collection<DataEntryForm> listDisctinctDataEntryFormByProgramStageIds( List<Integer> programStageIds );
Collection<DataEntryForm> listDisctinctDataEntryFormByDataSetIds( List<Integer> dataSetIds );
=== 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 2011-05-07 22:48:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java 2011-05-07 23:05:00 +0000
@@ -27,8 +27,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_BOOL;
+import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
+import static org.hisp.dhis.datavalue.DataValue.FALSE;
+import static org.hisp.dhis.datavalue.DataValue.TRUE;
+
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -36,6 +43,10 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.minmax.MinMaxDataElement;
import org.hisp.dhis.system.util.Filter;
import org.hisp.dhis.system.util.FilterUtils;
import org.springframework.transaction.annotation.Transactional;
@@ -49,6 +60,8 @@
implements DataEntryFormService
{
private static final Pattern IDENTIFIER_PATTERN = Pattern.compile( "value\\[(.*)\\].value:value\\[(.*)\\].value" );
+ private static final Pattern DATAELEMENT_PATTERN = Pattern.compile( "(<input.*?)[/]?>", Pattern.DOTALL );
+ private static final String EMPTY = "";
// ------------------------------------------------------------------------
// Dependencies
@@ -109,7 +122,7 @@
return dataEntryFormStore.getAllDataEntryForms();
}
- public String prepareDataEntryFormCode( String preparedCode )
+ public String prepareDataEntryFormCode( String htmlCode )
{
// ---------------------------------------------------------------------
// Buffer to contain the final result.
@@ -122,7 +135,7 @@
// ---------------------------------------------------------------------
Pattern patDataElement = Pattern.compile( "(<input.*?)[/]?>" );
- Matcher matDataElement = patDataElement.matcher( preparedCode );
+ Matcher matDataElement = patDataElement.matcher( htmlCode );
// ---------------------------------------------------------------------
// Iterate through all matching data element fields.
@@ -301,7 +314,203 @@
return sb.toString();
}
-
+
+ public String prepareDataEntryFormForEntry( String htmlCode,
+ Collection<DataValue> dataValues, Map<String, MinMaxDataElement> minMaxMap, String disabled, I18n i18n, DataSet dataSet )
+ {
+ // ---------------------------------------------------------------------
+ // Inline Javascript to add to HTML before outputting
+ // ---------------------------------------------------------------------
+
+ int i = 1;
+ final String jsCodeForInputFields = " name=\"entryfield\" $DISABLED onchange=\"saveValue( $DATAELEMENTID, $OPTIONCOMBOID, '$DATAELEMENTNAME' )\" style=\"text-align:center\" onkeyup=\"return keyPress(event, this)\" ";
+ final String jsCodeForSelectLists = " name=\"entryfield\" $DISABLED onchange=\"saveBoolean( $DATAELEMENTID, $OPTIONCOMBOID, this )\" onkeyup=\"return keyPress(event, this)\" >";
+ final String historyCode = " ondblclick='javascript:viewHistory( $DATAELEMENTID, $OPTIONCOMBOID, true )' ";
+
+ // ---------------------------------------------------------------------
+ // Metadata code to add to HTML before outputting
+ // ---------------------------------------------------------------------
+
+ final String metaDataCode = "<span id=\"value[$DATAELEMENTID].name\" style=\"display:none\">$DATAELEMENTNAME</span>"
+ + "<span id=\"value[$DATAELEMENTID].type\" style=\"display:none\">$DATAELEMENTTYPE</span>"
+ + "<div id=\"value[$DATAELEMENTID:$OPTIONCOMBOID].min\" style=\"display:none\">$MIN</div>"
+ + "<div id=\"value[$DATAELEMENTID:$OPTIONCOMBOID].max\" style=\"display:none\">$MAX</div>";
+
+ StringBuffer sb = new StringBuffer();
+
+ Matcher dataElementMatcher = DATAELEMENT_PATTERN.matcher( htmlCode );
+
+ // ---------------------------------------------------------------------
+ // Iterate through all matching data element fields
+ // ---------------------------------------------------------------------
+
+ Map<Integer, DataElement> dataElementMap = getDataElementMap( dataSet );
+
+ while ( dataElementMatcher.find() )
+ {
+ // -----------------------------------------------------------------
+ // Get HTML input field code
+ // -----------------------------------------------------------------
+
+ String dataElementCode = dataElementMatcher.group( 1 );
+
+ Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( dataElementCode );
+
+ if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
+ {
+ // -------------------------------------------------------------
+ // Get data element ID of data element
+ // -------------------------------------------------------------
+
+ int dataElementId = Integer.parseInt( identifierMatcher.group( 1 ) );
+ int optionComboId = Integer.parseInt( identifierMatcher.group( 2 ) );
+
+ DataElement dataElement = dataElementMap.get( dataElementId );
+
+ if ( dataElement == null )
+ {
+ return "Data Element Id :" + dataElementId + " not found in this data set";
+ }
+
+ // -------------------------------------------------------------
+ // Find value type of data element
+ // -------------------------------------------------------------
+
+ String dataElementValueType = dataElement.getType();
+
+ // -------------------------------------------------------------
+ // Find existing value of data element in data set
+ // -------------------------------------------------------------
+
+ String dataElementValue = getValue( dataValues, dataElementId, optionComboId );
+
+ // -------------------------------------------------------------
+ // Insert value of data element in output code
+ // -------------------------------------------------------------
+
+ if ( dataElement.getType().equals( DataElement.VALUE_TYPE_BOOL ) )
+ {
+ dataElementCode = dataElementCode.replace( "input", "select" );
+ dataElementCode = dataElementCode.replaceAll( "value=\".*?\"", "" );
+ }
+ else
+ {
+ if ( dataElementCode.contains( "value=\"\"" ) )
+ {
+ dataElementCode = dataElementCode.replace( "value=\"\"", "value=\"" + dataElementValue + "\"" );
+ }
+ else
+ {
+ dataElementCode += "value=\"" + dataElementValue + "\"";
+ }
+ }
+
+ // -------------------------------------------------------------
+ // Min-max values
+ // -------------------------------------------------------------
+
+ MinMaxDataElement minMaxDataElement = minMaxMap.get( dataElement.getId() + ":" + optionComboId );
+ String minValue = "No Min";
+ String maxValue = "No Max";
+
+ if ( minMaxDataElement != null )
+ {
+ minValue = String.valueOf( minMaxDataElement.getMin() );
+ maxValue = String.valueOf( minMaxDataElement.getMax() );
+ }
+
+ dataElementCode = dataElementCode.replaceAll( "view=\".*?\"", "" ); // For backwards compatibility
+
+ // -------------------------------------------------------------
+ // Insert title info
+ // -------------------------------------------------------------
+
+ StringBuilder title = new StringBuilder( "title=\"Name: " ).append( dataElement.getShortName() ).
+ append( " Type: " ).append( dataElement.getType() ).append( " Min: " ).append( minValue ).
+ append( " Max: " ).append( maxValue ).append( "\"" );
+
+ if ( dataElementCode.contains( "title=\"\"" ) )
+ {
+ dataElementCode = dataElementCode.replace( "title=\"\"", title );
+ }
+ else
+ {
+ dataElementCode += " " + title;
+ }
+
+ // -------------------------------------------------------------
+ // Append Javascript code and meta data (type/min/max) for
+ // persisting to output code, and insert value and type for
+ // fields
+ // -------------------------------------------------------------
+
+ String appendCode = dataElementCode;
+
+ if ( dataElement.getType().equals( VALUE_TYPE_BOOL ) )
+ {
+ appendCode += jsCodeForSelectLists + "tabindex=\"" + i++ + "\"";
+
+ appendCode += "<option value=\"\">" + i18n.getString( "no_value" ) + "</option>";
+
+ if ( dataElementValue.equals( TRUE ) )
+ {
+ appendCode += "<option value=\"true\" selected>" + i18n.getString( "yes" ) + "</option>";
+ }
+ else
+ {
+ appendCode += "<option value=\"true\">" + i18n.getString( "yes" ) + "</option>";
+ }
+
+ if ( dataElementValue.equals( FALSE ) )
+ {
+ appendCode += "<option value=\"false\" selected>" + i18n.getString( "no" ) + "</option>";
+ }
+ else
+ {
+ appendCode += "<option value=\"false\">" + i18n.getString( "no" ) + "</option>";
+ }
+
+ appendCode += "</select>";
+ }
+ else
+ {
+ appendCode += jsCodeForInputFields + "tabindex=\"" + i++ + "\"";
+
+ if ( dataElement.getType().equals( VALUE_TYPE_INT ) )
+ {
+ appendCode += historyCode;
+ }
+
+ appendCode += " />";
+ }
+
+ appendCode += metaDataCode;
+ appendCode = appendCode.replace( "$DATAELEMENTID", String.valueOf( dataElementId ) );
+ appendCode = appendCode.replace( "$DATAELEMENTNAME", dataElement.getName() );
+ appendCode = appendCode.replace( "$DATAELEMENTTYPE", dataElementValueType );
+ appendCode = appendCode.replace( "$OPTIONCOMBOID", String.valueOf( optionComboId ) );
+ appendCode = appendCode.replace( "$DISABLED", disabled );
+
+ if ( minMaxDataElement == null )
+ {
+ appendCode = appendCode.replace( "$MIN", minValue );
+ appendCode = appendCode.replace( "$MAX", maxValue );
+ }
+ else
+ {
+ appendCode = appendCode.replace( "$MIN", String.valueOf( minMaxDataElement.getMin() ) );
+ appendCode = appendCode.replace( "$MAX", String.valueOf( minMaxDataElement.getMax() ) );
+ }
+
+ dataElementMatcher.appendReplacement( sb, appendCode );
+ }
+ }
+
+ dataElementMatcher.appendTail( sb );
+
+ return sb.toString();
+ }
+
public Collection<DataEntryForm> listDisctinctDataEntryFormByProgramStageIds( List<Integer> programStageIds )
{
if ( programStageIds == null || programStageIds.isEmpty() )
@@ -334,5 +543,42 @@
}
} );
}
-
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Returns the value of the DataValue in the Collection of DataValues with
+ * the given data element identifier and category option combo id.
+ */
+ private String getValue( Collection<DataValue> dataValues, int dataElementId, int categoryOptionComboId )
+ {
+ for ( DataValue dataValue : dataValues )
+ {
+ if ( dataValue.getDataElement().getId() == dataElementId
+ && dataValue.getOptionCombo().getId() == categoryOptionComboId )
+ {
+ return dataValue.getValue();
+ }
+ }
+
+ return EMPTY;
+ }
+
+ /**
+ * Returns a Map of all DataElements in the given DataSet where the key is
+ * the DataElement identifier and the value is the DataElement.
+ */
+ private Map<Integer, DataElement> getDataElementMap( DataSet dataSet )
+ {
+ Map<Integer, DataElement> map = new HashMap<Integer, DataElement>();
+
+ for ( DataElement element : dataSet.getDataElements() )
+ {
+ map.put( element.getId(), element );
+ }
+
+ return map;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/FormAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/FormAction.java 2011-05-07 13:38:00 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/FormAction.java 2011-05-07 23:05:00 +0000
@@ -44,13 +44,13 @@
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dataelement.comparator.DataElementSortOrderComparator;
import org.hisp.dhis.dataentryform.DataEntryForm;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
import org.hisp.dhis.datalock.DataSetLock;
import org.hisp.dhis.datalock.DataSetLockService;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.datavalue.DataValueService;
import org.hisp.dhis.de.comments.StandardCommentsManager;
-import org.hisp.dhis.de.screen.DataEntryScreenManager;
import org.hisp.dhis.de.state.SelectedStateManager;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.minmax.MinMaxDataElement;
@@ -107,11 +107,11 @@
this.selectedStateManager = selectedStateManager;
}
- private DataEntryScreenManager dataEntryScreenManager;
+ private DataEntryFormService dataEntryFormService;
- public void setDataEntryScreenManager( DataEntryScreenManager dataEntryScreenManager )
+ public void setDataEntryFormService( DataEntryFormService dataEntryFormService )
{
- this.dataEntryScreenManager = dataEntryScreenManager;
+ this.dataEntryFormService = dataEntryFormService;
}
private DataElementCategoryService categoryService;
@@ -474,7 +474,7 @@
if ( cdeFormExists )
{
- customDataEntryFormCode = dataEntryScreenManager.populateCustomDataEntryScreenForMultiDimensional(
+ customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry(
dataEntryForm.getHtmlCode(), dataValues, minMaxMap, disabled, i18n, dataSet );
}
=== removed directory 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen'
=== removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DataEntryScreenManager.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DataEntryScreenManager.java 2011-01-25 14:49:09 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DataEntryScreenManager.java 1970-01-01 00:00:00 +0000
@@ -1,45 +0,0 @@
-package org.hisp.dhis.de.screen;
-
-/*
- * Copyright (c) 2004-2010, 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.
- */
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.datavalue.DataValue;
-import org.hisp.dhis.i18n.I18n;
-import org.hisp.dhis.minmax.MinMaxDataElement;
-
-/**
- * @author Abyot Asalefew
- * @version $Id$
- */
-public interface DataEntryScreenManager
-{
- String populateCustomDataEntryScreenForMultiDimensional( String dataEntryFormCode, Collection<DataValue> dataValues, Map<String, MinMaxDataElement> minMaxMap, String disabled, I18n i18n, DataSet dataSet );
-}
=== removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java 2011-05-07 22:34:06 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java 1970-01-01 00:00:00 +0000
@@ -1,300 +0,0 @@
-package org.hisp.dhis.de.screen;
-
-/*
- * Copyright (c) 2004-2010, 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.
- */
-
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_BOOL;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
-import static org.hisp.dhis.datavalue.DataValue.TRUE;
-import static org.hisp.dhis.datavalue.DataValue.FALSE;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-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.dataelement.DataElement;
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.datavalue.DataValue;
-import org.hisp.dhis.i18n.I18n;
-import org.hisp.dhis.minmax.MinMaxDataElement;
-
-/**
- * @author Abyot Asalefew
- * @version $Id$
- */
-public class DefaultDataEntryScreenManager
- implements DataEntryScreenManager
-{
- private static final Log log = LogFactory.getLog( DefaultDataEntryScreenManager.class );
-
- private static final String EMPTY = "";
- private static final Pattern DATAELEMENT_PATTERN = Pattern.compile( "(<input.*?)[/]?>", Pattern.DOTALL );
- private static final Pattern IDENTIFIER_PATTERN = Pattern.compile( "value\\[(.*)\\].value:value\\[(.*)\\].value" );
-
- // -------------------------------------------------------------------------
- // DataEntryScreenManager implementation
- // -------------------------------------------------------------------------
-
- public String populateCustomDataEntryScreenForMultiDimensional( String dataEntryFormCode,
- Collection<DataValue> dataValues, Map<String, MinMaxDataElement> minMaxMap, String disabled, I18n i18n, DataSet dataSet )
- {
- // ---------------------------------------------------------------------
- // Inline Javascript to add to HTML before outputting
- // ---------------------------------------------------------------------
- int i = 1;
- final String jsCodeForInputFields = " name=\"entryfield\" $DISABLED onchange=\"saveValue( $DATAELEMENTID, $OPTIONCOMBOID, '$DATAELEMENTNAME' )\" style=\"text-align:center\" onkeyup=\"return keyPress(event, this)\" ";
- final String jsCodeForSelectLists = " name=\"entryfield\" $DISABLED onchange=\"saveBoolean( $DATAELEMENTID, $OPTIONCOMBOID, this )\" onkeyup=\"return keyPress(event, this)\" >";
- final String historyCode = " ondblclick='javascript:viewHistory( $DATAELEMENTID, $OPTIONCOMBOID, true )' ";
-
- // ---------------------------------------------------------------------
- // Metadata code to add to HTML before outputting
- // ---------------------------------------------------------------------
-
- final String metaDataCode = "<span id=\"value[$DATAELEMENTID].name\" style=\"display:none\">$DATAELEMENTNAME</span>"
- + "<span id=\"value[$DATAELEMENTID].type\" style=\"display:none\">$DATAELEMENTTYPE</span>"
- + "<div id=\"value[$DATAELEMENTID:$OPTIONCOMBOID].min\" style=\"display:none\">$MIN</div>"
- + "<div id=\"value[$DATAELEMENTID:$OPTIONCOMBOID].max\" style=\"display:none\">$MAX</div>";
-
- StringBuffer sb = new StringBuffer();
-
- Matcher dataElementMatcher = DATAELEMENT_PATTERN.matcher( dataEntryFormCode );
-
- // ---------------------------------------------------------------------
- // Iterate through all matching data element fields
- // ---------------------------------------------------------------------
-
- Map<Integer, DataElement> dataElementMap = getDataElementMap( dataSet );
-
- while ( dataElementMatcher.find() )
- {
- // -----------------------------------------------------------------
- // Get HTML input field code
- // -----------------------------------------------------------------
-
- String dataElementCode = dataElementMatcher.group( 1 );
-
- Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher( dataElementCode );
-
- if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
- {
- // -------------------------------------------------------------
- // Get data element ID of data element
- // -------------------------------------------------------------
-
- int dataElementId = Integer.parseInt( identifierMatcher.group( 1 ) );
- int optionComboId = Integer.parseInt( identifierMatcher.group( 2 ) );
-
- DataElement dataElement = dataElementMap.get( dataElementId );
-
- if ( dataElement == null )
- {
- log.error( "Data Element Id: " + dataElementId + " not found in this data set" );
-
- return "Data Element Id :" + dataElementId + " not found in this data set";
- }
-
- // -------------------------------------------------------------
- // Find value type of data element
- // -------------------------------------------------------------
-
- String dataElementValueType = dataElement.getType();
-
- // -------------------------------------------------------------
- // Find existing value of data element in data set
- // -------------------------------------------------------------
-
- String dataElementValue = getValue( dataValues, dataElementId, optionComboId );
-
- // -------------------------------------------------------------
- // Insert value of data element in output code
- // -------------------------------------------------------------
-
- if ( dataElement.getType().equals( DataElement.VALUE_TYPE_BOOL ) )
- {
- dataElementCode = dataElementCode.replace( "input", "select" );
- dataElementCode = dataElementCode.replaceAll( "value=\".*?\"", "" );
- }
- else
- {
- if ( dataElementCode.contains( "value=\"\"" ) )
- {
- dataElementCode = dataElementCode.replace( "value=\"\"", "value=\"" + dataElementValue + "\"" );
- }
- else
- {
- dataElementCode += "value=\"" + dataElementValue + "\"";
- }
- }
-
- // -------------------------------------------------------------
- // Min-max values
- // -------------------------------------------------------------
-
- MinMaxDataElement minMaxDataElement = minMaxMap.get( dataElement.getId() + ":" + optionComboId );
- String minValue = "No Min";
- String maxValue = "No Max";
-
- if ( minMaxDataElement != null )
- {
- minValue = String.valueOf( minMaxDataElement.getMin() );
- maxValue = String.valueOf( minMaxDataElement.getMax() );
- }
-
- dataElementCode = dataElementCode.replaceAll( "view=\".*?\"", "" ); // For backwards compatibility
-
- // -------------------------------------------------------------
- // Insert title info
- // -------------------------------------------------------------
-
- StringBuilder title = new StringBuilder( "title=\"Name: " ).append( dataElement.getShortName() ).
- append( " Type: " ).append( dataElement.getType() ).append( " Min: " ).append( minValue ).
- append( " Max: " ).append( maxValue ).append( "\"" );
-
- if ( dataElementCode.contains( "title=\"\"" ) )
- {
- dataElementCode = dataElementCode.replace( "title=\"\"", title );
- }
- else
- {
- dataElementCode += " " + title;
- }
-
- // -------------------------------------------------------------
- // Append Javascript code and meta data (type/min/max) for
- // persisting to output code, and insert value and type for
- // fields
- // -------------------------------------------------------------
-
- String appendCode = dataElementCode;
-
- if ( dataElement.getType().equals( VALUE_TYPE_BOOL ) )
- {
- appendCode += jsCodeForSelectLists + "tabindex=\"" + i++ + "\"";
-
- appendCode += "<option value=\"\">" + i18n.getString( "no_value" ) + "</option>";
-
- if ( dataElementValue.equals( TRUE ) )
- {
- appendCode += "<option value=\"true\" selected>" + i18n.getString( "yes" ) + "</option>";
- }
- else
- {
- appendCode += "<option value=\"true\">" + i18n.getString( "yes" ) + "</option>";
- }
-
- if ( dataElementValue.equals( FALSE ) )
- {
- appendCode += "<option value=\"false\" selected>" + i18n.getString( "no" ) + "</option>";
- }
- else
- {
- appendCode += "<option value=\"false\">" + i18n.getString( "no" ) + "</option>";
- }
-
- appendCode += "</select>";
- }
- else
- {
- appendCode += jsCodeForInputFields + "tabindex=\"" + i++ + "\"";
-
- if ( dataElement.getType().equals( VALUE_TYPE_INT ) )
- {
- appendCode += historyCode;
- }
-
- appendCode += " />";
- }
-
- appendCode += metaDataCode;
- appendCode = appendCode.replace( "$DATAELEMENTID", String.valueOf( dataElementId ) );
- appendCode = appendCode.replace( "$DATAELEMENTNAME", dataElement.getName() );
- appendCode = appendCode.replace( "$DATAELEMENTTYPE", dataElementValueType );
- appendCode = appendCode.replace( "$OPTIONCOMBOID", String.valueOf( optionComboId ) );
- appendCode = appendCode.replace( "$DISABLED", disabled );
-
- if ( minMaxDataElement == null )
- {
- appendCode = appendCode.replace( "$MIN", minValue );
- appendCode = appendCode.replace( "$MAX", maxValue );
- }
- else
- {
- appendCode = appendCode.replace( "$MIN", String.valueOf( minMaxDataElement.getMin() ) );
- appendCode = appendCode.replace( "$MAX", String.valueOf( minMaxDataElement.getMax() ) );
- }
-
- dataElementMatcher.appendReplacement( sb, appendCode );
- }
- }
-
- dataElementMatcher.appendTail( sb );
-
- return sb.toString();
- }
-
- // -------------------------------------------------------------------------
- // Supportive methods
- // -------------------------------------------------------------------------
-
- /**
- * Returns the value of the DataValue in the Collection of DataValues with
- * the given data element identifier and category option combo id.
- */
- private String getValue( Collection<DataValue> dataValues, int dataElementId, int categoryOptionComboId )
- {
- for ( DataValue dataValue : dataValues )
- {
- if ( dataValue.getDataElement().getId() == dataElementId
- && dataValue.getOptionCombo().getId() == categoryOptionComboId )
- {
- return dataValue.getValue();
- }
- }
-
- return EMPTY;
- }
-
- /**
- * Returns a Map of all DataElements in the given DataSet where the key is
- * the DataElement identifier and the value is the DataElement.
- */
- private Map<Integer, DataElement> getDataElementMap( DataSet dataSet )
- {
- Map<Integer, DataElement> map = new HashMap<Integer, DataElement>();
-
- for ( DataElement element : dataSet.getDataElements() )
- {
- map.put( element.getId(), element );
- }
-
- return map;
- }
-}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2011-03-20 21:45:37 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2011-05-07 23:05:00 +0000
@@ -24,8 +24,6 @@
<property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
</bean>
- <bean id="org.hisp.dhis.de.screen.DataEntryScreenManager" class="org.hisp.dhis.de.screen.DefaultDataEntryScreenManager"/>
-
<!-- Actions -->
<bean id="org.hisp.dhis.de.action.LoadOrganisationUnitAction" class="org.hisp.dhis.de.action.LoadOrganisationUnitAction" scope="prototype">
@@ -59,7 +57,7 @@
<property name="dataSetLockService" ref="org.hisp.dhis.datalock.DataSetLockService" />
<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
<property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
- <property name="dataEntryScreenManager" ref="org.hisp.dhis.de.screen.DataEntryScreenManager" />
+ <property name="dataEntryFormService" ref="org.hisp.dhis.dataentryform.DataEntryFormService" />
<property name="standardCommentsManager" ref="org.hisp.dhis.de.comments.StandardCommentsManager" />
<property name="minMaxDataElementService" ref="org.hisp.dhis.minmax.MinMaxDataElementService" />
<property name="selectedStateManager" ref="org.hisp.dhis.de.state.SelectedStateManager" />
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.java 2011-01-21 13:14:16 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.java 2011-05-07 23:05:00 +0000
@@ -109,10 +109,8 @@
dataEntryForm.setName( nameField );
dataEntryForm.setHtmlCode( dataEntryFormService.prepareDataEntryFormCode( designTextarea ) );
dataEntryFormService.updateDataEntryForm( dataEntryForm );
- }
-
+ }
return SUCCESS;
}
-
}