dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24680
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12142: Only allow enrollment if person is not already enrolled to program. Allow filtering by status in ...
------------------------------------------------------------
revno: 12142
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-18 15:09:07 +0200
message:
Only allow enrollment if person is not already enrolled to program. Allow filtering by status in EnrollmentController.
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:50:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceService.java 2013-09-18 13:09:07 +0000
@@ -68,6 +68,8 @@
Collection<ProgramInstance> getProgramInstances( Collection<Program> programs, OrganisationUnit organisationUnit );
+ Collection<ProgramInstance> getProgramInstances( Collection<Program> programs, OrganisationUnit organisationUnit, int status );
+
Collection<ProgramInstance> getProgramInstances( Program program, Integer status );
Collection<ProgramInstance> getProgramInstances( Collection<Program> programs, Integer status );
=== 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-18 09:50:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstanceStore.java 2013-09-18 13:09:07 +0000
@@ -52,6 +52,8 @@
Collection<ProgramInstance> get( Collection<Program> programs, OrganisationUnit organisationUnit );
+ Collection<ProgramInstance> get( Collection<Program> programs, OrganisationUnit organisationUnit, int status );
+
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-18 12:19:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java 2013-09-18 13:09:07 +0000
@@ -88,6 +88,17 @@
}
@Override
+ public Enrollments getEnrollments( EnrollmentStatus status )
+ {
+ List<Program> programs = getProgramsWithRegistration();
+
+ List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>(
+ programInstanceService.getProgramInstances( programs, status.getValue() ) );
+
+ return getEnrollments( programInstances );
+ }
+
+ @Override
public Enrollments getEnrollments( Person person )
{
Patient patient = getPatient( person.getPerson() );
@@ -95,9 +106,18 @@
}
@Override
- public Enrollments getEnrollments( Patient patient )
- {
- List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>( programInstanceService.getProgramInstances( patient ) );
+ public Enrollments getEnrollments( Person person, EnrollmentStatus status )
+ {
+ Patient patient = getPatient( person.getPerson() );
+ return getEnrollments( patient, status );
+ }
+
+ @Override
+ public Enrollments getEnrollments( Patient patient, EnrollmentStatus status )
+ {
+ List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>(
+ programInstanceService.getProgramInstances( patient, status.getValue() ) );
+
return getEnrollments( programInstances );
}
@@ -109,16 +129,34 @@
}
@Override
+ public Enrollments getEnrollments( Program program, EnrollmentStatus status )
+ {
+ List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>(
+ programInstanceService.getProgramInstances( program, status.getValue() ) );
+
+ return getEnrollments( programInstances );
+ }
+
+ @Override
public Enrollments getEnrollments( OrganisationUnit organisationUnit )
{
List<Program> programs = getProgramsWithRegistration();
-
List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>( programInstanceService.getProgramInstances( programs, organisationUnit ) );
return getEnrollments( programInstances );
}
@Override
+ public Enrollments getEnrollments( OrganisationUnit organisationUnit, EnrollmentStatus status )
+ {
+ List<Program> programs = getProgramsWithRegistration();
+ List<ProgramInstance> programInstances = new ArrayList<ProgramInstance>(
+ programInstanceService.getProgramInstances( programs, organisationUnit, status.getValue() ) );
+
+ return getEnrollments( programInstances );
+ }
+
+ @Override
public Enrollments getEnrollments( Program program, OrganisationUnit organisationUnit )
{
return getEnrollments( programInstanceService.getProgramInstances( program, organisationUnit ) );
@@ -132,6 +170,13 @@
}
@Override
+ public Enrollments getEnrollments( Program program, Person person, EnrollmentStatus status )
+ {
+ Patient patient = getPatient( person.getPerson() );
+ return getEnrollments( programInstanceService.getProgramInstances( patient, program, status.getValue() ) );
+ }
+
+ @Override
public Enrollments getEnrollments( Collection<ProgramInstance> programInstances )
{
Enrollments enrollments = new Enrollments();
@@ -182,8 +227,17 @@
}
Patient patient = getPatient( enrollment.getPerson() );
+ Person person = personService.getPerson( patient );
Program program = getProgram( enrollment.getProgram() );
+ Enrollments enrollments = getEnrollments( program, person, EnrollmentStatus.ACTIVE );
+
+ if ( !enrollments.getEnrollments().isEmpty() )
+ {
+ return new ImportSummary( ImportStatus.ERROR, "Person " + person.getPerson() + " already have an active enrollment in program "
+ + program.getUid() );
+ }
+
ProgramInstance programInstance = programInstanceService.enrollPatient( patient, program, enrollment.getDateOfEnrollment(), enrollment.getDateOfIncident(),
patient.getOrganisationUnit(), format );
=== 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-18 12:19:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/EnrollmentService.java 2013-09-18 13:09:07 +0000
@@ -51,16 +51,28 @@
Enrollments getEnrollments();
+ Enrollments getEnrollments( EnrollmentStatus status );
+
Enrollments getEnrollments( Person person );
+ Enrollments getEnrollments( Person person, EnrollmentStatus status );
+
Enrollments getEnrollments( Patient patient );
+ Enrollments getEnrollments( Patient patient, EnrollmentStatus status );
+
Enrollments getEnrollments( Program program );
+ Enrollments getEnrollments( Program program, EnrollmentStatus status );
+
Enrollments getEnrollments( Program program, Person person );
+ Enrollments getEnrollments( Program program, Person person, EnrollmentStatus status );
+
Enrollments getEnrollments( OrganisationUnit organisationUnit );
+ Enrollments getEnrollments( OrganisationUnit organisationUnit, EnrollmentStatus status );
+
Enrollments getEnrollments( Program program, OrganisationUnit organisationUnit );
Enrollments getEnrollments( Collection<ProgramInstance> programInstances );
=== 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 12:19:37 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramInstanceService.java 2013-09-18 13:09:07 +0000
@@ -195,6 +195,11 @@
return programInstanceStore.get( programs, organisationUnit );
}
+ public Collection<ProgramInstance> getProgramInstances( Collection<Program> programs, OrganisationUnit organisationUnit, int status )
+ {
+ return programInstanceStore.get( programs, organisationUnit, status );
+ }
+
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-18 09:50:42 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/hibernate/HibernateProgramInstanceStore.java 2013-09-18 13:09:07 +0000
@@ -94,6 +94,14 @@
.add( Restrictions.eq( "patient.organisationUnit", organisationUnit ) ).list();
}
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public Collection<ProgramInstance> get( Collection<Program> programs, OrganisationUnit organisationUnit, int status )
+ {
+ return getCriteria( Restrictions.eq( "status", status ), Restrictions.in( "program", programs ) ).createAlias( "patient", "patient" )
+ .add( Restrictions.eq( "patient.organisationUnit", organisationUnit ) ).list();
+ }
+
@SuppressWarnings( "unchecked" )
public Collection<ProgramInstance> get( Program program, Integer status )
{
=== 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 12:19:37 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EnrollmentController.java 2013-09-18 13:09:07 +0000
@@ -34,6 +34,7 @@
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.EnrollmentStatus;
import org.hisp.dhis.dxf2.events.enrollment.Enrollments;
import org.hisp.dhis.dxf2.events.person.Person;
import org.hisp.dhis.dxf2.events.person.PersonService;
@@ -86,6 +87,7 @@
@RequestParam( value = "orgUnit", required = false ) String orgUnitUid,
@RequestParam( value = "program", required = false ) String programUid,
@RequestParam( value = "person", required = false ) String personUid,
+ @RequestParam( value = "status", required = false ) EnrollmentStatus status,
@RequestParam Map<String, String> parameters, Model model, HttpServletRequest request ) throws NotFoundException
{
WebOptions options = new WebOptions( parameters );
@@ -93,7 +95,7 @@
if ( orgUnitUid == null && programUid == null && personUid == null )
{
- enrollments = enrollmentService.getEnrollments();
+ enrollments = status != null ? enrollmentService.getEnrollments( status ) : enrollmentService.getEnrollments();
}
else if ( orgUnitUid != null && programUid != null )
{
@@ -107,22 +109,24 @@
Program program = getProgram( programUid );
Person person = getPerson( personUid );
- enrollments = enrollmentService.getEnrollments( program, person );
+ enrollments = status != null ? enrollmentService.getEnrollments( program, person, status )
+ : enrollmentService.getEnrollments( program, person );
}
else if ( orgUnitUid != null )
{
OrganisationUnit organisationUnit = getOrganisationUnit( orgUnitUid );
- enrollments = enrollmentService.getEnrollments( organisationUnit );
+ enrollments = status != null ? enrollmentService.getEnrollments( organisationUnit, status )
+ : enrollmentService.getEnrollments( organisationUnit );
}
else if ( programUid != null )
{
Program program = getProgram( programUid );
- enrollments = enrollmentService.getEnrollments( program );
+ enrollments = status != null ? enrollmentService.getEnrollments( program, status ) : enrollmentService.getEnrollments( program );
}
else
{
- Person person = getPerson( personUid );
- enrollments = enrollmentService.getEnrollments( person );
+ Person person = getPerson( personUid );
+ enrollments = status != null ? enrollmentService.getEnrollments( person, status ) : enrollmentService.getEnrollments( person );
}
model.addAttribute( "model", enrollments );