← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14705: Allow to search TEI by tracked-entity.

 

------------------------------------------------------------
revno: 14705
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-04-07 00:03:28 +0700
message:
  Allow to search TEI by tracked-entity.
modified:
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchTrackedEntityInstanceCriteria.vm


--
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-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2014-04-06 15:48:31 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java	2014-04-06 17:03:28 +0000
@@ -110,20 +110,6 @@
     @Override
     public Collection<Program> getPrograms( OrganisationUnit organisationUnit )
     {
-        /*
-         * Set<Program> programs = new HashSet<Program>();
-         * 
-         * for ( Program program : getAllPrograms() ) {
-         * Set<OrganisationUnitGroup> orgunitGroups =
-         * program.getOrganisationUnitGroups(); for ( OrganisationUnitGroup
-         * orgunitGroup : orgunitGroups ) { if (
-         * orgunitGroup.getMembers().contains( organisationUnit ) ) {
-         * programs.add( program ); } } if (
-         * program.getOrganisationUnits().contains( organisationUnit ) ) {
-         * programs.add( program ); } }
-         * 
-         * return i18n( i18nService, programs );
-         */
         return i18n( i18nService, programStore.get( organisationUnit ) );
     }
 
@@ -152,7 +138,7 @@
     @Override
     public Collection<Program> getPrograms( int type, OrganisationUnit orgunit )
     {
-        return i18n( i18nService, getPrograms( type, orgunit ) );
+        return i18n( i18nService, programStore.get( type, orgunit ) );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java	2014-04-06 15:48:31 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStore.java	2014-04-06 17:03:28 +0000
@@ -84,13 +84,27 @@
     @Override
     public Collection<Program> get( OrganisationUnit organisationUnit )
     {
-        Criteria criteria = getCriteria();
-        criteria.createAlias( "organisationUnits", "orgunit" );
-        criteria.createAlias( "organisationUnitGroups", "orgunitGroup" );
-        criteria.createAlias( "orgunitGroup.members", "orgunitMembers" );
-        criteria.add( Restrictions.or( Restrictions.eq( "orgunit.id", organisationUnit.getId() ),
-            Restrictions.eq( "orgunitMembers.id", organisationUnit.getId() ) ) );
-        return criteria.list();
+        Criteria criteria1 = getCriteria();
+        criteria1.createAlias( "organisationUnits", "orgunit" );
+        criteria1.add( Restrictions.eq( "orgunit.id", organisationUnit.getId() ) );
+
+        Criteria criteria2 = getCriteria();
+        criteria2.createAlias( "organisationUnitGroups", "orgunitGroup" );
+        criteria2.createAlias( "orgunitGroup.members", "orgunitMember" );
+        criteria2.add( Restrictions.eq( "orgunitMember.id", organisationUnit.getId() ) );
+
+        Collection<Program> programs = new HashSet<Program>();
+        if ( criteria1.list() != null )
+        {
+            programs.addAll( criteria1.list() );
+        }
+
+        if ( criteria2.list() != null )
+        {
+            programs.addAll( criteria2.list() );
+        }
+
+        return programs;
     }
 
     @SuppressWarnings( "unchecked" )

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2014-04-06 15:48:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2014-04-06 17:03:28 +0000
@@ -129,7 +129,10 @@
 function getSearchParams(page) {
 	var params = "ou=" + getFieldValue("orgunitId");
 	params += "&page=" + page;
-	if (getFieldValue('program') != '') {
+	if( getFieldValue('trackedEntity')!=''){
+		params += '&trackedEntity=' + getFieldValue('trackedEntity');
+	}
+	else if (getFieldValue('program') != '') {
 		params += "&program=" + getFieldValue('program');
 	}
 	
@@ -185,7 +188,7 @@
 			});
 		
 	params += '&ouMode=' + getFieldValue('ouMode');
-
+	
 	return params;
 }
 
@@ -1923,6 +1926,7 @@
 		showById('searchByIdTR');
 	}
 }
+
 function clearAndCloseSearch() {
 	$('#advancedSearchTB tr').each(function(i, item) {
 		if (i > 0 && $(this).id == undefined) {
@@ -1932,12 +1936,26 @@
 	addAttributeOption();
 	hideById('advanced-search');
 	showById('searchByIdTR');
+	enable('program');
+	setFieldValue('program', '');
 }
+
 function hideSearchCriteria() {
 	hideById('advanced-search');
 	showById('showSearchCriteriaDiv');
 }
+
 function showSearchCriteria() {
 	showById('advanced-search');
 	hideById('showSearchCriteriaDiv');
 }
+
+function trackedEntityOnChange()
+{
+	if( getFieldValue('trackedEntity')!=''){
+		disable('program');
+	}
+	else{
+		enable('program');
+	}
+}

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchTrackedEntityInstanceCriteria.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchTrackedEntityInstanceCriteria.vm	2014-04-04 17:58:28 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchTrackedEntityInstanceCriteria.vm	2014-04-06 17:03:28 +0000
@@ -83,6 +83,7 @@
 			<td>$i18n.getString('select_orgunit_for_search')</td>
 			<td><span id='orgunitForSearch'>$!organisationUnit.name</span></td>
 		</tr>
+		
 		<tr>
 			<td>$i18n.getString('orgunit_search_type')</td>
 			<td>
@@ -94,10 +95,10 @@
 			</td>
 		</tr>
 		
-		<tr id='trackedEntityTR' class='hidden'>
+		<tr id='trackedEntityTR'>
 			<td>$i18n.getString('tracked_entity')</td>
 			<td>
-				<select id='trackedEntity' name='trackedEntity'>
+				<select id='trackedEntity' name='trackedEntity' onchange='trackedEntityOnChange()'>
 					<option value="">[$i18n.getString('please_select')]</option>
 					#foreach($trackedEntity in $trackedEntities)
 						<option value="$trackedEntity.uid">$trackedEntity.name</option>