Table of Contents

Class MedicinesController

Namespace
adas_core.Controllers
Assembly
adas-core.dll
[Route("medicines")]
public class MedicinesController : ControllerBase
Inheritance
MedicinesController
Inherited Members
Extension Methods

Constructors

MedicinesController(IMedicineService, IAdminPanelService)

public MedicinesController(IMedicineService medicineService, IAdminPanelService adminPanelService)

Parameters

medicineService IMedicineService
adminPanelService IAdminPanelService

Methods

DeleteMedicine(string)

Deletes a medicine by its unique identifier.

[HttpDelete("{id}")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> DeleteMedicine(string id)

Parameters

id string

The unique identifier of the medicine to delete.

Returns

Task<IActionResult>

An IActionResult containing an HTTP 200 OK response upon successful deletion.

GetActiveMedicines(string)

Retrieves the list of active medicines associated with the specified patient. The patient identifier is validated to ensure it is a well-formed ObjectId before querying the medicine service.

[HttpGet("{patientId}")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> GetActiveMedicines(string patientId)

Parameters

patientId string

The identifier of the patient whose active medicines are being requested.

Returns

Task<IActionResult>

An IActionResult containing the active medicines for the patient wrapped in an HTTP 200 response.

Exceptions

BadRequestException

Thrown when patientId is not a valid ObjectId format.

GetAllGroups()

Retrieves all medicine groups from the medicine service and returns them as an HTTP 200 OK response. Access is restricted to users with the required role and permission for the "Source" entity's "DisplayId" action.

[HttpGet("groups")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> GetAllGroups()

Returns

Task<IActionResult>

An IActionResult containing the list of all medicine groups returned by the medicine service.

GetAllMedicines()

Retrieves all active medicines, restricted to users with the required authorization role and source/display permissions.

[HttpGet]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> GetAllMedicines()

Returns

Task<IActionResult>

An IActionResult containing the collection of active medicines returned by the medicine service wrapped in an HTTP 200 OK response.

GetCodes()

Retrieves the list of all medicine codes available in the system.

[HttpGet("codes")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> GetCodes()

Returns

Task<IActionResult>

An IActionResult containing the collection of medicine codes with an HTTP 200 OK response.

GetNames()

Retrieves the list of all medicine names. Requires the user to have the specified role permission and "DisplayId" permission for the "Source" resource.

[HttpGet("names")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> GetNames()

Returns

Task<IActionResult>

An IActionResult containing the collection of medicine names returned by the service.

GetPaginatedMedicines(PaginationFilter)

Retrieves a paginated list of medicines based on the provided pagination filter.

[HttpPost("paginated")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> GetPaginatedMedicines(PaginationFilter request)

Parameters

request PaginationFilter

The pagination filter containing paging criteria used to query the medicines.

Returns

Task<IActionResult>

An IActionResult containing the paginated medicines result on success.

Exceptions

BadRequestException

Thrown when the request is null, indicating missing required parameters.

GetTypes()

Retrieves all available medicine types, requiring authentication with the appropriate role and permission.

[HttpGet("types")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> GetTypes()

Returns

Task<IActionResult>

An IActionResult containing the list of all medicine types if successful.

PostMedicine(Medicine)

Creates and persists a new Medicine entry by delegating the insert operation to the admin panel service.

[HttpPost]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> PostMedicine(Medicine medicine)

Parameters

medicine Medicine

The medicine payload supplied in the request body to be created.

Returns

Task<IActionResult>

An IActionResult containing the newly inserted medicine wrapped in an HTTP 200 OK response.

Exceptions

BadRequestException

Thrown when the provided medicine is null, indicating missing required parameters.

UpdateMedicine(string, Medicine)

Updates an existing medicine record identified by the specified identifier. Validates the identifier format, retrieves the existing record to preserve its identity, and persists the updated medicine data.

[HttpPut("{id}")]
[AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
[PermissionAuthorize("Source", "DisplayId")]
public Task<IActionResult> UpdateMedicine(string id, Medicine medicine)

Parameters

id string

The string representation of the medicine's identifier used to locate the existing record.

medicine Medicine

The medicine payload containing the updated information to apply.

Returns

Task<IActionResult>

An IActionResult containing the updated medicine returned in an Ok response.

Exceptions

BadRequestException

Thrown when the provided id cannot be parsed as a valid ObjectId.