← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13747: Fixed bug - Remove healthworkerid from Automated message reminder function

 

------------------------------------------------------------
revno: 13747
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-01-16 13:21:47 +0700
message:
  Fixed bug - Remove healthworkerid from Automated message reminder function
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientAttributeService.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java


--
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-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientAttributeService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientAttributeService.java	2014-01-14 10:21:12 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/DefaultPatientAttributeService.java	2014-01-16 06:21:47 +0000
@@ -134,7 +134,6 @@
     public Collection<PatientAttribute> getPatientAttributesWithoutProgram()
     {
         Collection<PatientAttribute> patientAttributes = patientAttributeStore.getAll();
-        Iterator<PatientAttribute> iterator = patientAttributes.iterator();
 
         Collection<PatientAttribute> programAttributes = new HashSet<PatientAttribute>();
         Collection<Program> programs = programService.getAllPrograms();

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2014-01-15 10:26:26 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/patient/startup/TableAlteror.java	2014-01-16 06:21:47 +0000
@@ -106,7 +106,7 @@
 
     @Autowired
     private StatementBuilder statementBuilder;
-    
+
     // -------------------------------------------------------------------------
     // Action Implementation
     // -------------------------------------------------------------------------
@@ -299,7 +299,7 @@
 
         executeSql( "ALTER TABLE patientattribute DROP COLUMN displayedinlist" );
         executeSql( "ALTER TABLE patientidentifiertype DROP COLUMN persondisplayname" );
-        
+
         updateProgramAttributes();
     }
 
@@ -310,21 +310,25 @@
     private void updateProgramAttributes()
     {
         String autoIncrVal = statementBuilder.getAutoIncrementValue();
-        
+
         String attributeSql = "INSERT INTO program_attributes (programattributeid, attributeid, sort_order, displayinlist, programid) "
-            + "SELECT " + autoIncrVal + ", pp.patientattributeid, pp.sort_order, false, pp.programid "
-            + "FROM program_patientattributes pp";        
+            + "SELECT "
+            + autoIncrVal
+            + ", pp.patientattributeid, pp.sort_order, false, pp.programid "
+            + "FROM program_patientattributes pp";
         executeSql( attributeSql );
 
         String identifierSql = "INSERT INTO program_identifiertypes (programidentifiertypeid, identifiertypeid, sort_order, displayinlist, programid) "
-            + "SELECT " + autoIncrVal + ", pp.patientidentifiertypeid, pp.sort_order, false, pp.programid "
-            + "FROM program_patientidentifiertypes pp";        
+            + "SELECT "
+            + autoIncrVal
+            + ", pp.patientidentifiertypeid, pp.sort_order, false, pp.programid "
+            + "FROM program_patientidentifiertypes pp";
         executeSql( identifierSql );
-        
+
         executeSql( "DROP TABLE program_patientattributes" );
         executeSql( "DROP TABLE program_patientidentifiertypes" );
     }
-    
+
     private void updateUid()
     {
         updateUidColumn( "patientattribute" );
@@ -505,8 +509,11 @@
                 // Gender
                 // ---------------------------------------------------------------------
 
+                log.info( "Inserting dynamic atribute called Gender..." );
+
                 max++;
                 String uid = CodeGenerator.generateCode();
+
                 executeSql( "INSERT INTO patientattribute (patientattributeid, uid, lastUpdated, name, description, valueType, mandatory, inherit, displayOnVisitSchedule ) VALUES ("
                     + max
                     + ",'"
@@ -516,6 +523,10 @@
                     + "','Gender', 'Gender','"
                     + PatientAttribute.TYPE_COMBO + "', false, false, false)" );
 
+                log.info( "Inserted Gender attribute successfully." );
+
+                log.info( "Inserting data into Gender attribute..." );
+
                 Integer maxOpt = jdbcTemplate.queryForObject(
                     "select max(patientattributeoptionid) from patientattributeoption", Integer.class );
                 maxOpt++;
@@ -536,12 +547,16 @@
                 executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value, patientattributeoptionid ) SELECT patientid,"
                     + max + ",'T'," + maxOpt + " from patient where gender='T'" );
 
+                log.info( "Inserted data into gender attribute." );
+
                 // Update Case Aggregate Query Builder
                 String source = "[CP" + CaseAggregationCondition.SEPARATOR_OBJECT + "gender]";
                 String target = "[" + CaseAggregationCondition.OBJECT_PATIENT_ATTRIBUTE
                     + CaseAggregationCondition.SEPARATOR_OBJECT + max + "]";
                 updateFixedAttributeInCaseAggregate( source, target );
 
+                log.info( "Updated case aggregate query build formulas which have gender criteria" );
+
                 // Update custom entry form && validation criteria
                 removeFixedAttributeInCustomRegistrationForm( "gender", uid );
                 executeSql( "UPDATE validationcriteria SET property='gender' WHERE property='gender' " );
@@ -550,6 +565,8 @@
                 // Death date
                 // ---------------------------------------------------------------------
 
+                log.info( "Inserting dynamic atribute called Death date..." );
+
                 max++;
                 uid = CodeGenerator.generateCode();
                 executeSql( "INSERT INTO patientattribute (patientattributeid, uid, lastUpdated, name, description, valueType, mandatory, inherit, displayOnVisitSchedule ) VALUES ("
@@ -560,6 +577,9 @@
                     + DateUtils.getMediumDateString()
                     + "','Death date', 'Death date','"
                     + PatientAttribute.TYPE_DATE + "', false, false, false)" );
+
+                log.info( "Inserting data into Death date attribute..." );
+
                 executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value ) SELECT patientid,"
                     + max + ",deathDate from patient where deathDate is not null" );
 
@@ -571,6 +591,8 @@
                 // registrationDate
                 // ---------------------------------------------------------------------
 
+                log.info( "Inserting dynamic atribute called registration date..." );
+
                 max++;
                 uid = CodeGenerator.generateCode();
                 executeSql( "INSERT INTO patientattribute (patientattributeid, uid, lastUpdated, name, description, valueType, mandatory, inherit, displayOnVisitSchedule ) VALUES ("
@@ -582,6 +604,9 @@
                     + "','Registration date', 'Registration date','"
                     + PatientAttribute.TYPE_DATE
                     + "', false, false, false)" );
+
+                log.info( "Inserting data into registration date registration date..." );
+
                 executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value ) SELECT patientid,"
                     + max + ",registrationDate from patient where registrationDate is not null" );
 
@@ -593,6 +618,8 @@
                 // isDead
                 // ---------------------------------------------------------------------
 
+                log.info( "Inserting dynamic atribute called isDead..." );
+
                 max++;
                 uid = CodeGenerator.generateCode();
                 executeSql( "INSERT INTO patientattribute (patientattributeid, uid, lastUpdated, name, description, valueType, mandatory, inherit, displayOnVisitSchedule ) VALUES ("
@@ -603,6 +630,9 @@
                     + DateUtils.getMediumDateString()
                     + "','Is Dead', 'Is Dead','"
                     + PatientAttribute.TYPE_TRACKER_ASSOCIATE + "', false, false, false)" );
+
+                log.info( "Inserting data into isDead..." );
+
                 executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value ) SELECT patientid,"
                     + max + ",isDead from patient where isDead is not null" );
 
@@ -614,6 +644,8 @@
                 // underAge
                 // ---------------------------------------------------------------------
 
+                log.info( "Inserting dynamic atribute called underAge..." );
+
                 max++;
                 uid = CodeGenerator.generateCode();
                 executeSql( "INSERT INTO patientattribute (patientattributeid, uid, lastUpdated, description, name, valueType, mandatory, inherit, displayOnVisitSchedule ) VALUES ("
@@ -624,6 +656,9 @@
                     + DateUtils.getMediumDateString()
                     + "','Is under age', 'Is under age','"
                     + PatientAttribute.TYPE_TRACKER_ASSOCIATE + "', false, false, false)" );
+
+                log.info( "Inserting data into underAge..." );
+
                 executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value ) SELECT patientid,"
                     + max + ",isDead from patient where underAge=true" );
 
@@ -635,6 +670,8 @@
                 // DobType
                 // ---------------------------------------------------------------------
 
+                log.info( "Inserting dynamic atribute called DobType..." );
+
                 max++;
                 uid = CodeGenerator.generateCode();
                 executeSql( "INSERT INTO patientattribute (patientattributeid, uid, lastUpdated, description, name, valueType, mandatory, inherit, displayOnVisitSchedule ) VALUES ("
@@ -648,6 +685,8 @@
                 executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value ) SELECT patientid,"
                     + max + ",dobType from patient where dobType is not null" );
 
+                log.info( "Inserting data into DobType ..." );
+
                 maxOpt++;
                 executeSql( "INSERT INTO patientattributeoption (patientattributeoptionid, name, patientattributeid ) VALUES ('"
                     + maxOpt + "', 'A'," + max + ")" );
@@ -680,6 +719,8 @@
                 // Birthdate
                 // -------------------------------------------------------------
 
+                log.info( "Inserting dynamic atribute called Birthdate..." );
+
                 max++;
                 uid = CodeGenerator.generateCode();
                 executeSql( "INSERT INTO patientattribute (patientattributeid, uid, lastUpdated, name, description, valueType, mandatory, inherit, displayOnVisitSchedule ) VALUES ("
@@ -690,6 +731,9 @@
                     + DateUtils.getMediumDateString()
                     + "','Birth date', 'Birth date','"
                     + PatientAttribute.TYPE_DATE + "', false, false, false)" );
+
+                log.info( "Inserting data into Birthdate ..." );
+
                 executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value ) SELECT patientid,"
                     + max + ",birthdate from patient where birthdate is not null and dobType in ('D','V') " );
 
@@ -701,6 +745,8 @@
                 // Age
                 // -------------------------------------------------------------
 
+                log.info( "Inserting dynamic atribute called age..." );
+
                 max++;
                 uid = CodeGenerator.generateCode();
                 executeSql( "INSERT INTO patientattribute (patientattributeid, uid, lastUpdated, name, description, valueType, mandatory, inherit, displayOnVisitSchedule ) VALUES ("
@@ -711,6 +757,9 @@
                     + DateUtils.getMediumDateString()
                     + "','Age', 'Age','"
                     + PatientAttribute.TYPE_AGE + "', false, false, false)" );
+
+                log.info( "Inserting data into age ..." );
+
                 executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value ) SELECT patientid,"
                     + max + ",birthdate from patient where birthdate is not null and dobType='A' " );
 
@@ -722,6 +771,8 @@
                 // Phone number
                 // -------------------------------------------------------------
 
+                log.info( "Inserting dynamic atribute called Phone number ..." );
+
                 max++;
                 uid = CodeGenerator.generateCode();
                 executeSql( "INSERT INTO patientattribute (patientattributeid, uid, lastUpdated, name, description, valueType, mandatory, inherit, displayOnVisitSchedule ) VALUES ("
@@ -732,6 +783,9 @@
                     + DateUtils.getMediumDateString()
                     + "','Phone number', 'Phone number','"
                     + PatientAttribute.TYPE_PHONE_NUMBER + "', false, false, false)" );
+
+                log.info( "Inserting data into Phone number ..." );
+
                 executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value ) SELECT patientid,"
                     + max + ",phoneNumber from patient where phoneNumber is not null" );
 
@@ -751,6 +805,8 @@
                 // Patient full name
                 // -------------------------------------------------------------
 
+                log.info( "Inserting dynamic atribute called Full name ..." );
+
                 uid = CodeGenerator.generateCode();
                 executeSql( "INSERT INTO patientattribute (patientattributeid, uid, lastUpdated, name, description, valueType, mandatory, inherit, displayOnVisitSchedule ) VALUES ("
                     + max
@@ -760,6 +816,9 @@
                     + DateUtils.getMediumDateString()
                     + "','Full name', 'Full name','"
                     + PatientAttribute.TYPE_STRING + "', false, false, false)" );
+
+                log.info( "Inserting data into Full name ..." );
+
                 executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value ) SELECT patientid,"
                     + max + ",name from patient where name is not null" );
 
@@ -773,6 +832,8 @@
                 // User Associate
                 // -------------------------------------------------------------
 
+                log.info( "Inserting dynamic atribute called Staff ..." );
+
                 uid = CodeGenerator.generateCode();
                 executeSql( "INSERT INTO patientattribute (patientattributeid, uid, lastUpdated, name, description, valueType, mandatory, inherit, displayOnVisitSchedule ) VALUES ("
                     + max
@@ -782,12 +843,17 @@
                     + DateUtils.getMediumDateString()
                     + "','Staff', 'Staff','"
                     + PatientAttribute.TYPE_USERS + "', false, false, false)" );
+
+                log.info( "Inserting data into Staff ..." );
+
                 executeSql( "INSERT INTO patientattributevalue (patientid, patientattributeid, value ) SELECT patientid,"
                     + max
                     + ",healthworkerid from patient inner join userinfo on patient.healthworkerid=userinfo.userinfoid where patient.healthworkerid is not null" );
 
                 // Update custom entry form
                 removeFixedAttributeInCustomRegistrationForm( "associate", uid );
+                
+                log.info( "Dropping fixed properties of person ..." );
 
                 executeSql( "ALTER TABLE patient DROP COLUMN gender" );
                 executeSql( "ALTER TABLE patient DROP COLUMN deathDate" );

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java	2014-01-06 15:31:51 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java	2014-01-16 06:21:47 +0000
@@ -303,7 +303,7 @@
             + "              ON pa.patientattributeid=pav.patientattributeid " + "       WHERE pi.status= "
             + ProgramInstance.STATUS_ACTIVE
             + "         and prm.templatemessage is not NULL and prm.templatemessage != ''   "
-            + "         and pg.type=1 and prm.daysallowedsendmessage is not null    "
+            + "         and pg.type=1 and prm.daysallowedsendmessage is not null and pa.valuetype='phoneNumber' "
             + "         and ( DATE(now()) - DATE(pi." + dateToCompare + ") ) = prm.daysallowedsendmessage "
             + "         and prm.whenToSend is null and prm.dateToCompare='" + dateToCompare + "' and prm.sendto = "
             + PatientReminder.SEND_TO_PATIENT;
@@ -315,17 +315,29 @@
             + "   pg.name as programName, pi.dateofincident, pi.enrollmentdate,(DATE(now()) - DATE(pi.enrollmentdate) ) as days_since_erollment_date, "
             + "       (DATE(now()) - DATE(pi.dateofincident) ) as days_since_incident_date "
             + "    FROM patient p INNER JOIN programinstance pi "
-            + "           ON p.patientid=pi.patientid INNER JOIN program pg "
-            + "           ON pg.programid=pi.programid INNER JOIN organisationunit org "
-            + "           ON org.organisationunitid = p.organisationunitid INNER JOIN patientreminder prm "
-            + "           ON prm.programid = pi.programid INNER JOIN users us "
-            + "           ON us.userid=p.healthworkerid INNER JOIN userinfo uif "
-            + "           ON us.userid=uif.userinfoid " + "    WHERE pi.status = " + ProgramInstance.STATUS_ACTIVE
+            + "           ON p.patientid=pi.patientid "
+            + "INNER JOIN program pg "
+            + "           ON pg.programid=pi.programid "
+            + "INNER JOIN organisationunit org "
+            + "           ON org.organisationunitid = p.organisationunitid "
+            + "INNER JOIN patientreminder prm "
+            + "           ON prm.programid = pi.programid "
+            + "INNER JOIN patientattributevalue pav "
+            + "ON pav.patientid=p.patientid "
+            + " INNER JOIN patientattribute pa "
+            + " ON pa.patientattributeid=pav.patientattributeid "
+            + " INNER JOIN userinfo uif " 
+            + " ON pav.value=concat(uif.userinfoid ,'') "
+            + "    WHERE pi.status = " + ProgramInstance.STATUS_ACTIVE
+            + "      and pa.valueType='phoneNumber' "
             + "      and uif.phonenumber is not NULL and uif.phonenumber != '' "
             + "      and prm.templatemessage is not NULL and prm.templatemessage != '' "
-            + "      and pg.type=1 and prm.daysallowedsendmessage is not null " + "      and ( DATE(now()) - DATE( pi."
-            + dateToCompare + " ) ) = prm.daysallowedsendmessage " + "      and prm.dateToCompare='" + dateToCompare
-            + "'     and prm.whenToSend is null and prm.sendto =  " + PatientReminder.SEND_TO_ATTRIBUTE_TYPE_USERS;
+            + "      and pg.type=1 and prm.daysallowedsendmessage is not null " 
+            + "      and ( DATE(now()) - DATE( pi."
+            + dateToCompare + " ) ) = prm.daysallowedsendmessage " 
+            + "      and prm.dateToCompare='" + dateToCompare
+            + "'     and prm.whenToSend is null and prm.sendto =  " 
+            + PatientReminder.SEND_TO_ATTRIBUTE_TYPE_USERS;
     }
 
     private String sendMessageToOrgunitRegisteredSql( String dateToCompare )

=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2014-01-06 15:31:51 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramStageInstanceStore.java	2014-01-16 06:21:47 +0000
@@ -589,7 +589,7 @@
             + ProgramInstance.STATUS_ACTIVE
             + "     and prm.templatemessage is not NULL and prm.templatemessage != '' "
             + "     and pg.type=1 and prm.daysallowedsendmessage is not null  "
-            + "     and psi.executiondate is null "
+            + "     and psi.executiondate is null and pa.valuetype='phoneNumber' "
             + "     and (  DATE(now()) - DATE(psi.duedate) ) = prm.daysallowedsendmessage "
             + "     and prm.whentosend is null and prm.sendto = " + PatientReminder.SEND_TO_PATIENT;
     }
@@ -611,13 +611,15 @@
             + "               ON org.organisationunitid = p.organisationunitid "
             + "           INNER JOIN patientreminder prm  "
             + "               ON prm.programstageid = ps.programstageid "
-            + "           INNER JOIN users us"
-            + "               ON us.userid=p.healthworkerid "
+            + "           INNER JOIN patientattributevalue pav "
+            + "               ON pav.patientid=p.patientid "
+            + "           INNER JOIN patientattribute pa "
+            + "               ON pa.patientattributeid=pav.patientattributeid "
             + "           INNER JOIN userinfo uif "
-            + "               ON us.userid=uif.userinfoid "
+            + "               ON pav.value=concat(uif.userinfoid ,'') "
             + " WHERE pi.status="
             + ProgramInstance.STATUS_ACTIVE
-            + " and uif.phonenumber is not NULL and uif.phonenumber != '' "
+            + " and pa.valueType='phoneNumber' and uif.phonenumber is not NULL and uif.phonenumber != '' "
             + "               and prm.templatemessage is not NULL and prm.templatemessage != '' "
             + "               and pg.type=1 and prm.daysallowedsendmessage is not null "
             + "               and psi.executiondate is null "

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java	2014-01-09 15:34:25 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/UpdateProgramAction.java	2014-01-16 06:21:47 +0000
@@ -313,32 +313,43 @@
             RelationshipType relationshipType = relationshipTypeService.getRelationshipType( relationshipTypeId );
             program.setRelationshipType( relationshipType );
         }
-        
+
         program.setRelationshipFromA( relationshipFromA );
         program.setRelationshipText( relationshipText );
-        
-        program.getProgramPatientIdentifierTypes().clear();
-        program.getProgramPatientAttributes().clear();
-        
+
+        if ( program.getProgramPatientIdentifierTypes() != null )
+        {
+            program.getProgramPatientIdentifierTypes().clear();
+        }
+
+        if ( program.getProgramPatientAttributes() != null )
+        {
+            program.getProgramPatientAttributes().clear();
+        }
+
         int index = 0;
-        
+
         for ( String selectedPropertyId : selectedPropertyIds )
         {
             String[] ids = selectedPropertyId.split( "_" );
 
             if ( ids[0].equals( Patient.PREFIX_IDENTIFIER_TYPE ) )
             {
-                PatientIdentifierType identifierType = patientIdentifierTypeService.getPatientIdentifierType( Integer.parseInt( ids[1] ) );
-                ProgramPatientIdentifierType programPatientIdentifierType = new ProgramPatientIdentifierType( identifierType, index + 1, personDisplayNames.get( index ) );
+                PatientIdentifierType identifierType = patientIdentifierTypeService.getPatientIdentifierType( Integer
+                    .parseInt( ids[1] ) );
+                ProgramPatientIdentifierType programPatientIdentifierType = new ProgramPatientIdentifierType(
+                    identifierType, index + 1, personDisplayNames.get( index ) );
                 program.getProgramPatientIdentifierTypes().add( programPatientIdentifierType );
             }
             else if ( ids[0].equals( Patient.PREFIX_PATIENT_ATTRIBUTE ) )
             {
-                PatientAttribute patientAttribute = patientAttributeService.getPatientAttribute( Integer.parseInt( ids[1] ) );
-                ProgramPatientAttribute programPatientAttribute = new ProgramPatientAttribute( patientAttribute, index + 1, personDisplayNames.get( index ) );
+                PatientAttribute patientAttribute = patientAttributeService.getPatientAttribute( Integer
+                    .parseInt( ids[1] ) );
+                ProgramPatientAttribute programPatientAttribute = new ProgramPatientAttribute( patientAttribute,
+                    index + 1, personDisplayNames.get( index ) );
                 program.getProgramPatientAttributes().add( programPatientAttribute );
             }
-            
+
             index++;
         }