dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26179
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12968: implemented sql for filtering by person
------------------------------------------------------------
revno: 12968
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-11-19 11:21:42 +0100
message:
implemented sql for filtering by person
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DefaultEventStore.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-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-11-19 10:02:44 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/DefaultEventStore.java 2013-11-19 10:21:42 +0000
@@ -32,6 +32,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.hisp.dhis.dxf2.events.person.Person;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientService;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.system.util.TextUtils;
@@ -55,6 +57,9 @@
@Autowired
private JdbcTemplate jdbcTemplate;
+ @Autowired
+ private PatientService patientService;
+
private static final ObjectMapper objectMapper = new ObjectMapper();
@Override
@@ -139,8 +144,21 @@
public List<Event> getAll( List<Program> programs, List<ProgramStage> programStages, List<OrganisationUnit> organisationUnits, Person person, Date startDate, Date endDate )
{
List<Event> events = new ArrayList<Event>();
+
+ Integer personId = null;
+
+ if ( person != null )
+ {
+ Patient patient = patientService.getPatient( person.getPerson() );
+
+ if ( patient != null )
+ {
+ personId = patient.getId();
+ }
+ }
+
String sql = buildSql( getIdList( programs ), getIdList( programStages ), getIdList( organisationUnits ),
- startDate, endDate );
+ personId, startDate, endDate );
SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
@@ -201,7 +219,7 @@
return events;
}
- private String buildSql( List<Integer> programIds, List<Integer> programStageIds, List<Integer> orgUnitIds, Date startDate, Date endDate )
+ private String buildSql( List<Integer> programIds, List<Integer> programStageIds, List<Integer> orgUnitIds, Integer personId, Date startDate, Date endDate )
{
String sql = "select p.uid as p_uid, 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, "
+ "psi.executiondate as psi_executiondate, psi.completeduser as psi_completeduser, psi.coordinates as psi_coordinates," +
@@ -217,6 +235,19 @@
boolean startedWhere = false;
+ if ( personId != null )
+ {
+ if ( startedWhere )
+ {
+ sql += " and pa.patientid=" + personId;
+ }
+ else
+ {
+ sql += " where pa.patientid=" + personId;
+ startedWhere = true;
+ }
+ }
+
if ( !programIds.isEmpty() )
{
if ( startedWhere )