Class DiagnosisService
- Namespace
- adas_core.Application.Services
- Assembly
- adas-core.Application.dll
Provides the implementation of the IDiagnosisService contract, offering diagnosis-related operations as defined by the interface.
public class DiagnosisService : IDiagnosisService, IApiRequestService
- Inheritance
-
DiagnosisService
- Implements
- Inherited Members
- Extension Methods
Constructors
DiagnosisService(Lazy<IPatientService>, IOptions<ApiSettings>, IDiagnosisRepository, IDiagnosisArchiveRepository, ILogger<DiagnosisService>, IClientMessageService, ISubscribersService, Lazy<ICalculatedObservationsService>, IHttpContextAccessor, ILocalAuditService, IUnitService)
public DiagnosisService(Lazy<IPatientService> patientService, IOptions<ApiSettings> apiSettings, IDiagnosisRepository diagnosisRepository, IDiagnosisArchiveRepository diagnosisArchiveRepository, ILogger<DiagnosisService> logger, IClientMessageService clientMessageService, ISubscribersService subscribersService, Lazy<ICalculatedObservationsService> calculatedObservations, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService, IUnitService unitService)
Parameters
patientServiceLazy<IPatientService>apiSettingsIOptions<ApiSettings>diagnosisRepositoryIDiagnosisRepositorydiagnosisArchiveRepositoryIDiagnosisArchiveRepositoryloggerILogger<DiagnosisService>clientMessageServiceIClientMessageServicesubscribersServiceISubscribersServicecalculatedObservationsLazy<ICalculatedObservationsService>httpContextAccessorIHttpContextAccessorauditServiceILocalAuditServiceunitServiceIUnitService
Methods
Archive(Patient)
Archives the specified patient by delegating to the archival routine keyed by the patient's identifier.
public Task Archive(Patient patient)
Parameters
patientPatientThe patient to be archived. Its
Idis used to locate the record to archive.
Returns
ArchiveByPatientId(ObjectId)
Archives all diagnoses associated with the specified patient by copying them to the diagnosis archive repository and then deleting the original records.
public Task ArchiveByPatientId(ObjectId id)
Parameters
idObjectIdThe identifier of the patient whose diagnoses will be archived.
Returns
DeleteByPatientId(ObjectId)
Deletes all diagnoses associated with the specified patient identifier and records an audit log entry capturing the previous state of the records.
public Task DeleteByPatientId(ObjectId id)
Parameters
idObjectIdThe unique identifier of the patient whose diagnoses should be deleted.
Returns
FindByPatientIdAsync(ObjectId)
Asynchronously retrieves all patient diagnosis records associated with the specified patient identifier by delegating to the diagnosis repository.
public Task<IAsyncCursor<PatientDiagnosis>> FindByPatientIdAsync(ObjectId patientId)
Parameters
patientIdObjectIdThe unique identifier of the patient whose diagnosis records are to be retrieved.
Returns
- Task<IAsyncCursor<PatientDiagnosis>>
A task that represents the asynchronous operation, containing an asynchronous cursor over the matching PatientDiagnosis records.
GetByPatient(ObjectId)
Retrieves all diagnoses associated with the specified patient identifier from the diagnosis repository.
public Task<List<PatientDiagnosis>> GetByPatient(ObjectId id)
Parameters
idObjectIdThe unique identifier of the patient whose diagnoses are being requested.
Returns
- Task<List<PatientDiagnosis>>
A task that represents the asynchronous operation, containing a list of PatientDiagnosis records for the given patient.
GetByPatientId(ObjectId)
Asynchronously retrieves the list of patient diagnoses associated with the specified patient identifier by delegating to the diagnosis repository.
public Task<List<PatientDiagnosis>> GetByPatientId(ObjectId patientId)
Parameters
patientIdObjectIdThe unique identifier of the patient whose diagnoses are being retrieved.
Returns
- Task<List<PatientDiagnosis>>
A task that represents the asynchronous operation, containing a list of PatientDiagnosis records for the given patient.
Insert(PatientDiagnosis)
Inserts a patient diagnosis into the repository after mapping it to the underlying data model, and broadcasts the stored record. If the diagnosis cannot be mapped (returns null), the insert and broadcast operations are skipped.
public Task Insert(PatientDiagnosis diagnosis)
Parameters
diagnosisPatientDiagnosisThe patient diagnosis to insert.
Returns
InsertDiagnosis(PatientDiagnosis)
Inserts or updates a patient diagnosis, creating an audit log entry. If a diagnosis already exists for the same patient, code, and coding system, it is updated while preserving its identifier and original timestamp; otherwise a new record is inserted. A broadcast is dispatched asynchronously after a successful insert or update.
public Task InsertDiagnosis(PatientDiagnosis diagnosis)
Parameters
diagnosisPatientDiagnosisThe patient diagnosis to persist.
Returns
ProcessDiagnosis(List<PatientDiagnosis>, Patient, DateTime)
Processes a list of patient diagnoses by associating each entry with the specified patient and message time, then inserting them as diagnosis observations.
public Task ProcessDiagnosis(List<PatientDiagnosis> diagnosis, Patient patient, DateTime messageTime)
Parameters
diagnosisList<PatientDiagnosis>The list of patient diagnoses to be processed and inserted.
patientPatientThe patient whose identifier is assigned to each diagnosis entry.
messageTimeDateTimeThe timestamp assigned to each diagnosis entry during processing.
Returns
ProcessDiagnosisObservation(ApiRequest, Patient)
Processes a diagnosis observation from an API request and persists it as a patient diagnosis. Maps SNOMED-coded observation values to diagnosis properties (description, label, code, state, category, start/end time), falling back to the current date when the observation time is missing, and skipping processing if the observations collection is null.
public Task ProcessDiagnosisObservation(ApiRequest apiRequest, Patient patient)
Parameters
apiRequestApiRequestThe API request containing the observation codes, values, message time, and optional observation time used to build the diagnosis.
patientPatientThe patient associated with the diagnosis, whose identifier is assigned to the new PatientDiagnosis.
Returns
- Task
A task that represents the asynchronous insertion of the resulting PatientDiagnosis.
SaveRequest(ApiRequest)
Asynchronously saves the specified API request by delegating to an overload that accepts a secondary parameter, which is passed as null.
public Task SaveRequest(ApiRequest apiRequest)
Parameters
apiRequestApiRequestThe API request to save.
Returns
- Task
A task that represents the asynchronous save operation.
SaveRequest(ApiRequest, Patient?)
Processes an incoming API request for diagnosis-related observations, resolving the patient from the request when not supplied. Validates that at least one of the patient number or location unit name is provided, handles ORU_R01 and ORU_R40 observation messages, and triggers diagnosis observation processing when the observation code is recognized.
public Task SaveRequest(ApiRequest apiRequest, Patient? patient)
Parameters
apiRequestApiRequestThe API request containing the type, patient identifiers, location, and observation data to be processed.
patientPatientAn optional pre-resolved patient; when null, the patient is resolved via the patient service using the request data.
Returns
Exceptions
- ApiRequestException
Thrown when both the patient number and the location unit name are missing from the request, or when the request type is not valid for diagnosis processing.
SaveRequestAsync(ApiRequest)
Asynchronously saves the specified API request by delegating to the underlying save operation with a null secondary parameter.
public Task SaveRequestAsync(ApiRequest apiRequest)
Parameters
apiRequestApiRequestThe API request instance to persist.
Returns
- Task
A task that represents the asynchronous save operation.
UpdateManyObjectId(string, ObjectId, ObjectId)
Updates many diagnosis records, replacing the oldId with the new id for the specified nameId field, by delegating to the diagnosis repository.
public Task UpdateManyObjectId(string nameId, ObjectId id, ObjectId oldId)
Parameters
nameIdstringThe name of the identifier field used to locate the records to update.
idObjectIdThe new ObjectId to assign to the matching records.
oldIdObjectIdThe existing ObjectId to be replaced in the matching records.