dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24672
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12135: enrollment service, wip. controller can now query on program, orgUnit, person
------------------------------------------------------------
revno: 12135
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-18 11:50:42 +0200
message:
enrollment service, wip. controller can now query on program, orgUnit, person
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.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-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.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/ProgramInstanceService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java 2013-09-18 09:17:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java 2013-09-18 09:50:42 +0000
@@ -28,10 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Date;
-import java.util.Collection;
-import java.util.List;
-
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nFormat;
@@ -40,6 +36,10 @@
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.sms.outbound.OutboundSms;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
/**
* @author Abyot Asalefew
* @version $Id$
@@ -66,6 +66,8 @@
Collection<ProgramInstance> getProgramInstances( Collection<Program> programs );
+ Collection<ProgramInstance> getProgramInstances( Collection<Program> programs, OrganisationUnit organisationUnit );
+
Collection<ProgramInstance> getProgramInstances( Program program, Integer status );
Collection<ProgramInstance> getProgramInstances( Collection<Program> programs, Integer status );
@@ -119,8 +121,9 @@
/**
* Set status as skipped for overdue events; Remove scheduled events
- *
- * **/
+ * <p/>
+ * *
+ */
void cancelProgramInstanceStatus( ProgramInstance programInstance );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java 2013-09-17 15:26:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java 2013-09-18 09:50:42 +0000
@@ -50,6 +50,8 @@
Collection<ProgramInstance> get( Collection<Program> programs );
+ Collection<ProgramInstance> get( Collection<Program> programs, OrganisationUnit organisationUnit );
+
Collection<ProgramInstance> get( Program program, Integer status );
Collection<ProgramInstance> get( Collection<Program> programs, Integer status );
=== 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 2013-09-17 15:26:14 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2013-09-18 09:50:42 +0000
@@ -28,11 +28,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.dxf2.events.person.Person;
+import org.hisp.dhis.dxf2.events.person.PersonService;
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.ProgramInstance;
import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.program.ProgramService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
@@ -47,6 +51,15 @@
@Autowired
private ProgramInstanceService programInstanceService;
+ @Autowired
+ private ProgramService programService;
+
+ @Autowired
+ private PersonService personService;
+
+ @Autowired
+ private PatientService patientService;
+
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@@ -54,11 +67,20 @@
@Override
public Enrollments getEnrollments()
{
- List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>( programInstanceService.getAllProgramInstances() );
+ List<Program> programs = getProgramsWithRegistration();
+
+ List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>( programInstanceService.getProgramInstances( programs ) );
return getEnrollments( programInstances );
}
@Override
+ public Enrollments getEnrollments( Person person )
+ {
+ Patient patient = patientService.getPatient( person.getPerson() );
+ return getEnrollments( patient );
+ }
+
+ @Override
public Enrollments getEnrollments( Patient patient )
{
List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>( programInstanceService.getProgramInstances( patient ) );
@@ -68,19 +90,31 @@
@Override
public Enrollments getEnrollments( Program program )
{
- return null;
+ List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>( programInstanceService.getProgramInstances( program ) );
+ return getEnrollments( programInstances );
}
@Override
public Enrollments getEnrollments( OrganisationUnit organisationUnit )
{
- return null;
+ List<Program> programs = getProgramsWithRegistration();
+
+ List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>( programInstanceService.getProgramInstances( programs, organisationUnit ) );
+
+ return getEnrollments( programInstances );
}
@Override
public Enrollments getEnrollments( Program program, OrganisationUnit organisationUnit )
{
- return null;
+ return getEnrollments( programInstanceService.getProgramInstances( program, organisationUnit ) );
+ }
+
+ @Override
+ public Enrollments getEnrollments( Program program, Person person )
+ {
+ Patient patient = patientService.getPatient( person.getPerson() );
+ return getEnrollments( programInstanceService.getProgramInstances( patient, program ) );
}
@Override
@@ -113,4 +147,16 @@
return enrollment;
}
+
+ // -------------------------------------------------------------------------
+ // HELPERS
+ // -------------------------------------------------------------------------
+
+ private List<Program> getProgramsWithRegistration()
+ {
+ List<Program> programs = new ArrayList<Program>();
+ programs.addAll( programService.getPrograms( Program.SINGLE_EVENT_WITH_REGISTRATION ) );
+ programs.addAll( programService.getPrograms( Program.MULTIPLE_EVENTS_WITH_REGISTRATION ) );
+ return programs;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java 2013-09-17 15:26:14 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java 2013-09-18 09:50:42 +0000
@@ -28,6 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.dxf2.events.person.Person;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.program.Program;
@@ -46,10 +47,14 @@
Enrollments getEnrollments();
+ Enrollments getEnrollments( Person person );
+
Enrollments getEnrollments( Patient patient );
Enrollments getEnrollments( Program program );
+ Enrollments getEnrollments( Program program, Person person );
+
Enrollments getEnrollments( OrganisationUnit organisationUnit );
Enrollments getEnrollments( Program program, OrganisationUnit organisationUnit );
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2013-09-18 09:17:43 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2013-09-18 09:50:42 +0000
@@ -190,6 +190,11 @@
return programInstanceStore.get( programs );
}
+ public Collection<ProgramInstance> getProgramInstances( Collection<Program> programs, OrganisationUnit organisationUnit )
+ {
+ return programInstanceStore.get( programs, organisationUnit );
+ }
+
public Collection<ProgramInstance> getProgramInstances( Collection<Program> programs, Integer status )
{
return programInstanceStore.get( programs, status );
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java 2013-09-17 18:16:20 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java 2013-09-18 09:50:42 +0000
@@ -86,6 +86,14 @@
return getCriteria( Restrictions.in( "program", programs ) ).list();
}
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public Collection<ProgramInstance> get( Collection<Program> programs, OrganisationUnit organisationUnit )
+ {
+ return getCriteria( Restrictions.in( "program", programs ) ).createAlias( "patient", "patient" )
+ .add( Restrictions.eq( "patient.organisationUnit", organisationUnit ) ).list();
+ }
+
@SuppressWarnings( "unchecked" )
public Collection<ProgramInstance> get( Program program, Integer status )
{
@@ -217,9 +225,9 @@
sql += " UNION ( " + sendToHealthWorkerSql( dateToCompare ) + " ) ";
sql += " UNION ( " + sendMessageToOrgunitRegisteredSql( dateToCompare ) + " ) ";
-
+
sql += " UNION ( " + sendMessageToUsersSql( dateToCompare ) + " ) ";
-
+
sql += " UNION ( " + sendMessageToUserGroupsSql( dateToCompare ) + " ) ";
SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
@@ -268,10 +276,10 @@
schedulingProgramObjects.add( schedulingProgramObject );
}
-
+
return schedulingProgramObjects;
}
-
+
private String sendToPatientSql( String dateToCompare )
{
@@ -365,7 +373,7 @@
+ "' and prm.sendto = "
+ PatientReminder.SEND_TO_ALL_USERS_IN_ORGUGNIT_REGISTERED;
}
-
+
private String sendMessageToUserGroupsSql( String dateToCompare )
{
return "select pi.programinstanceid, uif.phonenumber,prm.templatemessage, p.name, org.name as orgunitName ,"
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.java 2013-09-18 09:33:46 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.java 2013-09-18 09:50:42 +0000
@@ -28,15 +28,18 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
import org.hisp.dhis.api.controller.WebOptions;
import org.hisp.dhis.api.controller.exception.NotFoundException;
+import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dxf2.events.enrollment.Enrollment;
import org.hisp.dhis.dxf2.events.enrollment.EnrollmentService;
import org.hisp.dhis.dxf2.events.enrollment.Enrollments;
+import org.hisp.dhis.dxf2.events.person.Person;
+import org.hisp.dhis.dxf2.events.person.PersonService;
+import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.program.Program;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -45,6 +48,9 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -57,21 +63,59 @@
@Autowired
private EnrollmentService enrollmentService;
+ @Autowired
+ private PersonService personService;
+
+ @Autowired
+ private IdentifiableObjectManager manager;
+
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
- @RequestMapping(value = "", method = RequestMethod.GET)
+ @RequestMapping( value = "", method = RequestMethod.GET )
public String getEnrollments(
@RequestParam(value = "orgUnit", required = false) String orgUnitUid,
@RequestParam(value = "program", required = false) String programUid,
@RequestParam(value = "person", required = false) String personUid,
- @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request )
+ @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request ) throws NotFoundException
{
WebOptions options = new WebOptions( parameters );
Enrollments enrollments;
- enrollments = enrollmentService.getEnrollments();
+ if ( orgUnitUid == null && programUid == null && personUid == null )
+ {
+ enrollments = enrollmentService.getEnrollments();
+ }
+ else if ( orgUnitUid != null && programUid != null )
+ {
+ OrganisationUnit organisationUnit = getOrganisationUnit( orgUnitUid );
+ Program program = getProgram( programUid );
+
+ enrollments = enrollmentService.getEnrollments( program, organisationUnit );
+ }
+ else if ( programUid != null && personUid != null )
+ {
+ Program program = getProgram( programUid );
+ Person person = getPerson( personUid );
+
+ enrollments = enrollmentService.getEnrollments( program, person );
+ }
+ else if ( orgUnitUid != null )
+ {
+ OrganisationUnit organisationUnit = getOrganisationUnit( orgUnitUid );
+ enrollments = enrollmentService.getEnrollments( organisationUnit );
+ }
+ else if ( programUid != null )
+ {
+ Program program = getProgram( programUid );
+ enrollments = enrollmentService.getEnrollments( program );
+ }
+ else
+ {
+ Person person = getPerson( personUid );
+ enrollments = enrollmentService.getEnrollments( person );
+ }
model.addAttribute( "model", enrollments );
model.addAttribute( "viewClass", options.getViewClass( "basic" ) );
@@ -106,4 +150,45 @@
return enrollment;
}
+
+ private Person getPerson( String id ) throws NotFoundException
+ {
+ Person person = personService.getPerson( id );
+
+ if ( person == null )
+ {
+ throw new NotFoundException( "Person", id );
+ }
+
+ return person;
+ }
+
+ private OrganisationUnit getOrganisationUnit( String id ) throws NotFoundException
+ {
+ OrganisationUnit organisationUnit = manager.get( OrganisationUnit.class, id );
+
+ if ( organisationUnit == null )
+ {
+ throw new NotFoundException( "OrganisationUnit", id );
+ }
+
+ return organisationUnit;
+ }
+
+ private Program getProgram( String id ) throws NotFoundException
+ {
+ Program program = manager.get( Program.class, id );
+
+ if ( program == null )
+ {
+ throw new NotFoundException( "Program", id );
+ }
+
+ return program;
+ }
+
+ private String getResourcePath( HttpServletRequest request, ImportSummary importSummary )
+ {
+ return ContextUtils.getContextPath( request ) + "/api/" + "enrollments" + "/" + importSummary.getReference();
+ }
}