Table of Contents

Class PatientService

Namespace
adas_core.Application.Services
Assembly
adas-core.Application.dll

Provides a concrete implementation of the IPatientService interface, encapsulating patient-related service operations.

public class PatientService : IPatientService, IApiRequestService
Inheritance
PatientService
Implements
Inherited Members
Extension Methods

Constructors

PatientService(IPatientRepository, IPatientArchiveRepository, Lazy<IObservationService>, Lazy<ITreatmentService>, IPoCMappingService, IDiagnosisService, IAppointmentService, Lazy<IPumpService>, IRecordingAlertService, IDischargeService, IOptions<ApiSettings>, IOptions<ListSettings>, ILogger<PatientService>, IClientMessageService, ISubscribersService, ISubscriberGroupedService, IUnitService, IDisplayService, IPointOfCareService, Lazy<IAdmissionService>, IDisplayConfigService, IGroupedObservationService, IPatientCarePlanService, IHttpContextAccessor, ILocalAuditService, IMasterListServiceFactory)

public PatientService(IPatientRepository patientRepository, IPatientArchiveRepository patientArchiveRepository, Lazy<IObservationService> observationService, Lazy<ITreatmentService> treatmentService, IPoCMappingService pocMappingService, IDiagnosisService diagnosisService, IAppointmentService appointmentService, Lazy<IPumpService> pumpService, IRecordingAlertService recordingAlertService, IDischargeService dischargeService, IOptions<ApiSettings> apiSettings, IOptions<ListSettings> listSettings, ILogger<PatientService> logger, IClientMessageService clientMessageService, ISubscribersService subscribersService, ISubscriberGroupedService subscriberGroupedService, IUnitService unitService, IDisplayService displayService, IPointOfCareService pointOfCareService, Lazy<IAdmissionService> admissionService, IDisplayConfigService displayConfigService, IGroupedObservationService groupedObservationService, IPatientCarePlanService patientCarePlanService, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService, IMasterListServiceFactory masterListServiceFactory)

Parameters

patientRepository IPatientRepository
patientArchiveRepository IPatientArchiveRepository
observationService Lazy<IObservationService>
treatmentService Lazy<ITreatmentService>
pocMappingService IPoCMappingService
diagnosisService IDiagnosisService
appointmentService IAppointmentService
pumpService Lazy<IPumpService>
recordingAlertService IRecordingAlertService
dischargeService IDischargeService
apiSettings IOptions<ApiSettings>
listSettings IOptions<ListSettings>
logger ILogger<PatientService>
clientMessageService IClientMessageService
subscribersService ISubscribersService
subscriberGroupedService ISubscriberGroupedService
unitService IUnitService
displayService IDisplayService
pointOfCareService IPointOfCareService
admissionService Lazy<IAdmissionService>
displayConfigService IDisplayConfigService
groupedObservationService IGroupedObservationService
patientCarePlanService IPatientCarePlanService
httpContextAccessor IHttpContextAccessor
auditService ILocalAuditService
masterListServiceFactory IMasterListServiceFactory

Methods

ArchiveDischargedPatients(int)

Archives discharged patients whose discharge time is older than the specified number of hours. Only patients with a non-null DisTime earlier than the calculated cutoff date are processed, and any error encountered during archiving is logged rather than propagated.

public Task ArchiveDischargedPatients(int hoursBeforeArchive)

Parameters

hoursBeforeArchive int

The number of hours that must elapse after a patient's discharge time before they are eligible for archiving.

Returns

Task

ArchiveNotUpdatedPatientsInInactivePoCSince(int)

method ArchiveNotUpdatedPatientsSince archive all patients who have not updated since in hoursBeforeArchive .

public Task ArchiveNotUpdatedPatientsInInactivePoCSince(int hoursBeforeArchive)

Parameters

hoursBeforeArchive int

Returns

Task

ArchivePatient(Patient)

Archives a patient according to the configured PatientService.OnArchiveAction: either inserts the patient into the archive repository (with the current UTC time as the archive date) or simply performs no archival step. The patient record is then deleted, an audit log entry is created, associated patient data is archived, and if the patient was assigned to a point of care, a delete broadcast is sent and that point of care is set to Available.

public Task ArchivePatient(Patient patient)

Parameters

patient Patient

The patient to archive. If its DisTime is null, it is set to the current UTC time before further processing.

Returns

Task

ArchivePatientData(ObjectId)

Archives or deletes all data associated with a patient based on the configured OnArchiveAction. When the action is set to Archive (the default), patient observations, treatments, diagnoses, appointments, pumps, recording alerts, and care plans are archived; when set to Delete, observations, treatments, diagnoses, appointments, pumps, and recording alerts are deleted (care plan archival is not performed in this case).

public Task ArchivePatientData(ObjectId patientid)

Parameters

patientid ObjectId

The MongoDB.Bson.ObjectId of the patient whose related data should be archived or deleted.

Returns

Task

ArchivePatientWithoutObservationsSinceDate(DateTime)

Archives patients who have not had observations recorded since the specified date, combining observation and pump service data to determine the last activity per patient, and also includes inactive PoC patients with no recent observations. Patients found in the patient collection are archived individually, while patients not found have their orphan observation data archived instead. Errors encountered while archiving individual patients or their data are logged, and any unexpected failure causes the original exception to be rethrown after logging.

public Task ArchivePatientWithoutObservationsSinceDate(DateTime date)

Parameters

date DateTime

The cutoff date; patients with no observations updated after this date will be archived.

Returns

Task

CountPatientsByUnitId(ObjectId)

Asynchronously retrieves the total number of patients associated with the specified unit identifier by delegating to the patient repository.

public Task<long> CountPatientsByUnitId(ObjectId unitId)

Parameters

unitId ObjectId

The MongoDB.Bson.ObjectId of the unit whose patients should be counted.

Returns

Task<long>

A Task<TResult> that resolves to the number of patients linked to the given unit.

CreatePatientFromRequest(ApiRequest, bool)

Creates a new patient from the provided API request, populates its fields, persists it to the repository, and records an audit log entry.

public Task<Patient?> CreatePatientFromRequest(ApiRequest apiRequest, bool ignoreLocation = false)

Parameters

apiRequest ApiRequest

The API request containing the data used to initialize the new patient.

ignoreLocation bool

When true, location information from the request is ignored during the patient update.

Returns

Task<Patient>

The newly created patient.

DeletePatientMasterListItem(OptionList, IEnumerable<Unit>, string)

Deletes a master list option from the records of all patients associated with the specified units, broadcasts the update, and removes the option from any related manual observations.

public Task DeletePatientMasterListItem(OptionList opt, IEnumerable<Unit> unitList, string typeName)

Parameters

opt OptionList

The master list option to be removed from patient records.

unitList IEnumerable<Unit>

The collection of units whose associated patients will be updated.

typeName string

The name of the master list type from which the option is being deleted.

Returns

Task

DischargeInactivePatients(DateTime, int)

Performs the discharge workflow for inactive patients by archiving discharged patients, patients not updated while in an inactive point of care, and patients without observations since the specified date. Manages a global flag indicating that the inactive patient check is in progress for the duration of the operation and logs any errors encountered.

public Task DischargeInactivePatients(DateTime sinceDate, int hoursBeforeArchive)

Parameters

sinceDate DateTime

The cutoff date used to archive patients who have not had any observations since this time.

hoursBeforeArchive int

The number of hours of inactivity used to determine which discharged and inactive point-of-care patients should be archived.

Returns

Task

ExitPatientById(ObjectId, bool)

Delete discharge and archive patient by id.

public Task ExitPatientById(ObjectId id, bool archivePatient = true)

Parameters

id ObjectId
archivePatient bool

Returns

Task

FindAll(bool)

Retrieves all patients, optionally enriching each patient with location details (bed, room, and unit name) resolved from the associated point of care and unit records.

public Task<List<Patient>> FindAll(bool withLocation = false)

Parameters

withLocation bool

When true, populates each patient's Bed, Room, and UnitString by looking up the related point of care and unit; when false, returns the patients without performing those lookups.

Returns

Task<List<Patient>>

A task containing the list of patients, with location fields populated when withLocation is true and the corresponding identifiers are present.

FindAllPatientWithFinishedProcedures(int)

Asynchronously retrieves all patients whose procedures have finished, using the specified time threshold to determine which finished procedures are eligible for archival.

public Task<List<Patient>> FindAllPatientWithFinishedProcedures(int archiveProcedureEndDateAfterMinutes)

Parameters

archiveProcedureEndDateAfterMinutes int

The minimum age, in minutes, of a finished procedure's end date used as the cutoff for including patients in the result.

Returns

Task<List<Patient>>

A task that represents the asynchronous operation, containing a list of Patient instances associated with finished procedures matching the specified threshold.

FindAllPatientWithFinishedTest(int)

Asynchronously retrieves all patients whose tests have finished, filtering based on the archive test end date threshold.

public Task<List<Patient>> FindAllPatientWithFinishedTest(int archiveTestEndDateAfterMinutes)

Parameters

archiveTestEndDateAfterMinutes int

The number of minutes after the archive test end date used to determine which finished tests to include.

Returns

Task<List<Patient>>

A task that represents the asynchronous operation, containing a list of patients with finished tests.

FindAllPatientWithFinishedTreatment(int)

Retrieves all patients whose treatments have finished, where the treatment ended more than the specified number of minutes ago, typically for archiving purposes.

public Task<List<Patient>> FindAllPatientWithFinishedTreatment(int archiveTreatmentEndDateAfterMinutes)

Parameters

archiveTreatmentEndDateAfterMinutes int

The minimum number of minutes that must have elapsed since the treatment end date for a patient to be included in the result.

Returns

Task<List<Patient>>

A task representing the asynchronous operation, containing a list of patients with finished treatments matching the archive criteria.

FindById(ObjectId, bool)

Retrieves a patient by their unique identifier, optionally enriching the result with location details (point of care, bed, room, and unit) when available. Returns null if the identifier is empty or the patient cannot be found.

public Task<Patient?> FindById(ObjectId id, bool withLocation = false)

Parameters

id ObjectId

The unique identifier of the patient to retrieve.

withLocation bool

When true, enriches the patient with location information such as bed, room, and unit name.

Returns

Task<Patient>

A Task<TResult> containing the found patient, or null if no patient matches the identifier or the identifier is empty.

Exceptions

NotFoundException

Thrown when the patient has an associated point of care that cannot be found.

FindByLocation(PatientLocation?)

Retrieves a Patient associated with the specified location by resolving the unit from its name and the point of care from the bed identifier within that unit. Returns null when the location is null or missing a unit name or bed, when no matching unit exists, or when no matching point of care is found.

public Task<Patient?> FindByLocation(PatientLocation? location)

Parameters

location PatientLocation

The patient location containing the unit name and bed used to locate the patient.

Returns

Task<Patient>

A Patient if one is found for the given location; otherwise, null.

FindByPatientId(string, bool)

Retrieves a patient by their unique patient identifier, optionally enriching the result with location details such as bed, room, and unit information.

public Task<Patient?> FindByPatientId(string patientId, bool withLocation = false)

Parameters

patientId string

The unique identifier of the patient to retrieve.

withLocation bool

When true, additional lookups are performed to populate the patient's bed, room, and unit information; otherwise only the patient record is returned.

Returns

Task<Patient>

The Patient matching the specified identifier, or null if no patient is found.

FindByPatientIdWithLocale(string, LocaleEnum)

Retrieves a patient by identifier and returns a locale-translated version of the patient record. Returns null when the patient cannot be resolved or has no associated unit, and falls back to the untranslated patient when the unit lookup fails.

public Task<Patient?> FindByPatientIdWithLocale(string patientId, LocaleEnum localeEnum)

Parameters

patientId string

The string representation of the patient identifier to parse and look up.

localeEnum LocaleEnum

The locale used to translate the patient data via the master list service.

Returns

Task<Patient>

A task containing the translated patient, the untranslated patient if the unit is not found, or null if the patient has no associated unit.

FindByPatientNumber(string, bool)

Retrieves a patient by their unique patient number, optionally enriching the result with location details such as bed, room, and unit name when the withLocation flag is enabled.

public Task<Patient?> FindByPatientNumber(string patientNumber, bool withLocation = false)

Parameters

patientNumber string

The unique identifier of the patient to look up.

withLocation bool

When set to true, populates the returned patient with bed and room information from the point of care and the unit name from the unit service, provided the patient has associated location identifiers.

Returns

Task<Patient>

A Task<TResult> containing the matching Patient if found; otherwise, null.

FindByPatientNumberArchived(string)

Retrieves an archived patient by their unique patient number from the archive repository. Returns null if no archived patient matches the provided patient number.

public Task<Patient?> FindByPatientNumberArchived(string patientNumber)

Parameters

patientNumber string

The unique patient number used to look up the archived patient.

Returns

Task<Patient>

The archived Patient if found; otherwise, null.

FindByPointOfCare(string)

Asynchronously retrieves the list of patients associated with the specified point of care by delegating to the patient repository.

public Task<List<Patient>> FindByPointOfCare(string pointOfCare)

Parameters

pointOfCare string

The point of care identifier used to filter patients.

Returns

Task<List<Patient>>

A task that represents the asynchronous operation, containing the list of Patient entities matching the specified point of care.

FindByPointOfCareId(ObjectId)

Retrieves a patient by their point of care identifier by delegating the lookup to the patient repository. Returns null when no matching patient is found.

public Task<Patient?> FindByPointOfCareId(ObjectId pocId)

Parameters

pocId ObjectId

The point of care identifier used to locate the patient.

Returns

Task<Patient>

A Patient if one is found with the specified point of care identifier; otherwise, null.

FindByUnitAndPocId(ObjectId, ObjectId)

Asynchronously retrieves a Patient associated with the specified unit and point of care identifier. Returns null if no matching patient is found.

public Task<Patient?> FindByUnitAndPocId(ObjectId unit, ObjectId pointOfCare)

Parameters

unit ObjectId

The identifier of the unit to search by.

pointOfCare ObjectId

The identifier of the point of care to search by.

Returns

Task<Patient>

A Patient if a match is found; otherwise, null.

FindInActivePoC()

Asynchronously retrieves a list of inactive patients of care (PoC) by delegating to the patient repository.

public Task<List<Patient>> FindInActivePoC()

Returns

Task<List<Patient>>

A task representing the asynchronous operation, containing a list of inactive Patient records.

FindInInactivePoC()

Retrieves a list of patients currently in active Point of Care (PoC).

public Task<List<Patient>> FindInInactivePoC()

Returns

Task<List<Patient>>

A task that represents the asynchronous operation, containing the list of patients in active PoC.

FindPatient(string?, string?, PatientLocation?, bool)

Locates a patient by first attempting a lookup using the patient number, then falling back to the patient identifier, and optionally performing a location-based search when explicitly requested or allowed by configuration.

public Task<Patient?> FindPatient(string? patientId, string? patientNumber, PatientLocation? location, bool findPatientByLocation = false)

Parameters

patientId string

The unique patient identifier used as a secondary lookup criterion when the patient number is not provided or yields no result.

patientNumber string

The patient number used as the primary lookup criterion.

location PatientLocation

The patient location used for a location-based lookup; the search only proceeds when both the unit name and the bed are set, and the location is mapped through the POC mapping service before being applied to the resulting patient.

findPatientByLocation bool

When true, allows a location-based lookup even if the corresponding configuration option is disabled.

Returns

Task<Patient>

The matching Patient if found by any of the attempted criteria, or null when no patient can be located.

FindPatientByApiRequest(ApiRequest)

Finds or creates a Patient based on the contents of an ApiRequest, handling ORU-style messages (AlarisPump, ORU_R01, ORU_R42, ORU_R40). Maps the incoming point of care through the mapping service, searches by patient number or location, and may create a new patient, push an existing one, or update an existing patient's location, attending doctor, and personal data according to configuration flags.

public Task<Patient?> FindPatientByApiRequest(ApiRequest apiRequest)

Parameters

apiRequest ApiRequest

The incoming API request containing the patient identifier, location, facility, request type, and optional person/doctor information used to resolve or create the patient.

Returns

Task<Patient>

A Task<TResult> that resolves to the resolved or newly created Patient, or null if the point of care cannot be mapped, the request is not handled, no matching patient is found and creation is disabled, or an error occurs while processing the request.

GenerateNurseCarePlanAndInsert(MasterListType, List<OptionList>?, Patient, User?)

Generates a nurse care plan for the specified patient by comparing the provided options against the patient's existing procedures, tests, or treatments, determines the corresponding CRUD action (Create, Update, Delete, or Archive), and persists the resulting patient care plan record(s).

public Task GenerateNurseCarePlanAndInsert(MasterListType carePlanType, List<OptionList>? options, Patient patient, User? user)

Parameters

carePlanType MasterListType

The type of care plan to process, selecting between procedures, tests, or treatments.

options List<OptionList>

The list of options to evaluate against the patient's current items; may be null.

patient Patient

The patient whose care plan is being generated.

user User

The user performing the action; may be null.

Returns

Task

GetBox(PointOfCare, bool, List<string>?)

Retrieves a Box populated with information for the given point of care, including the associated patient when one exists, and optionally the patient's most recent observations.

public Task<Box?> GetBox(PointOfCare poc, bool observations = false, List<string>? filterObservations = null)

Parameters

poc PointOfCare

The point of care used to locate the associated patient and to populate the box unit and bed.

observations bool

When true, the most recent observations for the patient are loaded and mapped by name; when false, only patient data is returned.

filterObservations List<string>

Optional list of observation names used to restrict which observations are retrieved; applies only when observations is true.

Returns

Task<Box>

A Task<TResult> containing the populated box. The HasPatient flag is set to false if no patient is found for the point of care, and the box's Observations are populated only when requested.

GetByPointOfCare(PointOfCare, bool, List<string>?)

Asynchronously retrieves the patient associated with the specified point of care, returning null if an error occurs during the lookup.

public Task<Patient?> GetByPointOfCare(PointOfCare item, bool observations = false, List<string>? filterObservations = null)

Parameters

item PointOfCare

The point of care used to locate the associated patient.

observations bool

Indicates whether related observations should be included in the result.

filterObservations List<string>

Optional list of observation identifiers used to filter observations when they are included.

Returns

Task<Patient>

A task that resolves to the matching Patient, or null if the lookup fails.

GetByPointOfCareAndLocale(PointOfCare, Unit?, LocaleEnum?)

Retrieves a patient associated with the specified point of care, optionally returning a locale-translated version when both unit and locale are provided.

public Task<Patient?> GetByPointOfCareAndLocale(PointOfCare item, Unit? unit, LocaleEnum? localeEnum)

Parameters

item PointOfCare

The point of care used to look up the patient.

unit Unit

The unit used to determine the translation; when null, the patient is returned without translation.

localeEnum LocaleEnum?

The target locale for translation; when null, the patient is returned without translation.

Returns

Task<Patient>

The matching Patient, or null if the patient is not found or an error occurs.

GetManualObservationName(string)

Retrieves the manual observation name associated with a given master list name by looking up the corresponding property in the ListSettings class via reflection and returning its ManualObservationName. Returns a localized error message string when the property is not found or when the resolved value is not a ListSettingItem.

public string GetManualObservationName(string masterListNameString)

Parameters

masterListNameString string

The name of the property in ListSettings whose associated manual observation name should be returned. Must match the property name exactly.

Returns

string

The ManualObservationName of the resolved ListSettingItem, or a descriptive error string if the property is not found or the property value is not a ListSettingItem.

GetPaginatedPatients(PaginationFilter)

Retrieves a paginated list of patients based on the specified filter, returning both the page data and the total document count.

public Task<PaginationResponse<Patient>> GetPaginatedPatients(PaginationFilter filter)

Parameters

filter PaginationFilter

The pagination filter containing the page number and page size used to calculate the skip and limit for the query.

Returns

Task<PaginationResponse<Patient>>

A task that represents the asynchronous operation. The task result contains a PaginationResponse<T> with the patients for the requested page, along with the total count and pagination metadata.

Insert(Patient)

Inserts a new patient into the repository after validating it. If the patient fails validation, the method returns without performing the insertion. After a successful insert, a new patient broadcast notification is dispatched asynchronously.

public Task Insert(Patient patient)

Parameters

patient Patient

The patient entity to be inserted into the repository.

Returns

Task

InsertAsync(Patient)

Asynchronously inserts a new patient into the system after validating it. If the patient fails validation, the method returns without performing the insert. On a successful insert, an audit log is created and a broadcast is dispatched to notify other components.

public Task InsertAsync(Patient patient)

Parameters

patient Patient

The patient entity to be inserted into the system.

Returns

Task

MergePatient(Patient, string)

Merges the data of an existing patient identified by oldPatientNumber into the provided patient, reassigning related records across multiple services and removing the old patient record. If the old patient is not found, the operation is skipped with a debug log; if the old patient has a point of care, the target patient is updated from the merge, a delete broadcast is sent, and the next admission for the old point of care is checked.

public Task MergePatient(Patient patient, string oldPatientNumber)

Parameters

patient Patient

The target patient that will absorb the old patient's data.

oldPatientNumber string

The patient number of the patient to be merged into patient.

Returns

Task

A task representing the asynchronous merge operation.

Move(Patient, ObjectId, ObjectId)

Moves a patient from one point of care to another, transferring the patient location data, updating the point of care statuses, and notifying any associated discharge record and subscribers.

public Task<bool> Move(Patient patient, ObjectId newPocId, ObjectId oldPocId)

Parameters

patient Patient

The patient to be moved to the new point of care.

newPocId ObjectId

The identifier of the destination point of care.

oldPocId ObjectId

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

Returns

Task<bool>

A task that resolves to true when the patient is successfully moved; otherwise, false if the new point of care is null, the old point of care is null, or the new point of care is already in use or locked.

SaveRequest(ApiRequest)

Processes an inbound API request, mapping locations, resolving the unit configuration, and applying the appropriate patient ADT (admit, discharge, transfer) workflow based on the request type. Handles patient admit, transfer, discharge, registration, update, cancellation, recovery, merge, identifier list, and patient number change events, as well as ICCA synchronization, delegating to patient, observation, diagnosis, and appointment services as needed.

public Task SaveRequest(ApiRequest apiRequest)

Parameters

apiRequest ApiRequest

The API request containing the ADT type, patient identifiers, locations, and related clinical data to be processed.

Returns

Task

Exceptions

ApiRequestException

Thrown when both the patient number and location unit name are missing for non-ICCA requests, or when the request type is not a valid patient ADT type.

SaveRequestAsync(ApiRequest)

Asynchronously saves the specified API request by delegating the operation to a background task.

public Task SaveRequestAsync(ApiRequest apiRequest)

Parameters

apiRequest ApiRequest

The API request to be saved.

Returns

Task

A Task that represents the asynchronous save operation.

SearchByPatientNumberAndDistinctUnit(string, ObjectId)

Searches for a patient by their patient number within a specific unit, ensuring the patient belongs to a different unit (distinct).

public Task<Patient?> SearchByPatientNumberAndDistinctUnit(string patientNumber, ObjectId unitId)

Parameters

patientNumber string

The patient number to search for.

unitId ObjectId

The identifier of the unit used to find a patient that is distinct from it.

Returns

Task<Patient>

A task containing the found Patient, or null if no matching patient is found.

SendNewPatientBroadcast(Patient)

Broadcasts a new patient notification to all subscribers whose registered locations include the patient's point of care.

public Task SendNewPatientBroadcast(Patient patient)

Parameters

patient Patient

The patient whose arrival should be broadcast to matching subscribers.

Returns

Task

A completed task once the broadcast has been dispatched.

SendPatientLocationBroadcast(object, PatientLocation, List<ObjectId>?)

Broadcasts a patient location update to all subscribers whose registered location identifiers intersect with the specified list. Returns immediately without broadcasting when the provided location identifiers are null or empty.

public Task SendPatientLocationBroadcast(object patient, PatientLocation location, List<ObjectId>? pocs)

Parameters

patient object

The patient associated with the location update.

location PatientLocation

The patient location information to broadcast.

pocs List<ObjectId>

The list of point-of-care location identifiers used to filter eligible subscribers. If null or empty, no broadcast is performed.

Returns

Task

SendPatientUpdateBroadcast(Patient)

Broadcasts a patient update to all WebSocket subscribers associated with the patient's point of care location, grouping subscribers by locale and dispatching a translated payload per subscriber. If the patient has no point of care id, the update is skipped and an error is logged.

public Task SendPatientUpdateBroadcast(Patient patient)

Parameters

patient Patient

The patient whose update will be broadcast; its point of care id is used to filter subscribers and its unit is used to resolve translations.

Returns

Task

Update(Patient)

Updates a patient record in the repository, handling special cases such as resolving duplicated "Sin cama" bed assignments from ICCADB by generating a unique bed identifier, and assigning a patient number when missing. Also creates an audit log comparing the previous and updated patient and asynchronously broadcasts the update.

public Task Update(Patient patient)

Parameters

patient Patient

The patient entity to update.

Returns

Task

UpdateAttendingDoctor(ObjectId, Person)

Updates the attending doctor for an existing patient, records the change in an audit log, and triggers a broadcast notification about the new attending doctor.

public Task UpdateAttendingDoctor(ObjectId id, Person doctor)

Parameters

id ObjectId

The unique identifier of the patient whose attending doctor is being updated.

doctor Person

The new attending doctor to assign to the patient.

Returns

Task

Exceptions

ConflictException

Thrown when the patient cannot be found by id before or after the update operation.

UpdateLocation(ObjectId, PatientLocation?)

Updates the location of a patient identified by id, moving them to the specified location. Validates the input, resolves the target unit and point of care, updates the patient record, creates an audit log, and broadcasts the location change to subscribers. When the previous point of care is flagged as recovered, the discharge time is cleared and a new patient broadcast is sent instead of a standard location broadcast. If any required entity (patient, old point of care, new unit, or new point of care) is not found, the update is aborted and logged.

public Task UpdateLocation(ObjectId id, PatientLocation? location)

Parameters

id ObjectId

The identifier of the patient whose location will be updated.

location PatientLocation

The new patient location, or null to abort the update.

Returns

Task

UpdateOne(Patient)

Updates an existing patient record in the repository and creates an audit log capturing both the previous and updated states.

public Task<Patient?> UpdateOne(Patient updatedPatient)

Parameters

updatedPatient Patient

The patient object containing the updated information, identified by its Id.

Returns

Task<Patient>

The updated patient, or null if no matching patient was found or the update did not produce a result.

UpdatePatientAltable(ObjectId, OptionList, User?)

Updates the altable option of a patient, creating or removing the related discharge record when the altable type changes to or from "NotAltable".

public Task<Patient?> UpdatePatientAltable(ObjectId patientId, OptionList altable, User? user)

Parameters

patientId ObjectId

The identifier of the patient whose altable option will be updated.

altable OptionList

The new altable option to assign to the patient.

user User

The user performing the operation, used to attribute the generated nurse observation.

Returns

Task<Patient>

The updated Patient, or null if no patient was found with the specified id.

UpdatePatientData(ObjectId, string, Patient, bool)

Updates the patient data identified by the given id, including an audit log entry capturing the change, and broadcasts the update to subscribers. If the supplied patient has no associated person, only the broadcast is triggered and no repository update is performed.

public Task UpdatePatientData(ObjectId id, string patientNumber, Patient patient, bool updatePatientNumber = true)

Parameters

id ObjectId

The ObjectId of the patient to update.

patientNumber string

The patient number associated with the patient.

patient Patient

The patient entity containing the updated data.

updatePatientNumber bool

Indicates whether the patient number should be updated as part of the operation.

Returns

Task

Exceptions

ConflictException

Thrown when the patient cannot be found before or after the update operation.

UpdatePatientData(ObjectId, string, Person, bool)

Updates the data of an existing patient identified by id, optionally updating the patient number when updatePatientNumber is true. Throws a conflict exception if the patient cannot be found before or after the update, records the change through the audit service, and asynchronously broadcasts the updated patient data.

public Task UpdatePatientData(ObjectId id, string patientNumber, Person data, bool updatePatientNumber = true)

Parameters

id ObjectId

The unique identifier of the patient to update.

patientNumber string

The patient number associated with the patient.

data Person

The new Person data to apply to the patient.

updatePatientNumber bool

When true, the patient number is also updated; otherwise only the personal data is changed.

Returns

Task

Exceptions

ConflictException

Thrown when the patient cannot be found by id either before or after the update operation.

UpdatePatientDemographicData(ObjectId, Patient, User?)

Updates the demographic data of an existing patient, synchronizes the associated allergy, language barrier, and diagnosis master lists, records an audit log entry, and broadcasts the update. Throws a conflict exception when the patient cannot be found, and gracefully handles null language barrier, diagnosis, and allergy values.

public Task UpdatePatientDemographicData(ObjectId patientId, Patient person, User? user)

Parameters

patientId ObjectId

The unique identifier of the patient to update.

person Patient

The patient object containing the updated demographic data.

user User

The user performing the update, used for audit logging; may be null.

Returns

Task

Exceptions

ConflictException

Thrown when no patient is found for the specified patient ID.

UpdatePatientFromMerge(Patient, Patient)

Updates a patient by applying values from the latest nurse observations (such as visits, access control, therapeutic ceiling, mobility, passive sitting, language barrier, insulation, doctors, allergies and altable) and by merging any treatments, procedures and tests missing from the incoming patient with those of the previous patient record; then persists the patient, creates an audit log entry, and broadcasts the change.

public Task UpdatePatientFromMerge(Patient patient, Patient oldPatient)

Parameters

patient Patient

The incoming patient to be updated with merged data.

oldPatient Patient

The previous patient record whose missing treatments, procedures and tests are preserved during the merge.

Returns

Task

UpdatePatientIncomingData(ObjectId, Patient)

Updates the incoming data of an existing patient, records an audit log entry for the change, and broadcasts the updated patient information.

public Task UpdatePatientIncomingData(ObjectId patientId, Patient person)

Parameters

patientId ObjectId

The unique identifier of the patient to update.

person Patient

The patient object containing the updated incoming data.

Returns

Task

Exceptions

ConflictException

Thrown when the patient cannot be found by the given identifier, or when the incoming data update operation fails.

UpdatePatientIncomingData(ObjectId, Patient, PatientIncomeData, User)

Updates the patient record with incoming data and persists the income data as a nurse observation associated with the patient and the current user.

public Task UpdatePatientIncomingData(ObjectId patientId, Patient person, PatientIncomeData patientIncomeData, User user)

Parameters

patientId ObjectId

The unique identifier of the patient being updated.

person Patient

The patient entity containing the updated information to apply.

patientIncomeData PatientIncomeData

The patient income information to store as a new observation.

user User

The user performing the operation, recorded as the author of the observation.

Returns

Task

UpdatePatientMasterList(ObjectId, MasterListType, List<OptionList>, User?, List<OptionList>?)

Updates a specific master list section of a patient record based on the provided list type, generating associated nurse care plans or observations where applicable. Returns null if the patient cannot be found or if an exception occurs during the update.

public Task<Patient?> UpdatePatientMasterList(ObjectId patientId, MasterListType typeName, List<OptionList> updatedOptions, User? user, List<OptionList>? carePlanLog)

Parameters

patientId ObjectId

The unique identifier of the patient whose master list will be updated.

typeName MasterListType

The type of master list to update, which determines which patient property is modified and whether care plans or observations are generated.

updatedOptions List<OptionList>

The new list of options to assign to the patient for the specified master list type.

user User

The user performing the update, used for audit purposes and observation generation.

carePlanLog List<OptionList>

An optional list of care plan options used when generating care plans for Treatment, Procedure, and Test list types.

Returns

Task<Patient>

The updated Patient if the operation succeeds; otherwise, null if the patient is not found or an exception is caught.

UpdatePatientMasterListItemChange(UpdateOptionMasterListDto, IEnumerable<Unit>, string)

Updates the master list option for patients associated with the specified units, creates an audit log entry capturing the previous and updated state for each affected patient, and broadcasts the updated patient information.

public Task UpdatePatientMasterListItemChange(UpdateOptionMasterListDto opt, IEnumerable<Unit> unitList, string typeName)

Parameters

opt UpdateOptionMasterListDto

The master list option update data to apply to the patients.

unitList IEnumerable<Unit>

The collection of units whose associated patients will have the master list option updated.

typeName string

The name of the master list type used to identify which option to update.

Returns

Task