dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33904
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17367: allow to set uid of new program-instance in enrollment api
------------------------------------------------------------
revno: 17367
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-11-06 16:21:02 +0700
message:
allow to set uid of new program-instance in enrollment api
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.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/ProgramInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java 2014-10-16 05:49:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java 2014-11-06 09:21:02 +0000
@@ -287,6 +287,20 @@
/**
* Enroll a TrackedEntityInstance into a program. Must be run inside a transaction.
*
+ * @param uid UID to use for new instance
+ * @param entityInstance TrackedEntityInstance
+ * @param program Program
+ * @param enrollmentDate The date of enrollment
+ * @param dateOfIncident The date of incident
+ * @param orgunit Organisation Unit
+ * @return ProgramInsance
+ */
+ ProgramInstance enrollTrackedEntityInstance( String uid, TrackedEntityInstance entityInstance, Program program, Date enrollmentDate, Date dateOfIncident,
+ OrganisationUnit orgunit );
+
+ /**
+ * Enroll a TrackedEntityInstance into a program. Must be run inside a transaction.
+ *
* @param entityInstance TrackedEntityInstance
* @param program Program
* @param enrollmentDate The date of enrollment
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2014-10-25 07:31:44 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2014-11-06 09:21:02 +0000
@@ -366,7 +366,7 @@
return importSummary;
}
- ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance( entityInstance, program,
+ ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance( enrollment.getEnrollment(), entityInstance, program,
enrollment.getDateOfEnrollment(), enrollment.getDateOfIncident(), entityInstance.getOrganisationUnit() );
if ( programInstance == null )
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2014-10-16 06:17:19 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2014-11-06 09:21:02 +0000
@@ -28,15 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
+import org.hisp.dhis.common.CodeGenerator;
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.GridHeader;
import org.hisp.dhis.dataelement.DataElement;
@@ -66,6 +58,15 @@
import org.hisp.dhis.user.CurrentUserService;
import org.springframework.transaction.annotation.Transactional;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
/**
* @author Abyot Asalefew
*/
@@ -468,11 +469,19 @@
public ProgramInstance enrollTrackedEntityInstance( TrackedEntityInstance entityInstance, Program program,
Date enrollmentDate, Date dateOfIncident, OrganisationUnit organisationUnit )
{
+ return enrollTrackedEntityInstance( CodeGenerator.generateCode(), entityInstance, program, enrollmentDate, dateOfIncident, organisationUnit );
+ }
+
+ @Override
+ public ProgramInstance enrollTrackedEntityInstance( String uid, TrackedEntityInstance entityInstance,
+ Program program, Date enrollmentDate, Date dateOfIncident, OrganisationUnit organisationUnit )
+ {
// ---------------------------------------------------------------------
// Add program instance
// ---------------------------------------------------------------------
ProgramInstance programInstance = new ProgramInstance();
+ programInstance.setUid( CodeGenerator.isValidCode( uid ) ? uid : CodeGenerator.generateCode() );
programInstance.enrollTrackedEntityInstance( entityInstance, program );
@@ -824,7 +833,7 @@
&& rm.getWhenToSend() != null
&& rm.getWhenToSend() == status
&& (rm.getMessageType() == TrackedEntityInstanceReminder.MESSAGE_TYPE_DHIS_MESSAGE || rm
- .getMessageType() == TrackedEntityInstanceReminder.MESSAGE_TYPE_BOTH) )
+ .getMessageType() == TrackedEntityInstanceReminder.MESSAGE_TYPE_BOTH) )
{
int id = messageService.sendMessage( programInstance.getProgram().getDisplayName(),
reminderService.getMessageFromTemplate( rm, programInstance, format ), null,