=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttributeGroupService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttributeGroupService.java 2012-09-05 14:30:23 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/PatientAttributeGroupService.java 2013-02-18 08:23:36 +0000 @@ -27,6 +27,7 @@ package org.hisp.dhis.patient; import java.util.Collection; +import java.util.List; /** * @author Chau Thu Tran @@ -47,4 +48,6 @@ PatientAttributeGroup getPatientAttributeGroupByName( String name ); Collection getAllPatientAttributeGroups(); + + List getPatientAttributes( PatientAttributeGroup patientAttributeGroup ); } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientAttributeGroupService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientAttributeGroupService.java 2013-02-04 16:14:38 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientAttributeGroupService.java 2013-02-18 08:23:36 +0000 @@ -28,7 +28,9 @@ import static org.hisp.dhis.i18n.I18nUtils.i18n; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.hisp.dhis.i18n.I18nService; import org.springframework.transaction.annotation.Transactional; @@ -93,4 +95,9 @@ return i18n( i18nService, patientAttributeGroupStore.getAll() ); } + public List getPatientAttributes( PatientAttributeGroup patientAttributeGroup ) + { + return new ArrayList( i18n( i18nService, patientAttributeGroup.getAttributes() ) ); + } + } === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java 2013-01-21 08:13:02 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientService.java 2013-02-18 08:23:36 +0000 @@ -351,10 +351,7 @@ @Override public Collection sortPatientsByAttribute( Collection patients, PatientAttribute patientAttribute ) { - // List patientsSortedByAttribute = new - // ArrayList(); - - Collection sortedPatients = new ArrayList(); + Collection sortedPatients = new ArrayList(); // --------------------------------------------------------------------- // Better to fetch all attribute values at once than fetching the === 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-02-05 19:05:35 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/GetPatientAction.java 2013-02-18 08:23:36 +0000 @@ -26,7 +26,9 @@ */ package org.hisp.dhis.caseentry.action.patient; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -37,6 +39,7 @@ import org.hisp.dhis.patient.Patient; import org.hisp.dhis.patient.PatientAttribute; import org.hisp.dhis.patient.PatientAttributeGroup; +import org.hisp.dhis.patient.PatientAttributeGroupService; import org.hisp.dhis.patient.PatientAttributeService; import org.hisp.dhis.patient.PatientIdentifier; import org.hisp.dhis.patient.PatientIdentifierType; @@ -44,6 +47,7 @@ import org.hisp.dhis.patient.PatientRegistrationForm; import org.hisp.dhis.patient.PatientRegistrationFormService; import org.hisp.dhis.patient.PatientService; +import org.hisp.dhis.patient.comparator.PatientAttributeGroupSortOrderComparator; import org.hisp.dhis.patientattributevalue.PatientAttributeValue; import org.hisp.dhis.patientattributevalue.PatientAttributeValueService; import org.hisp.dhis.program.Program; @@ -84,9 +88,11 @@ private RelationshipTypeService relationshipTypeService; private PatientRegistrationFormService patientRegistrationFormService; - + private ProgramInstanceService programInstanceService; + private PatientAttributeGroupService attributeGroupService; + private I18n i18n; private I18nFormat format; @@ -121,7 +127,7 @@ private Relationship relationship; - private Map> attributeGroupsMap = new HashMap>(); + private Map> attributeGroupsMap = new HashMap>(); private Collection healthWorkers; @@ -138,7 +144,7 @@ { return customRegistrationForm; } - + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -160,28 +166,31 @@ if ( patientRegistrationForm != null ) { customRegistrationForm = patientRegistrationFormService.prepareDataEntryFormForAdd( - patientRegistrationForm.getDataEntryForm().getHtmlCode(), healthWorkers, patient, null, i18n, format ); + patientRegistrationForm.getDataEntryForm().getHtmlCode(), healthWorkers, patient, null, i18n, + format ); } } else { Program program = programService.getProgram( programId ); - Collection programInstances = programInstanceService.getProgramInstances( patient, program, false ); + Collection programInstances = programInstanceService.getProgramInstances( patient, + program, false ); ProgramInstance programInstance = null; - + if ( programInstances.iterator().hasNext() ) { programInstance = programInstances.iterator().next(); } - + PatientRegistrationForm patientRegistrationForm = patientRegistrationFormService .getPatientRegistrationForm( program ); - + if ( patientRegistrationForm != null ) { - customRegistrationForm = patientRegistrationFormService.prepareDataEntryFormForAdd( patientRegistrationForm - .getDataEntryForm().getHtmlCode(), healthWorkers, patient, programInstance, i18n, format ); + customRegistrationForm = patientRegistrationFormService.prepareDataEntryFormForAdd( + patientRegistrationForm.getDataEntryForm().getHtmlCode(), healthWorkers, patient, programInstance, + i18n, format ); } } @@ -199,39 +208,32 @@ // ------------------------------------------------------------------------- identifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes(); - Collection patientAttributes = patientAttributeService.getAllPatientAttributes(); - + Collection patientAttributesInProgram = new HashSet(); + Collection programs = programService.getAllPrograms(); for ( Program program : programs ) { identifierTypes.removeAll( program.getPatientIdentifierTypes() ); - patientAttributes.removeAll( program.getPatientAttributes() ); + patientAttributesInProgram.removeAll( program.getPatientAttributes() ); } - for ( PatientAttribute patientAttribute : patientAttributes ) + attributeGroups = new ArrayList( + attributeGroupService.getAllPatientAttributeGroups() ); + Collections.sort( attributeGroups, new PatientAttributeGroupSortOrderComparator() ); + for ( PatientAttributeGroup attributeGroup : attributeGroups ) { - PatientAttributeGroup attributeGroup = patientAttribute.getPatientAttributeGroup(); - - if ( attributeGroup != null ) - { - if ( attributeGroupsMap.containsKey( attributeGroup ) ) - { - Collection attributes = attributeGroupsMap.get( attributeGroup ); - attributes.add( patientAttribute ); - } - else - { - Collection attributes = new HashSet(); - attributes.add( patientAttribute ); - attributeGroupsMap.put( attributeGroup, attributes ); - } - } - else - { - noGroupAttributes.add( patientAttribute ); + List attributes = attributeGroupService.getPatientAttributes( attributeGroup ); + attributes.removeAll( patientAttributesInProgram ); + + if ( attributes.size() > 0 ) + { + attributeGroupsMap.put( attributeGroup.getId(), attributes ); } } - + + noGroupAttributes = patientAttributeService.getPatientAttributesWithoutGroup(); + noGroupAttributes.removeAll( patientAttributesInProgram ); + // ------------------------------------------------------------------------- // Get data // ------------------------------------------------------------------------- @@ -272,30 +274,7 @@ // ------------------------------------------------------------------------- // Get patient-attribute values // ------------------------------------------------------------------------- - - for ( PatientAttribute patientAttribute : patientAttributes ) - { - PatientAttributeGroup attributeGroup = patientAttribute.getPatientAttributeGroup(); - if ( attributeGroup != null ) - { - if ( attributeGroupsMap.containsKey( attributeGroup ) ) - { - Collection attributes = attributeGroupsMap.get( attributeGroup ); - attributes.add( patientAttribute ); - } - else - { - Collection attributes = new HashSet(); - attributes.add( patientAttribute ); - attributeGroupsMap.put( attributeGroup, attributes ); - } - } - else - { - noGroupAttributes.add( patientAttribute ); - } - } - + Collection patientAttributeValues = patientAttributeValueService .getPatientAttributeValues( patient ); @@ -328,6 +307,11 @@ this.patientRegistrationFormService = patientRegistrationFormService; } + public void setAttributeGroupService( PatientAttributeGroupService attributeGroupService ) + { + this.attributeGroupService = attributeGroupService; + } + public void setI18n( I18n i18n ) { this.i18n = i18n; @@ -353,7 +337,7 @@ return healthWorkers; } - public Map> getAttributeGroupsMap() + public Map> getAttributeGroupsMap() { return attributeGroupsMap; } === 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-21 13:15:04 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/PatientDashboardAction.java 2013-02-18 08:23:36 +0000 @@ -41,13 +41,16 @@ import org.hisp.dhis.patient.PatientAudit; import org.hisp.dhis.patient.PatientAuditService; import org.hisp.dhis.patient.PatientIdentifier; +import org.hisp.dhis.patient.PatientIdentifierTypeService; import org.hisp.dhis.patient.PatientService; import org.hisp.dhis.patientattributevalue.PatientAttributeValue; import org.hisp.dhis.patientattributevalue.PatientAttributeValueService; import org.hisp.dhis.program.ProgramInstance; import org.hisp.dhis.program.ProgramInstanceService; +import org.hisp.dhis.program.ProgramService; import org.hisp.dhis.relationship.Relationship; import org.hisp.dhis.relationship.RelationshipService; +import org.hisp.dhis.relationship.RelationshipTypeService; import org.hisp.dhis.user.CurrentUserService; import com.opensymphony.xwork2.Action; @@ -78,6 +81,12 @@ private PatientAttributeService patientAttributeService; + private PatientIdentifierTypeService identifierTypeService; + + private ProgramService programService; + + private RelationshipTypeService relationshipTypeService; + private I18nFormat format; // ------------------------------------------------------------------------- @@ -100,7 +109,13 @@ private Collection patientAudits; - private Map calAttributeValueMap = new HashMap(); + private Map attributeMap = new HashMap(); + + private Map identifierMap = new HashMap(); + + private Map programMap = new HashMap(); + + private Map relationshipMap = new HashMap(); // ------------------------------------------------------------------------- // Action implementation @@ -111,6 +126,41 @@ this.patientAuditService = patientAuditService; } + public void setIdentifierTypeService( PatientIdentifierTypeService identifierTypeService ) + { + this.identifierTypeService = identifierTypeService; + } + + public Map getAttributeMap() + { + return attributeMap; + } + + public Map getIdentifierMap() + { + return identifierMap; + } + + public Map getProgramMap() + { + return programMap; + } + + public Map getRelationshipMap() + { + return relationshipMap; + } + + public void setProgramService( ProgramService programService ) + { + this.programService = programService; + } + + public void setRelationshipTypeService( RelationshipTypeService relationshipTypeService ) + { + this.relationshipTypeService = relationshipTypeService; + } + public void setFormat( I18nFormat format ) { this.format = format; @@ -141,11 +191,6 @@ this.currentUserService = currentUserService; } - public Map getCalAttributeValueMap() - { - return calAttributeValueMap; - } - public Collection getActiveProgramInstances() { return activeProgramInstances; @@ -211,10 +256,19 @@ { patient = patientService.getPatient( patientId ); - identifiers = patient.getIdentifiers(); + // --------------------------------------------------------------------- + // Get patient-attribute-values + // --------------------------------------------------------------------- attributeValues = patientAttributeValueService.getPatientAttributeValues( patient ); + for ( PatientAttributeValue attributeValue : attributeValues ) + { + Integer id = attributeValue.getPatientAttribute().getId(); + attributeMap.put( patientAttributeService.getPatientAttribute( id ).getDisplayName(), + attributeValue.getValue() ); + } + Collection calAttributes = patientAttributeService .getPatientAttributesByValueType( PatientAttribute.TYPE_CALCULATED ); @@ -224,11 +278,41 @@ format ); if ( value != null ) { - calAttributeValueMap.put( calAttribute.getName(), value ); - } - } - - relationship = relationshipService.getRelationshipsForPatient( patient ); + attributeMap.put( calAttribute.getDisplayName(), value + "" ); + } + } + + // --------------------------------------------------------------------- + // Get patient-identifiers + // --------------------------------------------------------------------- + + identifiers = patient.getIdentifiers(); + + for ( PatientIdentifier identifier : identifiers ) + { + if ( identifier.getIdentifierType() != null ) + { + identifierMap.put( + identifierTypeService.getPatientIdentifierType( identifier.getIdentifierType().getId() ) + .getDisplayName(), identifier.getIdentifier() ); + } + else + { + identifierMap.put( null, identifier.getIdentifier() ); + } + } + + // --------------------------------------------------------------------- + // Get relationship + // --------------------------------------------------------------------- + + Collection relationships = relationshipService.getRelationshipsForPatient( patient ); + + for ( Relationship relationship : relationships ) + { + relationshipMap.put( relationshipTypeService.getRelationshipType( relationship.getId() ).getDisplayName(), + relationship ); + } Collection programInstances = programInstanceService.getProgramInstances( patient ); @@ -246,6 +330,12 @@ { activeProgramInstances.add( programInstance ); } + + Integer programId = programInstance.getProgram().getId(); + if ( !programMap.containsKey( programId ) ) + { + programMap.put( programId, programService.getProgram( programId ).getDisplayName() ); + } } // --------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java' --- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java 2013-02-08 12:46:09 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/patient/ShowAddPatientFormAction.java 2013-02-18 08:23:36 +0000 @@ -27,9 +27,12 @@ package org.hisp.dhis.caseentry.action.patient; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import org.hisp.dhis.i18n.I18n; @@ -38,11 +41,13 @@ import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager; import org.hisp.dhis.patient.PatientAttribute; import org.hisp.dhis.patient.PatientAttributeGroup; +import org.hisp.dhis.patient.PatientAttributeGroupService; import org.hisp.dhis.patient.PatientAttributeService; import org.hisp.dhis.patient.PatientIdentifierType; import org.hisp.dhis.patient.PatientIdentifierTypeService; import org.hisp.dhis.patient.PatientRegistrationForm; import org.hisp.dhis.patient.PatientRegistrationFormService; +import org.hisp.dhis.patient.comparator.PatientAttributeGroupSortOrderComparator; import org.hisp.dhis.program.Program; import org.hisp.dhis.program.ProgramService; import org.hisp.dhis.user.User; @@ -67,13 +72,6 @@ this.selectionManager = selectionManager; } - private PatientAttributeService patientAttributeService; - - public void setPatientAttributeService( PatientAttributeService patientAttributeService ) - { - this.patientAttributeService = patientAttributeService; - } - private PatientIdentifierTypeService patientIdentifierTypeService; public void setPatientIdentifierTypeService( PatientIdentifierTypeService patientIdentifierTypeService ) @@ -95,6 +93,20 @@ this.patientRegistrationFormService = patientRegistrationFormService; } + private PatientAttributeService attributeService; + + public void setAttributeService( PatientAttributeService attributeService ) + { + this.attributeService = attributeService; + } + + private PatientAttributeGroupService attributeGroupService; + + public void setAttributeGroupService( PatientAttributeGroupService attributeGroupService ) + { + this.attributeGroupService = attributeGroupService; + } + private I18n i18n; public void setI18n( I18n i18n ) @@ -148,9 +160,9 @@ return organisationUnit; } - private Map> attributeGroupsMap = new HashMap>(); + private Map> attributeGroupsMap = new HashMap>(); - public Map> getAttributeGroupsMap() + public Map> getAttributeGroupsMap() { return attributeGroupsMap; } @@ -169,6 +181,13 @@ return program; } + private List attributeGroups; + + public List getAttributeGroups() + { + return attributeGroups; + } + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -205,40 +224,31 @@ if ( customRegistrationForm == null ) { identifierTypes = patientIdentifierTypeService.getAllPatientIdentifierTypes(); - Collection patientAttributes = patientAttributeService.getAllPatientAttributes(); + + Collection patientAttributesInProgram = new HashSet(); Collection programs = programService.getAllPrograms(); for ( Program program : programs ) { identifierTypes.removeAll( program.getPatientIdentifierTypes() ); - patientAttributes.removeAll( program.getPatientAttributes() ); + patientAttributesInProgram.addAll( program.getPatientAttributes() ); } - attributeGroupsMap = new HashMap>(); - for ( PatientAttribute patientAttribute : patientAttributes ) + attributeGroups = new ArrayList( + attributeGroupService.getAllPatientAttributeGroups() ); + Collections.sort( attributeGroups, new PatientAttributeGroupSortOrderComparator() ); + for ( PatientAttributeGroup attributeGroup : attributeGroups ) { - if ( !patientAttribute.getValueType().equals( PatientAttribute.TYPE_CALCULATED ) ) + List attributes = attributeGroupService.getPatientAttributes( attributeGroup ); + attributes.removeAll( patientAttributesInProgram ); + + if ( attributes.size() > 0 ) { - PatientAttributeGroup attributeGroup = patientAttribute.getPatientAttributeGroup(); - if ( attributeGroup != null ) - { - if ( attributeGroupsMap.containsKey( attributeGroup ) ) - { - Collection attributes = attributeGroupsMap.get( attributeGroup ); - attributes.add( patientAttribute ); - } - else - { - Collection attributes = new HashSet(); - attributes.add( patientAttribute ); - attributeGroupsMap.put( attributeGroup, attributes ); - } - } - else - { - noGroupAttributes.add( patientAttribute ); - } + attributeGroupsMap.put( attributeGroup.getId(), attributes ); } } + + noGroupAttributes = attributeService.getPatientAttributesWithoutGroup(); + noGroupAttributes.removeAll( patientAttributesInProgram ); } 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 2013-02-04 03:09:04 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2013-02-18 08:23:36 +0000 @@ -435,6 +435,9 @@ ref="org.hisp.dhis.patient.PatientRegistrationFormService" /> + + + - + @@ -499,6 +502,9 @@ + + + + + + === 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 2013-02-13 15:58:32 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientDashboard.vm 2013-02-18 08:23:36 +0000 @@ -1,3 +1,6 @@ +$identifierMap + +

$i18n.getString( 'patient_management' ) • $i18n.getString( 'patient_dashboard' ) @@ -52,34 +55,27 @@ #end - #foreach( $identifier in $identifiers ) + #foreach( $identifierTypeName in $identifierMap.ketSet() ) - #if($!identifier.identifierType) - $identifier.identifierType.displayName + #if($!identifier) + $identifierTypeName #else $i18n.getString("system_identifier") #end - $identifier.identifier + $identifierMap.get($identifierTypeName) #end - #foreach( $attributeName in $calAttributeValueMap.keySet() ) - + #foreach( $attributeName in $attributeMap.keySet() ) + + #set( $attributeValue=$$attributeMap.get($attributeName) ) $attributeName - $calAttributeValueMap.get($attributeName) - - #end - #foreach( $attributeValue in $attributeValues ) - - $attributeValue.patientAttribute.displayName - #if($attributeValue.patientAttribute.valueType=='YES/NO') - #if($attributeValue.value=='true') - $i18n.getString("yes") - #else - $i18n.getString("no") - #end + #if($attributeValue=='true') + $i18n.getString("yes") + #elseif( $attributeValue=='false') + $i18n.getString("no") #else - $encoder.htmlEncode($attributeValue.value) + $encoder.htmlEncode($attributeValue) #end @@ -118,7 +114,7 @@ #if($programInstance.program.type==1) - • $programStageInstance.programStage.displayName ($format.formatDate($programStageInstance.dueDate)) + • $programMap.get($programInstance.program.id) ($format.formatDate($programStageInstance.dueDate)) #end === 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-02-13 15:58:32 +0000 +++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/patientForm.vm 2013-02-18 08:23:36 +0000 @@ -139,10 +139,10 @@ - #foreach ($attributeGroup in $attributeGroupsMap.keySet() ) + #foreach ($attributeGroup in $attributeGroups )   $attributeGroup.displayName - #set($attributes = $attributeGroupsMap.get($attributeGroup)) + #set($attributes = $attributeGroupsMap.get($attributeGroup.id)) #foreach($attribute in $attributes ) #set($value = "") #set($value = $patientAttributeValueMap.get($attribute.id))