forked from Bahmni/default-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BAH-1013 | Events raised for recurring appointments and fix weekly re…
…curring appointment (Bahmni#28) * Sowmika, Bindu | MOBN-927 | Create event records for recurring appointments creation * Sowmika, Bindu | MOBN-927 | Create event records for recurring appointments update * Sowmika, Bindu | MOBN-927 | Create event records for recurring appointments change status * Sowmika, Bindu | MOBN-927 | Retain removed appointments in patient appointment occurrence table to get event records * Sowmika, Bindu | MOBN-927 | Create event records for single recurring appointment update * Sowmika, Bindu | MOBN-927 | Add voided field to defaultAppointmentResponse * Sowmika, Bindu | MOBN-927 | Add recurring appointments url for event records * Sowmika, Bindu | MOBN-927 | Peer review changes * Vineela, Bindu | MOBN-998 | Add dayCode handling if we have a related appointment in the series for extend sceanrio * Kirity, Vineela | MOBN-1032 | Cover the existing functionality with test cases and Fix Missing appointment while editing a recurring appointment * Ignore the test case which is yet to be modified * Siva, Vinisha | Fix weekly recurring extension bug * Siva, Vinisha | Fix weekly recurring bug extension when any appointment in pattern got moved and removed * Add integration test for extending weekly recurring appointments * Bindu | Addresses the PR review comments Co-authored-by: sowmika <[email protected]> Co-authored-by: Himabindu Thungathurty <[email protected]> Co-authored-by: binduak <[email protected]> Co-authored-by: Siva Rachakonda <[email protected]>
- Loading branch information
1 parent
1960eeb
commit 86cba2e
Showing
22 changed files
with
2,018 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
api/src/main/java/org/openmrs/module/appointments/advice/RecurringAppointmentsAdvice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package org.openmrs.module.appointments.advice; | ||
|
||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.appointments.model.Appointment; | ||
import org.openmrs.module.appointments.model.AppointmentRecurringPattern; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.openmrs.module.appointments.constants.AppointmentsEventRecordsConstants.CATEGORY; | ||
import static org.openmrs.module.appointments.constants.AppointmentsEventRecordsConstants.RAISE_EVENT_GLOBAL_PROPERTY; | ||
|
||
public class RecurringAppointmentsAdvice extends AbstractBaseAdvice { | ||
|
||
private static final String TITLE = "RecurringAppointments"; | ||
private static final String VALIDATE_AND_SAVE = "validateAndSave"; | ||
private static final String UPDATE = "update"; | ||
private static final String CHANGE_STATUS = "changeStatus"; | ||
private static final List<String> METHOD_NAMES = Arrays.asList(VALIDATE_AND_SAVE, UPDATE, CHANGE_STATUS); | ||
private static final String URL_PATTERN_GLOBAL_PROPERTY = "atomfeed.event.urlPatternForRecurringAppointments"; | ||
private static final String DEFAULT_URL_PATTERN = "/openmrs/ws/rest/v1/recurring-appointments?uuid={uuid}"; | ||
|
||
@Override | ||
public void afterReturning(Object returnValue, Method method, Object[] arguments, Object target) throws Throwable { | ||
List<Appointment> updatedAppointments = new ArrayList<>(); | ||
if (VALIDATE_AND_SAVE.equals(method.getName()) || isAllRecurringAppointmentsUpdate(method, returnValue)) { | ||
AppointmentRecurringPattern appointmentRecurringPattern = (AppointmentRecurringPattern) returnValue; | ||
updatedAppointments = new ArrayList<>(appointmentRecurringPattern.getAppointments()); | ||
} else if (isSingleRecurringAppointmentUpdate(method, returnValue)) { | ||
updatedAppointments = (List<Appointment>) arguments[1]; | ||
} else if (CHANGE_STATUS.equals(method.getName())) { | ||
updatedAppointments = (List<Appointment>) returnValue; | ||
} | ||
raiseEventsForAppointments(method, arguments, target, updatedAppointments); | ||
} | ||
|
||
private void raiseEventsForAppointments(Method method, Object[] arguments, Object target, | ||
List<Appointment> appointments) throws Throwable { | ||
for (Appointment appointment : appointments) { | ||
super.afterReturning(appointment, method, arguments, target); | ||
} | ||
} | ||
|
||
private boolean isSingleRecurringAppointmentUpdate(Method method, Object processedReturnValue) { | ||
return UPDATE.equals(method.getName()) && (processedReturnValue instanceof Appointment); | ||
} | ||
|
||
private boolean isAllRecurringAppointmentsUpdate(Method method, Object processedReturnValue) { | ||
return UPDATE.equals(method.getName()) && (processedReturnValue instanceof AppointmentRecurringPattern); | ||
} | ||
|
||
@Override | ||
protected String getContents(Object returnValue) { | ||
return getUrlPattern(URL_PATTERN_GLOBAL_PROPERTY, DEFAULT_URL_PATTERN) | ||
.replace("{uuid}", ((Appointment) returnValue).getUuid()); | ||
} | ||
|
||
@Override | ||
protected String getTitle() { | ||
return TITLE; | ||
} | ||
|
||
@Override | ||
protected String getCategory() { | ||
return CATEGORY; | ||
} | ||
|
||
@Override | ||
protected boolean shouldRaiseEventForMethod(String methodName) { | ||
return METHOD_NAMES.contains(methodName); | ||
} | ||
|
||
@Override | ||
protected boolean shouldRaiseEvent() { | ||
return Boolean.valueOf(Context.getAdministrationService().getGlobalProperty(RAISE_EVENT_GLOBAL_PROPERTY)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ain/java/org/openmrs/module/appointments/constants/AppointmentsEventRecordsConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.openmrs.module.appointments.constants; | ||
|
||
public class AppointmentsEventRecordsConstants { | ||
public static final String CATEGORY = "appointments"; | ||
public static final String RAISE_EVENT_GLOBAL_PROPERTY = "atomfeed.publish.eventsForAppointments"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.