# Interface IPatientRepository

Namespace
  adas_core.Application.Repositories.Interfaces

Assembly
  adas-core.Application.dll

    public interface IPatientRepository : IMongoRepository<Patient>

Inherited Members
  IMongoRepository<Patient>.Collection
  IMongoRepository<Patient>.GetCollectionName()
  IMongoRepository<Patient>.InsertOneAsync(Patient)
  IMongoRepository<Patient>.DeleteAsync(ObjectId)
  IMongoRepository<Patient>.UpdateOneAsync(ObjectId, Patient)

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

## Methods

### CountByUnitId(ObjectId)

Asynchronously retrieves the total count of records associated with the specified unit identifier.

    Task<long> CountByUnitId(ObjectId unitId)

#### Parameters

`unitId` ObjectId

  The identifier of the unit whose associated records should be counted.

#### Returns

Task<long>

  A task that represents the asynchronous operation, containing the total count of matching records.

### Delete(ObjectId)

Deletes the item identified by the specified identifier.

    Task Delete(ObjectId id)

#### Parameters

`id` ObjectId

  The identifier of the item to delete.

#### Returns

Task

### DeleteMasterListOption(List<ObjectId>, OptionList, string)

Deletes the specified master list option and returns the patients affected by its removal.

    Task<IEnumerable<Patient>> DeleteMasterListOption(List<ObjectId> unitIds, OptionList opt, string typeName)

#### Parameters

`unitIds` List<ObjectId>

  The identifiers of the units whose master list option should be deleted.

`opt` OptionList

  The master list option to remove.

`typeName` string

  The name of the master list type to which the option belongs.

#### Returns

Task<IEnumerable<Patient>>

  A task that yields the collection of patients impacted by deleting the master list option.

### FindAll()

Asynchronously retrieves all Patient records.

    Task<List<Patient>> FindAll()

#### Returns

Task<List<Patient>>

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

### FindAllPatientWithFinishedProcedures(int)

Asynchronously retrieves all patients who have completed procedures, filtering by the number of minutes that have elapsed since the procedure end date for archival purposes.

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

#### Parameters

`archiveProcedureEndDateAfterMinutes` int

  The number of minutes after the procedure end date used to determine which finished procedures are eligible for archive retrieval.

#### Returns

Task<List<Patient>>

  A task that represents the asynchronous operation. The task result contains a list of patients with finished procedures matching the archive criteria.

### FindAllPatientWithFinishedTests(int)

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

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

#### Parameters

`archiveTestEndDateAfterMinutes` int

  The number of minutes after which a test is considered finished and eligible for retrieval.

#### 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 treatment has been finished and is eligible for archival based on the specified end date threshold.

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

#### Parameters

`archiveTreatmentEndDateAfterMinutes` int

  The number of minutes after the treatment end date used as the archival threshold.

#### Returns

Task<List<Patient>>

  A task that represents the asynchronous operation, containing a list of patients with finished treatments that meet the archival criteria.

### FindById(ObjectId)

Retrieves a patient by their unique identifier, returning `null` when no matching patient exists.

    Task<Patient?> FindById(ObjectId id)

#### Parameters

`id` ObjectId

  The unique MongoDB.Bson.ObjectId of the patient to look up.

#### 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, or null if no patient is found at that location.

    Task<Patient?> FindByLocation(PatientLocation location)

#### Parameters

`location` PatientLocation

  The location used to look up the patient.

#### Returns

Task<Patient>

  A task that represents the asynchronous operation, containing the Patient if found; otherwise, null.

### FindByPatientId(ObjectId)

Asynchronously retrieves a patient from the data store by their unique identifier.

    Task<Patient?> FindByPatientId(ObjectId patientId)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient to look up.

#### Returns

Task<Patient>

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

### FindByPatientId(string)

Asynchronously retrieves a Patient that matches the specified patient identifier.

    Task<Patient?> FindByPatientId(string patientId)

#### Parameters

`patientId` string

  The unique identifier of the patient to look up.

#### Returns

Task<Patient>

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

### FindByPatientNumber(string)

Asynchronously retrieves a Patient by their unique patient number. Returns `null` when no patient matches the provided identifier.

    Task<Patient?> FindByPatientNumber(string patientNumber)

#### Parameters

`patientNumber` string

  The unique patient number used to look up the patient.

#### Returns

Task<Patient>

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

### FindByPointOfCare(ObjectId)

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

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

#### Parameters

`pointOfCare` ObjectId

  The unique identifier of the point of care used to filter patients.

#### Returns

Task<List<Patient>>

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

### 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 filter patients.

#### Returns

Task<List<Patient>>

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

### FindByPointOfCareId(ObjectId)

Retrieves a patient by their point-of-care identifier, returning `null` when no matching patient is found.

    Task<Patient?> FindByPointOfCareId(ObjectId pointOfCare)

#### Parameters

`pointOfCare` ObjectId

  The unique identifier of the point-of-care location used to look up the patient.

#### Returns

Task<Patient>

  A task that resolves to the matching Patient, or `null` if no patient is associated with the specified point-of-care id.

### FindByUnitAndPocId(ObjectId, ObjectId)

Asynchronously retrieves the patient matching the specified unit and point of care identifier.

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

#### Parameters

`unit` ObjectId

  The identifier of the unit used to locate the patient.

`pointOfCare` ObjectId

  The point of care identifier used together with the unit to locate the patient.

#### Returns

Task<Patient>

  A task that resolves to the Patient associated with the given unit and point of care.

### FindDischargedPatients()

Asynchronously retrieves a list of patients who have been discharged.

    Task<List<Patient>> FindDischargedPatients()

#### Returns

Task<List<Patient>>

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

### FindInActivePoC()

Asynchronously retrieves a list of patients who have an inactive Point of Care (PoC) assignment.

    Task<List<Patient>> FindInActivePoC()

#### Returns

Task<List<Patient>>

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

### FindInInactivePoC()

Asynchronously retrieves a list of patients who are currently marked as inactive points of contact (PoC).

    Task<List<Patient>> FindInInactivePoC()

#### Returns

Task<List<Patient>>

  A task that represents the asynchronous operation. The task result contains a list of inactive PoC patients.

### FindPatientsNotUpdatedSince(DateTime)

Retrieves a list of patients whose records have not been updated since the specified date.

    Task<List<Patient>> FindPatientsNotUpdatedSince(DateTime date)

#### Parameters

`date` DateTime

  The cutoff date; patients last updated before this date will be included in the result.

#### Returns

Task<List<Patient>>

  A task that represents the asynchronous operation. The task result contains a list of Patient objects that have not been updated since the specified date.

### GetPaginatedPatients(PaginationFilter)

Retrieves a paginated, fluent query of patients based on the specified pagination filter.

    IFindFluent<Patient, Patient> GetPaginatedPatients(PaginationFilter filter)

#### Parameters

`filter` PaginationFilter

  The pagination filter that defines page size, page number, and additional criteria applied to the patient query.

#### Returns

IFindFluent<Patient, Patient>

  An MongoDB.Driver.IFindFluent<TDocument, TProjection> representing the paginated patient query that can be further composed before execution.

### GetPatientsByUnitIds(List<ObjectId>, string)

Asynchronously retrieves a list of Patient objects associated with the specified unit identifiers and patient type.

    Task<List<Patient>> GetPatientsByUnitIds(List<ObjectId> unitIds, string typeName)

#### Parameters

`unitIds` List<ObjectId>

  The list of unit identifiers used to filter the patients to be returned.

`typeName` string

  The name of the patient type used to further refine the query results.

#### Returns

Task<List<Patient>>

  A Task<TResult> that represents the asynchronous operation, containing a list of Patient objects matching the provided unit identifiers and type.

### SearchByPatientNumberAndDistinctUnit(string, ObjectId)

Asynchronously searches for a patient by their patient number within a specific unit, ensuring the patient is associated with a distinct unit.

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

#### Parameters

`patientNumber` string

  The unique patient number used to identify the patient.

`unitId` ObjectId

  The identifier of the unit to constrain the search to a distinct unit context.

#### Returns

Task<Patient>

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

### Update(Patient)

Updates the information of an existing patient in the system.

    Task Update(Patient patient)

#### Parameters

`patient` Patient

  The patient entity containing the updated information to be persisted.

#### Returns

Task

### UpdateAttendingDoctor(ObjectId, Person)

Updates the attending doctor for the record identified by the specified id.

    Task UpdateAttendingDoctor(ObjectId id, Person attendingDoctor)

#### Parameters

`id` ObjectId

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

`attendingDoctor` Person

  The person to be set as the new attending doctor.

#### Returns

Task

### UpdateLocation(ObjectId, ObjectId)

Updates the location of the entity identified by the specified identifier.

    Task UpdateLocation(ObjectId id, ObjectId location)

#### Parameters

`id` ObjectId

  The identifier of the entity whose location will be updated.

`location` ObjectId

  The identifier of the new location to associate with the entity.

#### Returns

Task

### UpdateLocation(ObjectId, PatientLocation)

Asynchronously updates the location of a patient identified by the specified identifier.

    Task UpdateLocation(ObjectId id, PatientLocation location)

#### Parameters

`id` ObjectId

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

`location` PatientLocation

  The new patient location data to apply to the existing record.

#### Returns

Task

### UpdateMasterListOption(List<ObjectId>, UpdateOptionMasterListDto, string)

Updates a master list option for the specified units and returns the patients affected by the change.

    Task<List<Patient>> UpdateMasterListOption(List<ObjectId> unitIds, UpdateOptionMasterListDto opt, string typeName)

#### Parameters

`unitIds` List<ObjectId>

  The list of unit identifiers whose patients should be considered for the update.

`opt` UpdateOptionMasterListDto

  The DTO containing the master list option update details.

`typeName` string

  The name of the option type being updated.

#### Returns

Task<List<Patient>>

  A task that resolves to the list of patients impacted by the master list option update.

### UpdateOne(Patient)

Updates an existing patient record and returns the updated patient, or null if the patient was not found.

    Task<Patient?> UpdateOne(Patient updatedPatient)

#### Parameters

`updatedPatient` Patient

  The patient containing the updated information.

#### Returns

Task<Patient>

  A task that represents the asynchronous operation. The task result contains the updated Patient, or null if no matching patient exists.

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

Updates the patient data identified by the specified id, optionally updating the patient number when `updatePatientNumber` is true.

    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 record.

`updatePatientNumber` bool

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

#### Returns

Task

### UpdatePatientDemographicData(ObjectId, Patient)

Updates the demographic data of an existing patient identified by the given identifier.

    Task<Patient?> UpdatePatientDemographicData(ObjectId patientId, Patient person)

#### Parameters

`patientId` ObjectId

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

`person` Patient

  The patient object containing the updated demographic information.

#### Returns

Task<Patient>

  A task that represents the asynchronous operation. The task result contains the updated Patient, or `null` if the patient was not found.

### UpdatePatientIncomingData(ObjectId, Patient)

Updates the incoming data for the specified patient and returns the updated patient record.

    Task<Patient?> UpdatePatientIncomingData(ObjectId patientId, Patient person)

#### Parameters

`patientId` ObjectId

  The unique identifier of the patient whose incoming data should be updated.

`person` Patient

  The patient object containing the incoming data to apply.

#### Returns

Task<Patient>

  A task that represents the asynchronous operation. The task result contains the updated Patient, or `null` if the patient was not found.