← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13644: Fixed bug - Don't save post comment of events

 

------------------------------------------------------------
revno: 13644
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-01-08 09:53:44 +0700
message:
  Fixed bug - Don't save post comment of events
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramExpression.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramExpressionService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SavePatientCommentAction.java
  dhis-2/dhis-web/dhis-web-caseentry/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-api/src/main/java/org/hisp/dhis/program/ProgramExpression.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramExpression.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramExpression.java	2014-01-08 02:53:44 +0000
@@ -42,6 +42,7 @@
 
     public static final String SEPARATOR_ID = "\\.";
     public static String OBJECT_PROGRAM_STAGE_DATAELEMENT = "DE";
+    public static String OBJECT_PROGRAM_STAGE = "PS";
 
     public static final String SEPARATOR_OBJECT = ":";
     public static final String DUE_DATE = "DUE_DATE";    

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java	2014-01-03 09:32:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java	2014-01-08 02:53:44 +0000
@@ -31,6 +31,7 @@
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.message.MessageConversation;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.patientcomment.PatientComment;
 import org.hisp.dhis.sms.outbound.OutboundSms;
 
 import java.util.ArrayList;
@@ -43,7 +44,7 @@
  */
 /**
  * @author abyot
- *
+ * 
  */
 public class ProgramStageInstance
     extends BaseIdentifiableObject
@@ -81,6 +82,8 @@
 
     private List<MessageConversation> messageConversations = new ArrayList<MessageConversation>();
 
+    private PatientComment patientComment;
+
     private Integer status = ACTIVE_STATUS;
 
     private Double longitude;
@@ -102,7 +105,6 @@
 
     public ProgramStageInstance( ProgramInstance programInstance, ProgramStage programStage )
     {
-        this();
         this.programInstance = programInstance;
         this.programStage = programStage;
     }
@@ -314,9 +316,19 @@
     public void setLatitude( Double latitude )
     {
         this.latitude = latitude;
-    }  
-
-	public Integer getEventStatus()
+    }
+
+    public PatientComment getPatientComment()
+    {
+        return patientComment;
+    }
+
+    public void setPatientComment( PatientComment patientComment )
+    {
+        this.patientComment = patientComment;
+    }
+
+    public Integer getEventStatus()
     {
         if ( this.status != 0 )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramExpressionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramExpressionService.java	2013-11-13 07:40:27 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramExpressionService.java	2014-01-08 02:53:44 +0000
@@ -53,7 +53,7 @@
     implements ProgramExpressionService
 {
     private final String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "([a-zA-Z0-9\\- ]+["
-        + SEPARATOR_ID + "[0-9]+]*)" + "\\]";
+        + SEPARATOR_ID + "[a-zA-Z0-9\\- ]+]*)" + "\\]";
 
     private final String INVALID_CONDITION = "Invalid condition";
 
@@ -121,11 +121,11 @@
         ProgramStageInstance programStageInstance, Map<String, String> patientDataValueMap )
     {
         String value = "";
-        if ( ProgramExpression.DUE_DATE.equals( programExpression.getExpression() ) )
+        if ( programExpression.getExpression().contains( ProgramExpression.DUE_DATE ) )
         {
             value = DateUtils.getMediumDateString( programStageInstance.getDueDate() );
         }
-        else if ( ProgramExpression.REPORT_DATE.equals( programExpression.getExpression() ) )
+        else if ( programExpression.getExpression().contains( ProgramExpression.REPORT_DATE ) )
         {
             value = DateUtils.getMediumDateString( programStageInstance.getExecutionDate() );
         }
@@ -148,10 +148,10 @@
             }
 
             matcher.appendTail( description );
-           
+
             value = description.toString();
         }
-        
+
         return value;
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java	2013-11-22 03:31:28 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramValidationService.java	2014-01-08 02:53:44 +0000
@@ -29,6 +29,7 @@
  */
 
 import static org.hisp.dhis.program.ProgramExpression.OBJECT_PROGRAM_STAGE_DATAELEMENT;
+import static org.hisp.dhis.program.ProgramExpression.OBJECT_PROGRAM_STAGE;
 import static org.hisp.dhis.program.ProgramExpression.SEPARATOR_ID;
 import static org.hisp.dhis.program.ProgramExpression.SEPARATOR_OBJECT;
 
@@ -54,8 +55,8 @@
 public class DefaultProgramValidationService
     implements ProgramValidationService
 {
-    private final String regExp = "\\[" + OBJECT_PROGRAM_STAGE_DATAELEMENT + SEPARATOR_OBJECT + "([a-zA-Z0-9\\- ]+["
-        + SEPARATOR_ID + "[0-9]*]*)" + "\\]";
+    private final String regExp = "\\[(" + OBJECT_PROGRAM_STAGE_DATAELEMENT + "|" + OBJECT_PROGRAM_STAGE + ")"
+        + SEPARATOR_OBJECT + "([a-zA-Z0-9\\- ]+[" + SEPARATOR_ID + "[a-zA-Z0-9\\- ]*]*)" + "\\]";
 
     private ProgramValidationStore validationStore;
 
@@ -150,7 +151,7 @@
             patientDataValues = patientDataValueService.getPatientDataValues( programStageInstance.getProgramInstance()
                 .getProgramStageInstances() );
         }
-        
+
         Map<String, String> patientDataValueMap = new HashMap<String, String>( patientDataValues.size() );
         for ( PatientDataValue patientDataValue : patientDataValues )
         {
@@ -170,6 +171,7 @@
             String rightSideValue = expressionService.getProgramExpressionValue( validate.getRightSide(),
                 programStageInstance, patientDataValueMap );
             String operator = validate.getOperator().getMathematicalOperator();
+            
             if ( (leftSideValue != null && rightSideValue != null && !((operator.equals( "==" ) && leftSideValue
                 .compareTo( rightSideValue ) == 0)
                 || (operator.equals( "<" ) && leftSideValue.compareTo( rightSideValue ) < 0)
@@ -202,7 +204,7 @@
         {
             Collection<DataElement> dataElements = getDataElementInExpression( validation );
             Collection<ProgramStage> programStages = getProgramStageInExpression( validation );
-            
+
             if ( dataElements.contains( psdataElement.getDataElement() )
                 && programStages.contains( psdataElement.getProgramStage() ) )
             {
@@ -216,7 +218,7 @@
     public Collection<ProgramValidation> getProgramValidation( ProgramStage programStage )
     {
         Collection<ProgramValidation> programValidation = getProgramValidation( programStage.getProgram() );
-
+        
         Iterator<ProgramValidation> iter = programValidation.iterator();
 
         Pattern pattern = Pattern.compile( regExp );
@@ -228,7 +230,7 @@
             String expression = validation.getLeftSide().getExpression() + " "
                 + validation.getRightSide().getExpression();
             Matcher matcher = pattern.matcher( expression );
-
+System.out.println("\n\n===\n expression : " + expression);
             boolean flag = false;
             while ( matcher.find() )
             {
@@ -239,7 +241,7 @@
                 String[] ids = info[1].split( SEPARATOR_ID );
 
                 int programStageId = Integer.parseInt( ids[0] );
-
+System.out.println("\n\n === programStageId "  + programStageId );
                 if ( programStageId == programStage.getId() )
                 {
                     flag = true;
@@ -265,7 +267,8 @@
         Collection<DataElement> dataElements = new HashSet<DataElement>();
 
         Pattern pattern = Pattern.compile( regExp );
-        String expression = programValidation.getLeftSide().getExpression() + " " + programValidation.getRightSide().getExpression();
+        String expression = programValidation.getLeftSide().getExpression() + " "
+            + programValidation.getRightSide().getExpression();
         Matcher matcher = pattern.matcher( expression );
         while ( matcher.find() )
         {
@@ -289,7 +292,8 @@
         Collection<ProgramStage> programStages = new HashSet<ProgramStage>();
 
         Pattern pattern = Pattern.compile( regExp );
-        String expression = programValidation.getLeftSide().getExpression() + " " + programValidation.getRightSide().getExpression();
+        String expression = programValidation.getLeftSide().getExpression() + " "
+            + programValidation.getRightSide().getExpression();
         Matcher matcher = pattern.matcher( expression );
 
         while ( matcher.find() )

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml	2013-12-16 08:29:52 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml	2014-01-08 02:53:44 +0000
@@ -40,23 +40,27 @@
 			<many-to-many class="org.hisp.dhis.sms.outbound.OutboundSms"
 				column="outboundsmsid" />
 		</list>
-		
+
 		<list name="messageConversations" table="programstageinstance_messageconversation">
 			<key column="programstageinstanceid" />
 			<list-index column="sort_order" base="1" />
 			<many-to-many class="org.hisp.dhis.message.MessageConversation"
 				column="messageconversationid" />
 		</list>
-		
+
 		<property name="status" column="status" />
 
 		<property name="longitude" />
 
 		<property name="latitude" />
-		
+
 		<property name="completedUser" />
 
 		<property name="completedDate" />
-					
+		
+		<many-to-one name="patientComment" cascade="all"
+			class="org.hisp.dhis.patientcomment.PatientComment" column="patientcommentid"
+			foreign-key="fk_programinstance_patientcommentid" />
+
 	</class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SavePatientCommentAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SavePatientCommentAction.java	2014-01-02 13:45:23 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/reminder/SavePatientCommentAction.java	2014-01-08 02:53:44 +0000
@@ -29,11 +29,8 @@
  */
 
 import java.util.Date;
-import java.util.Set;
 
 import org.hisp.dhis.patientcomment.PatientComment;
-import org.hisp.dhis.program.ProgramInstance;
-import org.hisp.dhis.program.ProgramInstanceService;
 import org.hisp.dhis.program.ProgramStageInstance;
 import org.hisp.dhis.program.ProgramStageInstanceService;
 import org.hisp.dhis.user.CurrentUserService;
@@ -58,13 +55,6 @@
     {
         this.programStageInstanceService = programStageInstanceService;
     }
-    
-    private ProgramInstanceService programInstanceService;
-
-    public void setProgramInstanceService( ProgramInstanceService programInstanceService )
-    {
-        this.programInstanceService = programInstanceService;
-    }
 
     private CurrentUserService currentUserService;
 
@@ -98,25 +88,22 @@
     public String execute()
     {
         ProgramStageInstance programStageInstance = programStageInstanceService
-            .getProgramStageInstance( programStageInstanceId );  
-        
-        ProgramInstance programInstance = programStageInstance.getProgramInstance();
-                
-        Set<PatientComment> patientComments = programInstance.getPatientComments();
+            .getProgramStageInstance( programStageInstanceId );
 
         if ( commentText != null && !commentText.isEmpty() )
         {
-            PatientComment patientComment = new PatientComment();       
+            PatientComment patientComment = new PatientComment();
 
             patientComment.setCommentText( commentText );
             patientComment.setCreator( currentUserService.getCurrentUsername() );
             patientComment.setCreatedDate( new Date() );
-            patientComments.add(patientComment);
-            
-            programInstanceService.updateProgramInstance( programInstance );           
-            
-        }        
-        
+
+            programStageInstance.setPatientComment( patientComment );
+
+            programStageInstanceService.updateProgramStageInstance( programStageInstance );
+
+        }
+
         return SUCCESS;
     }
 }

=== 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-01-07 15:02:45 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2014-01-08 02:53:44 +0000
@@ -1025,8 +1025,6 @@
 		scope="prototype">
 		<property name="programStageInstanceService"
 			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
-                <property name="programInstanceService"
-			ref="org.hisp.dhis.program.ProgramInstanceService" />
 		<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
 	</bean>