← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7875: Add formula to generate the number of person who visited a program-stagae x(th) time

 

------------------------------------------------------------
revno: 7875
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-08-08 17:42:47 +0700
message:
  Add formula to generate the number of person who visited a program-stagae x(th) time
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.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-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2012-07-11 07:43:32 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2012-08-08 10:42:47 +0000
@@ -27,6 +27,7 @@
 
 package org.hisp.dhis.caseaggregation;
 
+import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.AGGRERATION_COUNT;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.AGGRERATION_SUM;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT;
 import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT_ATTRIBUTE;
@@ -82,7 +83,7 @@
     private final String regExp = "\\[(" + OBJECT_PATIENT + "|" + OBJECT_PROGRAM + "|" + OBJECT_PROGRAM_STAGE + "|"
         + OBJECT_PROGRAM_STAGE_PROPERTY + "|" + OBJECT_PATIENT_PROGRAM_STAGE_PROPERTY + "|"
         + OBJECT_PROGRAM_STAGE_DATAELEMENT + "|" + OBJECT_PATIENT_ATTRIBUTE + "|" + OBJECT_PATIENT_PROPERTY + "|"
-        + OBJECT_PROGRAM_PROPERTY + ")" + SEPARATOR_OBJECT + "([a-zA-Z0-9@#\\- ]+[" + SEPARATOR_ID + "[0-9]*]*)"
+        + OBJECT_PROGRAM_PROPERTY + ")" + SEPARATOR_OBJECT + "([a-zA-Z0-9@#\\- ]+[" + SEPARATOR_ID + "[a-zA-Z0-9]*]*)"
         + "\\]";
 
     private final String IS_NULL = "is null";
@@ -99,6 +100,8 @@
 
     private final String IN_CONDITION_END_SIGN = "#";
 
+    private final String IN_CONDITION_COUNT_X_TIMES = "COUNT";
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -384,7 +387,6 @@
                 else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM_STAGE ) )
                 {
                     int objectId = Integer.parseInt( ids[0] );
-
                     ProgramStage programStage = programStageService.getProgramStage( objectId );
 
                     if ( programStage == null )
@@ -392,8 +394,10 @@
                         return INVALID_CONDITION;
                     }
 
+                    String count = (ids.length == 2) ? SEPARATOR_ID + ids[1] : "";
                     matcher.appendReplacement( description, "[" + OBJECT_PROGRAM_STAGE + SEPARATOR_OBJECT
-                        + programStage.getName() + "]" );
+                        + programStage.getName() + count + "]" );
+
                 }
             }
 
@@ -661,7 +665,15 @@
                 }
                 else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM_STAGE ) )
                 {
-                    condition = getConditionForProgramStage( info[1], operator, orgunitId, startDate, endDate );
+                    String[] ids = info[1].split( SEPARATOR_ID );
+                    if ( ids.length == 2 && ids[1].equals( IN_CONDITION_COUNT_X_TIMES ) )
+                    {
+                        condition = getConditionForCountProgramStage( ids[0], operator, orgunitId, startDate, endDate );
+                    }
+                    else
+                    {
+                        condition = getConditionForProgramStage( ids[0], operator, orgunitId, startDate, endDate );
+                    }
                 }
                 else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM_STAGE_PROPERTY ) )
                 {
@@ -908,6 +920,34 @@
             + "' AND psi.organisationunitid = " + orgunitId + " ";
     }
 
+    private String getConditionForCountProgramStage( String programStageId, String operator, int orgunitId,
+        String startDate, String endDate )
+    {
+        String select = "SELECT distinct(pi.patientid) ";
+
+        if ( operator.equals( AGGRERATION_SUM ) )
+        {
+            select = "SELECT psi.programstageinstanceid ";
+        }
+
+        select += "FROM programstageinstance as psi "
+            + "INNER JOIN programstage as ps ON psi.programstageid = ps.programstageid "
+            + "INNER JOIN programinstance as pi ON pi.programinstanceid = psi.programinstanceid "
+            + "WHERE psi.organisationunitid = " + orgunitId + " and psi.programstageid = " + programStageId + " "
+            + "AND psi.executionDate >= '" + startDate + "' AND psi.executionDate <= '" + endDate + "' "
+            + "GROUP BY psi.programinstanceid ";
+
+        if ( operator.equals( AGGRERATION_COUNT ) )
+        {
+            select += ",pi.patientid ";
+        }
+
+        select += "HAVING count(psi.programstageinstanceid) ";
+
+        return select;
+
+    }
+
     private String getConditionForProgramStageProperty( String property, String operator, int orgunitId,
         String startDate, String endDate )
     {

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2012-08-07 10:05:02 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties	2012-08-08 10:42:47 +0000
@@ -254,4 +254,5 @@
 intro_patient_aggregation_query_builder = Define formulas, expressions, rules for aggregation data from name-based to aggregation system
 show_incident_date = Show incident date
 display_date_of_incident = Display date of incident
-patient_attribute_group_sort_order = Person attribute group sort order
\ No newline at end of file
+patient_attribute_group_sort_order = Person attribute group sort order
+visit_selected_program_stage_x_th_times = Visit selected program stage x(th) times
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.vm	2012-07-24 08:07:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/caseAggregationForm.vm	2012-08-08 10:42:47 +0000
@@ -65,6 +65,7 @@
 				<td>
 					<select multiple id="programStageProperty" size="10"  name="programStageProperty" ondblclick="insertInfo(this, true);" disabled >
 						<option value="[PS:*]">$i18n.getString( "visit_selected_program_stage" )</option>
+						<option value="[PS:*.COUNT]">$i18n.getString( "visit_selected_program_stage_x_th_times" )</option>
 						<option value="[PS:*] AND [PSP:DATE@executionDate#-DATE@dueDate#]">$i18n.getString( "report_date" ) - $i18n.getString( "due_date" )</option>
 						<option value="[PS:*] AND [PC:DATE@executionDate#-DATE@birthDate#]">$i18n.getString( "report_date" ) - $i18n.getString( "date_of_birth" )</option>
 					</select>