← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21062: ProgramService, removed unused methods

 

------------------------------------------------------------
revno: 21062
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2015-11-15 22:39:57 +0100
message:
  ProgramService, removed unused methods
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/program/DefaultProgramService.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/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<Program> getByCurrentUser( ProgramType type );
 
     void mergeWithCurrentUserOrganisationUnits( Program program, Collection<OrganisationUnit> mergeOrganisationUnits );
-    
-    /**
-     * @param htmlCode
-     * @param program
-     * @param healthWorkers
-     * @param instance
-     * @param programInstance
-     * @param i18n
-     * @param format
-     * @return
-     */
-    String prepareDataEntryFormForAdd( String htmlCode, Program program, Collection<User> 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<User> 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 = "<input value='[" + i18n.getString( "missing_instance_attribute" ) + " " + uid
-                        + "]' title='[" + i18n.getString( "missing_instance_attribute" ) + " " + uid + "]'>/";
-                }
-                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 = "<input id=\"" + property + "\" name=\"" + property + "\" tabindex=\"" + index
-                    + "\" value=\"" + value + "\" " + TAG_CLOSE;
-                if ( property.equals( PROGRAM_ENROLLMENT_DATE ) )
-                {
-                    if ( program != null && program.getSelectEnrollmentDatesInFuture() )
-                    {
-                        inputHtml += "<script>datePicker(\"" + property + "\", true);</script>";
-                    }
-                    else
-                    {
-                        inputHtml += "<script>datePickerValid(\"" + property + "\", true);</script>";
-                    }
-                }
-                else if ( property.equals( PROGRAM_INCIDENT_DATE ) )
-                {
-                    if ( program != null && program.getSelectIncidentDatesInFuture() )
-                    {
-                        inputHtml += "<script>datePicker(\"" + property + "\", true);</script>";
-                    }
-                    else
-                    {
-                        inputHtml += "<script>datePickerValid(\"" + property + "\", true);</script>";
-                    }
-                }
-            }
-
-            inputMatcher.appendReplacement( sb, inputHtml );
-        }
-
-        inputMatcher.appendTail( sb );
-
-        String entryForm = sb.toString();
-        String dobType = "";
-        if ( hasBirthdate && hasAge )
-        {
-            dobType = "<select id=\'dobType\' name=\"dobType\" style=\'width:120px\' onchange=\'dobTypeOnChange(\"instanceForm\")\' >";
-            dobType += "<option value=\"V\" >" + i18n.getString( "verified" ) + "</option>";
-            dobType += "<option value=\"D\" >" + i18n.getString( "declared" ) + "</option>";
-            dobType += "<option value=\"A\" >" + i18n.getString( "approximated" ) + "</option>";
-            dobType += "</select>";
-        }
-        else if ( hasBirthdate )
-        {
-            dobType = "<input type=\'hidden\' id=\'dobType\' name=\"dobType\" value=\'V\'>";
-        }
-        else if ( hasAge )
-        {
-            dobType = "<input type=\'hidden\' id=\'dobType\' name=\"dobType\" value=\'A\'>";
-        }
-
-        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 += "<option value=\"\" selected>" + i18n.getString( "no_value" ) + "</option>";
-                inputHtml += "<option value=\"true\">" + i18n.getString( "yes" ) + "</option>";
-                inputHtml += "<option value=\"false\">" + i18n.getString( "no" ) + "</option>";
-            }
-            else if ( value.equals( "true" ) )
-            {
-                inputHtml += "<option value=\"\">" + i18n.getString( "no_value" ) + "</option>";
-                inputHtml += "<option value=\"true\" selected >" + i18n.getString( "yes" ) + "</option>";
-                inputHtml += "<option value=\"false\">" + i18n.getString( "no" ) + "</option>";
-            }
-            else if ( value.equals( "false" ) )
-            {
-                inputHtml += "<option value=\"\">" + i18n.getString( "no_value" ) + "</option>";
-                inputHtml += "<option value=\"true\">" + i18n.getString( "yes" ) + "</option>";
-                inputHtml += "<option value=\"false\" selected >" + i18n.getString( "no" ) + "</option>";
-            }
-
-            inputHtml += "</select>";
-        }
-        else if ( attribute.hasOptionSet() )
-        {
-            inputHtml = inputHtml.replaceFirst( "input", "select" ) + ">";
-            inputHtml += "<option value=\"\" selected>" + i18n.getString( "no_value" ) + "</option>";
-            for ( Option option : attribute.getOptionSet().getOptions() )
-            {
-                String optionValue = option.getName();
-                inputHtml += "<option value=\"" + optionValue + "\" ";
-                if ( optionValue.equals( value ) )
-                {
-                    inputHtml += " selected ";
-                }
-                inputHtml += ">" + optionValue + "</option>";
-            }
-            inputHtml += "</select>";
-        }
-        else if ( ValueType.DATE == attribute.getValueType() )
-        {
-            String jQueryCalendar = "<script>";
-            if ( allowDateInFuture )
-            {
-                jQueryCalendar += "datePicker";
-            }
-            else
-            {
-                jQueryCalendar += "datePickerValid";
-            }
-            jQueryCalendar += "(\"attr" + attribute.getId() + "\", false, false);</script>";
-
-            inputHtml += " value=\"" + value + "\"" + TAG_CLOSE;
-            inputHtml += jQueryCalendar;
-        }
-        else
-        {
-            inputHtml += " value=\"" + value + "\"" + TAG_CLOSE;
-        }
-
-        return inputHtml;
-    }
-
-    private Object getValueFromProgram( String property, ProgramInstance programInstance )
-    {
-        try
-        {
-            return ProgramInstance.class.getMethod( "get" + property ).invoke( programInstance );
-        }
-        catch ( Exception ex )
-        {
-            ex.printStackTrace();
-        }
-        return null;
-    }
 }