=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java 2015-09-16 14:49:50 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java 2015-11-15 21:39:57 +0000 @@ -32,11 +32,8 @@ import java.util.List; import java.util.regex.Pattern; -import org.hisp.dhis.i18n.I18n; -import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.trackedentity.TrackedEntity; -import org.hisp.dhis.trackedentity.TrackedEntityInstance; import org.hisp.dhis.user.User; import org.hisp.dhis.validation.ValidationCriteria; @@ -240,17 +237,4 @@ List getByCurrentUser( ProgramType type ); void mergeWithCurrentUserOrganisationUnits( Program program, Collection mergeOrganisationUnits ); - - /** - * @param htmlCode - * @param program - * @param healthWorkers - * @param instance - * @param programInstance - * @param i18n - * @param format - * @return - */ - String prepareDataEntryFormForAdd( String htmlCode, Program program, Collection healthWorkers, - TrackedEntityInstance instance, ProgramInstance programInstance, I18n i18n, I18nFormat format ); } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramService.java 2015-10-19 14:51:03 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramService.java 2015-11-15 21:39:57 +0000 @@ -32,32 +32,19 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.List; import java.util.Set; -import java.util.regex.Matcher; -import org.apache.commons.lang3.StringUtils; -import org.hisp.dhis.common.ValueType; -import org.hisp.dhis.i18n.I18n; -import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.i18n.I18nService; -import org.hisp.dhis.option.Option; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitQueryParams; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.trackedentity.TrackedEntity; -import org.hisp.dhis.trackedentity.TrackedEntityAttribute; -import org.hisp.dhis.trackedentity.TrackedEntityAttributeService; -import org.hisp.dhis.trackedentity.TrackedEntityInstance; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserAuthorityGroup; import org.hisp.dhis.user.UserService; import org.hisp.dhis.validation.ValidationCriteria; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import com.google.common.collect.Sets; @@ -69,16 +56,6 @@ public class DefaultProgramService implements ProgramService { - private static final String TAG_OPEN = "<"; - - private static final String TAG_CLOSE = "/>"; - - private static final String PROGRAM_INCIDENT_DATE = "incidentDate"; - - private static final String PROGRAM_ENROLLMENT_DATE = "enrollmentDate"; - - private static final String DOB_FIELD = "@DOB_FIELD"; - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -118,12 +95,6 @@ this.organisationUnitService = organisationUnitService; } - @Autowired - private TrackedEntityAttributeService attributeService; - - @Autowired - private TrackedEntityAttributeValueService attributeValueService; - // ------------------------------------------------------------------------- // Implementation methods // ------------------------------------------------------------------------- @@ -335,263 +306,4 @@ updateProgram( program ); } - - @Override - public String prepareDataEntryFormForAdd( String htmlCode, Program program, Collection healthWorkers, - TrackedEntityInstance instance, ProgramInstance programInstance, I18n i18n, I18nFormat format ) - { - int index = 1; - - StringBuffer sb = new StringBuffer(); - - Matcher inputMatcher = INPUT_PATTERN.matcher( htmlCode ); - - boolean hasBirthdate = false; - boolean hasAge = false; - - while ( inputMatcher.find() ) - { - // ----------------------------------------------------------------- - // Get HTML input field code - // ----------------------------------------------------------------- - - String inputHtml = inputMatcher.group(); - Matcher dynamicAttrMatcher = DYNAMIC_ATTRIBUTE_PATTERN.matcher( inputHtml ); - Matcher programMatcher = PROGRAM_PATTERN.matcher( inputHtml ); - - index++; - - String hidden = ""; - String style = ""; - Matcher classMarcher = CLASS_PATTERN.matcher( inputHtml ); - if ( classMarcher.find() ) - { - hidden = classMarcher.group( 2 ); - } - - Matcher styleMarcher = STYLE_PATTERN.matcher( inputHtml ); - if ( styleMarcher.find() ) - { - style = styleMarcher.group( 2 ); - } - - if ( dynamicAttrMatcher.find() && dynamicAttrMatcher.groupCount() > 0 ) - { - String uid = dynamicAttrMatcher.group( 1 ); - TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( uid ); - - if ( attribute == null ) - { - inputHtml = "/"; - } - else - { - // Get value - String value = ""; - if ( instance != null ) - { - TrackedEntityAttributeValue attributeValue = attributeValueService - .getTrackedEntityAttributeValue( instance, attribute ); - if ( attributeValue != null ) - { - value = attributeValue.getValue(); - } - } - - inputHtml = getAttributeField( inputHtml, attribute, program, value, i18n, index, hidden, style ); - - } - - } - else if ( programMatcher.find() && programMatcher.groupCount() > 0 ) - { - String property = programMatcher.group( 1 ); - - // Get value - String value = ""; - if ( programInstance != null ) - { - value = format.formatDate( ((Date) getValueFromProgram( StringUtils.capitalize( property ), - programInstance )) ); - } - - inputHtml = ""; - } - else - { - inputHtml += ""; - } - } - else if ( property.equals( PROGRAM_INCIDENT_DATE ) ) - { - if ( program != null && program.getSelectIncidentDatesInFuture() ) - { - inputHtml += ""; - } - else - { - inputHtml += ""; - } - } - } - - inputMatcher.appendReplacement( sb, inputHtml ); - } - - inputMatcher.appendTail( sb ); - - String entryForm = sb.toString(); - String dobType = ""; - if ( hasBirthdate && hasAge ) - { - dobType = ""; - } - else if ( hasBirthdate ) - { - dobType = ""; - } - else if ( hasAge ) - { - dobType = ""; - } - - entryForm = entryForm.replaceFirst( DOB_FIELD, dobType ); - entryForm = entryForm.replaceAll( DOB_FIELD, "" ); - - return entryForm; - } - - // ------------------------------------------------------------------------- - // Supportive methods - // ------------------------------------------------------------------------- - - private String getAttributeField( String inputHtml, TrackedEntityAttribute attribute, Program program, - String value, I18n i18n, int index, String hidden, String style ) - { - boolean mandatory = false; - boolean allowDateInFuture = false; - - if ( program != null && program.getAttribute( attribute ) != null ) - { - ProgramTrackedEntityAttribute programAttribute = program.getAttribute( attribute ); - mandatory = programAttribute.isMandatory(); - allowDateInFuture = programAttribute.getAllowFutureDate(); - } - - inputHtml = TAG_OPEN + "input id=\"attr" + attribute.getId() + "\" name=\"attr" + attribute.getId() - + "\" tabindex=\"" + index + "\" style=\"" + style + "\""; - - inputHtml += "\" class=\"" + hidden + " {validate:{required:" + mandatory; - - if ( ValueType.NUMBER == attribute.getValueType() ) - { - inputHtml += ",number:true"; - } - else if ( ValueType.PHONE_NUMBER == attribute.getValueType() ) - { - inputHtml += ",phone:true"; - } - - inputHtml += "}}\" "; - - if ( ValueType.PHONE_NUMBER == attribute.getValueType() ) - { - inputHtml += " phoneNumber value=\"" + value + "\"" + TAG_CLOSE; - } - else if ( ValueType.TRUE_ONLY == attribute.getValueType() ) - { - inputHtml += " type='checkbox' value='true' "; - if ( value.equals( "true" ) ) - { - inputHtml += " checked "; - } - } - else if ( ValueType.BOOLEAN == attribute.getValueType() ) - { - inputHtml = inputHtml.replaceFirst( "input", "select" ) + ">"; - - if ( value.equals( "" ) ) - { - inputHtml += ""; - inputHtml += ""; - inputHtml += ""; - } - else if ( value.equals( "true" ) ) - { - inputHtml += ""; - inputHtml += ""; - inputHtml += ""; - } - else if ( value.equals( "false" ) ) - { - inputHtml += ""; - inputHtml += ""; - inputHtml += ""; - } - - inputHtml += ""; - } - else if ( attribute.hasOptionSet() ) - { - inputHtml = inputHtml.replaceFirst( "input", "select" ) + ">"; - inputHtml += ""; - for ( Option option : attribute.getOptionSet().getOptions() ) - { - String optionValue = option.getName(); - inputHtml += "