dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #42235
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21578: add PSI.storedBy
------------------------------------------------------------
revno: 21578
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-01-05 12:42:04 +0700
message:
add PSI.storedBy
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.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-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java 2016-01-04 14:27:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java 2016-01-05 05:42:04 +0000
@@ -37,7 +37,6 @@
import org.hisp.dhis.trackedentitycomment.TrackedEntityComment;
import java.util.ArrayList;
-import java.util.Calendar;
import java.util.Date;
import java.util.List;
@@ -51,6 +50,8 @@
private ProgramStage programStage;
+ private String storedBy;
+
private Date dueDate;
private Date executionDate;
@@ -114,6 +115,16 @@
this.programStage = programStage;
}
+ public String getStoredBy()
+ {
+ return storedBy;
+ }
+
+ public void setStoredBy( String storedBy )
+ {
+ this.storedBy = storedBy;
+ }
+
public String getCompletedBy()
{
return completedBy;
@@ -238,35 +249,4 @@
{
return status;
}
-
- public EventStatus getEventStatus()
- {
- if ( status == EventStatus.COMPLETED )
- {
- return status;
- }
- else if ( this.getExecutionDate() != null )
- {
- return EventStatus.VISITED;
- }
- else
- {
- // -------------------------------------------------------------
- // If a program stage is not provided even a day after its due
- // date, then that service is alerted red - because we are
- // getting late
- // -------------------------------------------------------------
-
- Calendar dueDateCalendar = Calendar.getInstance();
- dueDateCalendar.setTime( this.getDueDate() );
- dueDateCalendar.add( Calendar.DATE, 1 );
-
- if ( dueDateCalendar.getTime().before( new Date() ) )
- {
- return EventStatus.OVERDUE;
- }
-
- return EventStatus.SCHEDULE;
- }
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2016-01-04 14:27:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2016-01-05 05:42:04 +0000
@@ -714,7 +714,9 @@
executeSql( "UPDATE program SET version=0 WHERE version IS NULL" );
executeSql( "update program set shortname = substring(name,0,50) where shortname is null" );
executeSql( "update program set categorycomboid = " + defaultCategoryComboId + " where categorycomboid is null" );
+
executeSql( "update programstageinstance set attributeoptioncomboid = " + defaultOptionComboId + " where attributeoptioncomboid is null" );
+ executeSql( "update programstageinstance set storedby=completedby where storedby is null" );
executeSql( "ALTER TABLE datavalue ALTER COLUMN lastupdated TYPE timestamp" );
executeSql( "ALTER TABLE completedatasetregistration ALTER COLUMN date TYPE timestamp" );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml 2016-01-04 14:27:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/program/hibernate/ProgramStageInstance.hbm.xml 2016-01-05 05:42:04 +0000
@@ -25,6 +25,8 @@
<many-to-one name="attributeOptionCombo" class="org.hisp.dhis.dataelement.DataElementCategoryOptionCombo"
column="attributeoptioncomboid" foreign-key="fk_programstageinstance_attributeoptioncomboid" />
+ <property name="storedBy" />
+
<property name="dueDate" column="duedate" />
<property name="executionDate" column="executiondate" type="timestamp" index="programstageinstance_executiondate" />
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2016-01-04 14:27:34 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2016-01-05 05:42:04 +0000
@@ -657,18 +657,21 @@
}
String storedBy = getStoredBy( event, null, user );
+ programStageInstance.setStoredBy( storedBy );
+
+ String completedBy = getCompletedBy( event, null, user );
if ( event.getStatus() == EventStatus.ACTIVE )
{
programStageInstance.setStatus( EventStatus.ACTIVE );
+ programStageInstance.setCompletedBy( null );
programStageInstance.setCompletedDate( null );
- programStageInstance.setCompletedBy( null );
}
else if ( event.getStatus() == EventStatus.COMPLETED )
{
+ programStageInstance.setStatus( EventStatus.COMPLETED );
+ programStageInstance.setCompletedBy( completedBy );
programStageInstance.setCompletedDate( executionDate );
- programStageInstance.setStatus( EventStatus.COMPLETED );
- programStageInstance.setCompletedBy( storedBy );
if ( !programStageInstance.isCompleted() )
{
@@ -867,7 +870,8 @@
event.setStatus( programStageInstance.getStatus() );
event.setEventDate( DateUtils.getLongDateString( programStageInstance.getExecutionDate() ) );
event.setDueDate( DateUtils.getLongDateString( programStageInstance.getDueDate() ) );
- event.setStoredBy( programStageInstance.getCompletedBy() );
+ event.setStoredBy( programStageInstance.getStoredBy() );
+ event.setCompletedBy( programStageInstance.getCompletedBy() );
event.setCompletedDate( DateUtils.getLongDateString( programStageInstance.getCompletedDate() ) );
UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
@@ -1022,9 +1026,33 @@
storedBy = User.getSafeUsername( fallbackUser );
}
+
return storedBy;
}
+ private String getCompletedBy( Event event, ImportSummary importSummary, User fallbackUser )
+ {
+ String completedBy = event.getCompletedBy();
+
+ if ( completedBy == null )
+ {
+ completedBy = User.getSafeUsername( fallbackUser );
+ }
+ else if ( completedBy.length() >= 31 )
+ {
+ if ( importSummary != null )
+ {
+ importSummary.getConflicts().add(
+ new ImportConflict( "completed by", completedBy
+ + " is more than 31 characters, using current username instead" ) );
+ }
+
+ completedBy = User.getSafeUsername( fallbackUser );
+ }
+
+ return completedBy;
+ }
+
private void saveDataValue( ProgramStageInstance programStageInstance, String storedBy, DataElement dataElement,
String value, Boolean providedElsewhere, TrackedEntityDataValue dataValue, ImportSummary importSummary )
{
@@ -1075,20 +1103,20 @@
private ProgramStageInstance createProgramStageInstance( ProgramStage programStage, ProgramInstance programInstance,
OrganisationUnit organisationUnit, Date dueDate, Date executionDate, int status,
- Coordinate coordinate, String storedBy, String programStageInstanceUid, DataElementCategoryOptionCombo coc )
+ Coordinate coordinate, String completedBy, String programStageInstanceUid, DataElementCategoryOptionCombo coc )
{
ProgramStageInstance programStageInstance = new ProgramStageInstance();
programStageInstance.setUid( CodeGenerator.isValidCode( programStageInstanceUid ) ? programStageInstanceUid : CodeGenerator.generateCode() );
updateProgramStageInstance( programStage, programInstance, organisationUnit, dueDate, executionDate, status,
- coordinate, storedBy, programStageInstance, coc );
+ coordinate, completedBy, programStageInstance, coc );
return programStageInstance;
}
private void updateProgramStageInstance( ProgramStage programStage, ProgramInstance programInstance,
OrganisationUnit organisationUnit, Date dueDate, Date executionDate, int status, Coordinate coordinate,
- String storedBy, ProgramStageInstance programStageInstance, DataElementCategoryOptionCombo coc )
+ String completedBy, ProgramStageInstance programStageInstance, DataElementCategoryOptionCombo coc )
{
programStageInstance.setProgramInstance( programInstance );
programStageInstance.setProgramStage( programStage );
@@ -1123,7 +1151,7 @@
{
programStageInstance.setStatus( EventStatus.COMPLETED );
programStageInstance.setCompletedDate( new Date() );
- programStageInstance.setCompletedBy( storedBy );
+ programStageInstance.setCompletedBy( completedBy );
programStageInstanceService.completeProgramStageInstance( programStageInstance, i18nManager.getI18nFormat() );
}
}
@@ -1151,6 +1179,7 @@
Date dueDate = DateUtils.parseDate( event.getDueDate() );
String storedBy = getStoredBy( event, importSummary, user );
+ String completedBy = getCompletedBy( event, importSummary, user );
DataElementCategoryOptionCombo coc = categoryService.getDefaultDataElementCategoryOptionCombo();
@@ -1169,12 +1198,12 @@
if ( programStageInstance == null )
{
programStageInstance = createProgramStageInstance( programStage, programInstance, organisationUnit,
- dueDate, eventDate, event.getStatus().getValue(), event.getCoordinate(), storedBy, event.getEvent(), coc );
+ dueDate, eventDate, event.getStatus().getValue(), event.getCoordinate(), completedBy, event.getEvent(), coc );
}
else
{
updateProgramStageInstance( programStage, programInstance, organisationUnit, dueDate, eventDate, event
- .getStatus().getValue(), event.getCoordinate(), storedBy, programStageInstance, coc );
+ .getStatus().getValue(), event.getCoordinate(), completedBy, programStageInstance, coc );
}
saveTrackedEntityComment( programStageInstance, event, storedBy );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java 2016-01-04 14:27:34 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java 2016-01-05 05:42:04 +0000
@@ -119,7 +119,7 @@
event.setTrackedEntityInstance( rowSet.getString( "tei_uid" ) );
- event.setStoredBy( rowSet.getString( "psi_completedby" ) );
+ event.setStoredBy( rowSet.getString( "psi_storedby" ) );
event.setOrgUnitName( rowSet.getString( "ou_name" ) );
event.setDueDate( DateUtils.getLongGmtDateString( rowSet.getDate( "psi_duedate" ) ) );
event.setEventDate( DateUtils.getLongGmtDateString( rowSet.getDate( "psi_executiondate" ) ) );
@@ -346,7 +346,7 @@
String sql =
"select psi.programstageinstanceid as psi_id, psi.uid as psi_uid, psi.status as psi_status, psi.executiondate as psi_executiondate, psi.duedate as psi_duedate, psi.completedby as psi_completedby, " +
- "psi.longitude as psi_longitude, psi.latitude as psi_latitude, psi.created as psi_created, psi.lastupdated as psi_lastupdated, psi.completeddate as psi_completeddate, " +
+ "psi.storedby as psi_storedby, psi.longitude as psi_longitude, psi.latitude as psi_latitude, psi.created as psi_created, psi.lastupdated as psi_lastupdated, psi.completeddate as psi_completeddate, " +
"pi.uid as pi_uid, pi.status as pi_status, pi.followup as pi_followup, p.uid as p_uid, p.code as p_code, " +
"p.type as p_type, ps.uid as ps_uid, ps.code as ps_code, ps.capturecoordinates as ps_capturecoordinates, " +
"ou.uid as ou_uid, ou.code as ou_code, ou.name as ou_name, tei.trackedentityinstanceid as tei_id, tei.uid as tei_uid " +