=== 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 2013-12-18 08:01:59 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttribute.java 2013-12-19 04:00:58 +0000 @@ -39,6 +39,8 @@ import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.common.view.DetailedView; +import java.util.Calendar; +import java.util.Date; import java.util.HashSet; import java.util.Set; @@ -65,11 +67,13 @@ public static final String TYPE_TRUE_ONLY = "trueOnly"; public static final String TYPE_COMBO = "combo"; - + public static final String TYPE_PHONE_NUMBER = "phoneNumber"; - + public static final String TYPE_TRACKER_ASSOCIATE = "trackerAssociate"; + public static final String TYPE_AGE = "age"; + private String description; private String valueType; @@ -108,7 +112,7 @@ this.mandatory = mandatory; this.inherit = inherit; this.displayOnVisitSchedule = displayOnVisitSchedule; - + setAutoFields(); } @@ -123,7 +127,7 @@ { return TYPE_INT.equals( valueType ); } - + // ------------------------------------------------------------------------- // Getters and setters // ------------------------------------------------------------------------- @@ -269,4 +273,39 @@ { this.sortOrderInVisitSchedule = sortOrderInVisitSchedule; } + + public static Date getDateFromAge( int age ) + { + Calendar todayCalendar = Calendar.getInstance(); + todayCalendar.clear( Calendar.MILLISECOND ); + todayCalendar.clear( Calendar.SECOND ); + todayCalendar.clear( Calendar.MINUTE ); + todayCalendar.set( Calendar.HOUR_OF_DAY, 0 ); + + todayCalendar.add( Calendar.YEAR, -1 * age ); + + return todayCalendar.getTime(); + } + + public static int getAgeFromDate( Date date ) + { + Calendar birthCalendar = Calendar.getInstance(); + birthCalendar.setTime( date ); + + Calendar todayCalendar = Calendar.getInstance(); + + int age = todayCalendar.get( Calendar.YEAR ) - birthCalendar.get( Calendar.YEAR ); + + if ( todayCalendar.get( Calendar.MONTH ) < birthCalendar.get( Calendar.MONTH ) ) + { + age--; + } + else if ( todayCalendar.get( Calendar.MONTH ) == birthCalendar.get( Calendar.MONTH ) + && todayCalendar.get( Calendar.DAY_OF_MONTH ) < birthCalendar.get( Calendar.DAY_OF_MONTH ) ) + { + age--; + } + + return age; + } } \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddPatientAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddPatientAction.java 2013-12-18 08:01:59 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/AddPatientAction.java 2013-12-19 04:00:58 +0000 @@ -38,6 +38,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.struts2.ServletActionContext; +import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager; import org.hisp.dhis.patient.Patient; @@ -93,6 +94,8 @@ private OrganisationUnitSelectionManager selectionManager; + private I18nFormat format; + // ------------------------------------------------------------------------- // Input // ------------------------------------------------------------------------- @@ -210,6 +213,11 @@ attributeValue = new PatientAttributeValue(); attributeValue.setPatient( patient ); attributeValue.setPatientAttribute( attribute ); + + if ( attribute.getValueType().equals( PatientAttribute.TYPE_AGE ) ) + { + value = format.formatDate( PatientAttribute.getDateFromAge( Integer.parseInt( value ) ) ); + } attributeValue.setValue( value ); if ( PatientAttribute.TYPE_COMBO.equalsIgnoreCase( attribute.getValueType() ) ) @@ -225,10 +233,6 @@ // Someone deleted this option ... } } - else - { - attributeValue.setValue( value.trim() ); - } patientAttributeValues.add( attributeValue ); } } @@ -238,7 +242,7 @@ // Save patient // ------------------------------------------------------------------------- - Integer id = patientService.createPatient( patient, representativeId, relationshipTypeId, + patientService.createPatient( patient, representativeId, relationshipTypeId, patientAttributeValues ); // ------------------------------------------------------------------------- @@ -337,6 +341,11 @@ this.patientService = patientService; } + public void setFormat( I18nFormat format ) + { + this.format = format; + } + public void setPatientIdentifierService( PatientIdentifierService patientIdentifierService ) { this.patientIdentifierService = patientIdentifierService; === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java 2013-12-16 04:27:26 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java 2013-12-19 04:00:58 +0000 @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -281,15 +282,18 @@ PatientIdentifierType idType = null; Patient representative = patient.getRepresentative(); - relationship = relationshipService.getRelationship( representative, patient ); - - for ( PatientIdentifier representativeIdentifier : representative.getIdentifiers() ) + if ( representative != null ) { - if ( representativeIdentifier.getIdentifierType() != null - && representativeIdentifier.getIdentifierType().isRelated() ) + relationship = relationshipService.getRelationship( representative, patient ); + + for ( PatientIdentifier representativeIdentifier : representative.getIdentifiers() ) { - identiferMap.put( representativeIdentifier.getIdentifierType().getId(), - representativeIdentifier.getIdentifier() ); + if ( representativeIdentifier.getIdentifierType() != null + && representativeIdentifier.getIdentifierType().isRelated() ) + { + identiferMap.put( representativeIdentifier.getIdentifierType().getId(), + representativeIdentifier.getIdentifier() ); + } } } @@ -312,8 +316,14 @@ for ( PatientAttributeValue patientAttributeValue : patientAttributeValues ) { - patientAttributeValueMap.put( patientAttributeValue.getPatientAttribute().getId(), - patientAttributeValue.getValue() ); + String value = patientAttributeValue.getValue(); + if ( patientAttributeValue.getPatientAttribute().getValueType().equals( PatientAttribute.TYPE_AGE ) ) + { + Date date = format.parseDate( value ); + value = PatientAttribute.getAgeFromDate( date ) + ""; + } + + patientAttributeValueMap.put( patientAttributeValue.getPatientAttribute().getId(), value ); } } === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/UpdatePatientAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/UpdatePatientAction.java 2013-12-18 08:01:59 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/UpdatePatientAction.java 2013-12-19 04:00:58 +0000 @@ -37,6 +37,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.struts2.ServletActionContext; +import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager; import org.hisp.dhis.patient.Patient; @@ -83,6 +84,8 @@ private OrganisationUnitSelectionManager selectionManager; + private I18nFormat format; + // ------------------------------------------------------------------------- // Input // ------------------------------------------------------------------------- @@ -198,6 +201,11 @@ if ( StringUtils.isNotBlank( value ) ) { + if ( attribute.getValueType().equals( PatientAttribute.TYPE_AGE ) ) + { + value = format.formatDate( PatientAttribute.getDateFromAge( Integer.parseInt( value ) ) ); + } + attributeValue = patientAttributeValueService.getPatientAttributeValue( patient, attribute ); if ( attributeValue == null ) @@ -263,6 +271,11 @@ this.userService = userService; } + public void setFormat( I18nFormat format ) + { + this.format = format; + } + public void setHealthWorker( Integer healthWorker ) { this.healthWorker = healthWorker; === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm 2013-12-18 08:01:59 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm 2013-12-19 04:00:58 +0000 @@ -80,31 +80,33 @@