=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2013-05-30 02:20:29 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2013-05-30 07:18:04 +0000 @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; +import java.util.Iterator; import java.util.List; import org.hisp.dhis.common.Grid; @@ -84,6 +85,13 @@ this.patientDataValueService = patientDataValueService; } + private ProgramService programService; + + public void setProgramService( ProgramService programService ) + { + this.programService = programService; + } + // ------------------------------------------------------------------------- // Implementation methods // ------------------------------------------------------------------------- @@ -208,8 +216,6 @@ attrGrid.addHeader( new GridHeader( i18n.getString( "value" ), false, true ) ); attrGrid.addHeader( new GridHeader( "", true, false ) ); - Collection patientAttributes = patient.getAttributes(); - // --------------------------------------------------------------------- // Add fixed attribues // --------------------------------------------------------------------- @@ -240,24 +246,35 @@ // Add dynamic attribues // --------------------------------------------------------------------- - for ( PatientAttribute patientAttribute : patientAttributes ) + Collection programs = programService + .getProgramsByCurrentUser( Program.MULTIPLE_EVENTS_WITH_REGISTRATION ); + programs.addAll( programService.getProgramsByCurrentUser( Program.SINGLE_EVENT_WITH_REGISTRATION ) ); + + Collection attributeValues = patientAttributeValueService + .getPatientAttributeValues( patient ); + Iterator iterAttribute = attributeValues.iterator(); + + for ( Program program : programs ) + { + Collection atttributes = program.getPatientAttributes(); + while ( iterAttribute.hasNext() ) + { + PatientAttributeValue attributeValue = iterAttribute.next(); + if ( !atttributes.contains( attributeValue.getPatientAttribute() ) ) + { + iterAttribute.remove(); + } + } + } + + for ( PatientAttributeValue attributeValue : attributeValues ) { attrGrid.addRow(); - attrGrid.addValue( patientAttribute.getDisplayName() ); - PatientAttributeValue attributeValue = patientAttributeValueService.getPatientAttributeValue( patient, - patientAttribute ); - String value = ""; - if ( attributeValue == null ) - { - value = PatientAttributeValue.UNKNOWN; - } - else if ( attributeValue.getPatientAttribute().getValueType().equals( PatientAttribute.TYPE_BOOL ) ) - { - value = i18n.getString( attributeValue.getValue() ); - } - else - { - value = attributeValue.getValue(); + attrGrid.addValue( attributeValue.getPatientAttribute().getDisplayName() ); + String value = attributeValue.getValue(); + if ( attributeValue.getPatientAttribute().getValueType().equals( PatientAttribute.TYPE_BOOL ) ) + { + value = i18n.getString( value ); } attrGrid.addValue( value ); @@ -267,21 +284,36 @@ // Add identifier // --------------------------------------------------------------------- - for ( PatientIdentifier identifier : patient.getIdentifiers() ) + Collection identifiers = patient.getIdentifiers(); + Iterator iterIdentifier = identifiers.iterator(); + + for ( Program program : programs ) + { + Collection identifierTypes = program.getPatientIdentifierTypes(); + while ( iterIdentifier.hasNext() ) + { + PatientIdentifier identifier = iterIdentifier.next(); + if ( !identifierTypes.contains( identifier.getIdentifierType() ) ) + { + iterIdentifier.remove(); + } + } + } + + for ( PatientIdentifier identifier : identifiers ) { attrGrid.addRow(); - PatientIdentifierType idType = identifier.getIdentifierType(); if ( idType != null ) { attrGrid.addValue( idType.getName() ); - attrGrid.addValue( identifier.getIdentifier() ); } else { attrGrid.addValue( i18n.getString( "system_identifier" ) ); - attrGrid.addValue( identifier.getIdentifier() ); + } + attrGrid.addValue( identifier.getIdentifier() ); } grids.add( attrGrid ); @@ -296,15 +328,18 @@ { for ( ProgramInstance programInstance : programInstances ) { - Grid gridProgram = getProgramInstanceReport( programInstance, i18n, format ); - - // --------------------------------------------------------------------- - // Grids for program-stage-instance - // --------------------------------------------------------------------- - - getProgramStageInstancesReport( gridProgram, programInstance, format, i18n ); - - grids.add( gridProgram ); + if ( programs.contains( programInstance.getProgram() ) ) + { + Grid gridProgram = getProgramInstanceReport( programInstance, i18n, format ); + + // --------------------------------------------------------------------- + // Grids for program-stage-instance + // --------------------------------------------------------------------- + + getProgramStageInstancesReport( gridProgram, programInstance, format, i18n ); + + grids.add( gridProgram ); + } } } @@ -377,14 +412,14 @@ } PatientComment patientComment = programInstance.getPatientComment(); - if( patientComment != null ) + if ( patientComment != null ) { grid.addRow(); grid.addValue( i18n.getString( "comment" ) + " " + i18n.getString( "on" ) + " " + format.formatDateTime( patientComment.getCreatedDate() ) ); grid.addValue( patientComment.getCommentText() ); } - + // Get sms of the program-instance List messasges = programInstance.getOutboundSms(); === 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 2013-05-02 08:41:20 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-05-30 07:18:04 +0000 @@ -216,6 +216,8 @@ ref="org.hisp.dhis.patientattributevalue.PatientAttributeValueService" /> +