-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3712bfe
commit f3e379b
Showing
6 changed files
with
77 additions
and
45 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
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
46 changes: 46 additions & 0 deletions
46
api/src/main/java/org/openmrs/module/htmlformentry/appointment/AppointmentsAbstractor.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,46 @@ | ||
package org.openmrs.module.htmlformentry.appointment; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.openmrs.Encounter; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.appointments.model.Appointment; | ||
import org.openmrs.module.appointments.model.AppointmentStatus; | ||
import org.openmrs.module.appointments.service.AppointmentsService; | ||
|
||
/** | ||
* Calls to the AppointmentService are abstracted here, rather than directly accessed in the Form | ||
* Entry Session to avoid runtime class loading issues in instances where the Appointments module is | ||
* not present | ||
*/ | ||
public class AppointmentsAbstractor { | ||
|
||
public void markAppointmentsAsCheckedInAndAssociateWithEncounter(List<Object> appointments, Encounter encounter) { | ||
for (Object appointmentObject : appointments) { | ||
Appointment appointment = (Appointment) appointmentObject; | ||
if (appointment.getStatus() == AppointmentStatus.Scheduled) { | ||
Context.getService(AppointmentsService.class).changeStatus(appointment, | ||
AppointmentStatus.CheckedIn.toString(), encounter.getEncounterDatetime()); | ||
} | ||
if (appointment.getFulfillingEncounters() != null) { | ||
appointment.getFulfillingEncounters().add(encounter); | ||
} else { | ||
appointment.setFulfillingEncounters(Collections.singleton(encounter)); | ||
} | ||
// see: https://bahmni.atlassian.net/browse/BAH-3855 for why we need to call the Supplier<Appointment> version of validateAndSave | ||
Context.getService(AppointmentsService.class).validateAndSave(() -> appointment); | ||
} | ||
} | ||
|
||
public void disassociateAppointmentsFromEncounter(List<Object> appointments, Encounter encounter) { | ||
for (Object appointmentObject : appointments) { | ||
Appointment appointment = (Appointment) appointmentObject; | ||
if (appointment.getFulfillingEncounters() != null) { | ||
appointment.getFulfillingEncounters().remove(encounter); | ||
// see: https://bahmni.atlassian.net/browse/BAH-3855 for why we need to call the Supplier<Appointment> version of validateAndSave | ||
Context.getService(AppointmentsService.class).validateAndSave(() -> appointment); | ||
} | ||
} | ||
} | ||
} |
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