# Class AdmissionController

Namespace
  adas_core.Controllers

Assembly
  adas-core.dll

Provides API endpoints for managing patient admission records in the ADAS system.

    [Route("admissions")]
    [ApiController]
    public class AdmissionController : ControllerBase

Inheritance
  object
  ControllerBase
  AdmissionController

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

### AdmissionController(ILogger<AdmissionController>, IAdmissionService, IPatientService, IUnitService)

Initializes a new instance of the AdmissionController class.

    public AdmissionController(ILogger<AdmissionController> logger, IAdmissionService admissionService, IPatientService patientService, IUnitService unitService)

#### Parameters

`logger` ILogger<AdmissionController>

  The logger instance used to log diagnostic information for the controller.

`admissionService` IAdmissionService

  The service responsible for handling admission-related business logic.

`patientService` IPatientService

  The service responsible for managing patient-related operations.

`unitService` IUnitService

  The service responsible for managing unit-related operations.

#### Exceptions

ArgumentNullException

  Thrown when any of the parameters `logger`, `admissionService`, `patientService`, or `unitService` is `null`.

## Methods

### AdmitNewPatient(Admission)

Admits a new patient by updating the admission record and registering the patient in the specified unit, provided the unit is configured for manual admission.

    [HttpPost("admit/new-patient")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> AdmitNewPatient(Admission admission)

#### Parameters

`admission` Admission

  The admission details, including the target unit identifier and patient health number (NHC), used to update the admission and locate the patient.

#### Returns

Task<IActionResult>

  An IActionResult containing the admitted patient information when the operation succeeds.

#### Exceptions

BadRequestException

  Thrown when the `admission` parameter is null.

NotFoundException

  Thrown when no unit configuration is found for the specified unit identifier.

ConflictException

  Thrown when the target unit operates in automatic census mode, or when the patient cannot be retrieved after the admission is registered.

### AdmitPatient(string)

Admits a patient identified by the admission identifier, ensuring the admission exists, belongs to a unit with manual admit enabled, and that a matching patient record is available.

    [HttpPost("{id}/admission")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> AdmitPatient(string id)

#### Parameters

`id` string

  The string identifier of the admission; must be a valid ObjectId.

#### Returns

Task<IActionResult>

  An IActionResult containing the admitted patient when the operation succeeds.

#### Exceptions

BadRequestException

  Thrown when `id` is not a valid ObjectId format.

NotFoundException

  Thrown when no admission exists for the given id, or when the admission's unit configuration cannot be found.

ConflictException

  Thrown when the unit's configuration has manual admit disabled, or when no patient record matches the admission's patient number.

### CreateNewAdmission(Admission)

Creates a new admission record by validating the input and inserting it via the admission service. Throws a bad request exception if the admission payload is missing or the required NHC identifier is empty.

    [HttpPost]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> CreateNewAdmission(Admission admission)

#### Parameters

`admission` Admission

  The admission data to create, provided in the request body.

#### Returns

Task<IActionResult>

  An IActionResult containing the newly created admission wrapped in an OK response.

#### Exceptions

BadRequestException

  Thrown when `admission` is null or when its NHC field is null or empty.

### DeleteAdmissionById(string)

Deletes an admission record identified by the specified id, after validating the id format and confirming the resource exists.

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

#### Parameters

`id` string

  The string identifier of the admission to delete; expected to be a valid ObjectId.

#### Returns

Task<IActionResult>

  An IActionResult that returns OK when the admission is successfully deleted.

#### Exceptions

BadRequestException

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

NotFoundException

  Thrown when no admission is found for the specified id.

### GetAdmissionbyId(string)

Retrieves an admission by its identifier, validating the ID format and returning the admission record if it exists.

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

#### Parameters

`id` string

  The string identifier of the admission to retrieve.

#### Returns

Task<IActionResult>

  An IActionResult containing the admission details when found.

#### Exceptions

BadRequestException

  Thrown when the provided `id` is not a valid ObjectId format.

NotFoundException

  Thrown when no admission matching the provided `id` is found.

### GetAllAdmissions()

Retrieves all admissions records.

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

#### Returns

Task<IActionResult>

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

### ReturnPatientToAdmission(string)

Returns a patient to the admissions list by processing the patient-to-admission transition for the given patient id. Validates the id format, resolves the patient's unit configuration, and blocks the operation when the unit operates in automatic (non-manual-move) mode.

    [HttpPost("{id}/patient-to-admission")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> ReturnPatientToAdmission(string id)

#### Parameters

`id` string

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

#### Returns

Task<IActionResult>

  An IActionResult representing an HTTP 200 OK response when the patient is successfully returned to admissions.

#### Exceptions

BadRequestException

  Thrown when the provided `id` is not a valid identifier format.

NotFoundException

  Thrown when no unit configuration is found for the patient's unit.

ConflictException

  Thrown when the unit's configuration has manual move disabled, indicating the census is in automatic mode.

### ReturnPatientToAdmission(string, string)

Handles a GET request to return a patient to admission by searching admission records associated with the specified patient number and unit. Validates the unit identifier format before delegating the search to the admission service.

    [HttpGet("{patientNumber}/{unitId}")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> ReturnPatientToAdmission(string patientNumber, string unitId)

#### Parameters

`patientNumber` string

  The unique identifier of the patient to be returned to admission.

`unitId` string

  The identifier of the unit used to scope the admission search; must be a valid ObjectId.

#### Returns

Task<IActionResult>

  An IActionResult containing the matching admission records returned by the service.

#### Exceptions

BadRequestException

  Thrown when `unitId` is not a valid ObjectId format.

### ReturnToAdmissionFromTemporalBed(Admission, string)

Handles the process of returning a patient from a temporal bed back to their admission record. Validates the provided patient identifier format and delegates the transfer operation to the admission service.

    [HttpPost("{id}/temporal-bed")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> ReturnToAdmissionFromTemporalBed(Admission admission, string id)

#### Parameters

`admission` Admission

  The admission data containing the details required to restore the patient to the admissions list.

`id` string

  The string representation of the patient's identifier from the route, expected to be a valid ObjectId.

#### Returns

Task<IActionResult>

  An IActionResult that returns HTTP 200 (OK) when the patient is successfully returned to admissions.

#### Exceptions

BadRequestException

  Thrown when the provided `id` is not in a valid ObjectId format.

### UpdateAdmission(Admission)

Updates an existing admission record using the provided data, after validating the NHC identifier.

    [HttpPut]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> UpdateAdmission(Admission admission)

#### Parameters

`admission` Admission

  The admission entity containing the updated information to persist.

#### Returns

Task<IActionResult>

  An IActionResult indicating the outcome of the update operation.

#### Exceptions

BadRequestException

  Thrown when the admission's NHC is null or empty.