Class MasterListServiceFactory
- Namespace
- adas_core.Application.Services
- Assembly
- adas-core.Application.dll
public class MasterListServiceFactory : IMasterListServiceFactory
- Inheritance
-
MasterListServiceFactory
- Implements
- Inherited Members
- Extension Methods
Constructors
MasterListServiceFactory(IServiceProvider, ILogger<MasterListServiceFactory>, IOptions<ListSettings>)
public MasterListServiceFactory(IServiceProvider serviceProvider, ILogger<MasterListServiceFactory> logger, IOptions<ListSettings> listSettings)
Parameters
serviceProviderIServiceProviderloggerILogger<MasterListServiceFactory>listSettingsIOptions<ListSettings>
Methods
GetMasterListById(MasterListType, ObjectId, LocaleEnum?)
Asynchronously retrieves a master list item by its identifier, using reflection to dispatch the call to the appropriate service based on the specified master list type.
public Task<object?> GetMasterListById(MasterListType masterListType, ObjectId masterListId, LocaleEnum? dataLocale)
Parameters
masterListTypeMasterListTypeThe type of master list used to resolve the underlying service that will handle the request.
masterListIdObjectIdThe unique identifier of the master list item to retrieve.
dataLocaleLocaleEnum?An optional locale used to localize the returned data; may be
nullwhen localization is not required.
Returns
- Task<object>
A task that resolves to the retrieved master list item as an object, or
nullwhen the awaited result has no value.
Exceptions
- InvalidOperationException
Thrown when no service is registered for the supplied
masterListType, or when the target service does not expose a compatibleGetMasterListByIdmethod matching the expected parameters.
GetMasterListOptionById(MasterListType, ObjectId, ObjectId, LocaleEnum?)
Retrieves a master list option by its identifier using reflection to dynamically resolve and invoke the appropriate service method based on the specified master list type.
public Task<object?> GetMasterListOptionById(MasterListType masterListType, ObjectId masterListId, ObjectId masterListOptionId, LocaleEnum? dataLocale)
Parameters
masterListTypeMasterListTypeThe type of master list whose service implementation should be resolved.
masterListIdObjectIdThe identifier of the master list containing the option to retrieve.
masterListOptionIdObjectIdThe identifier of the specific option to look up within the master list.
dataLocaleLocaleEnum?Optional locale used to localize the returned data; falls back to Default when not provided.
Returns
- Task<object>
A task that resolves to the located master list option as an object, or null if the underlying task produced no result.
Exceptions
- InvalidOperationException
Thrown when no service implementation is registered for the given
masterListType.- InvalidOperationException
Thrown when the resolved service does not expose the expected
FindOptionItemByIdmethod.
GetMasterListSpecificType(MasterListType)
Returns the specific Type associated with the given masterListType, mapping each enumeration value to its corresponding concrete list type (e.g., AllergyList, DiagnosisList, DoctorList, etc.). If no specific mapping is found, the base MasterList type is returned as the fallback.
public Type GetMasterListSpecificType(MasterListType masterListType)
Parameters
masterListTypeMasterListTypeThe enumeration value identifying which master list category to resolve to its concrete type.
Returns
- Type
The Type that implements the requested master list category, or MasterList when no specific type applies.
GetPatientTraslated(Unit?, LocaleEnum?, Patient?)
Returns a patient with its option list fields translated to the specified locale, using the master list identifiers from the provided unit.
If the patient is null, returns null; if the locale is Default or the unit is null, the patient is returned unchanged.
Translations are applied to single or collection OptionList properties (origin, diagnosis, visits, allergies, procedures, etc.) by resolving each option's id against the matching master list and updating its Name.
public Task<Patient?> GetPatientTraslated(Unit? unit, LocaleEnum? locale, Patient? patient)
Parameters
unitUnitThe unit whose master list identifiers are used to resolve translations for each patient field.
localeLocaleEnum?The target locale for translation; when set to
Default, no translation is performed.patientPatientThe patient whose option list values will be translated in place.
Returns
- Task<Patient>
A task that resolves to the same Patient instance with translated option names, or null if the input patient is null.
GetService(Type)
Resolves a generic IMasterListService<T> instance when the requested service type is a generic MasterListService<T>. Throws an exception if the service type is not compatible or if the underlying service cannot be resolved.
public object GetService(Type serviceType)
Parameters
serviceTypeTypeThe type of the service to resolve. Must be a generic type based on
MasterListService<>to be successfully handled.
Returns
- object
The resolved service instance implementing IMasterListService<T> for the corresponding item type.
Exceptions
- InvalidOperationException
Thrown when the requested
serviceTypeis not a genericMasterListService<>, or when no implementation of IMasterListService<T> can be resolved for the requested item type.
GetService(MasterListType)
Resolves and returns a service instance for the specified master list type by dynamically constructing the generic MasterListService<T> type and retrieving the registered service.
public object GetService(MasterListType serviceName)
Parameters
serviceNameMasterListTypeThe master list type used to resolve the corresponding service type from the adas_core.Domain.Models.Masters namespace.
Returns
- object
An object representing the resolved service instance for the requested master list type.
Exceptions
- BadRequestException
Thrown when the type corresponding to
serviceNamecannot be resolved in the adas_core.Domain.Models.Masters namespace.- NotFoundException
Thrown when the generic service type cannot be constructed for the resolved type parameter.
GetTypedMasterList(MasterListType, MasterList)
Returns a specific MasterList subtype instance resolved from masterListType, with properties mapped from the provided masterList. Returns null when the specific type cannot be instantiated via reflection.
public object? GetTypedMasterList(MasterListType masterListType, MasterList masterList)
Parameters
masterListTypeMasterListTypeThe discriminator used to resolve the concrete MasterList subtype to create.
masterListMasterListThe source MasterList whose properties are mapped onto the created specific instance.
Returns
- object
The created specific MasterList instance with mapped properties, or null if reflection failed to create the instance.
InsertMasterList(MasterListType, MasterList)
Inserts a master list by dynamically resolving the appropriate service for the given masterListType and invoking its InsertMasterList method via reflection.
public Task<object?> InsertMasterList(MasterListType masterListType, MasterList masterList)
Parameters
masterListTypeMasterListTypeThe type used to resolve the target service and the specific typed master list instance.
masterListMasterListThe master list entity to be converted and inserted.
Returns
- Task<object>
The result produced by the dynamically invoked
InsertMasterListmethod, ornullwhen the awaited task exposes no result value.
Exceptions
- InvalidOperationException
Thrown when no service is registered for the specified
masterListType, when the master list cannot be converted to its expected typed instance, or when theInsertMasterListmethod cannot be found on the resolved service.
StringNurseObs()
Retrieves the list of nurse observation names by reflecting over the configured ListSettings instance,
collecting the ManualObservationName of every ListSettingItem property whose value is not null or empty,
and appending the fixed observation "PatientIncomingData".
public List<string> StringNurseObs()
Returns
- List<string>
A list of nurse observation names, including all configured manual observations and the fixed "PatientIncomingData" entry.
UpdateMasterList(MasterListType, MasterList)
Updates a master list entry by dynamically resolving the appropriate service for the given masterListType and invoking its UpdateMasterList method via reflection on the typed master list.
public Task<object?> UpdateMasterList(MasterListType masterListType, MasterList masterList)
Parameters
masterListTypeMasterListTypeThe type of master list that determines which service to resolve and which target method to invoke.
masterListMasterListThe master list instance to be updated, which is converted to its specific type before the service method is invoked.
Returns
- Task<object>
The
Resultvalue of the awaited task returned by the invokedUpdateMasterListmethod, or null if the result property is not available.
Exceptions
- InvalidOperationException
Thrown when no service is registered for the specified
masterListType.- InvalidOperationException
Thrown when the provided
masterListcannot be converted to its specific typed master list.- InvalidOperationException
Thrown when the resolved service does not expose an
UpdateMasterListmethod matching the typed master list argument.