Table of Contents

Class PatientController

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

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.