← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4833: Add description for patient-attributes and programs of patient aggredation.

 

------------------------------------------------------------
revno: 4833
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-10-05 15:42:46 +0700
message:
  Add description for patient-attributes and programs of patient aggredation.
modified:
  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/resources/META-INF/dhis/beans.xml


--
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	2011-09-22 05:46:07 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java	2011-10-05 08:42:46 +0000
@@ -50,10 +50,14 @@
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientAttribute;
+import org.hisp.dhis.patient.PatientAttributeService;
 import org.hisp.dhis.patient.PatientService;
 import org.hisp.dhis.patientdatavalue.PatientDataValue;
 import org.hisp.dhis.patientdatavalue.PatientDataValueService;
 import org.hisp.dhis.period.Period;
+import org.hisp.dhis.program.Program;
+import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.program.ProgramStage;
 import org.hisp.dhis.program.ProgramStageService;
 import org.hisp.dhis.system.util.DateUtils;
@@ -78,6 +82,8 @@
 
     private final String PROPERTY_AGE = "age";
 
+    private final String INVALID_CONDITION = "Invalid condition";
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -94,6 +100,10 @@
 
     private DataElementCategoryService categoryService;
 
+    private ProgramService programService;
+
+    private PatientAttributeService patientAttributeService;
+
     // -------------------------------------------------------------------------
     // Getters && Setters
     // -------------------------------------------------------------------------
@@ -103,6 +113,16 @@
         this.aggregationConditionStore = aggregationConditionStore;
     }
 
+    public void setPatientAttributeService( PatientAttributeService patientAttributeService )
+    {
+        this.patientAttributeService = patientAttributeService;
+    }
+
+    public void setProgramService( ProgramService programService )
+    {
+        this.programService = programService;
+    }
+
     public void setProgramStageService( ProgramStageService programStageService )
     {
         this.programStageService = programStageService;
@@ -234,18 +254,11 @@
 
     public String getConditionDescription( String condition )
     {
-        StringBuffer decription = new StringBuffer();
-
-        String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "[0-9]+" + SEPARATOR_ID
-            + "[0-9]+" + SEPARATOR_ID + "[0-9]+" + "\\]";
-
-        // ---------------------------------------------------------------------
-        // parse expressions
-        // ---------------------------------------------------------------------
-
-        Pattern pattern = Pattern.compile( regExp );
-
-        Matcher matcher = pattern.matcher( condition );
+        StringBuffer description = new StringBuffer();
+
+        Pattern patternCondition = Pattern.compile( regExp );
+
+        Matcher matcher = patternCondition.matcher( condition );
 
         while ( matcher.find() )
         {
@@ -253,30 +266,64 @@
             match = match.replaceAll( "[\\[\\]]", "" );
 
             String[] info = match.split( SEPARATOR_OBJECT );
-            String[] ids = info[1].split( SEPARATOR_ID );
-
-            int programStageId = Integer.parseInt( ids[0] );
-            ProgramStage programStage = programStageService.getProgramStage( programStageId );
-
-            int dataElementId = Integer.parseInt( ids[1] );
-            DataElement dataElement = dataElementService.getDataElement( dataElementId );
-
-            int categoryOptionId = Integer.parseInt( ids[2] );
-            DataElementCategoryOptionCombo optionCombo = categoryService
-                .getDataElementCategoryOptionCombo( categoryOptionId );
-
-            if ( programStage == null || dataElement == null || optionCombo == null )
-            {
-                return "Invalid condition";
-            }
-
-            matcher.appendReplacement( decription, "[" + programStage.getName() + SEPARATOR_ID + dataElement.getName()
-                + optionCombo.getName() + "]" );
+
+            if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM_STAGE_DATAELEMENT ) )
+            {
+                String[] ids = info[1].split( SEPARATOR_ID );
+
+                int programStageId = Integer.parseInt( ids[0] );
+                ProgramStage programStage = programStageService.getProgramStage( programStageId );
+
+                int dataElementId = Integer.parseInt( ids[1] );
+                DataElement dataElement = dataElementService.getDataElement( dataElementId );
+
+                int categoryOptionId = Integer.parseInt( ids[2] );
+                DataElementCategoryOptionCombo optionCombo = categoryService
+                    .getDataElementCategoryOptionCombo( categoryOptionId );
+
+                if ( programStage == null || dataElement == null || optionCombo == null )
+                {
+                    return INVALID_CONDITION;
+                }
+
+                matcher.appendReplacement( description, "[" + programStage.getName() + SEPARATOR_ID
+                    + dataElement.getName() + optionCombo.getName() + "]" );
+            }
+            else
+            {
+                String[] ids = info[1].split( SEPARATOR_ID );
+                
+                int objectId = Integer.parseInt(ids[0]);
+                
+                if ( info[0].equalsIgnoreCase( OBJECT_PATIENT_ATTRIBUTE ) )
+                {
+                    PatientAttribute patientAttribute = patientAttributeService.getPatientAttribute( objectId );
+
+                    if ( patientAttribute == null )
+                    {
+                        return INVALID_CONDITION;
+                    }
+
+                    matcher.appendReplacement( description, "[" + OBJECT_PATIENT_ATTRIBUTE + SEPARATOR_OBJECT + patientAttribute.getName() + "]" );
+                }
+                else if ( info[0].equalsIgnoreCase( OBJECT_PROGRAM ) )
+                {
+                    Program program = programService.getProgram( objectId );
+
+                    if ( program == null )
+                    {
+                        return INVALID_CONDITION;
+                    }
+
+                    matcher.appendReplacement( description, "[" + OBJECT_PROGRAM + SEPARATOR_OBJECT + program.getName() + "]" );
+                }
+            }
+
         }
 
-        matcher.appendTail( decription );
+        matcher.appendTail( description );
 
-        return decription.toString();
+        return description.toString();
     }
 
     public Collection<DataElement> getDataElementsInCondition( String aggregationExpression )

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2011-09-06 02:47:21 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml	2011-10-05 08:42:46 +0000
@@ -179,7 +179,9 @@
         <property name="patientService" ref="org.hisp.dhis.patient.PatientService" />     	
         <property name="dataValueService" ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
         <property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />     	
-        <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />     	     	
+        <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+        <property name="programService" ref="org.hisp.dhis.program.ProgramService" />
+        <property name="patientAttributeService" ref="org.hisp.dhis.patient.PatientAttributeService" />      	     	
     </bean>
     
 	<bean id="org.hisp.dhis.program.nextvisit.NextVisitGenerator"