# Class MedicinesController

Namespace
  adas_core.Controllers

Assembly
  adas-core.dll

    [Route("medicines")]
    public class MedicinesController : ControllerBase

Inheritance
  object
  ControllerBase
  MedicinesController

Inherited Members
  ControllerBase.StatusCode(int)
  ControllerBase.StatusCode(int, object)
  ControllerBase.Content(string)
  ControllerBase.Content(string, string)
  ControllerBase.Content(string, string, Encoding)
  ControllerBase.Content(string, MediaTypeHeaderValue)
  ControllerBase.NoContent()
  ControllerBase.Ok()
  ControllerBase.Ok(object)
  ControllerBase.Redirect(string)
  ControllerBase.RedirectPermanent(string)
  ControllerBase.RedirectPreserveMethod(string)
  ControllerBase.RedirectPermanentPreserveMethod(string)
  ControllerBase.LocalRedirect(string)
  ControllerBase.LocalRedirectPermanent(string)
  ControllerBase.LocalRedirectPreserveMethod(string)
  ControllerBase.LocalRedirectPermanentPreserveMethod(string)
  ControllerBase.RedirectToAction()
  ControllerBase.RedirectToAction(string)
  ControllerBase.RedirectToAction(string, object)
  ControllerBase.RedirectToAction(string, string)
  ControllerBase.RedirectToAction(string, string, object)
  ControllerBase.RedirectToAction(string, string, string)
  ControllerBase.RedirectToAction(string, string, object, string)
  ControllerBase.RedirectToActionPreserveMethod(string, string, object, string)
  ControllerBase.RedirectToActionPermanent(string)
  ControllerBase.RedirectToActionPermanent(string, object)
  ControllerBase.RedirectToActionPermanent(string, string)
  ControllerBase.RedirectToActionPermanent(string, string, string)
  ControllerBase.RedirectToActionPermanent(string, string, object)
  ControllerBase.RedirectToActionPermanent(string, string, object, string)
  ControllerBase.RedirectToActionPermanentPreserveMethod(string, string, object, string)
  ControllerBase.RedirectToRoute(string)
  ControllerBase.RedirectToRoute(object)
  ControllerBase.RedirectToRoute(string, object)
  ControllerBase.RedirectToRoute(string, string)
  ControllerBase.RedirectToRoute(string, object, string)
  ControllerBase.RedirectToRoutePreserveMethod(string, object, string)
  ControllerBase.RedirectToRoutePermanent(string)
  ControllerBase.RedirectToRoutePermanent(object)
  ControllerBase.RedirectToRoutePermanent(string, object)
  ControllerBase.RedirectToRoutePermanent(string, string)
  ControllerBase.RedirectToRoutePermanent(string, object, string)
  ControllerBase.RedirectToRoutePermanentPreserveMethod(string, object, string)
  ControllerBase.RedirectToPage(string)
  ControllerBase.RedirectToPage(string, object)
  ControllerBase.RedirectToPage(string, string)
  ControllerBase.RedirectToPage(string, string, object)
  ControllerBase.RedirectToPage(string, string, string)
  ControllerBase.RedirectToPage(string, string, object, string)
  ControllerBase.RedirectToPagePermanent(string)
  ControllerBase.RedirectToPagePermanent(string, object)
  ControllerBase.RedirectToPagePermanent(string, string)
  ControllerBase.RedirectToPagePermanent(string, string, string)
  ControllerBase.RedirectToPagePermanent(string, string, object, string)
  ControllerBase.RedirectToPagePreserveMethod(string, string, object, string)
  ControllerBase.RedirectToPagePermanentPreserveMethod(string, string, object, string)
  ControllerBase.File(byte[], string)
  ControllerBase.File(byte[], string, bool)
  ControllerBase.File(byte[], string, string)
  ControllerBase.File(byte[], string, string, bool)
  ControllerBase.File(byte[], string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(byte[], string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.File(byte[], string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(byte[], string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.File(Stream, string)
  ControllerBase.File(Stream, string, bool)
  ControllerBase.File(Stream, string, string)
  ControllerBase.File(Stream, string, string, bool)
  ControllerBase.File(Stream, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(Stream, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.File(Stream, string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(Stream, string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.File(string, string)
  ControllerBase.File(string, string, bool)
  ControllerBase.File(string, string, string)
  ControllerBase.File(string, string, string, bool)
  ControllerBase.File(string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.File(string, string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.File(string, string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.PhysicalFile(string, string)
  ControllerBase.PhysicalFile(string, string, bool)
  ControllerBase.PhysicalFile(string, string, string)
  ControllerBase.PhysicalFile(string, string, string, bool)
  ControllerBase.PhysicalFile(string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.PhysicalFile(string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.PhysicalFile(string, string, string, DateTimeOffset?, EntityTagHeaderValue)
  ControllerBase.PhysicalFile(string, string, string, DateTimeOffset?, EntityTagHeaderValue, bool)
  ControllerBase.Unauthorized()
  ControllerBase.Unauthorized(object)
  ControllerBase.NotFound()
  ControllerBase.NotFound(object)
  ControllerBase.BadRequest()
  ControllerBase.BadRequest(object)
  ControllerBase.BadRequest(ModelStateDictionary)
  ControllerBase.UnprocessableEntity()
  ControllerBase.UnprocessableEntity(object)
  ControllerBase.UnprocessableEntity(ModelStateDictionary)
  ControllerBase.Conflict()
  ControllerBase.Conflict(object)
  ControllerBase.Conflict(ModelStateDictionary)
  ControllerBase.Problem(string, string, int?, string, string)
  ControllerBase.ValidationProblem(ValidationProblemDetails)
  ControllerBase.ValidationProblem(ModelStateDictionary)
  ControllerBase.ValidationProblem()
  ControllerBase.ValidationProblem(string, string, int?, string, string, ModelStateDictionary)
  ControllerBase.Created()
  ControllerBase.Created(string, object)
  ControllerBase.Created(Uri, object)
  ControllerBase.CreatedAtAction(string, object)
  ControllerBase.CreatedAtAction(string, object, object)
  ControllerBase.CreatedAtAction(string, string, object, object)
  ControllerBase.CreatedAtRoute(string, object)
  ControllerBase.CreatedAtRoute(object, object)
  ControllerBase.CreatedAtRoute(string, object, object)
  ControllerBase.Accepted()
  ControllerBase.Accepted(object)
  ControllerBase.Accepted(Uri)
  ControllerBase.Accepted(string)
  ControllerBase.Accepted(string, object)
  ControllerBase.Accepted(Uri, object)
  ControllerBase.AcceptedAtAction(string)
  ControllerBase.AcceptedAtAction(string, string)
  ControllerBase.AcceptedAtAction(string, object)
  ControllerBase.AcceptedAtAction(string, string, object)
  ControllerBase.AcceptedAtAction(string, object, object)
  ControllerBase.AcceptedAtAction(string, string, object, object)
  ControllerBase.AcceptedAtRoute(object)
  ControllerBase.AcceptedAtRoute(string)
  ControllerBase.AcceptedAtRoute(string, object)
  ControllerBase.AcceptedAtRoute(object, object)
  ControllerBase.AcceptedAtRoute(string, object, object)
  ControllerBase.Challenge()
  ControllerBase.Challenge(params string[])
  ControllerBase.Challenge(AuthenticationProperties)
  ControllerBase.Challenge(AuthenticationProperties, params string[])
  ControllerBase.Forbid()
  ControllerBase.Forbid(params string[])
  ControllerBase.Forbid(AuthenticationProperties)
  ControllerBase.Forbid(AuthenticationProperties, params string[])
  ControllerBase.SignIn(ClaimsPrincipal)
  ControllerBase.SignIn(ClaimsPrincipal, string)
  ControllerBase.SignIn(ClaimsPrincipal, AuthenticationProperties)
  ControllerBase.SignIn(ClaimsPrincipal, AuthenticationProperties, string)
  ControllerBase.SignOut()
  ControllerBase.SignOut(AuthenticationProperties)
  ControllerBase.SignOut(params string[])
  ControllerBase.SignOut(AuthenticationProperties, params string[])
  ControllerBase.TryUpdateModelAsync<TModel>(TModel)
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string)
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string, IValueProvider)
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string, params Expression<Func<TModel, object>>[])
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string, Func<ModelMetadata, bool>)
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string, IValueProvider, params Expression<Func<TModel, object>>[])
  ControllerBase.TryUpdateModelAsync<TModel>(TModel, string, IValueProvider, Func<ModelMetadata, bool>)
  ControllerBase.TryUpdateModelAsync(object, Type, string)
  ControllerBase.TryUpdateModelAsync(object, Type, string, IValueProvider, Func<ModelMetadata, bool>)
  ControllerBase.TryValidateModel(object)
  ControllerBase.TryValidateModel(object, string)
  ControllerBase.HttpContext
  ControllerBase.Request
  ControllerBase.Response
  ControllerBase.RouteData
  ControllerBase.ModelState
  ControllerBase.ControllerContext
  ControllerBase.MetadataProvider
  ControllerBase.ModelBinderFactory
  ControllerBase.Url
  ControllerBase.ObjectValidator
  ControllerBase.ProblemDetailsFactory
  ControllerBase.User
  ControllerBase.Empty
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## 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.