← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14796: Fixed bug - Display -1 in Edit profile form and error when to update TEI profile; Error when to d...

 

------------------------------------------------------------
revno: 14796
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-04-11 17:56:57 +0800
message:
  Fixed bug - Display -1 in Edit profile form and error when to update TEI profile; Error when to display phone-number value in Add/Update TEI form.
modified:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetTrackedEntityInstanceAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/TrackedEntityInstanceDashboardAction.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/UpdateTrackedEntityInstanceAction.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-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java	2014-04-06 15:48:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java	2014-04-11 09:56:57 +0000
@@ -61,216 +61,235 @@
  * @author Abyot Asalefew Gizaw
  * @version $Id$
  */
-public class AddTrackedEntityInstanceAction implements Action {
-	public static final String PREFIX_ATTRIBUTE = "attr";
-
-	// -------------------------------------------------------------------------
-	// Dependencies
-	// -------------------------------------------------------------------------
-
-	private TrackedEntityInstanceService entityInstanceService;
-
-	private TrackedEntityAttributeService attributeService;
-
-	private RelationshipTypeService relationshipTypeService;
-
-	private RelationshipService relationshipService;
-
-	private OrganisationUnitSelectionManager selectionManager;
-
-	@Autowired
-	private TrackedEntityService trackedEntityService;
-
-	@Autowired
-	private ProgramService programService;
-
-	@Autowired
-	private TrackedEntityAttributeValueService attributeValueService;
-
-	private I18nFormat format;
-
-	// -------------------------------------------------------------------------
-	// Input
-	// -------------------------------------------------------------------------
-
-	private Integer representativeId;
-
-	private Integer relationshipTypeId;
-
-	private Integer relationshipId;
-
-	private boolean relationshipFromA;
-
-	private Integer trackedEntityId;
-
-	private String programId;
-
-	private String message;
-
-	// -------------------------------------------------------------------------
-	// Action implementation
-	// -------------------------------------------------------------------------
-
-	public String execute() {
-		OrganisationUnit organisationUnit = selectionManager
-				.getSelectedOrganisationUnit();
-		TrackedEntityInstance entityInstance = new TrackedEntityInstance();
-		TrackedEntity trackedEntity = null;
-
-		if (programId != null) {
-			Program program = programService.getProgram(programId);
-			trackedEntity = program.getTrackedEntity();
-		} else {
-			trackedEntity = trackedEntityService
-					.getTrackedEntity(trackedEntityId);
-		}
-
-		entityInstance.setTrackedEntity(trackedEntity);
-		entityInstance.setOrganisationUnit(organisationUnit);
-
-		// ---------------------------------------------------------------------
-		// Tracked Entity Attributes
-		// ---------------------------------------------------------------------
-
-		TrackedEntityInstance relationship = null;
-
-		if (relationshipId != null && relationshipTypeId != null) {
-			relationship = entityInstanceService
-					.getTrackedEntityInstance(relationshipId);
-		}
-
-		HttpServletRequest request = ServletActionContext.getRequest();
-
-		Collection<TrackedEntityAttribute> attributes = attributeService
-				.getAllTrackedEntityAttributes();
-
-		Set<TrackedEntityAttributeValue> attributeValues = new HashSet<TrackedEntityAttributeValue>();
-
-		TrackedEntityAttributeValue attributeValue = null;
-
-		if (attributes != null && attributes.size() > 0) {
-			for (TrackedEntityAttribute attribute : attributes) {
-				String value = request.getParameter(PREFIX_ATTRIBUTE
-						+ attribute.getId());
-				if (StringUtils.isNotBlank(value)) {
-					attributeValue = new TrackedEntityAttributeValue();
-					attributeValue.setEntityInstance(entityInstance);
-					attributeValue.setAttribute(attribute);
-
-					if (attribute.getValueType().equals(
-							TrackedEntityAttribute.TYPE_AGE)) {
-						value = format.formatDate(TrackedEntityAttribute
-								.getDateFromAge(Integer.parseInt(value)));
-					}
-
-					attributeValue.setValue(value.trim());
-					attributeValues.add(attributeValue);
-				} else if (attribute.getInherit() && relationship != null) {
-					TrackedEntityAttributeValue av = attributeValueService
-							.getTrackedEntityAttributeValue(relationship,
-									attribute);
-					if (av != null) {
-						attributeValue = new TrackedEntityAttributeValue();
-						attributeValue.setEntityInstance(entityInstance);
-						attributeValue.setAttribute(attribute);
-						attributeValue.setValue(av.getValue());
-
-						attributeValues.add(attributeValue);
-					}
-				}
-			}
-		}
-
-		int entityInstanceId = entityInstanceService
-				.createTrackedEntityInstance(entityInstance, representativeId,
-						relationshipTypeId, attributeValues);
-
-		// -------------------------------------------------------------------------
-		// Create relationship
-		// -------------------------------------------------------------------------
-
-		if (relationship != null) {
-			Relationship rel = new Relationship();
-			if (relationshipFromA) {
-				rel.setEntityInstanceA(relationship);
-				rel.setEntityInstanceB(entityInstance);
-			} else {
-				rel.setEntityInstanceA(entityInstance);
-				rel.setEntityInstanceB(relationship);
-			}
-			if (relationshipTypeId != null) {
-				RelationshipType relType = relationshipTypeService
-						.getRelationshipType(relationshipTypeId);
-				if (relType != null) {
-					rel.setRelationshipType(relType);
-					relationshipService.addRelationship(rel);
-				}
-			}
-		}
-
-		message = entityInstance.getUid() + "_" + entityInstanceId;
-
-		return SUCCESS;
-	}
-
-	// -----------------------------------------------------------------------------
-	// Getter/Setter
-	// -----------------------------------------------------------------------------
-
-	public void setRelationshipTypeService(
-			RelationshipTypeService relationshipTypeService) {
-		this.relationshipTypeService = relationshipTypeService;
-	}
-
-	public void setRelationshipId(Integer relationshipId) {
-		this.relationshipId = relationshipId;
-	}
-
-	public void setRelationshipFromA(boolean relationshipFromA) {
-		this.relationshipFromA = relationshipFromA;
-	}
-
-	public void setRelationshipService(RelationshipService relationshipService) {
-		this.relationshipService = relationshipService;
-	}
-
-	public void setSelectionManager(
-			OrganisationUnitSelectionManager selectionManager) {
-		this.selectionManager = selectionManager;
-	}
-
-	public void setTrackedEntityId(Integer trackedEntityId) {
-		this.trackedEntityId = trackedEntityId;
-	}
-
-	public void setProgramId(String programId) {
-		this.programId = programId;
-	}
-
-	public String getMessage() {
-		return message;
-	}
-
-	public void setEntityInstanceService(
-			TrackedEntityInstanceService entityInstanceService) {
-		this.entityInstanceService = entityInstanceService;
-	}
-
-	public void setFormat(I18nFormat format) {
-		this.format = format;
-	}
-
-	public void setAttributeService(
-			TrackedEntityAttributeService attributeService) {
-		this.attributeService = attributeService;
-	}
-
-	public void setRepresentativeId(Integer representativeId) {
-		this.representativeId = representativeId;
-	}
-
-	public void setRelationshipTypeId(Integer relationshipTypeId) {
-		this.relationshipTypeId = relationshipTypeId;
-	}
+public class AddTrackedEntityInstanceAction
+    implements Action
+{
+    public static final String PREFIX_ATTRIBUTE = "attr";
+
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private TrackedEntityInstanceService entityInstanceService;
+
+    private TrackedEntityAttributeService attributeService;
+
+    private RelationshipTypeService relationshipTypeService;
+
+    private RelationshipService relationshipService;
+
+    private OrganisationUnitSelectionManager selectionManager;
+
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
+    @Autowired
+    private ProgramService programService;
+
+    @Autowired
+    private TrackedEntityAttributeValueService attributeValueService;
+
+    private I18nFormat format;
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer representativeId;
+
+    private Integer relationshipTypeId;
+
+    private Integer relationshipId;
+
+    private boolean relationshipFromA;
+
+    private Integer trackedEntityId;
+
+    private String programId;
+
+    private String message;
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+    {
+        OrganisationUnit organisationUnit = selectionManager.getSelectedOrganisationUnit();
+        TrackedEntityInstance entityInstance = new TrackedEntityInstance();
+        TrackedEntity trackedEntity = null;
+
+        if ( programId != null )
+        {
+            Program program = programService.getProgram( programId );
+            trackedEntity = program.getTrackedEntity();
+        }
+        else
+        {
+            trackedEntity = trackedEntityService.getTrackedEntity( trackedEntityId );
+        }
+
+        entityInstance.setTrackedEntity( trackedEntity );
+        entityInstance.setOrganisationUnit( organisationUnit );
+
+        // ---------------------------------------------------------------------
+        // Tracked Entity Attributes
+        // ---------------------------------------------------------------------
+
+        TrackedEntityInstance relationship = null;
+
+        if ( relationshipId != null && relationshipTypeId != null )
+        {
+            relationship = entityInstanceService.getTrackedEntityInstance( relationshipId );
+        }
+
+        HttpServletRequest request = ServletActionContext.getRequest();
+
+        Collection<TrackedEntityAttribute> attributes = attributeService.getAllTrackedEntityAttributes();
+
+        Set<TrackedEntityAttributeValue> attributeValues = new HashSet<TrackedEntityAttributeValue>();
+
+        TrackedEntityAttributeValue attributeValue = null;
+
+        if ( attributes != null && attributes.size() > 0 )
+        {
+            for ( TrackedEntityAttribute attribute : attributes )
+            {
+                String value = request.getParameter( PREFIX_ATTRIBUTE + attribute.getId() );
+                if ( StringUtils.isNotBlank( value ) )
+                {
+                    attributeValue = new TrackedEntityAttributeValue();
+                    attributeValue.setEntityInstance( entityInstance );
+                    attributeValue.setAttribute( attribute );
+
+                    if ( attribute.getValueType().equals( TrackedEntityAttribute.TYPE_AGE ) )
+                    {
+                        value = format.formatDate( TrackedEntityAttribute.getDateFromAge( Integer.parseInt( value ) ) );
+                    }
+                    
+                    attributeValue.setValue( value.trim() );
+                    attributeValues.add( attributeValue );
+                }
+                else if ( attribute.getInherit() && relationship != null )
+                {
+                    TrackedEntityAttributeValue av = attributeValueService.getTrackedEntityAttributeValue(
+                        relationship, attribute );
+                    if ( av != null )
+                    {
+                        attributeValue = new TrackedEntityAttributeValue();
+                        attributeValue.setEntityInstance( entityInstance );
+                        attributeValue.setAttribute( attribute );
+                        attributeValue.setValue( av.getValue() );
+
+                        attributeValues.add( attributeValue );
+                    }
+                }
+            }
+        }
+
+        int entityInstanceId = entityInstanceService.createTrackedEntityInstance( entityInstance, representativeId,
+            relationshipTypeId, attributeValues );
+
+        // -------------------------------------------------------------------------
+        // Create relationship
+        // -------------------------------------------------------------------------
+
+        if ( relationship != null )
+        {
+            Relationship rel = new Relationship();
+            if ( relationshipFromA )
+            {
+                rel.setEntityInstanceA( relationship );
+                rel.setEntityInstanceB( entityInstance );
+            }
+            else
+            {
+                rel.setEntityInstanceA( entityInstance );
+                rel.setEntityInstanceB( relationship );
+            }
+            if ( relationshipTypeId != null )
+            {
+                RelationshipType relType = relationshipTypeService.getRelationshipType( relationshipTypeId );
+                if ( relType != null )
+                {
+                    rel.setRelationshipType( relType );
+                    relationshipService.addRelationship( rel );
+                }
+            }
+        }
+
+        message = entityInstance.getUid() + "_" + entityInstanceId;
+
+        return SUCCESS;
+    }
+
+    // -----------------------------------------------------------------------------
+    // Getter/Setter
+    // -----------------------------------------------------------------------------
+
+    public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService )
+    {
+        this.relationshipTypeService = relationshipTypeService;
+    }
+
+    public void setRelationshipId( Integer relationshipId )
+    {
+        this.relationshipId = relationshipId;
+    }
+
+    public void setRelationshipFromA( boolean relationshipFromA )
+    {
+        this.relationshipFromA = relationshipFromA;
+    }
+
+    public void setRelationshipService( RelationshipService relationshipService )
+    {
+        this.relationshipService = relationshipService;
+    }
+
+    public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
+    {
+        this.selectionManager = selectionManager;
+    }
+
+    public void setTrackedEntityId( Integer trackedEntityId )
+    {
+        this.trackedEntityId = trackedEntityId;
+    }
+
+    public void setProgramId( String programId )
+    {
+        this.programId = programId;
+    }
+
+    public String getMessage()
+    {
+        return message;
+    }
+
+    public void setEntityInstanceService( TrackedEntityInstanceService entityInstanceService )
+    {
+        this.entityInstanceService = entityInstanceService;
+    }
+
+    public void setFormat( I18nFormat format )
+    {
+        this.format = format;
+    }
+
+    public void setAttributeService( TrackedEntityAttributeService attributeService )
+    {
+        this.attributeService = attributeService;
+    }
+
+    public void setRepresentativeId( Integer representativeId )
+    {
+        this.representativeId = representativeId;
+    }
+
+    public void setRelationshipTypeId( Integer relationshipTypeId )
+    {
+        this.relationshipTypeId = relationshipTypeId;
+    }
 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetTrackedEntityInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetTrackedEntityInstanceAction.java	2014-04-06 15:48:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/GetTrackedEntityInstanceAction.java	2014-04-11 09:56:57 +0000
@@ -68,303 +68,330 @@
  * @author Abyot Asalefew Gizaw
  * @version $Id$
  */
-public class GetTrackedEntityInstanceAction implements Action {
-	// -------------------------------------------------------------------------
-	// Dependencies
-	// -------------------------------------------------------------------------
-
-	private TrackedEntityInstanceService entityInstanceService;
-
-	public void setEntityInstanceService(
-			TrackedEntityInstanceService entityInstanceService) {
-		this.entityInstanceService = entityInstanceService;
-	}
-
-	private ProgramService programService;
-
-	public void setProgramService(ProgramService programService) {
-		this.programService = programService;
-	}
-
-	private RelationshipTypeService relationshipTypeService;
-
-	public void setRelationshipTypeService(
-			RelationshipTypeService relationshipTypeService) {
-		this.relationshipTypeService = relationshipTypeService;
-	}
-
-	private TrackedEntityFormService trackedEntityFormService;
-
-	public void setTrackedEntityFormService(
-			TrackedEntityFormService trackedEntityFormService) {
-		this.trackedEntityFormService = trackedEntityFormService;
-	}
-
-	private TrackedEntityAttributeGroupService attributeGroupService;
-
-	public void setAttributeGroupService(
-			TrackedEntityAttributeGroupService attributeGroupService) {
-		this.attributeGroupService = attributeGroupService;
-	}
-
-	private TrackedEntityAttributeService attributeService;
-
-	public void setAttributeService(
-			TrackedEntityAttributeService attributeService) {
-		this.attributeService = attributeService;
-	}
-
-	@Autowired
-	private TrackedEntityService trackedEntityService;
-
-	@Autowired
-	private ProgramInstanceService programInstanceService;
-
-	private I18n i18n;
-
-	public void setI18n(I18n i18n) {
-		this.i18n = i18n;
-	}
-
-	private I18nFormat format;
-
-	public void setFormat(I18nFormat format) {
-		this.format = format;
-	}
-
-	// -------------------------------------------------------------------------
-	// Input/Output
-	// -------------------------------------------------------------------------
-
-	private String id;
-
-	public void setId(String id) {
-		this.id = id;
-	}
-
-	private Collection<RelationshipType> relationshipTypes;
-
-	public Collection<RelationshipType> getRelationshipTypes() {
-		return relationshipTypes;
-	}
-
-	private TrackedEntityInstance entityInstance;
-
-	public TrackedEntityInstance getEntityInstance() {
-		return entityInstance;
-	}
-
-	private Collection<Program> programs;
-
-	public Collection<Program> getPrograms() {
-		return programs;
-	}
-
-	private Map<Integer, String> attributeValueMap = new HashMap<Integer, String>();
-
-	public Map<Integer, String> getAttributeValueMap() {
-		return attributeValueMap;
-	}
-
-	private Collection<TrackedEntityAttribute> noGroupAttributes = new HashSet<TrackedEntityAttribute>();
-
-	public Collection<TrackedEntityAttribute> getNoGroupAttributes() {
-		return noGroupAttributes;
-	}
-
-	private List<TrackedEntityAttributeGroup> attributeGroups;
-
-	public List<TrackedEntityAttributeGroup> getAttributeGroups() {
-		return attributeGroups;
-	}
-
-	private Relationship relationship;
-
-	public Relationship getRelationship() {
-		return relationship;
-	}
-
-	private Map<Integer, Collection<TrackedEntityAttribute>> attributeGroupsMap = new HashMap<Integer, Collection<TrackedEntityAttribute>>();
-
-	public Map<Integer, Collection<TrackedEntityAttribute>> getAttributeGroupsMap() {
-		return attributeGroupsMap;
-	}
-
-	private Collection<User> healthWorkers;
-
-	public Collection<User> getHealthWorkers() {
-		return healthWorkers;
-	}
-
-	public void setTrackedEntityForm(TrackedEntityForm trackedEntityForm) {
-		this.trackedEntityForm = trackedEntityForm;
-	}
-
-	private String programId;
-
-	public void setProgramId(String programId) {
-		this.programId = programId;
-	}
-
-	private Map<String, List<TrackedEntityAttribute>> attributesMap = new HashMap<String, List<TrackedEntityAttribute>>();
-
-	public Map<String, List<TrackedEntityAttribute>> getAttributesMap() {
-		return attributesMap;
-	}
-
-	private TrackedEntityForm trackedEntityForm;
-
-	public TrackedEntityForm getTrackedEntityForm() {
-		return trackedEntityForm;
-	}
-
-	private String customRegistrationForm;
-
-	public String getCustomRegistrationForm() {
-		return customRegistrationForm;
-	}
-
-	private Integer programStageInstanceId;
-
-	public Integer getProgramStageInstanceId() {
-		return programStageInstanceId;
-	}
-
-	public void setProgramStageInstanceId(Integer programStageInstanceId) {
-		this.programStageInstanceId = programStageInstanceId;
-	}
-
-	private List<TrackedEntity> trackedEntities;
-
-	public List<TrackedEntity> getTrackedEntities() {
-		return trackedEntities;
-	}
-
-	private Map<Integer, Boolean> mandatoryMap = new HashMap<Integer, Boolean>();
-
-	public Map<Integer, Boolean> getMandatoryMap() {
-		return mandatoryMap;
-	}
-
-	// -------------------------------------------------------------------------
-	// Action implementation
-	// -------------------------------------------------------------------------
-
-	public String execute() throws Exception {
-		relationshipTypes = relationshipTypeService.getAllRelationshipTypes();
-		trackedEntities = new ArrayList<TrackedEntity>(
-				trackedEntityService.getAllTrackedEntity());
-		entityInstance = entityInstanceService.getTrackedEntityInstance(id);
-
-		healthWorkers = entityInstance.getOrganisationUnit().getUsers();
-		Program program = null;
-
-		if (programId == null) {
-			trackedEntityForm = trackedEntityFormService
-					.getCommonTrackedEntityForm();
-
-			if (trackedEntityForm != null
-					&& trackedEntityForm.getDataEntryForm() != null) {
-				customRegistrationForm = trackedEntityFormService
-						.prepareDataEntryFormForAdd(trackedEntityForm
-								.getDataEntryForm().getHtmlCode(),
-								trackedEntityForm.getProgram(), healthWorkers,
-								entityInstance, null, i18n, format);
-			}
-		} else {
-			program = programService.getProgram(programId);
-			trackedEntityForm = trackedEntityFormService
-					.getTrackedEntityForm(program);
-
-			Collection<ProgramInstance> programInstances = programInstanceService
-					.getProgramInstances(entityInstance, program,
-							ProgramInstance.STATUS_ACTIVE);
-			ProgramInstance programIntance = null;
-			if (programInstances != null) {
-				programIntance = programInstances.iterator().next();
-			}
-			if (trackedEntityForm != null
-					&& trackedEntityForm.getDataEntryForm() != null) {
-				customRegistrationForm = trackedEntityFormService
-						.prepareDataEntryFormForAdd(trackedEntityForm
-								.getDataEntryForm().getHtmlCode(),
-								trackedEntityForm.getProgram(), healthWorkers,
-								entityInstance, programIntance, i18n, format);
-			}
-		}
-
-		List<TrackedEntityAttribute> attributes = new ArrayList<TrackedEntityAttribute>();
-
-		if (customRegistrationForm == null) {
-			attributeGroups = new ArrayList<TrackedEntityAttributeGroup>(
-					attributeGroupService.getAllTrackedEntityAttributeGroups());
-			Collections.sort(attributeGroups,
-					new TrackedEntityAttributeGroupSortOrderComparator());
-
-			if (program == null) {
-				attributes = new ArrayList<TrackedEntityAttribute>(
-						attributeService.getAllTrackedEntityAttributes());
-				Collection<Program> programs = programService.getAllPrograms();
-				for (Program p : programs) {
-					for (ProgramTrackedEntityAttribute programAttribute : p
-							.getAttributes()) {
-						if (!programAttribute.isDisplayInList()) {
-							attributes.remove(programAttribute.getAttribute());
-						}
-					}
-				}
-
-				for (TrackedEntityAttribute attribute : attributes) {
-					mandatoryMap.put(attribute.getId(), false);
-				}
-			} else {
-				attributes = program.getTrackedEntityAttributes();
-				for (ProgramTrackedEntityAttribute programAttribute : program
-						.getAttributes()) {
-					mandatoryMap.put(programAttribute.getAttribute().getId(),
-							programAttribute.isMandatory());
-				}
-			}
-
-			for (TrackedEntityAttribute attribute : attributes) {
-				TrackedEntityAttributeGroup attributeGroup = attribute
-						.getAttributeGroup();
-				String groupName = (attributeGroup == null) ? ""
-						: attributeGroup.getDisplayName();
-				if (attributesMap.containsKey(groupName)) {
-					List<TrackedEntityAttribute> attrs = attributesMap
-							.get(groupName);
-					attrs.add(attribute);
-				} else {
-					List<TrackedEntityAttribute> attrs = new ArrayList<TrackedEntityAttribute>();
-					attrs.add(attribute);
-					attributesMap.put(groupName, attrs);
-				}
-			}
-
-		}
-
-		// -------------------------------------------------------------------------
-		// Get attribute values
-		// -------------------------------------------------------------------------
-
-		Collection<TrackedEntityAttributeValue> attributeValues = entityInstance
-				.getAttributeValues();
-
-		for (TrackedEntityAttributeValue attributeValue : attributeValues) {
-			String value = attributeValue.getValue();
-
-			if (attributeValue.getAttribute().getValueType()
-					.equals(TrackedEntityAttribute.TYPE_AGE)) {
-				Date date = format.parseDate(value);
-				value = TrackedEntityAttribute.getAgeFromDate(date) + "";
-			}
-
-			attributeValueMap.put(attributeValue.getAttribute().getId(), value);
-		}
-
-		return SUCCESS;
-
-	}
+public class GetTrackedEntityInstanceAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private TrackedEntityInstanceService entityInstanceService;
+
+    public void setEntityInstanceService( TrackedEntityInstanceService entityInstanceService )
+    {
+        this.entityInstanceService = entityInstanceService;
+    }
+
+    private ProgramService programService;
+
+    public void setProgramService( ProgramService programService )
+    {
+        this.programService = programService;
+    }
+
+    private RelationshipTypeService relationshipTypeService;
+
+    public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService )
+    {
+        this.relationshipTypeService = relationshipTypeService;
+    }
+
+    private TrackedEntityFormService trackedEntityFormService;
+
+    public void setTrackedEntityFormService( TrackedEntityFormService trackedEntityFormService )
+    {
+        this.trackedEntityFormService = trackedEntityFormService;
+    }
+
+    private TrackedEntityAttributeGroupService attributeGroupService;
+
+    public void setAttributeGroupService( TrackedEntityAttributeGroupService attributeGroupService )
+    {
+        this.attributeGroupService = attributeGroupService;
+    }
+
+    private TrackedEntityAttributeService attributeService;
+
+    public void setAttributeService( TrackedEntityAttributeService attributeService )
+    {
+        this.attributeService = attributeService;
+    }
+
+    @Autowired
+    private TrackedEntityService trackedEntityService;
+
+    @Autowired
+    private ProgramInstanceService programInstanceService;
+
+    private I18n i18n;
+
+    public void setI18n( I18n i18n )
+    {
+        this.i18n = i18n;
+    }
+
+    private I18nFormat format;
+
+    public void setFormat( I18nFormat format )
+    {
+        this.format = format;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input/Output
+    // -------------------------------------------------------------------------
+
+    private String id;
+
+    public void setId( String id )
+    {
+        this.id = id;
+    }
+
+    private Collection<RelationshipType> relationshipTypes;
+
+    public Collection<RelationshipType> getRelationshipTypes()
+    {
+        return relationshipTypes;
+    }
+
+    private TrackedEntityInstance entityInstance;
+
+    public TrackedEntityInstance getEntityInstance()
+    {
+        return entityInstance;
+    }
+
+    private Collection<Program> programs;
+
+    public Collection<Program> getPrograms()
+    {
+        return programs;
+    }
+
+    private Map<Integer, String> attributeValueMap = new HashMap<Integer, String>();
+
+    public Map<Integer, String> getAttributeValueMap()
+    {
+        return attributeValueMap;
+    }
+
+    private Collection<TrackedEntityAttribute> noGroupAttributes = new HashSet<TrackedEntityAttribute>();
+
+    public Collection<TrackedEntityAttribute> getNoGroupAttributes()
+    {
+        return noGroupAttributes;
+    }
+
+    private List<TrackedEntityAttributeGroup> attributeGroups;
+
+    public List<TrackedEntityAttributeGroup> getAttributeGroups()
+    {
+        return attributeGroups;
+    }
+
+    private Relationship relationship;
+
+    public Relationship getRelationship()
+    {
+        return relationship;
+    }
+
+    private Map<Integer, Collection<TrackedEntityAttribute>> attributeGroupsMap = new HashMap<Integer, Collection<TrackedEntityAttribute>>();
+
+    public Map<Integer, Collection<TrackedEntityAttribute>> getAttributeGroupsMap()
+    {
+        return attributeGroupsMap;
+    }
+
+    private Collection<User> healthWorkers;
+
+    public Collection<User> getHealthWorkers()
+    {
+        return healthWorkers;
+    }
+
+    public void setTrackedEntityForm( TrackedEntityForm trackedEntityForm )
+    {
+        this.trackedEntityForm = trackedEntityForm;
+    }
+
+    private String programId;
+
+    public void setProgramId( String programId )
+    {
+        this.programId = programId;
+    }
+
+    private Map<String, List<TrackedEntityAttribute>> attributesMap = new HashMap<String, List<TrackedEntityAttribute>>();
+
+    public Map<String, List<TrackedEntityAttribute>> getAttributesMap()
+    {
+        return attributesMap;
+    }
+
+    private TrackedEntityForm trackedEntityForm;
+
+    public TrackedEntityForm getTrackedEntityForm()
+    {
+        return trackedEntityForm;
+    }
+
+    private String customRegistrationForm;
+
+    public String getCustomRegistrationForm()
+    {
+        return customRegistrationForm;
+    }
+
+    private Integer programStageInstanceId;
+
+    public Integer getProgramStageInstanceId()
+    {
+        return programStageInstanceId;
+    }
+
+    public void setProgramStageInstanceId( Integer programStageInstanceId )
+    {
+        this.programStageInstanceId = programStageInstanceId;
+    }
+
+    private List<TrackedEntity> trackedEntities;
+
+    public List<TrackedEntity> getTrackedEntities()
+    {
+        return trackedEntities;
+    }
+
+    private Map<Integer, Boolean> mandatoryMap = new HashMap<Integer, Boolean>();
+
+    public Map<Integer, Boolean> getMandatoryMap()
+    {
+        return mandatoryMap;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        relationshipTypes = relationshipTypeService.getAllRelationshipTypes();
+        trackedEntities = new ArrayList<TrackedEntity>( trackedEntityService.getAllTrackedEntity() );
+        entityInstance = entityInstanceService.getTrackedEntityInstance( id );
+
+        healthWorkers = entityInstance.getOrganisationUnit().getUsers();
+        Program program = null;
+
+        if ( programId == null || programId.isEmpty() )
+        {
+            trackedEntityForm = trackedEntityFormService.getCommonTrackedEntityForm();
+
+            if ( trackedEntityForm != null && trackedEntityForm.getDataEntryForm() != null )
+            {
+                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd( trackedEntityForm
+                    .getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(), healthWorkers, entityInstance,
+                    null, i18n, format );
+            }
+        }
+        else
+        {
+            program = programService.getProgram( programId );
+            trackedEntityForm = trackedEntityFormService.getTrackedEntityForm( program );
+
+            Collection<ProgramInstance> programInstances = programInstanceService.getProgramInstances( entityInstance,
+                program, ProgramInstance.STATUS_ACTIVE );
+            ProgramInstance programIntance = null;
+            if ( programInstances != null )
+            {
+                programIntance = programInstances.iterator().next();
+            }
+            if ( trackedEntityForm != null && trackedEntityForm.getDataEntryForm() != null )
+            {
+                customRegistrationForm = trackedEntityFormService.prepareDataEntryFormForAdd( trackedEntityForm
+                    .getDataEntryForm().getHtmlCode(), trackedEntityForm.getProgram(), healthWorkers, entityInstance,
+                    programIntance, i18n, format );
+            }
+        }
+
+        List<TrackedEntityAttribute> attributes = new ArrayList<TrackedEntityAttribute>();
+
+        if ( customRegistrationForm == null )
+        {
+            attributeGroups = new ArrayList<TrackedEntityAttributeGroup>(
+                attributeGroupService.getAllTrackedEntityAttributeGroups() );
+            Collections.sort( attributeGroups, new TrackedEntityAttributeGroupSortOrderComparator() );
+
+            if ( program == null )
+            {
+                attributes = new ArrayList<TrackedEntityAttribute>( attributeService.getAllTrackedEntityAttributes() );
+                Collection<Program> programs = programService.getAllPrograms();
+                for ( Program p : programs )
+                {
+                    for ( ProgramTrackedEntityAttribute programAttribute : p.getAttributes() )
+                    {
+                        if ( !programAttribute.isDisplayInList() )
+                        {
+                            attributes.remove( programAttribute.getAttribute() );
+                        }
+                    }
+                }
+
+                for ( TrackedEntityAttribute attribute : attributes )
+                {
+                    mandatoryMap.put( attribute.getId(), false );
+                }
+            }
+            else
+            {
+                attributes = program.getTrackedEntityAttributes();
+                for ( ProgramTrackedEntityAttribute programAttribute : program.getAttributes() )
+                {
+                    mandatoryMap.put( programAttribute.getAttribute().getId(), programAttribute.isMandatory() );
+                }
+            }
+
+            for ( TrackedEntityAttribute attribute : attributes )
+            {
+                TrackedEntityAttributeGroup attributeGroup = attribute.getAttributeGroup();
+                String groupName = (attributeGroup == null) ? "" : attributeGroup.getDisplayName();
+                if ( attributesMap.containsKey( groupName ) )
+                {
+                    List<TrackedEntityAttribute> attrs = attributesMap.get( groupName );
+                    attrs.add( attribute );
+                }
+                else
+                {
+                    List<TrackedEntityAttribute> attrs = new ArrayList<TrackedEntityAttribute>();
+                    attrs.add( attribute );
+                    attributesMap.put( groupName, attrs );
+                }
+            }
+
+        }
+
+        // -------------------------------------------------------------------------
+        // Get attribute values
+        // -------------------------------------------------------------------------
+
+        Collection<TrackedEntityAttributeValue> attributeValues = entityInstance.getAttributeValues();
+
+        for ( TrackedEntityAttributeValue attributeValue : attributeValues )
+        {
+            String value = attributeValue.getValue();
+
+            if ( attributeValue.getAttribute().getValueType().equals( TrackedEntityAttribute.TYPE_AGE ) )
+            {
+                Date date = format.parseDate( value );
+                value = TrackedEntityAttribute.getAgeFromDate( date ) + "";
+            }
+
+            attributeValueMap.put( attributeValue.getAttribute().getId(), value );
+        }
+
+        return SUCCESS;
+
+    }
 
 }

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/TrackedEntityInstanceDashboardAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/TrackedEntityInstanceDashboardAction.java	2014-03-31 16:44:18 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/TrackedEntityInstanceDashboardAction.java	2014-04-11 09:56:57 +0000
@@ -232,8 +232,11 @@
                 value = TrackedEntityAttribute.getAgeFromDate( date ) + "";
             }
             
-            attributeValue.setValue( value );
-            attributeValues.add( attributeValue );
+            TrackedEntityAttributeValue av = new TrackedEntityAttributeValue();
+            av.setEntityInstance( entityInstance );
+            av.setAttribute( attributeValue.getAttribute() );
+            av.setValue( value );
+            attributeValues.add( av );
         }
 
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/UpdateTrackedEntityInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/UpdateTrackedEntityInstanceAction.java	2014-04-06 15:48:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/UpdateTrackedEntityInstanceAction.java	2014-04-11 09:56:57 +0000
@@ -103,7 +103,7 @@
 				.getTrackedEntityInstance(id);
 		TrackedEntity trackedEntity = null;
 
-		if (programId != null) {
+		if ( programId != null && !programId.isEmpty() ) {
 			Program program = programService.getProgram(programId);
 			trackedEntity = program.getTrackedEntity();
 		} else {