# Class PatientController

Namespace
  adas_core.Controllers

Assembly
  adas-core.dll

    [Route("persons")]
    [ApiController]
    public class PatientController : ControllerBase

Inheritance
  object
  ControllerBase
  PatientController

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

### PatientController(IPatientService, IObservationService, IAdminPanelService, IUserService, IUnitService)

Initializes a new instance of the PatientController class.

    public PatientController(IPatientService patientService, IObservationService observationService, IAdminPanelService adminPanelService, IUserService userService, IUnitService unitService)

#### Parameters

`patientService` IPatientService

  The service responsible for managing patient-related operations.

`observationService` IObservationService

  The service responsible for managing patient observations.

`adminPanelService` IAdminPanelService

  The service responsible for administrative panel operations on patients.

`userService` IUserService

  The service responsible for user management and authentication.

`unitService` IUnitService

  The service responsible for unit-related operations.

## Methods

### ArchivePatientProcedure(string, List<OptionList>)

Archives a patient procedure by removing it from the patient's procedure list and recording the change in the master list. Validates the caller identity, the format of the patient identifier, and applies a default description of "Deleted" when none is provided.

    [HttpPost("{id}/archived-procedure")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> ArchivePatientProcedure(string id, List<OptionList> options)

#### Parameters

`id` string

  The string representation of the patient identifier whose procedure will be archived.

`options` List<OptionList>

  The list of options describing the procedure to archive; the first entry is used to match the procedure name and to record the change.

#### Returns

Task<IActionResult>

  An IActionResult containing the updated patient data when the operation succeeds.

#### Exceptions

UnauthorizedException

  Thrown when the current user identity name is not available in the HTTP context.

BadRequestException

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

### ArchivePatientTest(string, List<OptionList>)

Archives a patient test by removing it from the patient's test master list and ensuring the test description defaults to "Deleted" when not supplied.

    [HttpPost("{id}/archived-test")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> ArchivePatientTest(string id, List<OptionList> options)

#### Parameters

`id` string

  The unique identifier of the patient whose test is being archived.

`options` List<OptionList>

  The option entries describing the test to archive; the first entry's name identifies the test and its description is set to "Deleted" if null.

#### Returns

Task<IActionResult>

  An IActionResult containing the updated patient record on success.

#### Exceptions

UnauthorizedException

  Thrown when the current user has no identity name associated with the request.

BadRequestException

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

### ArchivePatientTreatment(string, List<OptionList>)

Archives a patient's treatment by removing the specified treatment from the patient's treatment list and updating the master list with the archived information.

    [HttpPost("{id}/archived-treatment")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> ArchivePatientTreatment(string id, List<OptionList> options)

#### Parameters

`id` string

  The unique identifier of the patient whose treatment is being archived.

`options` List<OptionList>

  The list of options containing the treatment details to be archived; the first option's description defaults to "Deleted" if not provided.

#### Returns

Task<IActionResult>

  The updated patient data after the treatment has been archived.

#### Exceptions

UnauthorizedException

  Thrown when the current user's identity name is not available in the HTTP context.

BadRequestException

  Thrown when the provided patient ID is not in a valid ObjectId format.

### DeletePatientById(string)

Deletes (archives) a patient by its identifier, validating the id format and verifying the patient exists before performing the soft delete operation.

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

#### Parameters

`id` string

  The string representation of the patient's ObjectId to be archived.

#### Returns

Task<IActionResult>

  An IActionResult containing the archived patient wrapped in an Ok response.

#### Exceptions

BadRequestException

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

NotFoundException

  Thrown when no patient is found matching the specified id.

### ExitPatientById(string)

Exits (discharges) the patient identified by the provided id. Validates the patient and unit configuration, ensuring manual discharge is enabled before performing the operation.

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

#### Parameters

`id` string

  The string identifier of the patient to discharge; must be a valid ObjectId.

#### Returns

Task<IActionResult>

  An IActionResult that returns HTTP 200 (OK) when the patient is successfully exited.

#### Exceptions

BadRequestException

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

NotFoundException

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

ConflictException

  Thrown when the unit operates in automatic census mode, disallowing manual discharge.

### GetActivePatients()

Retrieves the list of active patients for the PoC (Proof of Concept) workflow. Access is restricted to authorized users with the required role and source display permission.

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

#### Returns

Task<IActionResult>

  An IActionResult containing the collection of active patients returned by the service.

### GetAllPatients()

Retrieves all patient records, requiring the caller's role to include AuthSome and a granted "DisplayId" permission on the "Source" resource.

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

#### Returns

Task<IActionResult>

  An IActionResult containing the full collection of patients retrieved from the patient service.

### GetByPatientNumber(string)

Retrieves a patient record by their unique patient number. Access is restricted to users with the AuthSome role.

    [HttpGet("find-by-patientnumber/{patientNumber}")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    public Task<IActionResult> GetByPatientNumber(string patientNumber)

#### Parameters

`patientNumber` string

  The unique patient number used to look up the patient.

#### Returns

Task<IActionResult>

  An IActionResult containing the patient information returned by the service.

### GetLastObservation(string)

Retrieves the most recent observation for the specified patient. Validates the patient identifier format before delegating to the observation service to fetch the last record.

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

#### Parameters

`patientId` string

  The patient's identifier expected to be a valid ObjectId string.

#### Returns

Task<IActionResult>

  An IActionResult containing the last observation payload on success.

#### Exceptions

BadRequestException

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

### GetPaginatedPatients(PaginationFilter)

Retrieves a paginated list of patients based on the provided filter. Validates that the request is not null before delegating to the patient service.

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

#### Parameters

`request` PaginationFilter

  The pagination filter containing criteria for querying patients.

#### Returns

Task<IActionResult>

  An IActionResult containing the paginated patients when successful.

#### Exceptions

BadRequestException

  Thrown when the `request` is null.

### GetPatientById(string)

Retrieves a patient by its unique identifier, validating the identifier format before delegating to the patient service. Requires the caller to have the appropriate role and source-level display permission.

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

#### Parameters

`id` string

  The patient's identifier expected to be a valid ObjectId string.

#### Returns

Task<IActionResult>

  An IActionResult containing the patient data when found.

#### Exceptions

BadRequestException

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

### GetPatientsBasic()

Retrieves a basic list of all persons associated with registered patients, requiring the `AuthSome` role and the `Source.DisplayId` permission.

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

#### Returns

Task<IActionResult>

  An IActionResult containing an HTTP 200 response with the collection of person records derived from all patients.

### MovePatient(string, string, string)

Moves a patient from an existing point of care to a new one. Validates the identifiers, ensures the patient's unit allows manual moves, and performs the relocation through the patient service.

    [HttpGet("{patientId}/{oldPoc}/new-location/{newPoc}")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> MovePatient(string patientId, string newPoc, string oldPoc)

#### Parameters

`patientId` string

  The unique identifier of the patient to be relocated.

`newPoc` string

  The identifier of the destination point of care.

`oldPoc` string

  The identifier of the source point of care the patient is leaving.

#### Returns

Task<IActionResult>

  An IActionResult containing the result of the move operation when successful.

#### Exceptions

BadRequestException

  Thrown when `patientId`, `newPoc`, or `oldPoc` are not valid identifiers.

NotFoundException

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

ConflictException

  Thrown when the patient's unit is operating in automatic census mode, disallowing manual moves.

ConflictException

  Thrown when the move operation fails to complete successfully.

### PostNewPatient(AdmPanelRequest)

Creates a new patient record based on the provided request, after validating that the patient number is supplied and that no existing patient with the same number is already registered.

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

#### Parameters

`request` AdmPanelRequest

  The administration panel request payload containing the patient details, including the patient number to be used for the new record.

#### Returns

Task<IActionResult>

  An IActionResult containing the newly created patient on success, or a `Conflict` result if a patient with the same number already exists.

#### Exceptions

BadRequestException

  Thrown when `request` does not contain a valid patient number.

### ProcessRequest(PatientDto)

Processes an incoming patient request by constructing an ADT_A01 type API request with a new trace identifier, persisting it, and returning the updated patient record.

    [HttpPost("request")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> ProcessRequest(PatientDto patientDto)

#### Parameters

`patientDto` PatientDto

  The patient data transfer object containing the patient number, location, patient details, message time, and wait result used to build the request.

#### Returns

Task<IActionResult>

  An IActionResult containing the patient record retrieved after the request is saved.

### ProcessRequestApiRequest(ApiRequest)

Processes an incoming API request and persists the associated patient request data.

    [HttpPost("api-request")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> ProcessRequestApiRequest(ApiRequest apiRequest)

#### Parameters

`apiRequest` ApiRequest

  The API request payload received from the request body to be saved.

#### Returns

Task<IActionResult>

  An IActionResult that returns HTTP 200 (OK) when the request is successfully persisted.

### UpdatePatient(string, Patient)

Updates an existing patient record identified by the route parameter. Validates the identifier format before delegating the update to the patient service.

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

#### Parameters

`id` string

  The patient identifier provided in the route, expected to be a valid ObjectId.

`newPatient` Patient

  The updated patient data sent in the request body.

#### Returns

Task<IActionResult>

  An IActionResult containing the updated patient on success.

#### Exceptions

BadRequestException

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

### UpdatePatientAltable(string, OptionList)

Updates the alternate table (altable) configuration for a patient identified by the provided id. Validates the id format as an ObjectId and requires an authenticated user with the appropriate role and permission.

    [HttpPut("{id}/altable")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> UpdatePatientAltable(string id, OptionList altable)

#### Parameters

`id` string

  The string representation of the patient's ObjectId; must be parseable to a valid ObjectId.

`altable` OptionList

  The option list containing the new altable values to apply to the patient.

#### Returns

Task<IActionResult>

  An IActionResult containing the updated patient on success.

#### Exceptions

UnauthorizedException

  Thrown when the current user's identity name is not available in the HTTP context.

BadRequestException

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

### UpdatePatientData(AdmPanelRequest)

Updates an existing patient's data in the admin panel, after verifying the patient exists.

    [HttpPut]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> UpdatePatientData(AdmPanelRequest request)

#### Parameters

`request` AdmPanelRequest

  The admin panel request payload containing the patient information to update, supplied in the request body.

#### Returns

Task<IActionResult>

  An IActionResult containing the result of the updated patient data wrapped in an OkResult.

#### Exceptions

NotFoundException

  Thrown when no patient matching the request can be found.

### UpdatePatientDemographicData(string, Patient)

Updates the demographic data of an existing patient, identified by the provided ID, using the supplied patient payload. Validates that the caller is authenticated and that the patient ID is a valid ObjectId before performing the update.

    [HttpPut("{id}/demographic-data")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> UpdatePatientDemographicData(string id, Patient person)

#### Parameters

`id` string

  The string identifier of the patient whose demographic data will be updated.

`person` Patient

  The patient object containing the updated demographic information to persist.

#### Returns

Task<IActionResult>

  An IActionResult that returns an HTTP 200 OK response when the update succeeds.

#### Exceptions

UnauthorizedException

  Thrown when the current HTTP user identity name is not available.

BadRequestException

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

### UpdatePatientEntryDate(Patient)

Updates the admission (entry) date of an existing patient identified by the supplied patient identifier.

    [HttpPut("entry-date")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> UpdatePatientEntryDate(Patient patient)

#### Parameters

`patient` Patient

  The patient payload containing the identifier of the patient to update and the new `AdmTime` value to apply.

#### Returns

Task<IActionResult>

  An IActionResult containing the updated patient with the new admission date when the operation succeeds.

### UpdatePatientIncomingData(string, Patient)

Updates the incoming data of an existing patient, recording the changed fields for audit purposes. Performs a per-field comparison between the current patient record and the supplied payload, populating a change-tracking object for any differences in origin, diagnosis, admission time, and auxiliary fields.

    [HttpPut("{id}/incoming-data")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> UpdatePatientIncomingData(string id, Patient person)

#### Parameters

`id` string

  The identifier of the patient whose incoming data will be updated; must be a valid ObjectId.

`person` Patient

  The patient payload containing the new incoming data values to apply.

#### Returns

Task<IActionResult>

  An IActionResult representing an HTTP 200 OK response when the update succeeds.

#### Exceptions

UnauthorizedException

  Thrown when the current user identity name is not available in the HTTP context.

BadRequestException

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

### UpdatePatientLocation(AdmPanelRequest)

Updates the patient location based on the provided admin panel request payload. Requires the caller to have the AuthSome role and the appropriate permission for the "Source" resource by DisplayId.

    [HttpPut("location")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public IActionResult UpdatePatientLocation(AdmPanelRequest request)

#### Parameters

`request` AdmPanelRequest

  The admin panel request containing the data needed to update the patient location.

#### Returns

IActionResult

  An IActionResult containing the result of the patient location update operation.

### UpdatePatientMasterList(List<OptionList>, string, string)

Updates the master list of a patient for a specified list type after validating the request, the patient identifier, and the list type, then resolving the calling user.

    [HttpPost("{id}/master-list/{typeName}")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> UpdatePatientMasterList(List<OptionList> options, string typeName, string id)

#### Parameters

`options` List<OptionList>

  The list of options to apply to the patient's master list.

`typeName` string

  The name of the master list type to update; must parse to a valid MasterListType value.

`id` string

  The patient's identifier; must be a valid ObjectId.

#### Returns

Task<IActionResult>

  An IActionResult containing the updated patient on success.

#### Exceptions

UnauthorizedException

  Thrown when the current user has no identity name available.

BadRequestException

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

BadRequestException

  Thrown when `typeName` does not correspond to a valid MasterListType value.

### UpdatePerson(string, Person, string?)

Updates the person data associated with a patient identified by the route id. Validates the id format, ensures the patient's unit exists, and refuses the update when the unit is configured for automatic editing mode.

    [HttpPut("{id}/{patientNumber}/data")]
    [AuthorizeRoles(PermissionEnum.RolesType.AuthSome)]
    [PermissionAuthorize("Source", "DisplayId")]
    public Task<IActionResult> UpdatePerson(string id, Person person, string? patientNumber)

#### Parameters

`id` string

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

`person` Person

  The person payload containing the data to apply to the patient.

`patientNumber` string

  Optional patient number override from the route; when null, the existing patient number is used, falling back to an empty string.

#### Returns

Task<IActionResult>

#### Exceptions

BadRequestException

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

NotFoundException

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

ConflictException

  Thrown when the patient's unit is not configured for manual editing.