Class ConfigObservationService
- Namespace
- adas_core.Application.Services
- Assembly
- adas-core.Application.dll
Provides a concrete implementation of the IConfigObservationService contract for observing configuration state.
public class ConfigObservationService : IConfigObservationService
- Inheritance
-
ConfigObservationService
- Implements
- Inherited Members
- Extension Methods
Remarks
Acts as the default service type that fulfills the configuration observation interface.
Constructors
ConfigObservationService(IConfigObservationRepository, IOptions<ApiSettings>, IOptions<CacheSettings>, ILogger<ConfigObservationService>, IUnitService, IHttpContextAccessor, ILocalAuditService, ICacheService)
public ConfigObservationService(IConfigObservationRepository configObservationRepository, IOptions<ApiSettings> apiSettings, IOptions<CacheSettings> cacheSettings, ILogger<ConfigObservationService> logger, IUnitService unitService, IHttpContextAccessor httpContextAccessor, ILocalAuditService auditService, ICacheService cacheService)
Parameters
configObservationRepositoryIConfigObservationRepositoryapiSettingsIOptions<ApiSettings>cacheSettingsIOptions<CacheSettings>loggerILogger<ConfigObservationService>unitServiceIUnitServicehttpContextAccessorIHttpContextAccessorauditServiceILocalAuditServicecacheServiceICacheService
Methods
CreateConfig(ConfigObservation)
Creates a new configuration observation after verifying that no existing record shares the same identifier.
public Task<ConfigObservation?> CreateConfig(ConfigObservation configObservation)
Parameters
configObservationConfigObservationThe configuration observation entity to persist.
Returns
- Task<ConfigObservation>
The created ConfigObservation if the operation succeeds.
Exceptions
- BadRequestException
Thrown when a configuration observation with the same identifier already exists.
DeleteSingleConfigObservationItem(ConfigObservation)
Deletes a single configuration observation item, invalidating the related cache entries and recording an audit log of the operation. Throws a conflict exception if the item does not exist or the delete operation cannot be completed.
public Task<bool> DeleteSingleConfigObservationItem(ConfigObservation configObservationItem)
Parameters
configObservationItemConfigObservationThe configuration observation item to delete; its identifier is used to locate the existing record.
Returns
Exceptions
- ConflictException
Thrown when no configuration observation is found with the specified identifier, or when the underlying delete operation fails.
Get(string?)
Retrieves a ConfigObservation by its name, returning null when the name is not provided or the configuration is not found.
public Task<ConfigObservation?> Get(string? name)
Parameters
namestringThe name of the configuration to look up; if null or empty, the method returns
null.
Returns
- Task<ConfigObservation>
A ConfigObservation when a matching configuration is found and successfully processed; otherwise,
null.
GetAllCompact()
Retrieves a compact representation of all configuration observations by returning the total item count.
public Task<ConfigObservationDto> GetAllCompact()
Returns
- Task<ConfigObservationDto>
A ConfigObservationDto containing the total number of configuration observations.
GetAllConfigs(CancellationToken)
Retrieves all configuration observations using a cache-aside strategy. If no cached value exists, the data is fetched from the repository and cached using the key and TTL determined by the cache settings.
public Task<ICollection<ConfigObservation>> GetAllConfigs(CancellationToken ct = default)
Parameters
ctCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<ICollection<ConfigObservation>>
A collection of all ConfigObservation entries, sourced from cache when available or from the repository otherwise.
GetByCodeSysAndCode(string?, string?)
Retrieves a ConfigObservation that matches the specified coding system and code, processing it before returning. If no matching observation is found, a warning is logged and null is returned.
public Task<ConfigObservation?> GetByCodeSysAndCode(string? codingSystem, string? code)
Parameters
codingSystemstringThe coding system identifier used to filter the observation. May be null.
codestringThe code value used to filter the observation. May be null.
Returns
- Task<ConfigObservation>
A processed ConfigObservation if a match is found; otherwise, null.
GetConfig(ObjectId)
Retrieves a configuration observation by its identifier, using an in-memory cache with a configurable refresh timeout to reduce repository calls. Returns the cached value when available and not yet expired; otherwise fetches from the repository and caches the result, falling back to a new empty ConfigObservation when the repository does not find a matching record.
public Task<ConfigObservation?> GetConfig(ObjectId configObservationId)
Parameters
configObservationIdObjectIdThe unique identifier of the configuration observation to retrieve.
Returns
- Task<ConfigObservation>
The configuration observation obtained from cache or repository, or a new empty instance when no matching record exists.
GetConfigById(ObjectId)
Retrieves a configuration observation by its unique identifier from the repository. Returns null if no matching configuration observation is found.
public Task<ConfigObservation?> GetConfigById(ObjectId id)
Parameters
idObjectIdThe unique identifier of the configuration observation to retrieve.
Returns
- Task<ConfigObservation>
The configuration observation matching the specified identifier, or null if not found.
GetConfigByName(string)
Retrieves a configuration observation by its name, using a time-limited in-memory cache before falling back to the repository.
Returns null if name is null, empty, or whitespace, or if no matching configuration exists in the cache or repository.
Cache hits require a non-expired NextRefresh and use a case-insensitive name comparison.
public Task<ConfigObservation?> GetConfigByName(string name)
Parameters
namestringThe case-insensitive name of the configuration observation to look up.
Returns
- Task<ConfigObservation>
The matching ConfigObservation, or
nullif not found or the name is invalid.
GetConfigNames()
Retrieves the list of configuration names from the configuration observation repository.
public Task<List<string>> GetConfigNames()
Returns
- Task<List<string>>
A task that represents the asynchronous operation. The task result contains a list of configuration names.
GetConfigNames(string)
Retrieves the list of configuration names associated with the specified identifier by delegating to the configuration observation repository.
public Task<List<string>> GetConfigNames(string id)
Parameters
idstringThe identifier used to look up the related configuration names.
Returns
- Task<List<string>>
A task that represents the asynchronous operation, containing the list of configuration names matching the given identifier.
GetConfigObservationItem(string)
Retrieves configuration observation items matching the specified name. Returns the matching items if any are found; otherwise logs a warning and throws a NotFoundException.
public Task<IEnumerable<ConfigObservation>?> GetConfigObservationItem(string name)
Parameters
namestringThe name used to look up the configuration observation items.
Returns
- Task<IEnumerable<ConfigObservation>>
A collection of ConfigObservation items matching the specified name.
Exceptions
- NotFoundException
Thrown when no configuration observation items are found for the given name.
GetConfigObservationItemsByName(string)
Retrieves configuration observation items that match the specified name.
public Task<IEnumerable<ConfigObservation>> GetConfigObservationItemsByName(string name)
Parameters
namestringThe name used to filter configuration observation items.
Returns
- Task<IEnumerable<ConfigObservation>>
A collection of ConfigObservation items matching the specified name.
GetPaginatedItems(PaginationFilter)
Retrieves a paginated list of ConfigObservation items from the repository along with the total count, used to build pagination metadata for the response.
public Task<PaginationResponse<ConfigObservation>> GetPaginatedItems(PaginationFilter filter)
Parameters
filterPaginationFilterThe pagination filter containing the requested page number and page size used to retrieve the items and populate the response metadata.
Returns
- Task<PaginationResponse<ConfigObservation>>
A PaginationResponse<T> containing the items for the requested page and the total count of all available items.
GetSingleConfigObservationItem(string?, string?, string?, string?)
Retrieves a single ConfigObservation item that matches the specified code, coding system, name, and original name. Throws a not-found exception when no matching item exists in the repository.
public Task<ConfigObservation?> GetSingleConfigObservationItem(string? code, string? codingSystem, string? name, string? originalName)
Parameters
codestringThe code used to identify the configuration observation item.
codingSystemstringThe coding system associated with the item.
namestringThe name of the configuration observation item.
originalNamestringThe original name of the configuration observation item.
Returns
- Task<ConfigObservation>
The matching ConfigObservation item.
Exceptions
- NotFoundException
Thrown when no matching configuration observation item is found.
Get<T>(T, bool)
Retrieves a ConfigObservation that matches the supplied patient observation, either by name only or by a combination of code, coding system, and parent data fields.
public Task<ConfigObservation?> Get<T>(T obs, bool onlyByName = false) where T : BasePatientObservation
Parameters
obsTThe patient observation whose matching configuration should be resolved.
onlyByNameboolWhen
true, the lookup is restricted to matching by Name only; otherwise matching also considers code, coding system, and parent observation data.
Returns
- Task<ConfigObservation>
A Task<TResult> containing the matched ConfigObservation processed via
Process, ornullif no configuration items are available or no match is found.
Type Parameters
T
GroupedObservationStatus(GroupedField, Result, string, object, double?, double?)
Resolves the status of a grouped patient observation by retrieving the configuration for the given name and mapping the observation through group-specific, result-specific, or default configuration. Returns Ok when no configuration exists for the name or when the mapping does not produce a status.
public Task<StatusEnum.Type> GroupedObservationStatus(GroupedField groupedField, GroupedObservationEnum.Result result, string name, object value, double? min, double? max)
Parameters
groupedFieldGroupedFieldThe grouped field whose
Groupkey is used to look up group-specific configuration.resultGroupedObservationEnum.ResultThe grouped observation result whose name is used to look up result-specific configuration.
namestringThe observation name used to retrieve the configuration.
valueobjectThe observation value included in the mapping.
mindouble?The optional minimum reference value included in the mapping.
maxdouble?The optional maximum reference value included in the mapping.
Returns
- Task<StatusEnum.Type>
A task that resolves to the StatusEnum.Type computed from the mapped observation, or Ok when no applicable configuration or mapping status is found.
Map(PatientTreatment)
Maps a PatientTreatment by resolving the configuration observation for each of its requested give codes. Looks up the configuration by text when both the coding system and identifier are empty, otherwise by coding system and identifier. Returns null when the configuration is unknown and unknown treatments are ignored, or when the resolved configuration has no name; otherwise returns the original treatment.
public Task<PatientTreatment?> Map(PatientTreatment treatment)
Parameters
treatmentPatientTreatmentThe patient treatment whose requested give codes are resolved against the configuration store.
Returns
- Task<PatientTreatment>
The original PatientTreatment if a valid configuration is found, or
nullwhen the treatment should be discarded.
Map<T>(T, bool)
Maps a patient observation to a configured representation by looking up its corresponding configuration
and applying the mapping. When no matching configuration is found, returns null if unknown
observations should be ignored, or the original observation otherwise. If the resolved configuration
has an empty name, the mapping is aborted and null is returned.
public Task<T?> Map<T>(T obs, bool onlyByName = false) where T : BasePatientObservation
Parameters
obsTThe patient observation to be mapped.
onlyByNameboolIf
true, the configuration lookup is performed by name only; otherwise the full lookup is used.
Returns
- Task<T>
The mapped observation, the original observation when unknown observations are allowed, or
nullwhen mapping is ignored or the configuration is invalid.
Type Parameters
T
RemoveConfigItem(ObjectId)
Removes a configuration observation item by its identifier. Returns null when the item does not exist,
otherwise deletes it from the repository and invalidates the cached collection of configuration observations.
public Task<ConfigObservation?> RemoveConfigItem(ObjectId id)
Parameters
idObjectIdThe unique identifier of the configuration observation to remove.
Returns
- Task<ConfigObservation>
The removed ConfigObservation if it was found and deleted; otherwise,
null.
RemoveConfigItem(string)
Removes a configuration item identified by its name, creating an audit log entry prior to deletion and invalidating the related cache. Throws a conflict exception when no configuration item with the specified name is found.
public Task<ConfigObservation?> RemoveConfigItem(string itemName)
Parameters
itemNamestringThe name of the configuration item to remove.
Returns
- Task<ConfigObservation>
The removed ConfigObservation, or
nullif the repository did not return a result.
Exceptions
- ConflictException
Thrown when no configuration item is found with the specified name.
RetentionActions<T>(T)
Determines the retention action to apply for a patient observation by resolving its configured retention policy. Falls back to a "NoDelete" retention policy with no value when the observation has no associated configuration or its retention policy is null.
public Task<ObservatitonRetentionResult?> RetentionActions<T>(T obs) where T : BasePatientObservation
Parameters
obsTThe patient observation for which the retention action is being evaluated.
Returns
- Task<ObservatitonRetentionResult>
A task containing the resolved ObservatitonRetentionResult, or null when no configuration is available.
Type Parameters
TThe patient observation type, constrained to BasePatientObservation.
UpdateConfig(ConfigObservation)
Updates an existing ConfigObservation identified by its id and returns the updated entity. Throws a not found exception when the configuration observation does not exist, invalidates the related cache entries, and records an audit log of the change.
public Task<ConfigObservation?> UpdateConfig(ConfigObservation configObservationItem)
Parameters
configObservationItemConfigObservationThe configuration observation payload containing the identifier of the record to update.
Returns
- Task<ConfigObservation>
The updated ConfigObservation.
Exceptions
- NotFoundException
Thrown when no configuration observation exists for the supplied id.