← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12108: Allow to search persons by enrollment-date.

 

------------------------------------------------------------
revno: 12108
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-09-17 14:53:28 +0700
message:
  Allow to search persons by enrollment-date.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
  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/searchPatientCriteria.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-api/src/main/java/org/hisp/dhis/patient/Patient.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java	2013-09-12 11:20:41 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java	2013-09-17 07:53:28 +0000
@@ -75,6 +75,7 @@
     public static String PREFIX_FIXED_ATTRIBUTE = "fixedAttr";
     public static String PREFIX_PATIENT_ATTRIBUTE = "attr";
     public static String PREFIX_PROGRAM = "prg";
+    public static String PREFIX_PROGRAM_INSTANCE = "pi";
     public static String PREFIX_PROGRAM_EVENT_BY_STATUS = "stat";
     public static String PREFIX_PROGRAM_STAGE = "prgst";
 

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-09-16 11:43:45 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/hibernate/HibernatePatientStore.java	2013-09-17 07:53:28 +0000
@@ -180,7 +180,8 @@
 
     @Override
     @SuppressWarnings( "unchecked" )
-    public Collection<Patient> getByOrgUnitAndGender( OrganisationUnit organisationUnit, String gender, Integer min, Integer max )
+    public Collection<Patient> getByOrgUnitAndGender( OrganisationUnit organisationUnit, String gender, Integer min,
+        Integer max )
     {
         String hql = "select p from Patient p where p.organisationUnit = :organisationUnit and p.gender = :gender order by p.id DESC";
 
@@ -204,12 +205,13 @@
         Criteria criteria;
         if ( organisationUnit != null )
         {
-            criteria = getCriteria( Restrictions.eq( "organisationUnit", organisationUnit ) ).createAlias(
-                "programs", "program" ).add( Restrictions.eq( "program.id", program.getId() ) );
+            criteria = getCriteria( Restrictions.eq( "organisationUnit", organisationUnit ) ).createAlias( "programs",
+                "program" ).add( Restrictions.eq( "program.id", program.getId() ) );
         }
         else
         {
-            criteria = getCriteria().createAlias( "programs", "program" ).add( Restrictions.eq( "program.id", program.getId() ) );
+            criteria = getCriteria().createAlias( "programs", "program" ).add(
+                Restrictions.eq( "program.id", program.getId() ) );
         }
         criteria.addOrder( Order.desc( "id" ) );
 
@@ -222,11 +224,11 @@
 
     @Override
     @SuppressWarnings( "unchecked" )
-    public Collection<Patient> getByOrgUnitProgramGender( OrganisationUnit organisationUnit, Program program, String gender, int min, int max )
+    public Collection<Patient> getByOrgUnitProgramGender( OrganisationUnit organisationUnit, Program program,
+        String gender, int min, int max )
     {
         String hql = "select p from Patient p where p.organisationUnit = :organisationUnit and p.gender = :gender "
-            + " and :program member of p.programs"
-            + " order by p.id DESC";
+            + " and :program member of p.programs" + " order by p.id DESC";
 
         Query query = getQuery( hql );
         query.setEntity( "organisationUnit", organisationUnit );
@@ -427,8 +429,7 @@
     {
         String selector = count ? "count(*) " : "* ";
 
-        String sql = "select " + selector
-            + " from ( select distinct p.patientid, p.name, p.gender, p.phonenumber,";
+        String sql = "select " + selector + " from ( select distinct p.patientid, p.name, p.gender, p.phonenumber,";
 
         if ( identifierTypes != null )
         {
@@ -525,11 +526,26 @@
             }
             else if ( keys[0].equals( Patient.PREFIX_PROGRAM ) )
             {
-                sql += "(select programid from patient_programs where patientid=p.patientid and programid=" + id
-                    + " ) as " + Patient.PREFIX_PROGRAM + "_" + id + ",";
+                sql += "(select programid from programinstance pi where patientid=p.patientid and programid=" + id
+                    + "  and pi.status=0 ) as " + Patient.PREFIX_PROGRAM + "_" + id + ",";
                 otherWhere += operator + Patient.PREFIX_PROGRAM + "_" + id + "=" + id;
                 operator = " and ";
             }
+            else if ( keys[0].equals( Patient.PREFIX_PROGRAM_INSTANCE ) )
+            {
+                sql += "(select pi." + id + " from programinstance pi where patientid=p.patientid and pi.status=0 ";
+                if ( keys.length == 5 )
+                {
+                    sql += " and pi.programid=" + keys[4];
+                }
+                else
+                {
+                    sql += " limit 1 ";
+                }
+                sql += ") as " + Patient.PREFIX_PROGRAM_INSTANCE + "_" + id + ",";
+                otherWhere += operator + Patient.PREFIX_PROGRAM_INSTANCE + "_" + id + keys[2];
+                operator = " and ";
+            }
             else if ( keys[0].equals( Patient.PREFIX_PROGRAM_EVENT_BY_STATUS ) )
             {
                 isSearchEvent = true;
@@ -546,103 +562,103 @@
                     int statusEvent = Integer.parseInt( keys[index] );
                     switch ( statusEvent )
                     {
-                        case ProgramStageInstance.COMPLETED_STATUS:
-                            patientWhere += condition + operatorStatus
-                                + "( psi.executiondate is not null and  psi.executiondate>='" + keys[2]
-                                + "' and psi.executiondate<='" + keys[3] + "' and psi.completed=true ";
-                            // get events by orgunit children
-                            if ( keys[4].equals( "-1" ) )
-                            {
-                                patientWhere += " and psi.organisationunitid in( "
-                                    + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
-                            }
-                            // get events by selected orgunit
-                            else if ( !keys[4].equals( "0" ) )
-                            {
-                                patientWhere += " and psi.organisationunitid=" + keys[4];
-                            }
-                            patientWhere += ")";
-                            operatorStatus = " OR ";
-                            condition = "";
-                            continue;
-                        case ProgramStageInstance.VISITED_STATUS:
-                            patientWhere += condition + operatorStatus
-                                + "( psi.executiondate is not null and psi.executiondate>='" + keys[2]
-                                + "' and psi.executiondate<='" + keys[3] + "' and psi.completed=false ";
+                    case ProgramStageInstance.COMPLETED_STATUS:
+                        patientWhere += condition + operatorStatus
+                            + "( psi.executiondate is not null and  psi.executiondate>='" + keys[2]
+                            + "' and psi.executiondate<='" + keys[3] + "' and psi.completed=true ";
+                        // get events by orgunit children
+                        if ( keys[4].equals( "-1" ) )
+                        {
+                            patientWhere += " and psi.organisationunitid in( "
+                                + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
+                        }
+                        // get events by selected orgunit
+                        else if ( !keys[4].equals( "0" ) )
+                        {
+                            patientWhere += " and psi.organisationunitid=" + keys[4];
+                        }
+                        patientWhere += ")";
+                        operatorStatus = " OR ";
+                        condition = "";
+                        continue;
+                    case ProgramStageInstance.VISITED_STATUS:
+                        patientWhere += condition + operatorStatus
+                            + "( psi.executiondate is not null and psi.executiondate>='" + keys[2]
+                            + "' and psi.executiondate<='" + keys[3] + "' and psi.completed=false ";
 
-                            // get events by orgunit children
-                            if ( keys[4].equals( "-1" ) )
-                            {
-                                patientWhere += " and psi.organisationunitid in( "
-                                    + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
-                            }
-                            // get events by selected orgunit
-                            else if ( !keys[4].equals( "0" ) )
-                            {
-                                patientWhere += " and psi.organisationunitid=" + keys[4];
-                            }
-                            patientWhere += ")";
-                            operatorStatus = " OR ";
-                            condition = "";
-                            continue;
-                        case ProgramStageInstance.FUTURE_VISIT_STATUS:
-                            patientWhere += condition + operatorStatus + "( psi.executiondate is null and psi.duedate>='"
-                                + keys[2] + "' and psi.duedate<='" + keys[3]
-                                + "' and psi.status is null and (DATE(now()) - DATE(psi.duedate) <= 0) ";
-                            // get events by orgunit children
-                            if ( keys[4].equals( "-1" ) )
-                            {
-                                patientWhere += " and p.organisationunitid in( "
-                                    + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
-                            }
-                            // get events by selected orgunit
-                            else if ( !keys[4].equals( "0" ) )
-                            {
-                                patientWhere += " and p.organisationunitid=" + keys[4];
-                            }
-                            patientWhere += ")";
-                            operatorStatus = " OR ";
-                            condition = "";
-                            continue;
-                        case ProgramStageInstance.LATE_VISIT_STATUS:
-                            patientWhere += condition + operatorStatus + "( psi.executiondate is null and  psi.duedate>='"
-                                + keys[2] + "' and psi.duedate<='" + keys[3]
-                                + "' and psi.status is null  and (DATE(now()) - DATE(psi.duedate) > 0) ";
-                            // get events by orgunit children
-                            if ( keys[4].equals( "-1" ) )
-                            {
-                                patientWhere += " and p.organisationunitid in( "
-                                    + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
-                            }
-                            // get events by selected orgunit
-                            else if ( !keys[4].equals( "0" ) )
-                            {
-                                patientWhere += " and p.organisationunitid=" + keys[4];
-                            }
-                            patientWhere += ")";
-                            operatorStatus = " OR ";
-                            condition = "";
-                            continue;
-                        case ProgramStageInstance.SKIPPED_STATUS:
-                            patientWhere += condition + operatorStatus + "( psi.status=5 and  psi.duedate>='" + keys[2]
-                                + "' and psi.duedate<='" + keys[3] + "' ";
-                            // get events by orgunit children
-                            if ( keys[4].equals( "-1" ) )
-                            {
-                                patientWhere += " and psi.organisationunitid in( "
-                                    + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
-                            }
-                            // get events by selected orgunit
-                            else if ( !keys[4].equals( "0" ) )
-                            {
-                                patientWhere += " and p.organisationunitid=" + keys[4];
-                            }
-                            patientWhere += ")";
-                            operatorStatus = " OR ";
-                            condition = "";
-                            continue;
-                        default:
-                            continue;
+                        // get events by orgunit children
+                        if ( keys[4].equals( "-1" ) )
+                        {
+                            patientWhere += " and psi.organisationunitid in( "
+                                + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
+                        }
+                        // get events by selected orgunit
+                        else if ( !keys[4].equals( "0" ) )
+                        {
+                            patientWhere += " and psi.organisationunitid=" + keys[4];
+                        }
+                        patientWhere += ")";
+                        operatorStatus = " OR ";
+                        condition = "";
+                        continue;
+                    case ProgramStageInstance.FUTURE_VISIT_STATUS:
+                        patientWhere += condition + operatorStatus + "( psi.executiondate is null and psi.duedate>='"
+                            + keys[2] + "' and psi.duedate<='" + keys[3]
+                            + "' and psi.status is null and (DATE(now()) - DATE(psi.duedate) <= 0) ";
+                        // get events by orgunit children
+                        if ( keys[4].equals( "-1" ) )
+                        {
+                            patientWhere += " and p.organisationunitid in( "
+                                + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
+                        }
+                        // get events by selected orgunit
+                        else if ( !keys[4].equals( "0" ) )
+                        {
+                            patientWhere += " and p.organisationunitid=" + keys[4];
+                        }
+                        patientWhere += ")";
+                        operatorStatus = " OR ";
+                        condition = "";
+                        continue;
+                    case ProgramStageInstance.LATE_VISIT_STATUS:
+                        patientWhere += condition + operatorStatus + "( psi.executiondate is null and  psi.duedate>='"
+                            + keys[2] + "' and psi.duedate<='" + keys[3]
+                            + "' and psi.status is null  and (DATE(now()) - DATE(psi.duedate) > 0) ";
+                        // get events by orgunit children
+                        if ( keys[4].equals( "-1" ) )
+                        {
+                            patientWhere += " and p.organisationunitid in( "
+                                + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
+                        }
+                        // get events by selected orgunit
+                        else if ( !keys[4].equals( "0" ) )
+                        {
+                            patientWhere += " and p.organisationunitid=" + keys[4];
+                        }
+                        patientWhere += ")";
+                        operatorStatus = " OR ";
+                        condition = "";
+                        continue;
+                    case ProgramStageInstance.SKIPPED_STATUS:
+                        patientWhere += condition + operatorStatus + "( psi.status=5 and  psi.duedate>='" + keys[2]
+                            + "' and psi.duedate<='" + keys[3] + "' ";
+                        // get events by orgunit children
+                        if ( keys[4].equals( "-1" ) )
+                        {
+                            patientWhere += " and psi.organisationunitid in( "
+                                + TextUtils.getCommaDelimitedString( orgunitChilrenIds ) + " )";
+                        }
+                        // get events by selected orgunit
+                        else if ( !keys[4].equals( "0" ) )
+                        {
+                            patientWhere += " and p.organisationunitid=" + keys[4];
+                        }
+                        patientWhere += ")";
+                        operatorStatus = " OR ";
+                        condition = "";
+                        continue;
+                    default:
+                        continue;
                     }
                 }
                 if ( condition.isEmpty() )
@@ -663,20 +679,20 @@
                 int statusEvent = Integer.parseInt( keys[2] );
                 switch ( statusEvent )
                 {
-                    case ProgramStageInstance.COMPLETED_STATUS:
-                        patientWhere += "psi.completed=true";
-                        break;
-                    case ProgramStageInstance.VISITED_STATUS:
-                        patientWhere += "psi.executiondate is not null and psi.completed=false";
-                        break;
-                    case ProgramStageInstance.FUTURE_VISIT_STATUS:
-                        patientWhere += "psi.executiondate is null and psi.duedate >= now()";
-                        break;
-                    case ProgramStageInstance.LATE_VISIT_STATUS:
-                        patientWhere += "psi.executiondate is null and psi.duedate < now()";
-                        break;
-                    default:
-                        break;
+                case ProgramStageInstance.COMPLETED_STATUS:
+                    patientWhere += "psi.completed=true";
+                    break;
+                case ProgramStageInstance.VISITED_STATUS:
+                    patientWhere += "psi.executiondate is not null and psi.completed=false";
+                    break;
+                case ProgramStageInstance.FUTURE_VISIT_STATUS:
+                    patientWhere += "psi.executiondate is null and psi.duedate >= now()";
+                    break;
+                case ProgramStageInstance.LATE_VISIT_STATUS:
+                    patientWhere += "psi.executiondate is null and psi.duedate < now()";
+                    break;
+                default:
+                    break;
                 }
 
                 patientWhere += " and pgi.status=" + ProgramInstance.STATUS_ACTIVE + " ";

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-09-10 04:51:49 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties	2013-09-17 07:53:28 +0000
@@ -682,4 +682,5 @@
 update_comment = Update comment
 update_success = Update successfully
 send_message = Send message
-sms = SMS
\ No newline at end of file
+sms = SMS
+enrollment_date = Enrollment date
\ No newline at end of file

=== 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	2013-09-12 05:49:31 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/commons.js	2013-09-17 07:53:28 +0000
@@ -114,7 +114,8 @@
 	{
 		element.replaceWith( getAgeTextBox() );
 	}
-	else if ( attributeId=='fixedAttr_registrationDate' )
+	else if ( attributeId=='fixedAttr_registrationDate' ||
+		attributeId=='pi_enrollmentDate' )
 	{
 		element.replaceWith( getRegistrationDate(container) );
 		datePickerValid( 'searchText_' + container );
@@ -245,6 +246,7 @@
 	}
 	
 	var flag = false;
+	var addProgramId = false;
 	jQuery( '#advancedSearchTB tr' ).each( function( i, row ){
 		var dateOperator = "";
 		var p = "";
@@ -252,8 +254,9 @@
 			if(item.type!="button"){
 				if( idx == 0){
 					p = "&searchTexts=" + item.value;
-					if(item.value=='prg'){
+					if(item.value=='prg' || item.value=='pi_enrollmentDate'){
 						flag = true;
+						addProgramId = true;
 					}
 				}
 				else if( item.name == 'dateOperator'){
@@ -286,6 +289,11 @@
 		if( getFieldValue('searchByProgramStage') == "false" && !searchInAllFacility ){
 			p += "_" + getFieldValue('orgunitId');
 		}
+		
+		if( addProgramId ){
+			p += "_" + getFieldValue('programIdAddPatient');
+		}
+		
 		params += p;
 	});
 		

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm	2013-09-06 07:54:55 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/searchPatientCriteria.vm	2013-09-17 07:53:28 +0000
@@ -108,6 +108,7 @@
 					<option value="fixedAttr_age">$i18n.getString( "age_year" )</option>
 					<option value="fixedAttr_gender">$i18n.getString( "gender" )</option>
 					<option value="fixedAttr_phoneNumber">$i18n.getString( "phone_number" )</option>
+					<option value="pi_enrollmentDate">$i18n.getString( "enrollment_date" )</option>
 					#foreach( $attribute in $patientAttributes )
 						<option value="attr_$attribute.id" valueType='$attribute.valueType'>$encoder.htmlEncode( $attribute.displayName )</option>
 					#end
@@ -144,6 +145,7 @@
 						<option value="fixedAttr_age">$i18n.getString( "age_year" )</option>
 						<option value="fixedAttr_gender">$i18n.getString( "gender" )</option>
 						<option value="fixedAttr_phoneNumber">$i18n.getString( "phone_number" )</option>
+						<option value="pi_enrollmentDate">$i18n.getString( "enrollment_date" )</option>
 						#foreach( $attribute in $patientAttributes )
 							<option value="attr_$attribute.id" valueType='$attribute.valueType'>$encoder.htmlEncode( $attribute.displayName )</option>
 						#end