dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36863
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18846: Add PI.orgUnit ptr, used to register where enrollment occured, also used for events that are auto...
------------------------------------------------------------
revno: 18846
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-04-09 17:54:52 +0700
message:
Add PI.orgUnit ptr, used to register where enrollment occured, also used for events that are auto-generated (changed from using TEI.orgUnit)
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.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
dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml
--
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/ProgramInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java 2015-04-09 10:54:52 +0000
@@ -29,14 +29,18 @@
*/
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.ExportView;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.message.MessageConversation;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.sms.outbound.OutboundSms;
import org.hisp.dhis.trackedentity.TrackedEntityInstance;
import org.hisp.dhis.trackedentitycomment.TrackedEntityComment;
@@ -68,6 +72,8 @@
public static int STATUS_CANCELLED = 2;
+ private OrganisationUnit organisationUnit;
+
private Date dateOfIncident; // TODO rename to incidenceDate
private Date enrollmentDate;
@@ -261,6 +267,20 @@
// -------------------------------------------------------------------------
@JsonProperty
+ @JsonSerialize( as = BaseIdentifiableObject.class )
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public OrganisationUnit getOrganisationUnit()
+ {
+ return organisationUnit;
+ }
+
+ public void setOrganisationUnit( OrganisationUnit organisationUnit )
+ {
+ this.organisationUnit = organisationUnit;
+ }
+
+ @JsonProperty
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
public Date getDateOfIncident()
{
@@ -394,5 +414,4 @@
{
this.comments = comments;
}
-
}
=== 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 2015-04-05 20:00:35 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2015-04-09 10:54:52 +0000
@@ -30,7 +30,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.IdentifiableObjectUtils;
@@ -302,6 +301,11 @@
enrollment.setTrackedEntityInstance( programInstance.getEntityInstance().getUid() );
}
+ if ( programInstance.getOrganisationUnit() != null )
+ {
+ enrollment.setOrgUnit( programInstance.getOrganisationUnit().getUid() );
+ }
+
enrollment.setProgram( programInstance.getProgram().getUid() );
enrollment.setStatus( EnrollmentStatus.fromInt( programInstance.getStatus() ) );
enrollment.setDateOfEnrollment( programInstance.getEnrollmentDate() );
@@ -337,10 +341,9 @@
{
ImportSummary importSummary = new ImportSummary();
- org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance( enrollment
- .getTrackedEntityInstance() );
- TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService
- .getTrackedEntityInstance( entityInstance );
+ org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance = getTrackedEntityInstance( enrollment.getTrackedEntityInstance() );
+ TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance( entityInstance );
+
Program program = getProgram( enrollment.getProgram() );
Enrollments enrollments = getEnrollments( program, trackedEntityInstance, EnrollmentStatus.ACTIVE );
@@ -384,8 +387,11 @@
return importSummary;
}
+ OrganisationUnit organisationUnit = getOrganisationUnit( enrollment.getOrgUnit() );
+ System.err.println( "Enrollment: " + organisationUnit );
+
ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance( enrollment.getEnrollment(), entityInstance, program,
- enrollment.getDateOfEnrollment(), enrollment.getDateOfIncident(), entityInstance.getOrganisationUnit() );
+ enrollment.getDateOfEnrollment(), enrollment.getDateOfIncident(), organisationUnit );
if ( programInstance == null )
{
@@ -708,6 +714,18 @@
}
+ private OrganisationUnit getOrganisationUnit( String id )
+ {
+ OrganisationUnit organisationUnit = manager.search( OrganisationUnit.class, id );
+
+ if ( organisationUnit == null )
+ {
+ throw new IllegalArgumentException( "OrganisationUnit does not exist." );
+ }
+
+ return organisationUnit;
+ }
+
private List<ImportConflict> validateAttributeType( Attribute attribute )
{
List<ImportConflict> importConflicts = Lists.newArrayList();
=== 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 2015-03-06 11:40:00 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2015-04-09 10:54:52 +0000
@@ -484,6 +484,7 @@
ProgramInstance programInstance = new ProgramInstance();
programInstance.setUid( CodeGenerator.isValidCode( uid ) ? uid : CodeGenerator.generateCode() );
+ programInstance.setOrganisationUnit( organisationUnit );
programInstance.enrollTrackedEntityInstance( entityInstance, program );
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml 2014-06-27 10:55:57 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/resources/org/hisp/dhis/program/hibernate/ProgramInstance.hbm.xml 2015-04-09 10:54:52 +0000
@@ -4,65 +4,68 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
- <class name="org.hisp.dhis.program.ProgramInstance" table="programinstance">
-
- <id name="id" column="programinstanceid">
- <generator class="native" />
- </id>
-
- <property name="uid" column="uid" unique="true" length="11" />
-
- <property name="created" type="timestamp" />
-
- <property name="lastUpdated" type="timestamp" />
-
- <property name="dateOfIncident" column="dateofincident"
- not-null="true" />
-
- <property name="enrollmentDate" column="enrollmentdate"
- not-null="true" />
-
- <property name="endDate" column="enddate" />
-
- <property name="followup" column="followup" />
-
- <property name="status" />
-
- <many-to-one name="entityInstance"
- class="org.hisp.dhis.trackedentity.TrackedEntityInstance" column="trackedentityinstanceid"
- foreign-key="fk_programinstance_trackedentityinstanceid" />
-
- <many-to-one name="program" class="org.hisp.dhis.program.Program"
- column="programid" not-null="true" foreign-key="fk_programinstance_programid" />
-
- <set name="programStageInstances" order-by="executionDate,duedate">
- <key column="programinstanceid" />
- <one-to-many class="org.hisp.dhis.program.ProgramStageInstance" />
- </set>
-
- <list name="outboundSms" table="programinstance_outboundsms">
- <key column="programinstanceid" />
- <list-index column="sort_order" base="1" />
- <many-to-many class="org.hisp.dhis.sms.outbound.OutboundSms"
- column="outboundsmsid" />
- </list>
-
- <list name="messageConversations" table="programinstance_messageconversation">
- <key column="programinstanceid" />
- <list-index column="sort_order" base="1" />
- <many-to-many class="org.hisp.dhis.message.MessageConversation"
- column="messageconversationid" />
- </list>
-
- <list name="comments" table="programinstancecomments" cascade="all">
- <key column="programinstanceid"/>
- <list-index column="sort_order" base="1" />
- <many-to-many column="trackedentitycommentid" unique="true" class="org.hisp.dhis.trackedentitycomment.TrackedEntityComment"/>
- </list>
-
- <!--<many-to-one name="comment" cascade="all"
- class="org.hisp.dhis.trackedentitycomment.TrackedEntityComment"
- column="trackedentitycommentid" foreign-key="fk_programinstance_commentid" />-->
-
- </class>
+ <class name="org.hisp.dhis.program.ProgramInstance" table="programinstance">
+
+ <id name="id" column="programinstanceid">
+ <generator class="native" />
+ </id>
+
+ <property name="uid" column="uid" unique="true" length="11" />
+
+ <property name="created" type="timestamp" />
+
+ <property name="lastUpdated" type="timestamp" />
+
+ <property name="dateOfIncident" column="dateofincident"
+ not-null="true" />
+
+ <property name="enrollmentDate" column="enrollmentdate"
+ not-null="true" />
+
+ <property name="endDate" column="enddate" />
+
+ <property name="followup" column="followup" />
+
+ <property name="status" />
+
+ <many-to-one name="entityInstance"
+ class="org.hisp.dhis.trackedentity.TrackedEntityInstance" column="trackedentityinstanceid"
+ foreign-key="fk_programinstance_trackedentityinstanceid" />
+
+ <many-to-one name="program" class="org.hisp.dhis.program.Program"
+ column="programid" not-null="true" foreign-key="fk_programinstance_programid" />
+
+ <set name="programStageInstances" order-by="executionDate,duedate">
+ <key column="programinstanceid" />
+ <one-to-many class="org.hisp.dhis.program.ProgramStageInstance" />
+ </set>
+
+ <list name="outboundSms" table="programinstance_outboundsms">
+ <key column="programinstanceid" />
+ <list-index column="sort_order" base="1" />
+ <many-to-many class="org.hisp.dhis.sms.outbound.OutboundSms"
+ column="outboundsmsid" />
+ </list>
+
+ <list name="messageConversations" table="programinstance_messageconversation">
+ <key column="programinstanceid" />
+ <list-index column="sort_order" base="1" />
+ <many-to-many class="org.hisp.dhis.message.MessageConversation"
+ column="messageconversationid" />
+ </list>
+
+ <list name="comments" table="programinstancecomments" cascade="all">
+ <key column="programinstanceid" />
+ <list-index column="sort_order" base="1" />
+ <many-to-many column="trackedentitycommentid" unique="true" class="org.hisp.dhis.trackedentitycomment.TrackedEntityComment" />
+ </list>
+
+ <many-to-one name="organisationUnit" class="org.hisp.dhis.organisationunit.OrganisationUnit" column="organisationunitid"
+ foreign-key="fk_programinstance_organisationunitid" not-null="false" />
+
+ <!--<many-to-one name="comment" cascade="all"
+ class="org.hisp.dhis.trackedentitycomment.TrackedEntityComment"
+ column="trackedentitycommentid" foreign-key="fk_programinstance_commentid" />-->
+
+ </class>
</hibernate-mapping>