dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40573
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20595: auto-create PI if it doesnt exist in dxf2 event service
------------------------------------------------------------
revno: 20595
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-09 09:35:38 +0700
message:
auto-create PI if it doesnt exist in dxf2 event service
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.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-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 2015-10-01 13:06:22 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2015-10-09 02:35:38 +0000
@@ -30,7 +30,6 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -58,6 +57,7 @@
import org.hisp.dhis.dxf2.importsummary.ImportStatus;
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.dxf2.utils.InputUtils;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.i18n.I18nManager;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -85,7 +85,6 @@
import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueService;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
-import org.hisp.dhis.dxf2.utils.InputUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
@@ -110,7 +109,7 @@
implements EventService
{
private static final Log log = LogFactory.getLog( AbstractEventService.class );
-
+
public static final String OPTIONS_SEP = ";";
// -------------------------------------------------------------------------
@@ -164,10 +163,10 @@
@Autowired
protected IdentifiableObjectManager manager;
-
+
@Autowired
protected DataElementCategoryService categoryService;
-
+
@Autowired
protected InputUtils inputUtils;
@@ -368,8 +367,16 @@
if ( programInstances.isEmpty() )
{
- return new ImportSummary( ImportStatus.ERROR,
- "There is no program instance for program " + program.getUid() );
+ // this is a WOR program, so just create the PI if it doesn't exist (should only be one)
+ ProgramInstance pi = new ProgramInstance();
+ pi.setEnrollmentDate( new Date() );
+ pi.setIncidentDate( new Date() );
+ pi.setProgram( program );
+ pi.setStatus( ProgramStatus.ACTIVE );
+
+ programInstanceService.addProgramInstance( pi );
+
+ programInstances.add( pi );
}
else if ( programInstances.size() > 1 )
{
@@ -534,27 +541,27 @@
{
throw new IllegalQueryException( "Tracked entity instance is specified but does not exist: " + trackedEntityInstance );
}
-
+
if ( attributeCoc.isDefault() )
- {
+ {
DataElementCategoryCombo cc = null;
-
+
if ( pr != null )
{
- cc = pr.getCategoryCombo();
+ cc = pr.getCategoryCombo();
}
-
- if( cc == null && ps != null)
- {
+
+ if ( cc == null && ps != null )
+ {
cc = ps.getProgram().getCategoryCombo();
}
-
- if( cc != null && !cc.isDefault())
- {
+
+ if ( cc != null && !cc.isDefault() )
+ {
throw new IllegalQueryException( "Default attribute option combo is specified while program has non-default attribute category combo: " + cc.getUid() );
}
}
-
+
params.setProgram( pr );
params.setProgramStage( ps );
params.setOrgUnit( ou );
@@ -1036,7 +1043,7 @@
private void updateProgramStageInstance( ProgramStage programStage, ProgramInstance programInstance,
OrganisationUnit organisationUnit, Date dueDate, Date executionDate, int status, Coordinate coordinate,
- String storedBy, ProgramStageInstance programStageInstance, DataElementCategoryOptionCombo coc )
+ String storedBy, ProgramStageInstance programStageInstance, DataElementCategoryOptionCombo coc )
{
programStageInstance.setProgramInstance( programInstance );
programStageInstance.setProgramStage( programStage );
@@ -1088,14 +1095,14 @@
Date dueDate = DateUtils.parseDate( event.getDueDate() );
String storedBy = getStoredBy( event, importSummary, user );
-
+
DataElementCategoryOptionCombo coc = categoryService.getDefaultDataElementCategoryOptionCombo();
-
+
if ( event.getAttributeCategoryOptions() != null && program.getCategoryCombo() != null )
{
coc = inputUtils.getAttributeOptionCombo( program.getCategoryCombo(), event.getAttributeCategoryOptions() );
-
- if ( coc == null)
+
+ if ( coc == null )
{
importSummary.getConflicts().add( new ImportConflict( "Invalid attribute option combo for option names.", event.getAttributeCategoryOptions() ) );
}