=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java 2014-05-07 09:33:33 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceService.java 2014-05-08 13:39:17 +0000 @@ -197,15 +197,6 @@ //Collection getTrackedEntityInstances( OrganisationUnit organisationUnit, Program program ); /** - * Retrieve entityInstances base on Attribute - * - * @param attributeId - * @param value - * @return - */ - Collection getTrackedEntityInstance( Integer attributeId, String value ); - - /** * Search entityInstances base on OrganisationUnit and Program with result * limited name * @@ -240,13 +231,13 @@ * Register a new entityInstance * * @param entityInstance TrackedEntityInstance - * @param representativeId The id of entityInstance who is representative + * @param representativeId The uid of entityInstance who is representative * @param relationshipTypeId The id of relationship type defined * @param attributeValues Set of attribute values * * @return The error code after registering entityInstance */ - int createTrackedEntityInstance( TrackedEntityInstance entityInstance, Integer representativeId, + int createTrackedEntityInstance( TrackedEntityInstance entityInstance, String representativeId, Integer relationshipTypeId, Set attributeValues ); /** @@ -260,7 +251,7 @@ * @param valuesForDelete The entityInstance attribute values for deleting * */ - void updateTrackedEntityInstance( TrackedEntityInstance entityInstance, Integer representativeId, + void updateTrackedEntityInstance( TrackedEntityInstance entityInstance, String representativeId, Integer relationshipTypeId, List valuesForSave, List valuesForUpdate, Collection valuesForDelete ); === modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java' --- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java 2014-05-07 09:33:33 +0000 +++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityInstanceService.java 2014-05-08 13:39:17 +0000 @@ -456,7 +456,7 @@ } @Override - public int createTrackedEntityInstance( TrackedEntityInstance instance, Integer representativeId, + public int createTrackedEntityInstance( TrackedEntityInstance instance, String representativeId, Integer relationshipTypeId, Set attributeValues ) { int id = addTrackedEntityInstance( instance ); @@ -473,7 +473,7 @@ if ( representativeId != null ) { - TrackedEntityInstance representative = trackedEntityInstanceStore.get( representativeId ); + TrackedEntityInstance representative = trackedEntityInstanceStore.getByUid( representativeId ); if ( representative != null ) { instance.setRepresentative( representative ); @@ -556,19 +556,7 @@ } @Override - public Collection getTrackedEntityInstance( Integer attributeId, String value ) - { - TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute( attributeId ); - if ( attribute != null ) - { - return attributeValueService.getTrackedEntityInstance( attribute, value ); - } - - return null; - } - - @Override - public void updateTrackedEntityInstance( TrackedEntityInstance instance, Integer representativeId, + public void updateTrackedEntityInstance( TrackedEntityInstance instance, String representativeId, Integer relationshipTypeId, List valuesForSave, List valuesForUpdate, Collection valuesForDelete ) { @@ -591,7 +579,7 @@ if ( shouldSaveRepresentativeInformation( instance, representativeId ) ) { - TrackedEntityInstance representative = trackedEntityInstanceStore.get( representativeId ); + TrackedEntityInstance representative = trackedEntityInstanceStore.getByUid( representativeId ); if ( representative != null ) { @@ -614,14 +602,14 @@ } } - private boolean shouldSaveRepresentativeInformation( TrackedEntityInstance instance, Integer representativeId ) + private boolean shouldSaveRepresentativeInformation( TrackedEntityInstance instance, String representativeId ) { - if ( representativeId == null ) + if ( representativeId == null || representativeId.isEmpty() ) { return false; } - return instance.getRepresentative() == null || !(instance.getRepresentative().getId() == representativeId); + return instance.getRepresentative() == null || !(instance.getRepresentative().getUid() == representativeId); } @Override === modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceServiceTest.java' --- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceServiceTest.java 2014-05-07 09:33:33 +0000 +++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityInstanceServiceTest.java 2014-05-08 13:39:17 +0000 @@ -99,8 +99,6 @@ private TrackedEntityAttribute entityInstanceAttribute; - private int attributeId; - private Program programA; private Program programB; @@ -119,12 +117,13 @@ organisationUnitService.addOrganisationUnit( organisationUnitB ); entityInstanceAttribute = createTrackedEntityAttribute( 'A' ); - attributeId = attributeService.addTrackedEntityAttribute( entityInstanceAttribute ); + attributeService.addTrackedEntityAttribute( entityInstanceAttribute ); entityInstanceA1 = createTrackedEntityInstance( 'A', organisationUnit ); entityInstanceA2 = createTrackedEntityInstance( 'A', organisationUnitB ); entityInstanceA3 = createTrackedEntityInstance( 'A', organisationUnit, entityInstanceAttribute ); entityInstanceB1 = createTrackedEntityInstance( 'B', organisationUnit ); + entityInstanceB1.setUid( "UID-B1" ); entityInstanceB2 = createTrackedEntityInstance( 'B', organisationUnit, entityInstanceAttribute ); programA = createProgram( 'A', new HashSet(), organisationUnit ); @@ -204,38 +203,14 @@ entityInstanceService.addTrackedEntityInstance( entityInstanceA2 ); entityInstanceService.addTrackedEntityInstance( entityInstanceA3 ); - Collection entityInstances = entityInstanceService.getTrackedEntityInstances( organisationUnit, null, null ); + Collection entityInstances = entityInstanceService.getTrackedEntityInstances( + organisationUnit, null, null ); assertEquals( 2, entityInstances.size() ); assertTrue( entityInstances.contains( entityInstanceA1 ) ); assertTrue( entityInstances.contains( entityInstanceA3 ) ); } @Test - public void testGetTrackedEntityInstancesByAttribute() - { - entityInstanceService.addTrackedEntityInstance( entityInstanceA2 ); - entityInstanceService.addTrackedEntityInstance( entityInstanceA3 ); - entityInstanceService.addTrackedEntityInstance( entityInstanceB1 ); - entityInstanceService.addTrackedEntityInstance( entityInstanceB2 ); - - TrackedEntityAttributeValue attributeValue = createTrackedEntityAttributeValue( 'A', entityInstanceA3, - entityInstanceAttribute ); - Set entityInstanceAttributeValues = new HashSet(); - entityInstanceAttributeValues.add( attributeValue ); - - entityInstanceService.createTrackedEntityInstance( entityInstanceA3, null, null, entityInstanceAttributeValues ); - - Collection entityInstances = entityInstanceService.getTrackedEntityInstance( attributeId, "AttributeA" ); - - assertEquals( 1, entityInstances.size() ); - assertTrue( entityInstances.contains( entityInstanceA3 ) ); - - TrackedEntityInstance entityInstance = entityInstances.iterator().next(); - assertEquals( 1, entityInstance.getAttributeValues().size() ); - assertTrue( entityInstance.getAttributeValues().contains( attributeValue ) ); - } - - @Test public void testGetTrackedEntityInstancesByProgramOu() { programService.addProgram( programA ); @@ -251,8 +226,8 @@ programInstanceService.enrollTrackedEntityInstance( entityInstanceA2, programA, date, date, organisationUnit ); programInstanceService.enrollTrackedEntityInstance( entityInstanceB2, programB, date, date, organisationUnit ); - Collection entityInstances = entityInstanceService.getTrackedEntityInstances( organisationUnit, programA, 0, - 100 ); + Collection entityInstances = entityInstanceService.getTrackedEntityInstances( + organisationUnit, programA, 0, 100 ); assertEquals( 2, entityInstances.size() ); assertTrue( entityInstances.contains( entityInstanceA1 ) ); @@ -281,7 +256,7 @@ @Test public void testCreateTrackedEntityInstanceAndRelative() { - int idB = entityInstanceService.addTrackedEntityInstance( entityInstanceB1 ); + entityInstanceService.addTrackedEntityInstance( entityInstanceB1 ); RelationshipType relationshipType = createRelationshipType( 'A' ); int relationshipTypeId = relationshipTypeService.addRelationshipType( relationshipType ); @@ -291,14 +266,15 @@ Set entityInstanceAttributeValues = new HashSet(); entityInstanceAttributeValues.add( attributeValue ); - int idA = entityInstanceService.createTrackedEntityInstance( entityInstanceA1, idB, relationshipTypeId, entityInstanceAttributeValues ); + int idA = entityInstanceService.createTrackedEntityInstance( entityInstanceA1, entityInstanceB1.getUid(), + relationshipTypeId, entityInstanceAttributeValues ); assertNotNull( entityInstanceService.getTrackedEntityInstance( idA ) ); } @Test public void testUpdateTrackedEntityInstanceAndRelative() { - int idB = entityInstanceService.addTrackedEntityInstance( entityInstanceB1 ); + entityInstanceService.addTrackedEntityInstance( entityInstanceB1 ); RelationshipType relationshipType = createRelationshipType( 'A' ); int relationshipTypeId = relationshipTypeService.addRelationshipType( relationshipType ); @@ -308,15 +284,17 @@ entityInstanceAttribute ); Set entityInstanceAttributeValues = new HashSet(); entityInstanceAttributeValues.add( attributeValue ); - int idA = entityInstanceService.createTrackedEntityInstance( entityInstanceA3, idB, relationshipTypeId, entityInstanceAttributeValues ); + int idA = entityInstanceService.createTrackedEntityInstance( entityInstanceA3, entityInstanceB1.getUid(), + relationshipTypeId, entityInstanceAttributeValues ); assertNotNull( entityInstanceService.getTrackedEntityInstance( idA ) ); attributeValue.setValue( "AttributeB" ); List attributeValues = new ArrayList(); attributeValues.add( attributeValue ); - entityInstanceService.updateTrackedEntityInstance( entityInstanceA3, idB, relationshipTypeId, attributeValues, - new ArrayList(), new ArrayList() ); + entityInstanceService.updateTrackedEntityInstance( entityInstanceA3, entityInstanceB1.getUid(), + relationshipTypeId, attributeValues, new ArrayList(), + new ArrayList() ); assertEquals( "B", entityInstanceService.getTrackedEntityInstance( idA ).getName() ); } } === 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-12 12:12:30 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/AddTrackedEntityInstanceAction.java 2014-05-08 13:39:17 +0000 @@ -92,7 +92,7 @@ // Input // ------------------------------------------------------------------------- - private Integer representativeId; + private String representativeId; private Integer relationshipTypeId; @@ -269,7 +269,7 @@ this.attributeService = attributeService; } - public void setRepresentativeId( Integer representativeId ) + public void setRepresentativeId( String representativeId ) { this.representativeId = representativeId; } === removed file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SearchPersonAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SearchPersonAction.java 2014-03-18 08:10:10 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/SearchPersonAction.java 1970-01-01 00:00:00 +0000 @@ -1,135 +0,0 @@ -package org.hisp.dhis.caseentry.action.trackedentity; - -/* - * Copyright (c) 2004-2014, 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.HashMap; -import java.util.Map; - -import org.hisp.dhis.trackedentity.TrackedEntityInstance; -import org.hisp.dhis.trackedentity.TrackedEntityInstanceService; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue; -import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService; - -import com.opensymphony.xwork2.Action; - -/** - * @author Viet - * @version $Id$ - */ - -public class SearchPersonAction - implements Action -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private TrackedEntityInstanceService entityInstanceService; - - private TrackedEntityAttributeValueService attributeValueService; - - // ------------------------------------------------------------------------- - // Input - // ------------------------------------------------------------------------- - - private Integer attributeId; - - private String searchValue; - - // ------------------------------------------------------------------------- - // Output - // ------------------------------------------------------------------------- - - private Map attributeValueMap = new HashMap(); - - private Collection entityInstances; - - // ------------------------------------------------------------------------- - // Action implementation - // ------------------------------------------------------------------------- - - public String execute() - throws Exception - { - entityInstances = entityInstanceService.getTrackedEntityInstance( attributeId, searchValue ); - - if ( entityInstances != null && entityInstances.size() > 0 ) - { - for ( TrackedEntityInstance p : entityInstances ) - { - Collection attributeValues = attributeValueService - .getTrackedEntityAttributeValues( p ); - - for ( TrackedEntityAttributeValue attributeValue : attributeValues ) - { - attributeValueMap.put( - p.getId() + "_" + attributeValue.getAttribute().getId(), - attributeValue.getValue() ); - } - } - } - - return SUCCESS; - } - - // ------------------------------------------------------------------------- - // Getter/Setter - // ------------------------------------------------------------------------- - - public void setAttributeId( Integer attributeId ) - { - this.attributeId = attributeId; - } - - public void setEntityInstanceService( TrackedEntityInstanceService entityInstanceService ) - { - this.entityInstanceService = entityInstanceService; - } - - public Collection getEntityInstances() - { - return entityInstances; - } - - public Map getAttributeValueMap() - { - return attributeValueMap; - } - - public void setAttributeValueService( TrackedEntityAttributeValueService attributeValueService ) - { - this.attributeValueService = attributeValueService; - } - - public void setSearchValue( String searchValue ) - { - this.searchValue = searchValue; - } -} === 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-12 12:12:30 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/trackedentity/UpdateTrackedEntityInstanceAction.java 2014-05-08 13:39:17 +0000 @@ -79,7 +79,7 @@ private Integer id; - private Integer representativeId; + private String representativeId; private Integer relationshipTypeId; @@ -207,7 +207,7 @@ return entityInstance; } - public void setRepresentativeId( Integer representativeId ) + public void setRepresentativeId( String representativeId ) { this.representativeId = representativeId; } === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2014-05-07 10:09:11 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2014-05-08 13:39:17 +0000 @@ -364,13 +364,6 @@ - - - - - F_TRACKED_ENTITY_INSTANCE_ADD - - responseTrackedEntityInstances.vm - - F_TRACKED_ENTITY_INSTANCE_SEARCH - - responseRepresentative.vm === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/underage.js' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/underage.js 2014-02-10 05:42:16 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/underage.js 2014-05-08 13:39:17 +0000 @@ -23,7 +23,7 @@ ,data: jQuery("#addRepresentativeForm").serialize() ,dataType : "xml" ,success: function(xml){ - autoChoosePerson( xml ); + autoChooseTEI( xml ); } ,error: function() { @@ -49,7 +49,7 @@ else if( type == 'duplicate' ) { jQuery("#formContainer").hide(); - showPersons("listPersonsDuplicate", messageElement); + showTEIs("listPersonsDuplicate", messageElement); } } @@ -68,55 +68,98 @@ return params; } -function searchPerson() +function searchTEI() { - jQuery.ajax({ - type: "POST" - ,url: "searchPerson.action" - ,data: jQuery("#searchForm").serialize() - ,dataType : "xml" - ,success: function(xmlObject){ - showPersons( "searchForm div[id=listPersons]", xmlObject ); - } - ,error: function(request,status,errorThrown) - { - alert(i18n_error_connect_to_server); - } - }); + contentDiv = 'listEntityInstanceDiv'; + var params = "ou=" + getFieldValue("orgunitId"); + params += "&ouMode=ALL"; + params += "&attribute=" + getFieldValue("attributeId") + ":LIKE:" + getFieldValue('searchValue'); + + var p = params; + $('#attributeIds option').each(function(i, item){ + if ( p.indexOf(item.value) < 0 ) { + params += "&attribute=" + item.value; + } + }); + + $.ajax({ + type : "GET", + url : "../api/trackedEntityInstances.json", + data : params, + dataType : "json", + success : function(json) { + showTEIs( "searchForm div[id=listPersons]", json ); + } + }); } -function showPersons( divContainer, xmlElement ) +function showTEIs( divContainer, json ) { - var container = jQuery("#"+divContainer); + var container = jQuery( "#" + divContainer ); container.html(""); - var entityInstances = $(xmlElement).find('entityInstance'); - var sEntityInstance = ""; - - if ( entityInstances.length == 0 ) - { - var message = "

" + i18n_no_result + "

"; + if ( json.rows.length == 0 ){ + var message = "

" + i18n_no_result_found + "

"; container.html(message); } - - $( entityInstances ).each( function( i, entityInstance ) - { - sEntityInstance += "
"; - var attributes = $( entityInstance ).find('attribute'); - $( attributes ).each( function( i, attribute ) - { - sEntityInstance += "" - + "" - + " " - + ""; + else{ + var attList = new Array(); + var attDate = new Array(); + $('#attributeIds option').each(function(i, item) { + var valueType = $(item).attr('valueType'); + var value = $(item).val(); + if ( valueType == 'bool' || valueType == 'trueOnly' ) { + for (var i = idx; i < json.width; i++) { + if( value==json.headers[i].name ){ + attList.push(i); + } + else if( valueType=='date'){ + attDate.push(i); + } + } + } + else if ( valueType == 'date' ) { + for (var i = idx; i < json.width; i++) { + if( value==json.headers[i].name ){ + attDate.push(i); + } + } + } }); - sEntityInstance += ""; - sEntityInstance += "
" + $(attribute).find('name').text() + "" + $(attribute).find('value').text() + "
"; - container.append(i18n_duplicate_warning + "
" + sEntityInstance); - } ); + + var result = ""; + var idx = 4; + for ( var i in json.rows) { + result += "
"; + var cols = json.rows[i]; + var uid = cols[0]; + for (var j = idx; j < json.width; j++) { + var colVal = cols[j]; + if( colVal!=''){ + if (j == 4) { + colVal = json.metaData.names[colVal]; + } + + if( jQuery.inArray( j, attList )>=0 && colVal!="" ){ + colVal = (colVal=='true')? i18n_yes : i18n_no; + } + else if( jQuery.inArray( j, attDate )>=0 && colVal!="" ){ + colVal = colVal.split(' ')[0]; + } + result += "" + + "" + + " " + + ""; + } + } + result += ""; + result += "
" + json.headers[j].column + "" + colVal + "
"; + } + container.append(i18n_duplicate_warning + "
" + result); + } } -// Will be call after save new person successfully -function autoChoosePerson( xmlElement ) +// Will be call after save new TEI successfully +function autoChooseTEI( xmlElement ) { jQuery("#tab-2").html("
" + i18n_add_person_successfully + "
"); var root = jQuery(xmlElement); @@ -135,7 +178,7 @@ // Set Representative information to parent page. //------------------------------------------------------------------------------ -function choosePerson(this_) +function chooseTEI(this_) { var relationshipTypeId = jQuery("#searchForm [id=relationshipTypeId]").val(); if( isBlank( relationshipTypeId )) === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/underAgeForm.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/underAgeForm.vm 2014-02-07 20:25:49 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/underAgeForm.vm 2014-05-08 13:39:17 +0000 @@ -1,14 +1,13 @@