dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35703
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18274: implement identifier schemes for /api/events
------------------------------------------------------------
revno: 18274
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-02-16 15:37:44 +0700
message:
implement identifier schemes for /api/events
added:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/IdSchemes.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableProperty.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/EventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventStore.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.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/common/IdentifiableProperty.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableProperty.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableProperty.java 2015-02-16 08:37:44 +0000
@@ -33,5 +33,5 @@
*/
public enum IdentifiableProperty
{
- ID, UID, UUID, NAME, CODE;
+ ID, UID, UUID, NAME, CODE
}
=== 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-02-12 14:25:04 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2015-02-16 08:37:44 +0000
@@ -43,6 +43,7 @@
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.metadata.ImportOptions;
+import org.hisp.dhis.dxf2.utils.IdSchemes;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.i18n.I18nManager;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -374,11 +375,18 @@
@Override
public Events getEvents( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp,
- List<OrganisationUnit> organisationUnits, TrackedEntityInstance trackedEntityInstance, Date startDate,
- Date endDate, EventStatus status )
+ List<OrganisationUnit> organisationUnit, TrackedEntityInstance trackedEntityInstance, Date startDate, Date endDate, EventStatus status )
+ {
+ return getEvents( program, programStage, programStatus, followUp, organisationUnit, trackedEntityInstance, startDate, endDate, status, new IdSchemes() );
+ }
+
+ @Override
+ public Events getEvents( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp,
+ List<OrganisationUnit> organisationUnits, TrackedEntityInstance trackedEntityInstance, Date startDate, Date endDate, EventStatus status, IdSchemes idSchemes )
{
List<Event> eventList = eventStore.getAll( program, programStage, programStatus, followUp, organisationUnits,
- trackedEntityInstance, startDate, endDate, status );
+ trackedEntityInstance, startDate, endDate, status, idSchemes );
+
Events events = new Events();
events.setEvents( eventList );
@@ -581,7 +589,7 @@
{
programStageInstance.setStatus( EventStatus.VISITED );
}
-
+
OrganisationUnit organisationUnit = getOrganisationUnit( null, event.getOrgUnit() );
if ( organisationUnit == null )
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java 2015-02-16 08:37:44 +0000
@@ -28,10 +28,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.IdentifiableProperty;
import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance;
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.metadata.ImportOptions;
+import org.hisp.dhis.dxf2.utils.IdSchemes;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
@@ -59,6 +61,9 @@
Events getEvents( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp, List<OrganisationUnit> organisationUnit,
TrackedEntityInstance trackedEntityInstance, Date startDate, Date endDate, EventStatus status );
+ Events getEvents( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp, List<OrganisationUnit> organisationUnit,
+ TrackedEntityInstance trackedEntityInstance, Date startDate, Date endDate, EventStatus status, IdSchemes idSchemes );
+
Event getEvent( String uid );
Event getEvent( ProgramStageInstance programStageInstance );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventStore.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventStore.java 2015-02-16 08:37:44 +0000
@@ -28,7 +28,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.IdentifiableProperty;
import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance;
+import org.hisp.dhis.dxf2.utils.IdSchemes;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
@@ -45,4 +47,7 @@
{
List<Event> getAll( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp, List<OrganisationUnit> organisationUnits,
TrackedEntityInstance trackedEntityInstance, Date startDate, Date endDate, EventStatus status );
+
+ List<Event> getAll( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp, List<OrganisationUnit> organisationUnits,
+ TrackedEntityInstance trackedEntityInstance, Date startDate, Date endDate, EventStatus status, IdSchemes idSchemes );
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java 2015-02-12 20:24:32 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java 2015-02-16 08:37:44 +0000
@@ -33,7 +33,9 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.IdentifiableProperty;
import org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance;
+import org.hisp.dhis.dxf2.utils.IdSchemes;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.program.Program;
@@ -74,9 +76,16 @@
private static final ObjectMapper objectMapper = new ObjectMapper();
@Override
- public List<Event> getAll( Program program, ProgramStage programStage, ProgramStatus programStatus,
- Boolean followUp, List<OrganisationUnit> organisationUnits, TrackedEntityInstance trackedEntityInstance,
- Date startDate, Date endDate, EventStatus status )
+ public List<Event> getAll( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp,
+ List<OrganisationUnit> organisationUnits, TrackedEntityInstance trackedEntityInstance, Date startDate, Date endDate, EventStatus status )
+ {
+ return getAll( program, programStage, programStatus, followUp, organisationUnits, trackedEntityInstance,
+ startDate, endDate, status, new IdSchemes() );
+ }
+
+ @Override
+ public List<Event> getAll( Program program, ProgramStage programStage, ProgramStatus programStatus, Boolean followUp,
+ List<OrganisationUnit> organisationUnits, TrackedEntityInstance trackedEntityInstance, Date startDate, Date endDate, EventStatus status, IdSchemes idSchemes )
{
List<Event> events = new ArrayList<>();
@@ -119,8 +128,10 @@
event.setEvent( rowSet.getString( "psi_uid" ) );
event.setTrackedEntityInstance( rowSet.getString( "pa_uid" ) );
event.setStatus( EventStatus.valueOf( rowSet.getString( "psi_status" ) ) );
- event.setProgram( rowSet.getString( "p_uid" ) );
- event.setProgramStage( rowSet.getString( "ps_uid" ) );
+
+ event.setProgram( IdSchemes.getValue( rowSet.getString( "p_uid" ), rowSet.getString( "p_code" ), idSchemes.getProgramIdScheme() ) );
+ event.setProgramStage( IdSchemes.getValue( rowSet.getString( "ps_uid" ), rowSet.getString( "ps_code" ), idSchemes.getProgramStageIdScheme() ) );
+ event.setOrgUnit( IdSchemes.getValue( rowSet.getString( "ou_uid" ), rowSet.getString( "ou_code" ), idSchemes.getOrgUnitIdScheme() ) );
if ( rowSet.getInt( "p_type" ) != Program.SINGLE_EVENT_WITHOUT_REGISTRATION )
{
@@ -132,7 +143,6 @@
event.setTrackedEntityInstance( rowSet.getString( "tei_uid" ) );
event.setStoredBy( rowSet.getString( "psi_completeduser" ) );
- event.setOrgUnit( rowSet.getString( "ou_uid" ) );
event.setOrgUnitName( rowSet.getString( "ou_name" ) );
event.setDueDate( StringUtils.defaultIfEmpty(
@@ -181,7 +191,8 @@
DataValue dataValue = new DataValue();
dataValue.setValue( rowSet.getString( "pdv_value" ) );
dataValue.setProvidedElsewhere( rowSet.getBoolean( "pdv_providedelsewhere" ) );
- dataValue.setDataElement( rowSet.getString( "de_uid" ) );
+ dataValue.setDataElement( IdSchemes.getValue( rowSet.getString( "de_uid" ), rowSet.getString( "de_code" ), idSchemes.getDataElementIdScheme() ) );
+
dataValue.setStoredBy( rowSet.getString( "pdv_storedby" ) );
event.getDataValues().add( dataValue );
@@ -210,14 +221,14 @@
SqlHelper hlp = new SqlHelper();
String sql =
- "select pa.uid as tei_uid, pi.uid as pi_uid, pi.status as pi_status, pi.followup as pi_followup, p.uid as p_uid, " +
- "p.type as p_type, ps.uid as ps_uid, ps.capturecoordinates as ps_capturecoordinates, pa.uid as pa_uid, " +
- "psi.uid as psi_uid, psi.status as psi_status, ou.uid as ou_uid, ou.name as ou_name, " +
+ "select pa.uid as tei_uid, pi.uid as pi_uid, pi.status as pi_status, pi.followup as pi_followup, p.uid as p_uid, p.code as p_code, " +
+ "p.type as p_type, ps.uid as ps_uid, ps.code as ps_code, ps.capturecoordinates as ps_capturecoordinates, pa.uid as pa_uid, " +
+ "psi.uid as psi_uid, psi.status as psi_status, ou.uid as ou_uid, ou.code as ou_code, ou.name as ou_name, " +
"psi.executiondate as psi_executiondate, psi.duedate as psi_duedate, psi.completeduser as psi_completeduser, " +
"psi.longitude as psi_longitude, psi.latitude as psi_latitude, " +
"psinote.trackedentitycommentid as psinote_id, psinote.commenttext as psinote_value, " +
"psinote.createddate as psinote_soreddate, psinote.creator as psinote_storedby, " +
- "pdv.value as pdv_value, pdv.storedby as pdv_storedby, pdv.providedelsewhere as pdv_providedelsewhere, de.uid as de_uid " +
+ "pdv.value as pdv_value, pdv.storedby as pdv_storedby, pdv.providedelsewhere as pdv_providedelsewhere, de.uid as de_uid, de.code as de_code " +
"from program p " +
"left join programstage ps on ps.programid=p.programid " +
"left join programstageinstance psi on ps.programstageid=psi.programstageid " +
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/IdSchemes.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/IdSchemes.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/IdSchemes.java 2015-02-16 08:37:44 +0000
@@ -0,0 +1,124 @@
+package org.hisp.dhis.dxf2.utils;
+
+/*
+ * Copyright (c) 2004-2015, 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 org.hisp.dhis.common.IdentifiableProperty;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class IdSchemes
+{
+ private IdentifiableProperty idScheme;
+
+ private IdentifiableProperty dataElementIdScheme = IdentifiableProperty.UID;
+
+ private IdentifiableProperty categoryOptionComboIdScheme = IdentifiableProperty.UID;
+
+ private IdentifiableProperty orgUnitIdScheme = IdentifiableProperty.UID;
+
+ private IdentifiableProperty programIdScheme = IdentifiableProperty.UID;
+
+ private IdentifiableProperty programStageIdScheme = IdentifiableProperty.UID;
+
+ public IdSchemes()
+ {
+ }
+
+ public IdentifiableProperty getIdScheme()
+ {
+ return idScheme;
+ }
+
+ public IdentifiableProperty getIdentifiableProperty( IdentifiableProperty identifiableProperty )
+ {
+ return idScheme != null ? idScheme : identifiableProperty;
+ }
+
+ public void setIdScheme( IdentifiableProperty idScheme )
+ {
+ this.idScheme = idScheme;
+ }
+
+ public IdentifiableProperty getDataElementIdScheme()
+ {
+ return getIdentifiableProperty( dataElementIdScheme );
+ }
+
+ public void setDataElementIdScheme( IdentifiableProperty dataElementIdScheme )
+ {
+ this.dataElementIdScheme = dataElementIdScheme;
+ }
+
+ public IdentifiableProperty getCategoryOptionComboIdScheme()
+ {
+ return getIdentifiableProperty( categoryOptionComboIdScheme );
+ }
+
+ public void setCategoryOptionComboIdScheme( IdentifiableProperty categoryOptionComboIdScheme )
+ {
+ this.categoryOptionComboIdScheme = categoryOptionComboIdScheme;
+ }
+
+ public IdentifiableProperty getOrgUnitIdScheme()
+ {
+ return getIdentifiableProperty( orgUnitIdScheme );
+ }
+
+ public void setOrgUnitIdScheme( IdentifiableProperty orgUnitIdScheme )
+ {
+ this.orgUnitIdScheme = orgUnitIdScheme;
+ }
+
+ public IdentifiableProperty getProgramIdScheme()
+ {
+ return getIdentifiableProperty( programIdScheme );
+ }
+
+ public void setProgramIdScheme( IdentifiableProperty programIdScheme )
+ {
+ this.programIdScheme = programIdScheme;
+ }
+
+ public IdentifiableProperty getProgramStageIdScheme()
+ {
+ return getIdentifiableProperty( programStageIdScheme );
+ }
+
+ public void setProgramStageIdScheme( IdentifiableProperty programStageIdScheme )
+ {
+ this.programStageIdScheme = programStageIdScheme;
+ }
+
+ public static String getValue( String uid, String code, IdentifiableProperty identifiableProperty )
+ {
+ boolean idScheme = IdentifiableProperty.ID.equals( identifiableProperty ) || IdentifiableProperty.UID.equals( identifiableProperty );
+ return idScheme ? uid : code;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java 2015-02-16 08:37:44 +0000
@@ -48,6 +48,7 @@
import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
import org.hisp.dhis.dxf2.importsummary.ImportSummary;
import org.hisp.dhis.dxf2.metadata.ImportOptions;
+import org.hisp.dhis.dxf2.utils.IdSchemes;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
import org.hisp.dhis.event.EventStatus;
import org.hisp.dhis.importexport.ImportStrategy;
@@ -148,7 +149,8 @@
@RequestParam( required = false ) EventStatus status,
@RequestParam( required = false ) String attachment,
@RequestParam( required = false, defaultValue = "false" ) boolean skipHeader,
- @RequestParam Map<String, String> parameters, Model model, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ @RequestParam Map<String, String> parameters,
+ IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request ) throws IOException
{
WebOptions options = new WebOptions( parameters );
@@ -197,7 +199,8 @@
}
}
- Events events = eventService.getEvents( pr, prs, programStatus, followUp, organisationUnits, tei, startDate, endDate, status );
+ Events events = eventService.getEvents( pr, prs, programStatus, followUp, organisationUnits, tei, startDate, endDate, status, idSchemes );
+
if ( options.hasPaging() )
{
Pager pager = new Pager( options.getPage(), events.getEvents().size(), options.getPageSize() );
@@ -240,7 +243,7 @@
@RequestParam( required = false ) EventStatus status,
@RequestParam( required = false ) boolean skipMeta,
@RequestParam( required = false ) String attachment,
- @RequestParam Map<String, String> parameters, Model model, HttpServletResponse response, HttpServletRequest request )
+ @RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request )
{
WebOptions options = new WebOptions( parameters );
@@ -289,8 +292,8 @@
}
}
- Events events = eventService.getEvents( pr, prs, programStatus, followUp, organisationUnits, tei, startDate, endDate, status );
-
+ Events events = eventService.getEvents( pr, prs, programStatus, followUp, organisationUnits, tei, startDate, endDate, status, idSchemes );
+
if ( options.hasLinks() )
{
for ( Event event : events.getEvents() )