dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24782
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12201: more tests for eventService, added EventStatus to Events
------------------------------------------------------------
revno: 12201
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-09-23 10:37:56 +0200
message:
more tests for eventService, added EventStatus to Events
added:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventStatus.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollment.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollments.java
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/DefaultEventStore.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/Event.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.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 2013-09-23 07:28:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java 2013-09-23 08:37:56 +0000
@@ -28,16 +28,16 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.message.MessageConversation;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patientcomment.PatientComment;
import org.hisp.dhis.sms.outbound.OutboundSms;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
/**
* @author Abyot Asalefew
*/
@@ -49,6 +49,8 @@
*/
private static final long serialVersionUID = 6239130884678145713L;
+ public static final int ACTIVE_STATUS = 0;
+
public static final int COMPLETED_STATUS = 1;
public static final int VISITED_STATUS = 2;
@@ -77,7 +79,7 @@
private PatientComment patientComment;
- private Integer status;
+ private Integer status = ACTIVE_STATUS;
private String coordinates;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollment.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollment.java 2013-09-18 12:19:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollment.java 2013-09-23 08:37:56 +0000
@@ -38,7 +38,7 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@JacksonXmlRootElement( localName = "enrollment", namespace = DxfNamespaces.DXF_2_0 )
+@JacksonXmlRootElement(localName = "enrollment", namespace = DxfNamespaces.DXF_2_0)
public class Enrollment
{
private String enrollment;
@@ -57,8 +57,8 @@
{
}
- @JsonProperty( required = true )
- @JacksonXmlProperty( isAttribute = true )
+ @JsonProperty(required = true)
+ @JacksonXmlProperty(isAttribute = true)
public String getPerson()
{
return person;
@@ -69,8 +69,8 @@
this.person = person;
}
- @JsonProperty( required = true )
- @JacksonXmlProperty( isAttribute = true )
+ @JsonProperty(required = true)
+ @JacksonXmlProperty(isAttribute = true)
public String getEnrollment()
{
return enrollment;
@@ -81,8 +81,8 @@
this.enrollment = enrollment;
}
- @JsonProperty( required = true )
- @JacksonXmlProperty( isAttribute = true )
+ @JsonProperty(required = true)
+ @JacksonXmlProperty(isAttribute = true)
public String getProgram()
{
return program;
@@ -93,8 +93,8 @@
this.program = program;
}
- @JsonProperty( required = true )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JsonProperty(required = true)
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public EnrollmentStatus getStatus()
{
return status;
@@ -105,8 +105,8 @@
this.status = status;
}
- @JsonProperty( required = true )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JsonProperty(required = true)
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Date getDateOfEnrollment()
{
return dateOfEnrollment;
@@ -117,8 +117,8 @@
this.dateOfEnrollment = dateOfEnrollment;
}
- @JsonProperty( required = true )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @JsonProperty(required = true)
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Date getDateOfIncident()
{
return dateOfIncident;
@@ -128,4 +128,47 @@
{
this.dateOfIncident = dateOfIncident;
}
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ Enrollment that = (Enrollment) o;
+
+ if ( dateOfEnrollment != null ? !dateOfEnrollment.equals( that.dateOfEnrollment ) : that.dateOfEnrollment != null ) return false;
+ if ( dateOfIncident != null ? !dateOfIncident.equals( that.dateOfIncident ) : that.dateOfIncident != null ) return false;
+ if ( enrollment != null ? !enrollment.equals( that.enrollment ) : that.enrollment != null ) return false;
+ if ( person != null ? !person.equals( that.person ) : that.person != null ) return false;
+ if ( program != null ? !program.equals( that.program ) : that.program != null ) return false;
+ if ( status != that.status ) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = enrollment != null ? enrollment.hashCode() : 0;
+ result = 31 * result + (person != null ? person.hashCode() : 0);
+ result = 31 * result + (program != null ? program.hashCode() : 0);
+ result = 31 * result + (status != null ? status.hashCode() : 0);
+ result = 31 * result + (dateOfEnrollment != null ? dateOfEnrollment.hashCode() : 0);
+ result = 31 * result + (dateOfIncident != null ? dateOfIncident.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Enrollment{" +
+ "enrollment='" + enrollment + '\'' +
+ ", person='" + person + '\'' +
+ ", program='" + program + '\'' +
+ ", status=" + status +
+ ", dateOfEnrollment=" + dateOfEnrollment +
+ ", dateOfIncident=" + dateOfIncident +
+ '}';
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollments.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollments.java 2013-09-17 14:42:57 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/Enrollments.java 2013-09-23 08:37:56 +0000
@@ -61,4 +61,31 @@
{
this.enrollments = enrollments;
}
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o ) return true;
+ if ( o == null || getClass() != o.getClass() ) return false;
+
+ Enrollments that = (Enrollments) o;
+
+ if ( enrollments != null ? !enrollments.equals( that.enrollments ) : that.enrollments != null ) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return enrollments != null ? enrollments.hashCode() : 0;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Enrollments{" +
+ "enrollments=" + enrollments +
+ '}';
+ }
}
=== 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 2013-09-23 07:28:36 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2013-09-23 08:37:56 +0000
@@ -443,6 +443,7 @@
event.setCompleted( programStageInstance.isCompleted() );
event.setEvent( programStageInstance.getUid() );
+ event.setStatus( EventStatus.fromInt( programStageInstance.getStatus() ) );
event.setEventDate( programStageInstance.getExecutionDate().toString() );
event.setStoredBy( programStageInstance.getCompletedUser() );
event.setOrgUnit( programStageInstance.getOrganisationUnit().getUid() );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DefaultEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DefaultEventStore.java 2013-09-20 15:12:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DefaultEventStore.java 2013-09-23 08:37:56 +0000
@@ -39,9 +39,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdList;
@@ -121,6 +119,7 @@
event.setCompleted( rowSet.getBoolean( "psi_completed" ) );
event.setEvent( rowSet.getString( "psi_uid" ) );
+ event.setStatus( EventStatus.fromInt( rowSet.getInt( "psi_status" ) ) );
event.setProgram( rowSet.getString( "p_uid" ) );
event.setProgramStage( rowSet.getString( "ps_uid" ) );
event.setStoredBy( rowSet.getString( "psi_completeduser" ) );
@@ -144,7 +143,7 @@
private String buildSql( List<Integer> programIds, List<Integer> programStageIds, List<Integer> orgUnitIds, Date startDate, Date endDate )
{
- String sql = "select p.uid as p_uid, ps.uid as ps_uid, psi.uid as psi_uid, ou.uid as ou_uid, psi.executiondate as psi_executiondate," +
+ String sql = "select p.uid as p_uid, ps.uid as ps_uid, psi.uid as psi_uid, psi.status as psi_status, ou.uid as ou_uid, psi.executiondate as psi_executiondate," +
" psi.completeduser as psi_completeduser, psi.completed as psi_completed," +
" pdv.value as pdv_value, pdv.storedby as pdv_storedby, pdv.providedelsewhere as pdv_providedelsewhere, de.uid as de_uid" +
" from program p" +
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/Event.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/Event.java 2013-09-17 12:15:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/Event.java 2013-09-23 08:37:56 +0000
@@ -44,12 +44,14 @@
@JacksonXmlRootElement( localName = "event", namespace = DxfNamespaces.DXF_2_0 )
public class Event extends BaseLinkableObject
{
+ private String event;
+
+ private EventStatus status = EventStatus.ACTIVE;
+
private String program;
private String programStage;
- private String event;
-
private String orgUnit;
private String person;
@@ -70,6 +72,30 @@
@JsonProperty( required = true )
@JacksonXmlProperty( isAttribute = true )
+ public String getEvent()
+ {
+ return event;
+ }
+
+ public void setEvent( String event )
+ {
+ this.event = event;
+ }
+
+ @JsonProperty( required = true )
+ @JacksonXmlProperty( isAttribute = true )
+ public EventStatus getStatus()
+ {
+ return status;
+ }
+
+ public void setStatus( EventStatus status )
+ {
+ this.status = status;
+ }
+
+ @JsonProperty( required = true )
+ @JacksonXmlProperty( isAttribute = true )
public String getProgram()
{
return program;
@@ -92,18 +118,6 @@
this.programStage = programStage;
}
- @JsonProperty( required = true )
- @JacksonXmlProperty( isAttribute = true )
- public String getEvent()
- {
- return event;
- }
-
- public void setEvent( String event )
- {
- this.event = event;
- }
-
@JsonProperty
@JacksonXmlProperty( isAttribute = true )
public String getOrgUnit()
@@ -206,6 +220,7 @@
if ( person != null ? !person.equals( event1.person ) : event1.person != null ) return false;
if ( program != null ? !program.equals( event1.program ) : event1.program != null ) return false;
if ( programStage != null ? !programStage.equals( event1.programStage ) : event1.programStage != null ) return false;
+ if ( status != event1.status ) return false;
if ( storedBy != null ? !storedBy.equals( event1.storedBy ) : event1.storedBy != null ) return false;
return true;
@@ -214,9 +229,10 @@
@Override
public int hashCode()
{
- int result = program != null ? program.hashCode() : 0;
+ int result = event != null ? event.hashCode() : 0;
+ result = 31 * result + (status != null ? status.hashCode() : 0);
+ result = 31 * result + (program != null ? program.hashCode() : 0);
result = 31 * result + (programStage != null ? programStage.hashCode() : 0);
- result = 31 * result + (event != null ? event.hashCode() : 0);
result = 31 * result + (orgUnit != null ? orgUnit.hashCode() : 0);
result = 31 * result + (person != null ? person.hashCode() : 0);
result = 31 * result + (eventDate != null ? eventDate.hashCode() : 0);
@@ -231,9 +247,10 @@
public String toString()
{
return "Event{" +
- "program='" + program + '\'' +
+ "event='" + event + '\'' +
+ ", status=" + status +
+ ", program='" + program + '\'' +
", programStage='" + programStage + '\'' +
- ", event='" + event + '\'' +
", orgUnit='" + orgUnit + '\'' +
", person='" + person + '\'' +
", eventDate='" + eventDate + '\'' +
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventStatus.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventStatus.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventStatus.java 2013-09-23 08:37:56 +0000
@@ -0,0 +1,67 @@
+package org.hisp.dhis.dxf2.events.event;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "eventStatus", namespace = DxfNamespaces.DXF_2_0 )
+public enum EventStatus
+{
+ ACTIVE( 0 ), COMPLETED( 1 ), VISITED( 2 ), FUTURE_VISIT( 3 ), LATE_VISIT( 4 ), SKIPPED( 5 );
+
+ private final int value;
+
+ private EventStatus( int value )
+ {
+ this.value = value;
+ }
+
+ public int getValue()
+ {
+ return value;
+ }
+
+ public static EventStatus fromInt( int status )
+ {
+ for ( EventStatus eventStatus : EventStatus.values() )
+ {
+ if ( eventStatus.getValue() == status )
+ {
+ return eventStatus;
+ }
+ }
+
+ throw new IllegalArgumentException();
+ }
+}
+
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java 2013-09-23 07:49:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java 2013-09-23 08:37:56 +0000
@@ -32,6 +32,7 @@
import org.hisp.dhis.DhisTest;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dxf2.events.enrollment.Enrollment;
import org.hisp.dhis.dxf2.events.enrollment.EnrollmentService;
import org.hisp.dhis.dxf2.events.event.DataValue;
import org.hisp.dhis.dxf2.events.event.Event;
@@ -44,7 +45,6 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.program.Program;
-import org.hisp.dhis.program.ProgramInstance;
import org.hisp.dhis.program.ProgramInstanceService;
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageDataElement;
@@ -155,15 +155,6 @@
manager.update( programStageA );
manager.update( programA );
- ProgramInstance programInstance = new ProgramInstance();
- programInstance.setProgram( programA );
- programInstance.setDateOfIncident( new Date() );
- programInstance.setEnrollmentDate( new Date() );
-
- programInstanceService.addProgramInstance( programInstance );
- programA.getProgramInstances().add( programInstance );
- manager.update( programA );
-
createSuperuserAndInjectSecurityContext( 'A' );
// mocked format
@@ -187,6 +178,53 @@
assertThat( importSummary.getDescription(), CoreMatchers.containsString( "is not enrolled in program" ) );
}
+ @Test
+ public void testSaveWithEnrollmentShouldNotFail()
+ {
+ Enrollment enrollment = createEnrollment( programA.getUid(), personMaleA.getPerson() );
+ ImportSummary importSummary = enrollmentService.saveEnrollment( enrollment );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ Event event = createEvent( programA.getUid(), organisationUnitA.getUid(), personMaleA.getPerson() );
+ importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+ }
+
+ @Test
+ public void testSavingMultipleEventsShouldOnlyUpdate()
+ {
+ Enrollment enrollment = createEnrollment( programA.getUid(), personMaleA.getPerson() );
+ ImportSummary importSummary = enrollmentService.saveEnrollment( enrollment );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ Event event = createEvent( programA.getUid(), organisationUnitA.getUid(), personMaleA.getPerson() );
+ importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( 1, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+
+ event = createEvent( programA.getUid(), organisationUnitA.getUid(), personMaleA.getPerson() );
+ importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( 1, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+
+ event = createEvent( programA.getUid(), organisationUnitA.getUid(), personMaleA.getPerson() );
+ importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+
+ assertEquals( 1, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+ }
+
+ private Enrollment createEnrollment( String program, String person )
+ {
+ Enrollment enrollment = new Enrollment();
+ enrollment.setProgram( program );
+ enrollment.setPerson( person );
+
+ return enrollment;
+ }
+
private Event createEvent( String program, String orgUnit, String person )
{
Event event = new Event();