From 4b47256b38d5510c38d180b5f7a59239113b86e8 Mon Sep 17 00:00:00 2001 From: IamMujuziMoses Date: Thu, 4 Apr 2024 19:31:16 +0300 Subject: [PATCH] O3-3002: Queue Module - REST endpoints can be accessed without authentication. --- .../module/queue/api/QueueRoomService.java | 49 ++++++++++++++++++- .../queue/api/RoomProviderMapService.java | 49 ++++++++++++++++++- .../queue/utils/PrivilegeConstants.java | 16 ++++++ 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/queue/api/QueueRoomService.java b/api/src/main/java/org/openmrs/module/queue/api/QueueRoomService.java index 753463fb..b970e252 100644 --- a/api/src/main/java/org/openmrs/module/queue/api/QueueRoomService.java +++ b/api/src/main/java/org/openmrs/module/queue/api/QueueRoomService.java @@ -14,23 +14,70 @@ import java.util.List; import java.util.Optional; +import org.openmrs.annotation.Authorized; import org.openmrs.api.APIException; +import org.openmrs.api.OpenmrsService; import org.openmrs.module.queue.api.search.QueueRoomSearchCriteria; import org.openmrs.module.queue.model.QueueRoom; +import org.openmrs.module.queue.utils.PrivilegeConstants; -public interface QueueRoomService { +public interface QueueRoomService extends OpenmrsService { + /** + * Gets a queue room given uuid. + * + * @param uuid uuid of the queue room to be returned. + * @return {@link org.openmrs.module.queue.model.QueueRoom} + */ + @Authorized({ PrivilegeConstants.GET_QUEUE_ROOMS }) Optional getQueueRoomByUuid(@NotNull String uuid); + /** + * Gets a queue room by id. + * + * @param id queueRoomId - the id of the queue room to retrieve. + * @return {@link org.openmrs.module.queue.model.QueueRoom} + */ + @Authorized({ PrivilegeConstants.GET_QUEUE_ROOMS }) Optional getQueueRoomById(@NotNull int id); + /** + * @return {@link List} of all queue rooms + */ + @Authorized({ PrivilegeConstants.GET_QUEUE_ROOMS }) List getAllQueueRooms(); + /** + * Saves a queue room + * + * @param queueRoom the queue room to be saved + * @return saved {@link org.openmrs.module.queue.model.QueueRoom} + */ + @Authorized({ PrivilegeConstants.MANAGE_QUEUE_ROOMS }) QueueRoom saveQueueRoom(@NotNull QueueRoom queueRoom); + /** + * @return {@link List} of queue rooms that match the given + * {@link org.openmrs.module.queue.api.search.QueueRoomSearchCriteria} + */ + @Authorized({ PrivilegeConstants.GET_QUEUE_ROOMS }) List getQueueRooms(QueueRoomSearchCriteria searchCriteria); + /** + * Voids a queue room + * + * @param queueRoom the queue room to retire + * @param voidReason the reason for voiding the queue room + */ + @Authorized({ PrivilegeConstants.MANAGE_QUEUE_ROOMS }) void retireQueueRoom(@NotNull QueueRoom queueRoom, String voidReason); + /** + * Completely remove a queue room from the database + * + * @param queueRoom queue room to be deleted + * @throws org.openmrs.api.APIException + */ + @Authorized({ PrivilegeConstants.PURGE_QUEUE_ROOMS }) void purgeQueueRoom(@NotNull QueueRoom queueRoom) throws APIException; } diff --git a/api/src/main/java/org/openmrs/module/queue/api/RoomProviderMapService.java b/api/src/main/java/org/openmrs/module/queue/api/RoomProviderMapService.java index 7e30a50b..8d0a3f03 100644 --- a/api/src/main/java/org/openmrs/module/queue/api/RoomProviderMapService.java +++ b/api/src/main/java/org/openmrs/module/queue/api/RoomProviderMapService.java @@ -14,24 +14,71 @@ import java.util.List; import java.util.Optional; +import org.openmrs.annotation.Authorized; import org.openmrs.api.APIException; +import org.openmrs.api.OpenmrsService; import org.openmrs.module.queue.api.search.RoomProviderMapSearchCriteria; import org.openmrs.module.queue.model.RoomProviderMap; +import org.openmrs.module.queue.utils.PrivilegeConstants; -public interface RoomProviderMapService { +public interface RoomProviderMapService extends OpenmrsService { + /** + * Gets a room provider map given uuid. + * + * @param uuid uuid of the room provider map to be returned. + * @return {@link org.openmrs.module.queue.model.RoomProviderMap} + */ + @Authorized({ PrivilegeConstants.GET_ROOM_PROVIDER_MAPS }) Optional getRoomProviderMapByUuid(@NotNull String uuid); + /** + * Gets a room provider map by id. + * + * @param id roomProviderMapId - the id of the room provider map to retrieve. + * @return {@link org.openmrs.module.queue.model.RoomProviderMap} + */ + @Authorized({ PrivilegeConstants.GET_ROOM_PROVIDER_MAPS }) Optional getRoomProviderMapById(@NotNull int id); + /** + * Saves a room provider map + * + * @param roomProviderMap the room provider map to be saved + * @return saved {@link org.openmrs.module.queue.model.RoomProviderMap} + */ + @Authorized({ PrivilegeConstants.MANAGE_ROOM_PROVIDER_MAPS }) RoomProviderMap saveRoomProviderMap(@NotNull RoomProviderMap roomProviderMap); + /** + * @return {@link List} of all room provider maps + */ + @Authorized({ PrivilegeConstants.GET_ROOM_PROVIDER_MAPS }) List getAllRoomProviderMaps(); + /** + * @return {@link List} of room provider maps that match the given + * {@link org.openmrs.module.queue.api.search.RoomProviderMapSearchCriteria} + */ + @Authorized({ PrivilegeConstants.GET_ROOM_PROVIDER_MAPS }) List getRoomProviderMaps(RoomProviderMapSearchCriteria searchCriteria); + /** + * Voids a room provider map + * + * @param roomProviderMap the room provider map to retire + * @param voidReason the reason for voiding the room provider map + */ + @Authorized({ PrivilegeConstants.MANAGE_ROOM_PROVIDER_MAPS }) void voidRoomProviderMap(@NotNull RoomProviderMap roomProviderMap, String voidReason); + /** + * Completely remove a room provider map from the database + * + * @param roomProviderMap room provider map to be deleted + * @throws org.openmrs.api.APIException + */ + @Authorized({ PrivilegeConstants.PURGE_ROOM_PROVIDER_MAPS }) void purgeRoomProviderMap(@NotNull RoomProviderMap roomProviderMap) throws APIException; } diff --git a/api/src/main/java/org/openmrs/module/queue/utils/PrivilegeConstants.java b/api/src/main/java/org/openmrs/module/queue/utils/PrivilegeConstants.java index 9ce1d932..f1b19d70 100644 --- a/api/src/main/java/org/openmrs/module/queue/utils/PrivilegeConstants.java +++ b/api/src/main/java/org/openmrs/module/queue/utils/PrivilegeConstants.java @@ -33,6 +33,12 @@ public class PrivilegeConstants { @AddOnStartup(description = "Able to get/view queue entries") public static final String GET_QUEUE_ENTRIES = "Get Queue Entries"; + @AddOnStartup(description = "Able to get/view queue rooms") + public static final String GET_QUEUE_ROOMS = "Get Queue Rooms"; + + @AddOnStartup(description = "Able to get/view room provider maps") + public static final String GET_ROOM_PROVIDER_MAPS = "Get Room Provider Maps"; + // Delete Privilege Constants @AddOnStartup(description = "Able to delete/retire queues") public static final String DELETE_QUEUES = "Delete Queues"; @@ -45,8 +51,18 @@ public class PrivilegeConstants { @AddOnStartup(description = "Able to add/edit/retire queue entries") public static final String MANAGE_QUEUE_ENTRIES = "Manage Queue Entries"; + @AddOnStartup(description = "Able to add/edit/retire queue rooms") + public static final String MANAGE_QUEUE_ROOMS = "Manage Queue Rooms"; + + @AddOnStartup(description = "Able to add/edit/retire room provider maps") + public static final String MANAGE_ROOM_PROVIDER_MAPS = "Manage Room Provider Maps"; + // Purge Privilege Constants public static final String PURGE_QUEUES = "Purge Queues"; public static final String PURGE_QUEUE_ENTRIES = "Purge Queue Entries"; + + public static final String PURGE_QUEUE_ROOMS = "Purge Queue Rooms"; + + public static final String PURGE_ROOM_PROVIDER_MAPS = "Purge Room Provider Maps"; }