=== added directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report' === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/AbstractEventRowService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/AbstractEventRowService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/AbstractEventRowService.java 2014-09-17 14:53:33 +0000 @@ -0,0 +1,110 @@ +package org.hisp.dhis.dxf2.events.report; + +/* + * Copyright (c) 2004-2014, 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 java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.dxf2.events.event.Event; +import org.hisp.dhis.dxf2.events.event.EventService; +import org.hisp.dhis.dxf2.events.event.Events; +import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance; +import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstanceService; +import org.hisp.dhis.event.EventStatus; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.program.Program; +import org.hisp.dhis.program.ProgramStage; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * @author Abyot Asalefew Gizaw + * + */ +public class AbstractEventRowService + implements EventRowService +{ + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + @Autowired + private EventService eventService; + + @Autowired + private IdentifiableObjectManager manager; + + @Autowired + private TrackedEntityInstanceService trackedEntityInstanceService; + + @Override + public EventRows getOverDueEventRows( Program program, List organisationUnits, EventStatus status ) + { + List eventRowList = new ArrayList(); + EventRows eventRows = new EventRows(); + + Events events = eventService.getEvents( program, null, null, null, organisationUnits, null, null, null, status ); + + for ( Event event : events.getEvents() ) + { + if ( event.getTrackedEntityInstance() != null ) + { + TrackedEntityInstance tei = trackedEntityInstanceService.getTrackedEntityInstance( event.getTrackedEntityInstance() ); + EventRow eventRow = new EventRow(); + eventRow.setTrackedEntityInstance( event.getTrackedEntityInstance() ); + eventRow.setAttributes( tei.getAttributes() ); + eventRow.setEvent( event.getEvent() ); + eventRow.setProgram( program.getUid() ); + eventRow.setProgramStage( event.getProgramStage() ); + eventRow.setEventName( manager.get( ProgramStage.class, event.getProgramStage() ).getName() ); + eventRow.setRegistrationOrgUnit( manager.get( OrganisationUnit.class, tei.getOrgUnit() ).getName() ); + eventRow.setRegistrationDate( tei.getCreated() ); + //eventRow.setOrgUnit( event.getOrgUnit() ); + eventRow.setDueDate( event.getDueDate() ); + eventRow.setFollowup( event.getFollowup() ); + eventRowList.add( eventRow ); + } + } + + eventRows.setEventRows( eventRowList ); + + return eventRows; + } + + @Override + public EventRows getUpcomingEventRows( Program program, List organisationUnits, Date startDate, + Date endDate, EventStatus eventStatus ) + { + // TODO Auto-generated method stub + return null; + } + +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRow.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRow.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRow.java 2014-09-17 14:53:33 +0000 @@ -0,0 +1,324 @@ +package org.hisp.dhis.dxf2.events.report; + +/* + * Copyright (c) 2004-2014, 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.annotation.JsonProperty; +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.BaseLinkableObject; +import org.hisp.dhis.common.DxfNamespaces; +import org.hisp.dhis.dxf2.events.event.Note; +import org.hisp.dhis.dxf2.events.trackedentity.Attribute; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Abyot Asalefew Gizaw + * + */ + +@JacksonXmlRootElement( localName = "event", namespace = DxfNamespaces.DXF_2_0 ) +public class EventRow + extends BaseLinkableObject +{ + private String trackedEntityInstance; + + private List attributes = new ArrayList<>(); + + private String event; + + private String eventName; + + private String program; + + private String programStage; + + private String enrollment; + + private String eventOrgUnit; + + private String registrationOrgUnit; + + private String registrationDate; + + private String eventDate; + + private String dueDate; + + private Boolean followup; + + private List notes = new ArrayList<>(); + + public EventRow() + { + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public String getTrackedEntityInstance() + { + return trackedEntityInstance; + } + + public void setTrackedEntityInstance( String trackedEntityInstance ) + { + this.trackedEntityInstance = trackedEntityInstance; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public List getAttributes() + { + return attributes; + } + + public void setAttributes( List attributes ) + { + this.attributes = attributes; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public String getEvent() + { + return event; + } + + public void setEvent( String event ) + { + this.event = event; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public String getEventName() + { + return eventName; + } + + public void setEventName( String eventName ) + { + this.eventName = eventName; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public String getProgram() + { + return program; + } + + public void setProgram( String program ) + { + this.program = program; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public String getProgramStage() + { + return programStage; + } + + public void setProgramStage( String programStage ) + { + this.programStage = programStage; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public String getEnrollment() + { + return enrollment; + } + + public void setEnrollment( String enrollment ) + { + this.enrollment = enrollment; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public String getRegistrationOrgUnit() + { + return registrationOrgUnit; + } + + public void setRegistrationOrgUnit( String registrationOrgUnit ) + { + this.registrationOrgUnit = registrationOrgUnit; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public String getRegistrationDate() + { + return registrationDate; + } + + public void setRegistrationDate( String registrationDate ) + { + this.registrationDate = registrationDate; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public String getEventOrgUnit() + { + return eventOrgUnit; + } + + public void seteventOrgUnit( String eventOrgUnit ) + { + this.eventOrgUnit = eventOrgUnit; + } + + @JsonProperty( required = true ) + @JacksonXmlProperty( isAttribute = true ) + public String getEventDate() + { + return eventDate; + } + + public void setEventDate( String eventDate ) + { + this.eventDate = eventDate; + } + + @JsonProperty + @JacksonXmlProperty( isAttribute = true ) + public String getDueDate() + { + return dueDate; + } + + public void setDueDate( String dueDate ) + { + this.dueDate = dueDate; + } + + + @JsonProperty + @JacksonXmlElementWrapper( localName = "notes", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "note", namespace = DxfNamespaces.DXF_2_0 ) + public List getNotes() + { + return notes; + } + + public void setNotes( List notes ) + { + this.notes = notes; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public Boolean getFollowup() + { + return followup; + } + + public void setFollowup( Boolean followup ) + { + this.followup = followup; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + return true; + if ( o == null || getClass() != o.getClass() ) + return false; + + EventRow eventRow1 = (EventRow) o; + + if ( event != null ? !event.equals( eventRow1.event ) : eventRow1.event != null ) + return false; + if ( attributes != null ? !attributes.equals( eventRow1.attributes ) : eventRow1.attributes != null ) + return false; + + if ( eventDate != null ? !eventDate.equals( eventRow1.eventDate ) : eventRow1.eventDate != null ) + return false; + if ( dueDate != null ? !dueDate.equals( eventRow1.dueDate ) : eventRow1.dueDate != null ) + return false; + if ( eventOrgUnit != null ? !eventOrgUnit.equals( eventRow1.eventOrgUnit ) : eventRow1.eventOrgUnit != null ) + return false; + if ( registrationOrgUnit != null ? !registrationOrgUnit.equals( eventRow1.registrationOrgUnit ) : eventRow1.registrationOrgUnit != null ) + return false; + if ( registrationDate != null ? !registrationDate.equals( eventRow1.registrationDate ) : eventRow1.registrationDate != null ) + return false; + if ( trackedEntityInstance != null ? !trackedEntityInstance.equals( eventRow1.trackedEntityInstance ) + : eventRow1.trackedEntityInstance != null ) + return false; + if ( program != null ? !program.equals( eventRow1.program ) : eventRow1.program != null ) + return false; + if ( programStage != null ? !programStage.equals( eventRow1.programStage ) : eventRow1.programStage != null ) + return false; + + return true; + } + + @Override + public int hashCode() + { + int result = event != null ? event.hashCode() : 0; + result = 31 * result + (attributes != null ? attributes.hashCode() : 0); + result = 31 * result + (program != null ? program.hashCode() : 0); + result = 31 * result + (programStage != null ? programStage.hashCode() : 0); + result = 31 * result + (eventOrgUnit != null ? eventOrgUnit.hashCode() : 0); + result = 31 * result + (registrationOrgUnit != null ? registrationOrgUnit.hashCode() : 0); + result = 31 * result + (registrationDate != null ? registrationDate.hashCode() : 0); + result = 31 * result + (trackedEntityInstance != null ? trackedEntityInstance.hashCode() : 0); + result = 31 * result + (eventDate != null ? eventDate.hashCode() : 0); + result = 31 * result + (dueDate != null ? dueDate.hashCode() : 0); + return result; + } + + @Override + public String toString() + { + return "Event{" + + "event='" + event + '\'' + + ", eventName=" + eventName + + ", attributes=" + attributes + + ", program='" + program + '\'' + + ", programStage='" + programStage + '\'' + + ", eventOrgUnit='" + eventOrgUnit + '\'' + + ", registrationOrgUnit='" + registrationOrgUnit + '\'' + + ", registrationDate='" + registrationDate + '\'' + + ", trackedEntityInstance='" + trackedEntityInstance + '\'' + + ", eventDate='" + eventDate + '\'' + + ", dueDate='" + dueDate + '\'' + + '}'; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRowService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRowService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRowService.java 2014-09-17 14:53:33 +0000 @@ -0,0 +1,52 @@ +package org.hisp.dhis.dxf2.events.report; + +/* + * Copyright (c) 2004-2014, 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 java.util.Date; +import java.util.List; + +import org.hisp.dhis.event.EventStatus; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.program.Program; + +/** + * @author Abyot Asalefew Gizaw + * + */ +public interface EventRowService +{ + + // ------------------------------------------------------------------------- + // READ + // ------------------------------------------------------------------------- + + EventRows getOverDueEventRows( Program program, List organisationUnits, EventStatus status ); + + EventRows getUpcomingEventRows( Program program, List organisationUnits, Date startDate, Date endDate, EventStatus status ); +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRows.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRows.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/report/EventRows.java 2014-09-17 14:53:33 +0000 @@ -0,0 +1,109 @@ +package org.hisp.dhis.dxf2.events.report; + +import java.util.ArrayList; +import java.util.List; + +import org.hisp.dhis.common.DxfNamespaces; +import org.hisp.dhis.common.Pager; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +/* + * Copyright (c) 2004-2014, 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. + */ + +/** + * @author Abyot Asalefew Gizaw + * + */ + +@JacksonXmlRootElement( localName = "eventRows", namespace = DxfNamespaces.DXF_2_0 ) +public class EventRows +{ + private List eventRows = new ArrayList<>(); + + private Pager pager; + + public EventRows() + { + } + + @JsonProperty( "eventRows" ) + @JacksonXmlElementWrapper( localName = "eventRows", useWrapping = false, namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "eventRows", namespace = DxfNamespaces.DXF_2_0 ) + public List getEventRows() + { + return eventRows; + } + + public void setEventRows( List eventRows ) + { + this.eventRows = eventRows; + } + + @JsonProperty + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) + public Pager getPager() + { + return pager; + } + + public void setPager( Pager pager ) + { + this.pager = pager; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) return true; + if ( o == null || getClass() != o.getClass() ) return false; + + EventRows that = (EventRows) o; + + if ( eventRows != null ? !eventRows.equals( that.eventRows ) : that.eventRows != null ) return false; + + return true; + } + + @Override + public int hashCode() + { + return eventRows != null ? eventRows.hashCode() : 0; + } + + @Override + public String toString() + { + return "EventRows{" + + "eventRows=" + eventRows + + '}'; + } +}