=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java 2012-07-11 07:24:20 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationCondition.java 2012-12-21 09:23:20 +0000 @@ -70,6 +70,9 @@ public static String OBJECT_PROGRAM_STAGE_PROPERTY = "PSP"; public static String OBJECT_PATIENT_PROGRAM_STAGE_PROPERTY = "PC"; + + public static String OBJECT_PROGRAM_PROPERTY_INCIDENT_DATE = "dateOfIncident"; + public static String OBJECT_PROGRAM_PROPERTY_ENROLLEMENT_DATE = "enrollmentDate"; // ------------------------------------------------------------------------- // Fields === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttribute.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttribute.java 2012-09-23 09:30:13 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttribute.java 2012-12-21 09:23:20 +0000 @@ -60,6 +60,9 @@ public static final String TYPE_COMBO = "COMBO"; + public static final String TYPE_CALCULATED = "CALCULATED"; + + private String description; private String valueType; @@ -74,6 +77,8 @@ private Set attributeOptions; + private String expression; + // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- @@ -207,4 +212,14 @@ this.patientAttributeGroup = patientAttributeGroup; } + public String getExpression() + { + return expression; + } + + public void setExpression( String expression ) + { + this.expression = expression; + } + } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueService.java 2012-09-05 14:30:23 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patientattributevalue/PatientAttributeValueService.java 2012-12-21 09:23:20 +0000 @@ -29,6 +29,7 @@ import java.util.Collection; import java.util.Map; +import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.patient.Patient; import org.hisp.dhis.patient.PatientAttribute; import org.hisp.dhis.patient.PatientAttributeOption; @@ -74,4 +75,6 @@ Collection getPatient( PatientAttribute attribute, String value ); void updatePatientAttributeValues( PatientAttributeOption patientAttributeOption); + + Double getCalculatedPatientAttributeValue( Patient patient, PatientAttribute patientAttribute, I18nFormat format); } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/DefaultPatientAttributeValueService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/DefaultPatientAttributeValueService.java 2012-09-05 14:30:23 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patientattributevalue/DefaultPatientAttributeValueService.java 2012-12-21 09:23:20 +0000 @@ -26,7 +26,22 @@ */ package org.hisp.dhis.patientattributevalue; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT_ATTRIBUTE; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT_PROGRAM_STAGE_PROPERTY; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT_PROPERTY; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_PROPERTY; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_STAGE; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_STAGE_DATAELEMENT; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_STAGE_PROPERTY; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_PROPERTY_INCIDENT_DATE; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PROGRAM_PROPERTY_ENROLLEMENT_DATE; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_ID; +import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.SEPARATOR_OBJECT; + import java.util.Collection; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -34,10 +49,19 @@ import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.patient.Patient; import org.hisp.dhis.patient.PatientAttribute; import org.hisp.dhis.patient.PatientAttributeOption; +import org.hisp.dhis.patient.PatientAttributeService; +import org.hisp.dhis.program.Program; +import org.hisp.dhis.program.ProgramInstance; +import org.hisp.dhis.program.ProgramInstanceService; +import org.hisp.dhis.program.ProgramService; +import org.nfunk.jep.JEP; import org.springframework.transaction.annotation.Transactional; /** @@ -48,6 +72,14 @@ public class DefaultPatientAttributeValueService implements PatientAttributeValueService { + private final String CURRENT_DATE = "current_date"; + + private final String regExp = "\\[(" + CURRENT_DATE + "|" + 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 + "([0-9]+[" + SEPARATOR_ID + "[a-zA-Z0-9]*]*)" + "\\]"; + + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -59,6 +91,27 @@ this.patientAttributeValueStore = patientAttributeValueStore; } + private PatientAttributeService patientAttributeService; + + public void setPatientAttributeService( PatientAttributeService patientAttributeService ) + { + this.patientAttributeService = patientAttributeService; + } + + private ProgramService programService; + + public void setProgramService( ProgramService programService ) + { + this.programService = programService; + } + + private ProgramInstanceService programInstanceService; + + public void setProgramInstanceService( ProgramInstanceService programInstanceService ) + { + this.programInstanceService = programInstanceService; + } + // ------------------------------------------------------------------------- // Implementation methods // ------------------------------------------------------------------------- @@ -197,8 +250,8 @@ for ( PatientAttributeValue patientAttributeValue : getPatientAttributeValues( source ) ) { - PatientAttributeValue attributeValue = new PatientAttributeValue( patientAttributeValue - .getPatientAttribute(), destination, patientAttributeValue.getValue() ); + PatientAttributeValue attributeValue = new PatientAttributeValue( + patientAttributeValue.getPatientAttribute(), destination, patientAttributeValue.getValue() ); savePatientAttributeValue( attributeValue ); } @@ -213,9 +266,97 @@ { return patientAttributeValueStore.getPatient( attribute, value ); } - + public void updatePatientAttributeValues( PatientAttributeOption patientAttributeOption ) { patientAttributeValueStore.updatePatientAttributeValues( patientAttributeOption ); } + + public Double getCalculatedPatientAttributeValue( Patient patient, PatientAttribute patientAttribute, + I18nFormat format ) + { + StringBuffer result = new StringBuffer(); + + String expression = patientAttribute.getExpression(); + + Pattern patternCondition = Pattern.compile( regExp ); + + Matcher matcher = patternCondition.matcher( expression ); + + Date currentDate = new Date(); + + while ( matcher.find() ) + { + String match = matcher.group(); + match = match.replaceAll( "[\\[\\]]", "" ); + String property = matcher.group( 1 ); + if ( CURRENT_DATE.equals( property ) ) + { + matcher.appendReplacement( result, "0" ); + } + else + { + String[] infor = matcher.group( 2 ).split( SEPARATOR_ID ); + int id = Integer.parseInt( infor[0] ); + + if ( property.equalsIgnoreCase( OBJECT_PATIENT_ATTRIBUTE ) ) + { + PatientAttribute attribute = patientAttributeService.getPatientAttribute( id ); + PatientAttributeValue attributeValue = patientAttributeValueStore.get( patient, attribute ); + + if ( PatientAttribute.TYPE_INT.equals( attributeValue.getPatientAttribute().getValueType() ) ) + { + matcher.appendReplacement( result, attributeValue.getValue() ); + } + else if ( PatientAttribute.TYPE_DATE.equals( attributeValue.getPatientAttribute().getValueType() ) ) + { + matcher.appendReplacement( result, + getDays( currentDate, format.parseDate( attributeValue.getValue() ) ) + "" ); + } + } + else if ( property.equalsIgnoreCase( OBJECT_PATIENT_PROPERTY ) ) + { + matcher.appendReplacement( result, getDays( currentDate, patient.getBirthDate() ) + "" ); + } + else if ( property.equalsIgnoreCase( OBJECT_PROGRAM ) ) + { + Program program = programService.getProgram( id ); + Collection programInstances = programInstanceService.getProgramInstances( patient, + program, false ); + + Date value = null; + if ( programInstances != null && programInstances.size() > 0) + { + ProgramInstance programInstance = programInstances.iterator().next(); + String propProgram = infor[1]; + if ( OBJECT_PROGRAM_PROPERTY_INCIDENT_DATE.equals( propProgram ) ) + { + value = programInstance.getDateOfIncident(); + } + else if ( OBJECT_PROGRAM_PROPERTY_ENROLLEMENT_DATE.equals( propProgram ) ) + { + value = programInstance.getEnrollmentDate(); + } + } + else + { + return 0.0; + } + matcher.appendReplacement( result, getDays( currentDate, value ) + "" ); + } + } + } + + final JEP parser = new JEP(); + + parser.parseExpression( result.toString() ); + + return parser.getValue(); + } + + private long getDays( Date currentDate, Date dateValue ) + { + long interval = currentDate.getTime() - dateValue.getTime(); + return (-interval / 86400000); + } } === 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 2012-12-14 13:46:47 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2012-12-21 09:23:20 +0000 @@ -265,6 +265,12 @@ class="org.hisp.dhis.patientattributevalue.DefaultPatientAttributeValueService"> + + + + + === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/PatientDashboardAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/PatientDashboardAction.java 2012-12-18 05:57:32 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/PatientDashboardAction.java 2012-12-21 09:23:20 +0000 @@ -29,10 +29,15 @@ import java.util.Collection; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; +import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.patient.Patient; +import org.hisp.dhis.patient.PatientAttribute; +import org.hisp.dhis.patient.PatientAttributeService; import org.hisp.dhis.patient.PatientAudit; import org.hisp.dhis.patient.PatientAuditService; import org.hisp.dhis.patient.PatientIdentifier; @@ -71,6 +76,10 @@ private CurrentUserService currentUserService; + private PatientAttributeService patientAttributeService; + + private I18nFormat format; + // ------------------------------------------------------------------------- // Input && Output // ------------------------------------------------------------------------- @@ -91,6 +100,8 @@ private Collection patientAudits; + private Map calAttributeValueMap = new HashMap(); + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -100,6 +111,26 @@ this.patientAuditService = patientAuditService; } + public void setFormat( I18nFormat format ) + { + this.format = format; + } + + public void setAttributeValues( Collection attributeValues ) + { + this.attributeValues = attributeValues; + } + + public void setActiveProgramInstances( Collection activeProgramInstances ) + { + this.activeProgramInstances = activeProgramInstances; + } + + public void setPatientAttributeService( PatientAttributeService patientAttributeService ) + { + this.patientAttributeService = patientAttributeService; + } + public void setPatientAttributeValueService( PatientAttributeValueService patientAttributeValueService ) { this.patientAttributeValueService = patientAttributeValueService; @@ -110,6 +141,11 @@ this.currentUserService = currentUserService; } + public Map getCalAttributeValueMap() + { + return calAttributeValueMap; + } + public Collection getActiveProgramInstances() { return activeProgramInstances; @@ -179,6 +215,14 @@ attributeValues = patientAttributeValueService.getPatientAttributeValues( patient ); + Collection calAttributes = patientAttributeService.getPatientAttributesByValueType(PatientAttribute.TYPE_CALCULATED); + + for( PatientAttribute calAttribute : calAttributes ) + { + Double value = patientAttributeValueService.getCalculatedPatientAttributeValue( patient, calAttribute, format ); + calAttributeValueMap.put( calAttribute.getName(), value ); + } + relationship = relationshipService.getRelationshipsForPatient( patient ); Collection programInstances = programInstanceService.getProgramInstances( patient ); @@ -219,5 +263,4 @@ 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 2012-12-17 13:13:51 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2012-12-21 09:23:20 +0000 @@ -979,6 +979,7 @@ + === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm 2012-12-20 07:35:58 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm 2012-12-21 09:23:20 +0000 @@ -62,6 +62,12 @@ $identifier.identifier #end + #foreach( $attributeName in $calAttributeValueMap.keySet() ) + + $attributeName + $calAttributeValueMap.get($attributeName) + + #end #foreach( $attributeValue in $attributeValues ) $attributeValue.patientAttribute.name @@ -72,8 +78,6 @@ #else $i18n.getString("no") #end - #elseif($attributeValue.patientAttribute.valueType=='DATE') - $format.formatDate( $attributeValue.value ) #else $encoder.htmlEncode($attributeValue.value) #end === modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonPatientAttribute.vm' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonPatientAttribute.vm 2012-10-23 04:48:39 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonPatientAttribute.vm 2012-12-21 09:23:20 +0000 @@ -5,6 +5,7 @@ "description": "$!encoder.jsonEncode( ${patientAttribute.description} )", "mandatory": "$!{patientAttribute.mandatory}", "valueType": "$!patientAttribute.valueType", - "inherit": "$!patientAttribute.inherit" + "inherit": "$!patientAttribute.inherit", + "expression": "$!patientAttribute.expression" } } \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/AddPatientAttributeAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/AddPatientAttributeAction.java 2012-09-23 09:30:13 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/AddPatientAttributeAction.java 2012-12-21 09:23:20 +0000 @@ -60,7 +60,7 @@ { this.patientAttributeOptionService = patientAttributeOptionService; } - + // ------------------------------------------------------------------------- // Input/Output // ------------------------------------------------------------------------- @@ -101,12 +101,19 @@ } private Boolean inherit; - + public void setInherit( Boolean inherit ) { this.inherit = inherit; } - + + private String expression; + + public void setExpression( String expression ) + { + this.expression = expression; + } + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -119,13 +126,14 @@ patientAttribute.setName( name ); patientAttribute.setDescription( description ); patientAttribute.setValueType( valueType ); - + patientAttribute.setExpression( expression ); + mandatory = (mandatory == null) ? false : true; patientAttribute.setMandatory( mandatory ); - + inherit = (inherit == null) ? false : true; patientAttribute.setInherit( inherit ); - + patientAttributeService.savePatientAttribute( patientAttribute ); if ( PatientAttribute.TYPE_COMBO.equalsIgnoreCase( valueType ) ) === added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/GetCalPatientAttributeParamsAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/GetCalPatientAttributeParamsAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/GetCalPatientAttributeParamsAction.java 2012-12-21 09:23:20 +0000 @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2004-2009, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.patient.action.patientattribute; + +import java.util.ArrayList; +import java.util.Collection; + +import org.hisp.dhis.patient.PatientAttribute; +import org.hisp.dhis.patient.PatientAttributeService; +import org.hisp.dhis.program.Program; +import org.hisp.dhis.program.ProgramService; + +import com.opensymphony.xwork2.Action; + +/** + * @author Chau Thu Tran + * + * @version GetCalPatientAttributeParamsAction.java 2:35:22 PM Dec 21, 2012 $ + */ +public class GetCalPatientAttributeParamsAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependency + // ------------------------------------------------------------------------- + + private PatientAttributeService patientAttributeService; + + public void setPatientAttributeService( PatientAttributeService patientAttributeService ) + { + this.patientAttributeService = patientAttributeService; + } + + private ProgramService programService; + + public void setProgramService( ProgramService programService ) + { + this.programService = programService; + } + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private Collection programs = new ArrayList(); + + public Collection getPrograms() + { + return programs; + } + + private Collection patientAttributes = new ArrayList(); + + public Collection getPatientAttributes() + { + return patientAttributes; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + throws Exception + { + programs = programService.getAllPrograms(); + programs.removeAll( programService.getPrograms( Program.SINGLE_EVENT_WITHOUT_REGISTRATION ) ); + + patientAttributes = patientAttributeService.getAllPatientAttributes(); + patientAttributes.removeAll( patientAttributeService + .getPatientAttributesByValueType( PatientAttribute.TYPE_CALCULATED ) ); + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/UpdatePatientAttributeAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/UpdatePatientAttributeAction.java 2012-09-23 09:30:13 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/patientattribute/UpdatePatientAttributeAction.java 2012-12-21 09:23:20 +0000 @@ -129,6 +129,13 @@ this.inherit = inherit; } + private String expression; + + public void setExpression( String expression ) + { + this.expression = expression; + } + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -141,10 +148,11 @@ patientAttribute.setName( name ); patientAttribute.setDescription( description ); patientAttribute.setValueType( valueType ); + patientAttribute.setExpression( expression ); mandatory = (mandatory == null) ? false : true; patientAttribute.setMandatory( mandatory ); - + inherit = (inherit == null) ? false : true; patientAttribute.setInherit( inherit ); === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml 2012-12-14 13:46:47 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml 2012-12-21 09:23:20 +0000 @@ -151,6 +151,15 @@ ref="org.hisp.dhis.patient.PatientAttributeService" /> + + + + + === 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-12-14 08:30:30 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties 2012-12-21 09:23:20 +0000 @@ -323,4 +323,7 @@ expression_not_null = Expression is not null complete_allowed_only_if_validation_passes = Complete allowed only if validation passes ignore_to_generate_overdue_events = Ignore to generate overdue events -display_generate_event_box_after_completed = Display generate event box after completed \ No newline at end of file +display_generate_event_box_after_completed = Display generate event box after completed +calculated = Calculated +enrollment_date = Enrollment date +incident_date = Incident date \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml 2012-11-12 07:04:25 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml 2012-12-21 09:23:20 +0000 @@ -120,7 +120,7 @@ plainTextError - + @@ -191,6 +191,14 @@ F_PATIENTATTRIBUTE_DELETE + + + /dhis-web-maintenance-patient/jsonCalPatientAttributeParams.vm + + plainTextError + + $i18n.getString( "yes_no" ) + -
[ $i18n.getString( "add_more_option" ) ] - - +
[ $i18n.getString( "add_more_option" ) ] + + + + + + $i18n.getString( "params" ) + + + + + + $i18n.getString( "expression" ) + + + + + + + +
+ $i18n.getString( "description" ) +
$!description
+
+ + @@ -73,5 +97,9 @@ === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/addPatientAttributeForm.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/addPatientAttributeForm.js 2012-03-19 09:35:42 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/addPatientAttributeForm.js 2012-12-21 09:23:20 +0000 @@ -16,6 +16,6 @@ }); jQuery("#attributeComboRow").hide(); - + checkValueIsExist( "name", "validatePatientAttribute.action"); }); \ 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/javascript/patientAttribute.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientAttribute.js 2012-09-23 09:30:13 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/patientAttribute.js 2012-12-21 09:23:20 +0000 @@ -13,6 +13,7 @@ var inherit = ( json.patientAttribute.inherit == 'true') ? i18n_yes : i18n_no; setInnerHTML( 'inheritField', inherit ); setInnerHTML( 'valueTypeField', json.patientAttribute.valueType ); + setInnerHTML( 'expressionField', json.patientAttribute.expression ); showDetails(); }); @@ -32,15 +33,50 @@ { if ( jQuery(this_).val() == "COMBO" ) { - jQuery("#attributeComboRow").show(); + hideById("calculatedAttrTR"); + hideById("expressionTR"); + showById("attributeComboRow"); if( jQuery("#attrOptionContainer").find("input").length ==0 ) { ATTRIBUTE_OPTION.addOption(); ATTRIBUTE_OPTION.addOption(); } - }else { - jQuery("#attributeComboRow").hide(); - } + } + else if (jQuery(this_).val() == "CALCULATED"){ + if( jQuery("#availableAttribute option").length == 0 ) + { + jQuery.getJSON( 'getCalPatientAttributeParams.action', { }, + function ( json ) { + var patientAttributes = jQuery("#availableAttribute"); + patientAttributes.append( "" ); + patientAttributes.append( "" ); + for ( i in json.programs ) + { + var id = "[PG:" + json.programs[i].id + ".dateOfIncident]"; + patientAttributes.append( "" ); + var id = "[PG:" + json.programs[i].id + ".enrollmentDate]"; + patientAttributes.append( "" ); + } + for ( i in json.patientAttributes ) + { + var id = "[CA:" + json.patientAttributes[i].id + "]"; + patientAttributes.append( "" ); + } + }); + } + hideById("attributeComboRow"); + showById("calculatedAttrTR"); + showById("expressionTR"); + showById("descriptionTR"); + } + else + { + hideById("attributeComboRow"); + hideById("calculatedAttrTR"); + hideById("expressionTR"); + hideById("descriptionTR"); + } + }, checkOnSubmit : function () { @@ -92,4 +128,15 @@ { return "[ - ]"; } +} + +function getConditionDescription() +{ + $.postUTF8( 'getCaseAggregationDescription.action', + { + condition:getFieldValue('expression') + },function(html) + { + setInnerHTML('expDescription', html); + }); } \ 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/javascript/updatePatientAttributeForm.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/updatePatientAttributeForm.js 2012-03-19 09:35:42 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/updatePatientAttributeForm.js 2012-12-21 09:23:20 +0000 @@ -15,5 +15,10 @@ }); }); + ATTRIBUTE_OPTION.selectValueType(byId("valueType")); + if( getFieldValue('expression') != "" ){ + getConditionDescription(); + } + checkValueIsExist( "name", "validatePatientAttribute.action", {id:getFieldValue('id')}); }); \ No newline at end of file === added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/jsonCalPatientAttributeParams.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/jsonCalPatientAttributeParams.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/jsonCalPatientAttributeParams.vm 2012-12-21 09:23:20 +0000 @@ -0,0 +1,19 @@ +#set( $size = $!{patientAttributes.size()} ) +{ "patientAttributeParams": [ + #foreach( $patientAttribute in $!{patientAttributes} ) + { + "id": "$patientAttribute.id", + "name": "$!encoder.jsonEncode( ${patientAttribute.name} )" + }#if( $velocityCount < $size ),#end + #end + ], + #set( $size = $!{programs.size()} ) + "programs":[ + #foreach( $program in $programs ) + { + "id": "$program.id", + "name": "$!encoder.jsonEncode( ${program.name} )" + }#if( $velocityCount < $size ),#end + #end + ] +} \ 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/patientAttribute.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/patientAttribute.vm 2012-10-18 13:27:17 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/patientAttribute.vm 2012-12-21 09:23:20 +0000 @@ -60,6 +60,7 @@




+


=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteForm.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteForm.vm 2012-09-23 09:30:13 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/updatePatientAttibuteForm.vm 2012-12-21 09:23:20 +0000 @@ -49,6 +49,7 @@ + @@ -67,6 +68,27 @@ + + $i18n.getString( "params" ) + + + + + + $i18n.getString( "expression" ) + + + + + + + +
+ $i18n.getString( "description" ) +
$!description
+
+ + @@ -80,16 +102,12 @@