# Interface IPatientService

Namespace
  adas_core.Application.Services.Interfaces

Assembly
  adas-core.Application.dll

    public interface IPatientService : IApiRequestService

Inherited Members
  IApiRequestService.SaveRequestAsync(ApiRequest)
  IApiRequestService.SaveRequest(ApiRequest)

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

## Methods

### ArchiveDischargedPatients(int)

Archives patient records for patients who have been discharged longer than the specified time threshold.

    Task ArchiveDischargedPatients(int hoursBeforeArchive)

#### Parameters

`hoursBeforeArchive` int

  The number of hours a patient must have been discharged before being archived.

#### Returns

Task

### ArchivePatient(Patient)

Archives the specified patient record.

    Task ArchivePatient(Patient patient)

#### Parameters

`patient` Patient

  The patient to archive.

#### Returns

Task

### ArchivePatientData(ObjectId)

Archives the patient data identified by the specified patient identifier.

    Task ArchivePatientData(ObjectId patientid)

#### Parameters

`patientid` ObjectId

  The unique identifier of the patient whose data should be archived.

#### Returns

Task

### ArchivePatientWithoutObservationsSinceDate(DateTime)

Archives patients who have no observations recorded since the specified date.

    Task ArchivePatientWithoutObservationsSinceDate(DateTime date)

#### Parameters

`date` DateTime

  The cutoff date; patients without observations after this date are archived.

#### Returns

Task

### CountPatientsByUnitId(ObjectId)

Asynchronously counts the number of patients associated with the specified unit identifier.

    Task<long> CountPatientsByUnitId(ObjectId unitId)

#### Parameters

`unitId` ObjectId

  The ObjectId of the unit whose patients should be counted.

#### Returns

Task<long>

  A task that represents the asynchronous operation, containing the total count of patients for the given unit.

### CreatePatientFromRequest(ApiRequest, bool)

Creates a Patient instance from the provided ApiRequest, optionally ignoring location information during the creation process.

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

#### Parameters

`apiRequest` ApiRequest

  The API request containing the data used to construct the patient.

`ignoreLocation` bool

  When `true`, location information is ignored during patient creation. Defaults to `false`.

#### Returns

Task<Patient>

  A task that represents the asynchronous operation. The task result contains the created Patient, or `null` if the patient could not be created.

### DeletePatientMasterListItem(OptionList, IEnumerable<Unit>, string)

Deletes a patient master list item based on the specified option, unit list, and type name.

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

#### Parameters

`opt` OptionList

  The option list containing the details of the patient master list item to delete.

`unitList` IEnumerable<Unit>

  The collection of units associated with the patient master list item.

`typeName` string

  The name of the type identifying the patient master list item to be deleted.

#### Returns

Task

### DischargeInactivePatients(DateTime, int)

Discharges patients who have been inactive since the specified date and archives them after the defined retention period.

    Task DischargeInactivePatients(DateTime sinceDate, int hoursBeforeArchive)

#### Parameters

`sinceDate` DateTime

  The date used to identify patients that have been inactive since this point in time.

`hoursBeforeArchive` int

  The number of hours of inactivity that must elapse before a discharged patient is archived.

#### Returns

Task

### ExitPatientById(ObjectId, bool)

Exits a patient identified by the given identifier, optionally archiving the patient record.

    Task ExitPatientById(ObjectId id, bool archivePatient = true)

#### Parameters

`id` ObjectId

  The unique identifier of the patient to exit.

`archivePatient` bool

  When true, the patient record is archived as part of the exit process; when false, archiving is skipped.

#### Returns

Task

### FindAll(bool)

Retrieves all patients, optionally including their location data when requested.

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

#### Parameters

`withLocation` bool

  Indicates whether location information should be included in the returned patient records.

#### Returns

Task<List<Patient>>

  A task that represents the asynchronous operation, containing a list of Patient objects.

### FindAllPatientWithFinishedProcedures(int)

Asynchronously retrieves all patients whose procedures have been finished, filtering based on the specified archive threshold for procedure end times.

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

#### Parameters

`archiveProcedureEndDateAfterMinutes` int

  The number of minutes after the procedure end date used as the archive threshold to qualify patients with finished procedures.

#### Returns

Task<List<Patient>>

  A task that represents the asynchronous operation, containing a list of Patient objects that match the finished procedures criteria.

### FindAllPatientWithFinishedTest(int)

Asynchronously retrieves all patients who have completed a test, using the specified archive window in minutes to determine which tests are considered finished.

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

#### Parameters

`archiveTestEndDateAfterMinutes` int

  The time window in minutes applied to the test end date to identify tests that should be treated as finished/archived.

#### Returns

Task<List<Patient>>

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

### FindAllPatientWithFinishedTreatment(int)

Retrieves a list of patients whose treatments have finished, based on the specified archive time threshold in minutes after the treatment end date.

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

#### Parameters

`archiveTreatmentEndDateAfterMinutes` int

  The number of minutes after the treatment end date used to determine which finished treatments should be included.

#### Returns

Task<List<Patient>>

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

### FindById(ObjectId, bool)

Retrieves a patient by their unique identifier, optionally including location information. Returns `null` when no patient matches the provided identifier.

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

#### Parameters

`id` ObjectId

  The MongoDB.Bson.ObjectId used to look up the patient.

`withLocation` bool

  When `true`, includes the patient's location data in the result; otherwise, location data is omitted.

#### Returns

Task<Patient>

  A Task<TResult> that resolves to the matching Patient, or `null` if no patient is found.

### FindByLocation(PatientLocation?)

Asynchronously retrieves a patient associated with the specified location. Returns null if no matching patient is found or if the location is null.

    Task<Patient?> FindByLocation(PatientLocation? location)

#### Parameters

`location` PatientLocation

  The patient location used to search for a matching patient. May be null.

#### Returns

Task<Patient>

  A Task<TResult> that yields the matching Patient, or null if no patient is found.

### FindByPatientId(string, bool)

Asynchronously retrieves a patient by their unique patient identifier, optionally including location information.

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

#### Parameters

`patientId` string

  The unique identifier of the patient to find.

`withLocation` bool

  When set to `true`, includes location details in the returned patient; otherwise, only basic patient data is returned.

#### Returns

Task<Patient>

  A task that represents the asynchronous operation. The task result contains the found Patient, or `null` if no patient matches the specified identifier.

### FindByPatientIdWithLocale(string, LocaleEnum)

Asynchronously retrieves a patient by their unique identifier, applying the specified locale for localized data.

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

#### Parameters

`patientId` string

  The unique identifier of the patient to locate.

`localeEnum` LocaleEnum

  The locale to use when retrieving or formatting localized patient information.

#### Returns

Task<Patient>

  A task that resolves to the matching patient, or `null` if no patient is found for the given identifier.

### FindByPatientNumber(string, bool)

Retrieves a patient by their unique patient number, optionally including location information in the result.

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

#### Parameters

`patientNumber` string

  The unique patient number used to look up the patient.

`withLocation` bool

  When `true`, location information is included in the returned patient; otherwise, it is omitted.

#### Returns

Task<Patient>

  A task that yields the matching Patient if one is found, or `null` when no patient matches the given number.

### FindByPatientNumberArchived(string)

Asynchronously retrieves an archived Patient matching the specified patient number, returning `null` when no matching archived record is found.

    Task<Patient?> FindByPatientNumberArchived(string patientNumber)

#### Parameters

`patientNumber` string

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

#### Returns

Task<Patient>

  A Task<TResult> that yields the matching archived Patient, or `null` if no archived patient is found.

### FindByPointOfCare(string)

Asynchronously retrieves a list of patients associated with the specified point of care.

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

#### Parameters

`pointOfCare` string

  The point of care identifier used to locate matching patients.

#### Returns

Task<List<Patient>>

  A task that represents the asynchronous operation, containing a list of Patient objects that match the specified point of care.

### FindByPointOfCareId(ObjectId)

Asynchronously retrieves a patient associated with the specified Point of Care identifier.

    Task<Patient?> FindByPointOfCareId(ObjectId pocId)

#### Parameters

`pocId` ObjectId

  The ObjectId representing the Point of Care identifier used to look up the patient.

#### Returns

Task<Patient>

  A task that represents the asynchronous operation. The task result contains the matching Patient if found; otherwise, `null`.

### FindByUnitAndPocId(ObjectId, ObjectId)

Asynchronously retrieves a patient identified by the specified unit and point-of-care identifiers.

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

#### Parameters

`unit` ObjectId

  The unique identifier of the unit to search within.

`pointOfCare` ObjectId

  The unique identifier of the point-of-care associated with the patient.

#### Returns

Task<Patient>

  A task that yields the matching Patient, or `null` if no patient is found for the given unit and point-of-care.

### FindInActivePoC()

Asynchronously retrieves the list of inactive Patients of Care (PoC), allowing consumers to identify patients that are no longer active in the system for reporting, cleanup, or follow-up workflows.

    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 associated with inactive PoC records.

    Task<List<Patient>> FindInInactivePoC()

#### Returns

Task<List<Patient>>

  A task that represents the asynchronous operation. The task result contains a list of Patient objects associated with inactive PoC records.

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

Asynchronously locates a patient using the provided identifiers, supporting lookup by patient ID, patient number, or location when `findByLocation` is enabled.

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

#### Parameters

`patientId` string

  The unique identifier of the patient to find.

`patientNumber` string

  The patient number used as an alternative lookup key.

`location` PatientLocation

  The patient location used when searching by location.

`findByLocation` bool

  When `true`, the search is performed using the supplied `location` instead of the patient identifiers.

#### Returns

Task<Patient>

  A Task<TResult> that yields the matching Patient, or `null` if no patient is found.

### FindPatientByApiRequest(ApiRequest)

Asynchronously finds a patient based on the information provided in the specified API request.

    Task<Patient?> FindPatientByApiRequest(ApiRequest apiRequest)

#### Parameters

`apiRequest` ApiRequest

  The API request containing the data used to look up the patient.

#### Returns

Task<Patient>

  A task that represents the asynchronous operation. The task result contains the matching Patient if found, or null if no patient matches the request.

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

Generates a nurse care plan of the specified type, using the provided options, and inserts it for the patient.

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

#### Parameters

`carePlanType` MasterListType

  The master list type that determines which nurse care plan template to generate.

`options` List<OptionList>

  Optional list of options applied during care plan generation. May be null.

`patient` Patient

  The patient for whom the nurse care plan is generated and inserted.

`user` User

  The user associated with the care plan generation. May be null.

#### Returns

Task

  A task that completes when the nurse care plan has been generated and inserted.

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

Retrieves a Box associated with the specified PointOfCare, returning null when no box is found for the given point of care.

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

#### Parameters

`poc` PointOfCare

  The point of care used to look up the associated box.

`observations` bool

  When true, observations are included with the returned box; otherwise, observations are omitted.

`filterObservations` List<string>

  An optional list of observation identifiers used to restrict which observations are loaded when `observations` is true.

#### Returns

Task<Box>

  A Task<TResult> that resolves to the matching Box, or null if no box exists for the specified point of care.

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

Retrieves a Patient associated with the specified `item` point of care, returning `null` when no matching patient is found. When `observations` is `true`, the result includes the patient's observations, optionally restricted by the identifiers supplied in `filterObservations`.

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

#### Parameters

`item` PointOfCare

  The point of care used to look up the associated patient.

`observations` bool

  Indicates whether the patient's observations should be included in the returned patient.

`filterObservations` List<string>

  An optional list of observation identifiers used to filter which observations are returned when `observations` is `true`.

#### Returns

Task<Patient>

  A Task<TResult> that resolves to the matching Patient, or `null` if no patient is found for the given point of care.

### GetByPointOfCareAndLocale(PointOfCare, Unit?, LocaleEnum?)

Asynchronously retrieves a Patient matching the specified point of care, optionally narrowed by unit and locale.

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

#### Parameters

`item` PointOfCare

  The point of care used to locate the patient.

`unit` Unit

  An optional unit that further filters the lookup.

`localeEnum` LocaleEnum?

  An optional locale used to scope the search.

#### Returns

Task<Patient>

  A task that yields the matching Patient, or `null` when no patient is found.

### GetPaginatedPatients(PaginationFilter)

Retrieves a paginated list of patients based on the provided pagination filter.

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

#### Parameters

`filter` PaginationFilter

  The pagination filter that defines the paging criteria used to retrieve patients.

#### Returns

Task<PaginationResponse<Patient>>

  A task that represents the asynchronous operation. The task result contains a PaginationResponse<T> with the requested page of patients.

### Insert(Patient)

Asynchronously inserts a new patient record into the data store.

    Task Insert(Patient patient)

#### Parameters

`patient` Patient

  The patient entity to be inserted.

#### Returns

Task

### InsertAsync(Patient)

Asynchronously inserts the specified Patient into the data store.

    Task InsertAsync(Patient patient)

#### Parameters

`patient` Patient

  The patient entity to be persisted.

#### Returns

Task

### MergePatient(Patient, string)

Merges the specified patient record with the existing patient identified by the old patient number.

    Task MergePatient(Patient patient, string oldPatienNumber)

#### Parameters

`patient` Patient

  The patient data to merge into the existing record.

`oldPatienNumber` string

  The identifier of the existing patient record to be merged.

#### Returns

Task

### Move(Patient, ObjectId, ObjectId)

Moves the specified patient from the old point of care to the new point of care.

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

#### Parameters

`patient` Patient

  The patient to be moved.

`newPocId` ObjectId

  The identifier of the destination point of care.

`oldPocId` ObjectId

  The identifier of the source point of care.

#### Returns

Task<bool>

  A task that resolves to `true` if the move was successful; otherwise, `false`.

### SearchByPatientNumberAndDistinctUnit(string, ObjectId)

Searches for a patient by their patient number within a distinct unit.

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

#### Parameters

`patientNumber` string

  The patient number used to identify the patient.

`unitId` ObjectId

  The identifier of the distinct unit where the patient is registered.

#### Returns

Task<Patient>

  A task that represents the asynchronous operation. The task result contains the matching Patient if found; otherwise, null.

### SendNewPatientBroadcast(Patient)

Sends an asynchronous broadcast notification to inform relevant subscribers or systems about a newly registered patient.

    Task SendNewPatientBroadcast(Patient patient)

#### Parameters

`patient` Patient

  The patient whose information will be included in the broadcast notification.

#### Returns

Task

### SendPatientUpdateBroadcast(Patient)

Asynchronously sends a broadcast notification about an update to the specified patient.

    Task SendPatientUpdateBroadcast(Patient patient)

#### Parameters

`patient` Patient

  The patient whose update information will be broadcast.

#### Returns

Task

### Update(Patient)

Updates the specified patient record.

    Task Update(Patient patient)

#### Parameters

`patient` Patient

  The patient whose information will be updated.

#### Returns

Task

### UpdateAttendingDoctor(ObjectId, Person)

Updates the attending doctor for the entity identified by the specified identifier.

    Task UpdateAttendingDoctor(ObjectId id, Person doctor)

#### Parameters

`id` ObjectId

  The identifier of the entity whose attending doctor will be updated.

`doctor` Person

  The new attending doctor to assign to the entity.

#### Returns

Task

  A task that represents the asynchronous update operation.

### UpdateLocation(ObjectId, PatientLocation?)

Updates the location of a patient identified by the specified object identifier.

    Task UpdateLocation(ObjectId id, PatientLocation? location)

#### Parameters

`id` ObjectId

  The unique identifier of the patient whose location will be updated.

`location` PatientLocation

  The new patient location, or `null` if no location is provided.

#### Returns

Task

### UpdateOne(Patient)

Updates an existing patient record with the provided patient data. Returns the updated patient, or `null` if no matching patient was found.

    Task<Patient?> UpdateOne(Patient updatedPatient)

#### Parameters

`updatedPatient` Patient

  The patient object containing the updated information to be persisted.

#### Returns

Task<Patient>

  A Task<TResult> that resolves to the updated Patient, or `null` if the patient could not be found.

### UpdatePatientAltable(ObjectId, OptionList, User?)

Updates the altable (allergy table) information for the specified patient and returns the updated patient.

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

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose altable is being updated.

`altable` OptionList

  The option list containing the altable data to apply to the patient.

`user` User

  The user performing the update, or `null` when no user context is available.

#### Returns

Task<Patient>

  A task that resolves to the updated Patient, or `null` if the patient was not found.

### UpdatePatientData(ObjectId, string, Patient, bool)

Updates the patient data for the specified patient identified by `id` and `patientNumber`, applying the changes from the provided `patient` object. When `updatePatientNumber` is `true`, the patient number is also updated as part of the operation; otherwise, only the remaining patient fields are updated.

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

#### Parameters

`id` ObjectId

  The unique identifier of the patient record to update.

`patientNumber` string

  The current patient number used to locate the patient record.

`patient` Patient

  The patient object containing the updated data to be applied.

`updatePatientNumber` bool

  A flag indicating whether the patient number should also be updated; defaults to `true`.

#### Returns

Task

  A Task that represents the asynchronous update operation.

### UpdatePatientData(ObjectId, string, Person, bool)

Updates the data of an existing patient identified by the given identifier, optionally replacing the patient number when the `updatePatientNumber` flag is true.

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

#### Parameters

`id` ObjectId

  The unique identifier of the patient whose data will be updated.

`patientNumber` string

  The patient number to be applied to the patient.

`data` Person

  The person data to assign to the patient.

`updatePatientNumber` bool

  Indicates whether the patient number should also be updated; defaults to true.

#### Returns

Task

### UpdatePatientDemographicData(ObjectId, Patient, User?)

Asynchronously updates the demographic data of an existing patient identified by the specified patient identifier.

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

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose demographic data is to be updated.

`person` Patient

  The patient object containing the new demographic information to apply.

`user` User

  The user performing the update operation, or null if no user context is available.

#### Returns

Task

### UpdatePatientIncomingData(ObjectId, Patient)

Asynchronously updates the incoming data for the specified patient by applying the provided patient information.

    Task UpdatePatientIncomingData(ObjectId patientId, Patient person)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose incoming data is being updated.

`person` Patient

  The patient object containing the incoming data to be applied to the patient record.

#### Returns

Task

### UpdatePatientIncomingData(ObjectId, Patient, PatientIncomeData, User)

Updates the incoming income data of a patient using the specified changes and the user performing the operation.

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

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose income data is being updated.

`person` Patient

  The patient entity associated with the update.

`personDataChange` PatientIncomeData

  The income data changes to apply to the patient.

`user` User

  The user performing the update operation.

#### Returns

Task

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

Updates the specified master list for a patient with the provided options and returns the updated patient record.

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

#### Parameters

`patientId` ObjectId

  The identifier of the patient whose master list is being updated.

`typeName` MasterListType

  The type of master list to update.

`updatedOptions` List<OptionList>

  The new list of options to apply to the master list.

`user` User

  The user performing the update, or null if not specified.

`carePlanLog` List<OptionList>

  Optional care plan log entries associated with the update.

#### Returns

Task<Patient>

  A task that returns the updated Patient, or null if the patient was not found.

### UpdatePatientMasterListItemChange(UpdateOptionMasterListDto, IEnumerable<Unit>, string)

Updates a patient master list item change based on the provided update options, unit list, and type name.

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

#### Parameters

`opt` UpdateOptionMasterListDto

  The update options for the master list item.

`unitList` IEnumerable<Unit>

  The collection of units associated with the update.

`typeName` string

  The name of the type used to categorize the master list item.

#### Returns

Task