rama creada apartir de master en j
This commit is contained in:
@@ -8,6 +8,9 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides extension methods for configuring or building cache host instances.
|
||||
/// </summary>
|
||||
public static class CacheHostBuilderExtension
|
||||
{
|
||||
public static IHostBuilder UseCache(this IHostBuilder hostBuilder)
|
||||
|
||||
@@ -4,12 +4,23 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Provides a custom JSON conversion implementation for point of care data, extending the base <see cref="JsonConverter"/> functionality.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This converter is designed to handle the serialization and deserialization logic specific to point of care entities, tailoring the behavior inherited from the <see cref="JsonConverter"/> base class.
|
||||
/// </remarks>
|
||||
public class CustomPointOfCareConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the converter can convert the specified type. Returns <c>true</c> only when the supplied type is <see cref="PointOfCare"/>; otherwise, returns <c>false</c>.
|
||||
/// </summary>
|
||||
/// <param name="objectType">The type to evaluate for convertibility.</param>
|
||||
/// <returns><c>true</c> if <paramref name="objectType"/> equals <see cref="PointOfCare"/>; otherwise, <c>false</c>.</returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(PointOfCare);
|
||||
}
|
||||
{
|
||||
return objectType == typeof(PointOfCare);
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
|
||||
@@ -11,54 +11,75 @@ using MongoClient = MongoDB.Driver.MongoClient;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Provides extension methods for configuring MongoDB integration on a host builder.
|
||||
/// </summary>
|
||||
public static class MongoDbHostBuilderExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures the host builder with the MongoDB conventions and class map registrations required for the application.
|
||||
/// </summary>
|
||||
/// <param name="hostBuilder">The host builder to extend with the MongoDB configuration.</param>
|
||||
/// <returns>The same <see cref="IHostBuilder"/> instance, allowing further fluent configuration.</returns>
|
||||
public static IHostBuilder UseMongo(this IHostBuilder hostBuilder)
|
||||
{
|
||||
ConfigureMongoDbConventions();
|
||||
|
||||
ConfigureRegisterMapClass();
|
||||
|
||||
return hostBuilder;
|
||||
}
|
||||
{
|
||||
ConfigureMongoDbConventions();
|
||||
|
||||
ConfigureRegisterMapClass();
|
||||
|
||||
return hostBuilder;
|
||||
}
|
||||
/// <summary>
|
||||
/// Runs all pending MongoDB migrations found in the migrations assembly, updating the database schema to the latest version.
|
||||
/// </summary>
|
||||
/// <param name="host">The host whose services are used to resolve the <see cref="IMongoDatabase"/> instance.</param>
|
||||
/// <returns>The same <see cref="IHost"/> instance, enabling fluent chaining.</returns>
|
||||
public static IHost RunMongoMigrations(this IHost host)
|
||||
{
|
||||
using var scope = host.Services.CreateScope();
|
||||
|
||||
var database = scope.ServiceProvider.GetRequiredService<IMongoDatabase>();
|
||||
|
||||
var locator = new MigrationLocator();
|
||||
locator.LookForMigrationsInAssembly(
|
||||
typeof(adas_core.Infrastructure.Migrations.MongoMigrations.U_0_1_0_UpdateDataPatien).Assembly
|
||||
);
|
||||
|
||||
var runner = new MigrationRunner(
|
||||
database,
|
||||
collectionName: "migrations",
|
||||
migrationLocator: locator
|
||||
);
|
||||
|
||||
runner.UpdateToLatest();
|
||||
|
||||
return host;
|
||||
}
|
||||
{
|
||||
using var scope = host.Services.CreateScope();
|
||||
|
||||
var database = scope.ServiceProvider.GetRequiredService<IMongoDatabase>();
|
||||
|
||||
var locator = new MigrationLocator();
|
||||
locator.LookForMigrationsInAssembly(
|
||||
typeof(adas_core.Infrastructure.Migrations.MongoMigrations.U_0_1_0_UpdateDataPatien).Assembly
|
||||
);
|
||||
|
||||
var runner = new MigrationRunner(
|
||||
database,
|
||||
collectionName: "migrations",
|
||||
migrationLocator: locator
|
||||
);
|
||||
|
||||
runner.UpdateToLatest();
|
||||
|
||||
return host;
|
||||
}
|
||||
/// <summary>
|
||||
/// Configures and returns a MongoDB database instance using the provided connection settings.
|
||||
/// Validates that the connection string and database name are provided, and verifies that the database exists.
|
||||
/// </summary>
|
||||
/// <param name="dbSettings">The database settings containing the MongoDB connection string and database name.</param>
|
||||
/// <returns>The configured <see cref="IMongoDatabase"/> instance.</returns>
|
||||
/// <exception cref="Exception">Thrown when the connection string or database name is null or empty.</exception>
|
||||
/// <exception cref="Exception">Thrown when the specified database does not exist.</exception>
|
||||
private static IMongoDatabase ConfigureMongoDbConnection(IOptions<DatabaseSettings> dbSettings)
|
||||
{
|
||||
var connectionString = dbSettings.Value.ConnectionString;
|
||||
|
||||
var databaseName = dbSettings.Value.DatabaseName;
|
||||
|
||||
if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(databaseName))
|
||||
throw new Exception("DataBase connection string and name is requiered");
|
||||
|
||||
_mongoClient = new MongoClient(connectionString);
|
||||
|
||||
var mongoDb = _mongoClient.GetDatabase(databaseName);
|
||||
|
||||
if (mongoDb == null) throw new Exception("DataBase doesn't exist");
|
||||
|
||||
return mongoDb;
|
||||
}
|
||||
{
|
||||
var connectionString = dbSettings.Value.ConnectionString;
|
||||
|
||||
var databaseName = dbSettings.Value.DatabaseName;
|
||||
|
||||
if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(databaseName))
|
||||
throw new Exception("DataBase connection string and name is requiered");
|
||||
|
||||
_mongoClient = new MongoClient(connectionString);
|
||||
|
||||
var mongoDb = _mongoClient.GetDatabase(databaseName);
|
||||
|
||||
if (mongoDb == null) throw new Exception("DataBase doesn't exist");
|
||||
|
||||
return mongoDb;
|
||||
}
|
||||
|
||||
public static void ConfigureRegisterMapClass()
|
||||
{
|
||||
@@ -77,24 +98,28 @@ public static class MongoDbHostBuilderExtension
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers global MongoDB serialization conventions, including ignoring extra elements in BSON documents
|
||||
/// and using camelCase for element names, applied to all types in the application.
|
||||
/// </summary>
|
||||
public static void ConfigureMongoDbConventions()
|
||||
{
|
||||
var pack = new ConventionPack
|
||||
{
|
||||
new IgnoreExtraElementsConvention(true),
|
||||
new CamelCaseElementNameConvention()
|
||||
};
|
||||
|
||||
ConventionRegistry.Register(
|
||||
"Ignore Extra Elements Convention",
|
||||
pack,
|
||||
_ => true);
|
||||
|
||||
ConventionRegistry.Register(
|
||||
"Camel Case Convention",
|
||||
pack,
|
||||
_ => true);
|
||||
}
|
||||
var pack = new ConventionPack
|
||||
{
|
||||
new IgnoreExtraElementsConvention(true),
|
||||
new CamelCaseElementNameConvention()
|
||||
};
|
||||
|
||||
ConventionRegistry.Register(
|
||||
"Ignore Extra Elements Convention",
|
||||
pack,
|
||||
_ => true);
|
||||
|
||||
ConventionRegistry.Register(
|
||||
"Camel Case Convention",
|
||||
pack,
|
||||
_ => true);
|
||||
}
|
||||
|
||||
#region MongoDB
|
||||
|
||||
|
||||
@@ -9,125 +9,132 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that provides entity mapping configuration for Alarm entities.
|
||||
/// </summary>
|
||||
/// <remarks>Implements the <see cref="IEntityMapContributor"/> interface to participate in the entity mapping process.</remarks>
|
||||
public class AlarmMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for alarm-related domain types (including alarm configuration, audio, alarm items, patient observation alarms, inactivation states, sources, recording alerts, and performance), configuring enum serialization as strings, null-ignore behavior for optional members, default values where applicable, and unmapping members that should not be persisted. Registration is performed only when a class map for the type is not already registered, ensuring idempotent behavior.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AlarmConfig)))
|
||||
BsonClassMap.RegisterClassMap<AlarmConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Enabled).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.EndAfter).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Recording).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Beacon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OpenDoor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Priority).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AudioConfig).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AudioConfig)))
|
||||
BsonClassMap.RegisterClassMap<AudioConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(AlarmEnum.AudioAlarmType.Off)
|
||||
.SetSerializer(new EnumSerializer<AlarmEnum.AudioAlarmType>(BsonType.String));
|
||||
cm.MapMember(c => c.Path).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndAfter).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AlarmItem)))
|
||||
BsonClassMap.RegisterClassMap<AlarmItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Enabled).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.StartBefore).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndAfter).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Severity)
|
||||
.SetDefaultValue(AlarmEnum.Severity.None)
|
||||
.SetSerializer(new EnumSerializer<AlarmEnum.Severity>(BsonType.String));
|
||||
cm.MapMember(c => c.BeaconColor)
|
||||
.SetDefaultValue(AlarmEnum.BeaconColor.None)
|
||||
.SetSerializer(new EnumSerializer<AlarmEnum.BeaconColor>(BsonType.String));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientObservationAlarm)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<PatientObservationAlarm>(cm =>
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AlarmConfig)))
|
||||
BsonClassMap.RegisterClassMap<AlarmConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Enabled).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.EndAfter).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Recording).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Beacon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OpenDoor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Priority).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AudioConfig).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AudioConfig)))
|
||||
BsonClassMap.RegisterClassMap<AudioConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(AlarmEnum.AudioAlarmType.Off)
|
||||
.SetSerializer(new EnumSerializer<AlarmEnum.AudioAlarmType>(BsonType.String));
|
||||
cm.MapMember(c => c.Path).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndAfter).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AlarmItem)))
|
||||
BsonClassMap.RegisterClassMap<AlarmItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Enabled).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.StartBefore).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndAfter).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Severity)
|
||||
.SetDefaultValue(AlarmEnum.Severity.None)
|
||||
.SetSerializer(new EnumSerializer<AlarmEnum.Severity>(BsonType.String));
|
||||
cm.MapMember(c => c.BeaconColor)
|
||||
.SetDefaultValue(AlarmEnum.BeaconColor.None)
|
||||
.SetSerializer(new EnumSerializer<AlarmEnum.BeaconColor>(BsonType.String));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientObservationAlarm)))
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.InactivationState).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EventPhase)
|
||||
.SetDefaultValue(AlarmEnum.EventPhase.Continue)
|
||||
.SetSerializer(new EnumSerializer<AlarmEnum.EventPhase>(BsonType.String));
|
||||
cm.MapMember(c => c.Event).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EventId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.State)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<AlarmEnum.ObservationAlarmState>(
|
||||
new EnumSerializer<AlarmEnum.ObservationAlarmState>(BsonType.String)));
|
||||
cm.MapMember(c => c.Priority)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<AlarmEnum.ObservationAlarmPriority>(
|
||||
new EnumSerializer<AlarmEnum.ObservationAlarmPriority>(BsonType.String)));
|
||||
cm.MapMember(c => c.PriorityLevel)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<int>(new Int32Serializer()));
|
||||
cm.UnmapMember(c => c.AlarmConfig);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<AlarmEnum.ObservationAlarmType>(
|
||||
new EnumSerializer<AlarmEnum.ObservationAlarmType>(BsonType.String)));
|
||||
cm.MapMember(c => c.AlertColor).SetIgnoreIfNull(true)
|
||||
.SetSerializer(new StringSerializer(BsonType.String));
|
||||
cm.UnmapMember(c => c.MessageTime);
|
||||
cm.MapMember(c => c.Persist).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.Expired);
|
||||
cm.MapMember(c => c.Expires).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Sources).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<InactivationState>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Audio)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<AlarmEnum.AudioVideoState>(
|
||||
new EnumSerializer<AlarmEnum.AudioVideoState>(BsonType.String)));
|
||||
cm.MapMember(c => c.Visual)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<AlarmEnum.AudioVideoState>(
|
||||
new EnumSerializer<AlarmEnum.AudioVideoState>(BsonType.String)));
|
||||
cm.MapMember(c => c.Acknowledge).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<Source>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OriginalName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CodeSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Units).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Value).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Result).SetIgnoreIfNull(true);
|
||||
});
|
||||
BsonClassMap.RegisterClassMap<PatientObservationAlarm>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.InactivationState).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EventPhase)
|
||||
.SetDefaultValue(AlarmEnum.EventPhase.Continue)
|
||||
.SetSerializer(new EnumSerializer<AlarmEnum.EventPhase>(BsonType.String));
|
||||
cm.MapMember(c => c.Event).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EventId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.State)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<AlarmEnum.ObservationAlarmState>(
|
||||
new EnumSerializer<AlarmEnum.ObservationAlarmState>(BsonType.String)));
|
||||
cm.MapMember(c => c.Priority)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<AlarmEnum.ObservationAlarmPriority>(
|
||||
new EnumSerializer<AlarmEnum.ObservationAlarmPriority>(BsonType.String)));
|
||||
cm.MapMember(c => c.PriorityLevel)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<int>(new Int32Serializer()));
|
||||
cm.UnmapMember(c => c.AlarmConfig);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<AlarmEnum.ObservationAlarmType>(
|
||||
new EnumSerializer<AlarmEnum.ObservationAlarmType>(BsonType.String)));
|
||||
cm.MapMember(c => c.AlertColor).SetIgnoreIfNull(true)
|
||||
.SetSerializer(new StringSerializer(BsonType.String));
|
||||
cm.UnmapMember(c => c.MessageTime);
|
||||
cm.MapMember(c => c.Persist).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.Expired);
|
||||
cm.MapMember(c => c.Expires).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Sources).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<InactivationState>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Audio)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<AlarmEnum.AudioVideoState>(
|
||||
new EnumSerializer<AlarmEnum.AudioVideoState>(BsonType.String)));
|
||||
cm.MapMember(c => c.Visual)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<AlarmEnum.AudioVideoState>(
|
||||
new EnumSerializer<AlarmEnum.AudioVideoState>(BsonType.String)));
|
||||
cm.MapMember(c => c.Acknowledge).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<Source>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OriginalName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CodeSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Units).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Value).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Result).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientRecordingAlert)))
|
||||
BsonClassMap.RegisterClassMap<PatientRecordingAlert>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.IsRecording);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Performance)))
|
||||
BsonClassMap.RegisterClassMap<Performance>(cm => { cm.AutoMap(); });
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientRecordingAlert)))
|
||||
BsonClassMap.RegisterClassMap<PatientRecordingAlert>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.IsRecording);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Performance)))
|
||||
BsonClassMap.RegisterClassMap<Performance>(cm => { cm.AutoMap(); });
|
||||
}
|
||||
}
|
||||
@@ -7,66 +7,72 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that provides entity mapping configuration for the <see cref="PatientAppointment"/> type as part of the mapping framework.
|
||||
/// </summary>
|
||||
public class AppointmentMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the <see cref="PatientAppointment"/>, <see cref="PatientAppointmentResourceGroup"/>, and <see cref="Allergies"/> types, customizing the MongoDB serialization for their members. Registration is performed only if a class map for the type has not already been registered, making the call safe to invoke multiple times. Optional members are configured to be ignored when null, enum members are serialized as nullable string enums, and certain computed/action members are unmapped or assigned default collection values.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientAppointment)))
|
||||
BsonClassMap.RegisterClassMap<PatientAppointment>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientId).SetSerializer(new ObjectIdSerializer(BsonType.String));
|
||||
cm.MapMember(c => c.Patient).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Timings).SetDefaultValue(new List<Timing>());
|
||||
cm.MapMember(c => c.CreateTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UpdateTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PlacerOrder).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FillerOrder).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EventReason).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AppointmentReason).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AppointmentType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AppointmentOperationType)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<OperationType>(new EnumSerializer<OperationType>(BsonType.String)));
|
||||
cm.MapMember(c => c.AppointmentStatus)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<OperationType>(new EnumSerializer<OperationType>(BsonType.String)));
|
||||
cm.MapMember(c => c.Duration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.VisitNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PatientClass).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EpisodeActivation).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.PlacerContact).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FillerContact).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ResourceGroups).SetDefaultValue(new List<PatientAppointmentResourceGroup>());
|
||||
cm.MapMember(c => c.Allergies).SetDefaultValue(new List<Allergies>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientAppointmentResourceGroup)))
|
||||
BsonClassMap.RegisterClassMap<PatientAppointmentResourceGroup>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
cm.MapMember(c => c.Services).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Resources).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Locations).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Personnel).SetIgnoreIfNull(true);
|
||||
|
||||
cm.UnmapMember(c => c.ServicesActions);
|
||||
cm.UnmapMember(c => c.ResourcesActions);
|
||||
cm.UnmapMember(c => c.LocationsActions);
|
||||
cm.UnmapMember(c => c.PersonnelActions);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Allergies)))
|
||||
BsonClassMap.RegisterClassMap<Allergies>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.AllergenType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Allergen).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientAppointment)))
|
||||
BsonClassMap.RegisterClassMap<PatientAppointment>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientId).SetSerializer(new ObjectIdSerializer(BsonType.String));
|
||||
cm.MapMember(c => c.Patient).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Timings).SetDefaultValue(new List<Timing>());
|
||||
cm.MapMember(c => c.CreateTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UpdateTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PlacerOrder).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FillerOrder).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EventReason).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AppointmentReason).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AppointmentType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AppointmentOperationType)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<OperationType>(new EnumSerializer<OperationType>(BsonType.String)));
|
||||
cm.MapMember(c => c.AppointmentStatus)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<OperationType>(new EnumSerializer<OperationType>(BsonType.String)));
|
||||
cm.MapMember(c => c.Duration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.VisitNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PatientClass).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EpisodeActivation).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.PlacerContact).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FillerContact).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ResourceGroups).SetDefaultValue(new List<PatientAppointmentResourceGroup>());
|
||||
cm.MapMember(c => c.Allergies).SetDefaultValue(new List<Allergies>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientAppointmentResourceGroup)))
|
||||
BsonClassMap.RegisterClassMap<PatientAppointmentResourceGroup>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
cm.MapMember(c => c.Services).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Resources).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Locations).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Personnel).SetIgnoreIfNull(true);
|
||||
|
||||
cm.UnmapMember(c => c.ServicesActions);
|
||||
cm.UnmapMember(c => c.ResourcesActions);
|
||||
cm.UnmapMember(c => c.LocationsActions);
|
||||
cm.UnmapMember(c => c.PersonnelActions);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Allergies)))
|
||||
BsonClassMap.RegisterClassMap<Allergies>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.AllergenType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Allergen).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,34 +4,40 @@ using MongoDB.Bson.Serialization;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an entity map contributor that provides authentication-related mapping logic.
|
||||
/// </summary>
|
||||
public class AuthMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the <see cref="User"/> and <see cref="Authorization"/> types when no class map has been registered yet, configuring field serialization rules such as ignoring null or empty values, mapping the identifier to the "_id" element name, and unmapping navigation properties not intended for persistence.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(User)))
|
||||
BsonClassMap.RegisterClassMap<User>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Password)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetShouldSerializeMethod(obj => !string.IsNullOrEmpty(((User)obj).Password));
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.LockExpirationDate)
|
||||
.SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Authorization).SetElementName("Authorization")
|
||||
.SetShouldSerializeMethod(_ => false);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Authorization)))
|
||||
BsonClassMap.RegisterClassMap<Authorization>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.UnitId).SetIgnoreIfNull(true);
|
||||
cm.UnmapProperty(c => c.User);
|
||||
cm.UnmapProperty(c => c.Display);
|
||||
cm.UnmapProperty(c => c.Unit);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(User)))
|
||||
BsonClassMap.RegisterClassMap<User>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Password)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetShouldSerializeMethod(obj => !string.IsNullOrEmpty(((User)obj).Password));
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.LockExpirationDate)
|
||||
.SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Authorization).SetElementName("Authorization")
|
||||
.SetShouldSerializeMethod(_ => false);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Authorization)))
|
||||
BsonClassMap.RegisterClassMap<Authorization>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.UnitId).SetIgnoreIfNull(true);
|
||||
cm.UnmapProperty(c => c.User);
|
||||
cm.UnmapProperty(c => c.Display);
|
||||
cm.UnmapProperty(c => c.Unit);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -7,56 +7,65 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Provides mapping contributions for the <c>BannerConfig</c> entity by implementing the <see cref="IEntityMapContributor"/> contract.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Used as a contributor that participates in entity map configuration for banner-related data.
|
||||
/// </remarks>
|
||||
public class BannerConfigMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for banner-related configuration types, including <see cref="BannerItem"/>, <see cref="BannerItemConfig"/>, <see cref="BannerItemTableConfig"/>, and <see cref="HeaderBannerItemTableConfig"/>. Each map is only registered when no existing registration is found, and applies custom serialization (enum values stored as strings), null-ignoring behavior for optional members, and default values where appropriate.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(BannerItem)))
|
||||
BsonClassMap.RegisterClassMap<BannerItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<DisplayConfigEnums.BannerType>(
|
||||
new EnumSerializer<DisplayConfigEnums.BannerType>(BsonType.String)));
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.Config).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(BannerItemConfig)))
|
||||
BsonClassMap.RegisterClassMap<BannerItemConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.BannerItemDialogTableConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BannerItemTableConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MedicalStaffConfig).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(BannerItemTableConfig)))
|
||||
BsonClassMap.RegisterClassMap<BannerItemTableConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Config).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.TextColor).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HeaderBannerItemTableConfig)))
|
||||
BsonClassMap.RegisterClassMap<HeaderBannerItemTableConfig>(cm =>
|
||||
{
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<DisplayConfigEnums.CellType>(
|
||||
new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String)));
|
||||
cm.MapMember(c => c.SubType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Field).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GrowPriority).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Icon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.TextColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(BannerItem)))
|
||||
BsonClassMap.RegisterClassMap<BannerItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<DisplayConfigEnums.BannerType>(
|
||||
new EnumSerializer<DisplayConfigEnums.BannerType>(BsonType.String)));
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.Config).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(BannerItemConfig)))
|
||||
BsonClassMap.RegisterClassMap<BannerItemConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.BannerItemDialogTableConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BannerItemTableConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MedicalStaffConfig).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(BannerItemTableConfig)))
|
||||
BsonClassMap.RegisterClassMap<BannerItemTableConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Config).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.TextColor).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HeaderBannerItemTableConfig)))
|
||||
BsonClassMap.RegisterClassMap<HeaderBannerItemTableConfig>(cm =>
|
||||
{
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<DisplayConfigEnums.CellType>(
|
||||
new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String)));
|
||||
cm.MapMember(c => c.SubType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Field).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GrowPriority).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Icon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.TextColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,37 +6,48 @@ using LightBeacon = adas_core.Domain.Models.MongoModels.LightBeacon;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a map contributor that participates in entity mapping operations
|
||||
/// for beacon-related entities.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implements the <see cref="IEntityMapContributor"/> interface to contribute
|
||||
/// beacon-specific mapping logic.
|
||||
/// </remarks>
|
||||
public class BeaconMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for <see cref="LightBeacon"/>, <see cref="Options"/>, and <see cref="LightBeaconAbstract"/> types to configure their MongoDB serialization. Each registration is skipped if a class map for the type has already been registered, applying default values, element name mappings, and ignore-if-null settings to the respective members.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LightBeacon)))
|
||||
BsonClassMap.RegisterClassMap<LightBeacon>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Type).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Options).SetDefaultValue(new Options());
|
||||
cm.MapMember(c => c.InUse).SetIgnoreIfNull(true).SetIsRequired(false);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Options)))
|
||||
BsonClassMap.RegisterClassMap<Options>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Url).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Port).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Password).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Emulate).SetDefaultValue(false);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LightBeaconAbstract)))
|
||||
BsonClassMap.RegisterClassMap<LightBeaconAbstract>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Host);
|
||||
cm.MapMember(c => c.Password);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LightBeacon)))
|
||||
BsonClassMap.RegisterClassMap<LightBeacon>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Type).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Options).SetDefaultValue(new Options());
|
||||
cm.MapMember(c => c.InUse).SetIgnoreIfNull(true).SetIsRequired(false);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Options)))
|
||||
BsonClassMap.RegisterClassMap<Options>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Url).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Port).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Password).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Emulate).SetDefaultValue(false);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LightBeaconAbstract)))
|
||||
BsonClassMap.RegisterClassMap<LightBeaconAbstract>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Host);
|
||||
cm.MapMember(c => c.Password);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@ using Stream = adas_core.Domain.Models.MongoModels.Stream;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Provides configuration mapping contributions for box entities, implementing the <see cref="IEntityMapContributor"/> interface to participate in entity map setup.
|
||||
/// </summary>
|
||||
public class BoxConfigMapContributor : IEntityMapContributor
|
||||
{
|
||||
public void RegisterMaps()
|
||||
|
||||
@@ -5,35 +5,44 @@ using Stream = System.IO.Stream;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that participates in entity mapping operations related to camera entities.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implements the <see cref="IEntityMapContributor"/> interface to provide camera-specific mapping behavior within the entity mapping pipeline.
|
||||
/// </remarks>
|
||||
public class CameraContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the <see cref="Camera"/> and <see cref="Domain.Models.MongoModels.Stream"/> types with MongoDB, applying custom mapping conventions such as element name overrides, default values, and ignore-if-null behavior. Registration is performed only once; the method guards against duplicate registration by checking <see cref="BsonClassMap.IsClassMapRegistered(Type)"/> before registering.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Camera)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<Camera>(cm =>
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Camera)))
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Streams).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Ptz).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.Driver).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Ip).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Username).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Password).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.InUse).SetIgnoreIfNull(true).SetIsRequired(false);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<Domain.Models.MongoModels.Stream>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Rtsp).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Jpeg).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.WebRtc).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Hls).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Mp4).SetIgnoreIfNull(true);
|
||||
});
|
||||
BsonClassMap.RegisterClassMap<Camera>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Streams).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Ptz).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.Driver).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Ip).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Username).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Password).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.InUse).SetIgnoreIfNull(true).SetIsRequired(false);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<Domain.Models.MongoModels.Stream>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Rtsp).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Jpeg).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.WebRtc).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Hls).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Mp4).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,87 +7,93 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Provides card-specific mapping contributions by implementing the <see cref="IEntityMapContributor"/> contract within the entity mapping pipeline.
|
||||
/// </summary>
|
||||
public class CardMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the layout and configuration types used by the display configuration domain, including <see cref="SectionBoxLayout"/>, <see cref="CardDetailsConfig"/>, <see cref="CardRotatingLayout"/>, <see cref="Step"/>, and <see cref="HomeConfig"/>. Each map is only registered when no existing map is present, and the configuration establishes default values, enum-as-string serialization, and ignore-if-null behavior for nullable layout properties.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(SectionBoxLayout)))
|
||||
BsonClassMap.RegisterClassMap<SectionBoxLayout>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type).SetDefaultValue(DisplayConfigEnums.RowType.Simple)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.RowType>(BsonType.String));
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Subtitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Icon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GridColumn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderWidth).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderStyle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderRadius).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HProportion).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SectionUrl).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MinHeight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Subtitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Conditions).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Direction).SetDefaultValue(DisplayConfigEnums.DirectionEnum.Row)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.DirectionEnum>(BsonType.String));
|
||||
cm.MapMember(c => c.Rows).SetDefaultValue(new List<RowBoxLayout>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CardDetailsConfig)))
|
||||
BsonClassMap.RegisterClassMap<CardDetailsConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Header).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SmartSections).SetDefaultValue(new List<SectionBoxLayout>());
|
||||
cm.MapMember(c => c.NurseRows).SetDefaultValue(new List<RowDetailsConfig>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CardRotatingLayout)))
|
||||
BsonClassMap.RegisterClassMap<CardRotatingLayout>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.MillisecondsBeforeRotating).SetDefaultValue(3000);
|
||||
cm.MapMember(c => c.Order).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Data)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
cm.MapMember(c => c.Type).SetDefaultValue(DisplayConfigEnums.RotatingLayoutType.HomeSection)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.RotatingLayoutType>(BsonType.String));
|
||||
cm.MapMember(c => c.Mode).SetDefaultValue(DisplayConfigEnums.RotatingLayoutMode.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.RotatingLayoutMode>(BsonType.String));
|
||||
});
|
||||
|
||||
//standard card rotating layout
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Step)))
|
||||
BsonClassMap.RegisterClassMap<Step>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<DisplayConfigEnums.StepType>(
|
||||
new EnumSerializer<DisplayConfigEnums.StepType>(BsonType.String)));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HomeConfig)))
|
||||
BsonClassMap.RegisterClassMap<HomeConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.MinColumnSize).SetDefaultValue("250");
|
||||
cm.MapMember(c => c.ColumnsPerBreakpoint).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.BreakpointSize).SetDefaultValue("2000");
|
||||
cm.MapMember(c => c.CardAspectRatioHeight).SetDefaultValue("700");
|
||||
cm.MapMember(c => c.CardAspectRatioWidth).SetDefaultValue("500");
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(SectionBoxLayout)))
|
||||
BsonClassMap.RegisterClassMap<SectionBoxLayout>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type).SetDefaultValue(DisplayConfigEnums.RowType.Simple)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.RowType>(BsonType.String));
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Subtitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Icon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GridColumn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderWidth).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderStyle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderRadius).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HProportion).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SectionUrl).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MinHeight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Subtitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Conditions).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Direction).SetDefaultValue(DisplayConfigEnums.DirectionEnum.Row)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.DirectionEnum>(BsonType.String));
|
||||
cm.MapMember(c => c.Rows).SetDefaultValue(new List<RowBoxLayout>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CardDetailsConfig)))
|
||||
BsonClassMap.RegisterClassMap<CardDetailsConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Header).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SmartSections).SetDefaultValue(new List<SectionBoxLayout>());
|
||||
cm.MapMember(c => c.NurseRows).SetDefaultValue(new List<RowDetailsConfig>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CardRotatingLayout)))
|
||||
BsonClassMap.RegisterClassMap<CardRotatingLayout>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.MillisecondsBeforeRotating).SetDefaultValue(3000);
|
||||
cm.MapMember(c => c.Order).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Data)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
cm.MapMember(c => c.Type).SetDefaultValue(DisplayConfigEnums.RotatingLayoutType.HomeSection)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.RotatingLayoutType>(BsonType.String));
|
||||
cm.MapMember(c => c.Mode).SetDefaultValue(DisplayConfigEnums.RotatingLayoutMode.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.RotatingLayoutMode>(BsonType.String));
|
||||
});
|
||||
|
||||
//standard card rotating layout
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Step)))
|
||||
BsonClassMap.RegisterClassMap<Step>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<DisplayConfigEnums.StepType>(
|
||||
new EnumSerializer<DisplayConfigEnums.StepType>(BsonType.String)));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HomeConfig)))
|
||||
BsonClassMap.RegisterClassMap<HomeConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.MinColumnSize).SetDefaultValue("250");
|
||||
cm.MapMember(c => c.ColumnsPerBreakpoint).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.BreakpointSize).SetDefaultValue("2000");
|
||||
cm.MapMember(c => c.CardAspectRatioHeight).SetDefaultValue("700");
|
||||
cm.MapMember(c => c.CardAspectRatioWidth).SetDefaultValue("500");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -7,123 +7,129 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that participates in populating a cell-based map by implementing the entity map contribution contract.
|
||||
/// </summary>
|
||||
public class CellMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for <see cref="Cell"/>, <see cref="CellDetails"/>, <see cref="IconValueList"/>, <see cref="DialogConfig"/>, and <see cref="MedicalConfig"/> when they have not already been registered. Each registration configures default values, ignore-if-null behavior, and enum serialization for the corresponding type's members to control how instances are persisted in MongoDB.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Cell)))
|
||||
BsonClassMap.RegisterClassMap<Cell>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.CellType.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String));
|
||||
cm.MapMember(c => c.ChartSettings).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1.0);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconValueList)
|
||||
.SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Border).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderRadius).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Direction)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<DisplayConfigEnums.DirectionEnum>(
|
||||
new EnumSerializer<DisplayConfigEnums.DirectionEnum>(BsonType.String)));
|
||||
cm.MapMember(c => c.SubType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Size).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HideName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsVisible).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.IsColumn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValuePathKey).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BackgroundColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowIcon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FlexBasis).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Grow).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Shrink).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IndicatorHorizontal).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DialogConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowIndicator).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OnlyNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowArrow).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GraphConf).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Names).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GraphConf).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValuePathNested).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SubObs).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.TextRules).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsStatic).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CellDetails)))
|
||||
BsonClassMap.RegisterClassMap<CellDetails>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.TextRules).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String))
|
||||
.SetDefaultValue(DisplayConfigEnums.CellType.Default);
|
||||
cm.MapMember(c => c.ChartSettings).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SubType).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1.0);
|
||||
cm.MapMember(c => c.Cells).SetDefaultValue(new List<CellDetails>());
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsVisible).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ValuePathNested).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValuePathKey).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconValueList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BackgroundColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowIcon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FlexBasis).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FlexDirection).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Grow).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Shrink).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DialogConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsStatic).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(IconValueList)))
|
||||
BsonClassMap.RegisterClassMap<IconValueList>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.MinValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Width).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Height).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconList).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DialogConfig)))
|
||||
BsonClassMap.RegisterClassMap<DialogConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.IsDraggable).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.MedicalConfig).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(MedicalConfig)))
|
||||
BsonClassMap.RegisterClassMap<MedicalConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.HasFinalizeTime).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.HasStartTime).SetDefaultValue(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Cell)))
|
||||
BsonClassMap.RegisterClassMap<Cell>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.CellType.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String));
|
||||
cm.MapMember(c => c.ChartSettings).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1.0);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconValueList)
|
||||
.SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Border).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderRadius).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Direction)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<DisplayConfigEnums.DirectionEnum>(
|
||||
new EnumSerializer<DisplayConfigEnums.DirectionEnum>(BsonType.String)));
|
||||
cm.MapMember(c => c.SubType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Size).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HideName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsVisible).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.IsColumn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValuePathKey).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BackgroundColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowIcon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FlexBasis).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Grow).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Shrink).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IndicatorHorizontal).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DialogConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowIndicator).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OnlyNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowArrow).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GraphConf).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Names).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GraphConf).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValuePathNested).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SubObs).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.TextRules).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsStatic).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CellDetails)))
|
||||
BsonClassMap.RegisterClassMap<CellDetails>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.TextRules).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String))
|
||||
.SetDefaultValue(DisplayConfigEnums.CellType.Default);
|
||||
cm.MapMember(c => c.ChartSettings).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SubType).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1.0);
|
||||
cm.MapMember(c => c.Cells).SetDefaultValue(new List<CellDetails>());
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsVisible).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ValuePathNested).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValuePathKey).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconValueList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BackgroundColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowIcon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FlexBasis).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FlexDirection).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Grow).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Shrink).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DialogConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsStatic).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(IconValueList)))
|
||||
BsonClassMap.RegisterClassMap<IconValueList>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.MinValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Width).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Height).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconList).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DialogConfig)))
|
||||
BsonClassMap.RegisterClassMap<DialogConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.IsDraggable).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.MedicalConfig).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(MedicalConfig)))
|
||||
BsonClassMap.RegisterClassMap<MedicalConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.HasFinalizeTime).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.HasStartTime).SetDefaultValue(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,331 +4,342 @@ using MongoDB.Bson.Serialization;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that supplies color configuration mappings for entities
|
||||
/// by implementing the <see cref="IEntityMapContributor"/> interface.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Used as a pluggable component within the entity mapping pipeline to apply
|
||||
/// color-related configuration to mapped entities.
|
||||
/// </remarks>
|
||||
public class ColorConfigMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the <see cref="ColorConfig"/> type and its nested configuration types, providing default color and appearance values for properties such as levels, text, arrows, indicators, graphs, status boxes, therapy, tests, and procedures. Each class map is registered only if it has not already been registered, ensuring idempotent initialization of the MongoDB serialization mappings used by the color configuration system.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Level).SetDefaultValue(new ColorConfig.LevelColors
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig>(cm =>
|
||||
{
|
||||
Level1 = "#FFFFFF",
|
||||
Level2 = "#FAFF41",
|
||||
Level3 = "#F5A623",
|
||||
Level4 = "#C2510F",
|
||||
Level5 = "#FF5D6A"
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Text).SetDefaultValue(new ColorConfig.TextColors
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Level).SetDefaultValue(new ColorConfig.LevelColors
|
||||
{
|
||||
Level1 = "#FFFFFF",
|
||||
Level2 = "#FAFF41",
|
||||
Level3 = "#F5A623",
|
||||
Level4 = "#C2510F",
|
||||
Level5 = "#FF5D6A"
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Text).SetDefaultValue(new ColorConfig.TextColors
|
||||
{
|
||||
Normal = "#FFFFFF",
|
||||
Warning = "#FFAD26",
|
||||
Alert = "#FF5D6A",
|
||||
Improve = "#60D61D",
|
||||
Expired = "#333333"
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Arrow).SetDefaultValue(new ColorConfig.ArrowColors
|
||||
{
|
||||
Normal = "#FFFFFF",
|
||||
Warning = "#F5A623",
|
||||
Alert = "#FF5D6A",
|
||||
Improve = "#60D61D"
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Indicator).SetDefaultValue(new ColorConfig.IndicatorColors
|
||||
{
|
||||
Empty = "#CCCCCC",
|
||||
Warning = "#FFAD26",
|
||||
Normal = "#60D61D",
|
||||
Alert = "#FF5D6A",
|
||||
Background = "#000000",
|
||||
EmptyBackground = "#CCCCCC"
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Graph).SetDefaultValue(new ColorConfig.GraphColors
|
||||
{
|
||||
Alert = "#FF5D6A",
|
||||
Warning = "#FFAD26",
|
||||
Normal = "#60D61D"
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxNumber).SetDefaultValue(new ColorConfig.StatusBoxNumberColors
|
||||
{
|
||||
Reserved =
|
||||
new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
InUse = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Available = new ColorConfig.AppearanceSettings
|
||||
{ BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Locked = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Transferable = new ColorConfig.AppearanceSettings
|
||||
{ BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Exitus = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Altable = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" }
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxStatusColor).SetDefaultValue(new ColorConfig.StatusBoxNumberColors
|
||||
{
|
||||
Reserved =
|
||||
new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
InUse = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Available = new ColorConfig.AppearanceSettings
|
||||
{ BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Locked = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Transferable = new ColorConfig.AppearanceSettings
|
||||
{ BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Exitus = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Altable = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" }
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Therapy).SetDefaultValue(new ColorConfig.TherapyColors
|
||||
{
|
||||
Default = new ColorConfig.AppearanceSettings(),
|
||||
Finished = new ColorConfig.AppearanceSettings(),
|
||||
Initialized = new ColorConfig.AppearanceSettings(),
|
||||
InProgress = new ColorConfig.AppearanceSettings()
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Test).SetDefaultValue(new ColorConfig.TestColors
|
||||
{
|
||||
Default = new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00A4E1",
|
||||
TextColor = "#FFF"
|
||||
},
|
||||
Finished = new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00C49B",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-tick.svg",
|
||||
IconDefault = "icTick"
|
||||
},
|
||||
Initialized = new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF"
|
||||
},
|
||||
Expired = new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-clock.svg",
|
||||
IconDefault = "icClock"
|
||||
}
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Procedure).SetDefaultValue(new ColorConfig.ProcedureColors
|
||||
{
|
||||
Default = new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00A4E1",
|
||||
TextColor = "#FFF"
|
||||
},
|
||||
Finished = new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00C49B",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-tick.svg",
|
||||
IconDefault = "icTick"
|
||||
},
|
||||
Initialized = new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF"
|
||||
},
|
||||
Expired = new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-clock.svg",
|
||||
IconDefault = "icClock"
|
||||
}
|
||||
}).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.StatusBoxNumberColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.StatusBoxNumberColors>(cm =>
|
||||
{
|
||||
Normal = "#FFFFFF",
|
||||
Warning = "#FFAD26",
|
||||
Alert = "#FF5D6A",
|
||||
Improve = "#60D61D",
|
||||
Expired = "#333333"
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Arrow).SetDefaultValue(new ColorConfig.ArrowColors
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Reserved).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#FFF84C",
|
||||
TextColor = "#000000"
|
||||
});
|
||||
cm.MapMember(c => c.InUse).SetDefaultValue(new ColorConfig.AppearanceSettings());
|
||||
cm.MapMember(c => c.Available).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#57B812",
|
||||
TextColor = "#000000"
|
||||
});
|
||||
cm.MapMember(c => c.Locked).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#000000"
|
||||
});
|
||||
cm.MapMember(c => c.Transferable).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#57B812",
|
||||
TextColor = "#000000"
|
||||
});
|
||||
cm.MapMember(c => c.Exitus).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#24BFF9",
|
||||
TextColor = "#000000"
|
||||
});
|
||||
cm.MapMember(c => c.Altable).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#24BFF9",
|
||||
TextColor = "#000000"
|
||||
});
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.TherapyColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.TherapyColors>(cm =>
|
||||
{
|
||||
Normal = "#FFFFFF",
|
||||
Warning = "#F5A623",
|
||||
Alert = "#FF5D6A",
|
||||
Improve = "#60D61D"
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Indicator).SetDefaultValue(new ColorConfig.IndicatorColors
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Default).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00A4E1",
|
||||
TextColor = "#FFF",
|
||||
IconInvertColor = 1
|
||||
});
|
||||
cm.MapMember(c => c.Initialized).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#FFF",
|
||||
TextColor = "#000"
|
||||
});
|
||||
cm.MapMember(c => c.Finished).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#FFF",
|
||||
TextColor = "#000",
|
||||
Icon = "assets/icon/light-theme/ic-tick.svg",
|
||||
IconDefault = "icTick"
|
||||
});
|
||||
cm.MapMember(c => c.InProgress).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#FFF",
|
||||
TextColor = "#000"
|
||||
});
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.AppearanceSettings)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.AppearanceSettings>(cm =>
|
||||
{
|
||||
Empty = "#CCCCCC",
|
||||
Warning = "#FFAD26",
|
||||
Normal = "#60D61D",
|
||||
Alert = "#FF5D6A",
|
||||
Background = "#000000",
|
||||
EmptyBackground = "#CCCCCC"
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Graph).SetDefaultValue(new ColorConfig.GraphColors
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.TextColor).SetDefaultValue("#000000");
|
||||
cm.MapMember(c => c.BackgroundColor).SetDefaultValue("#FFFFFF");
|
||||
cm.MapMember(c => c.Icon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconDefault).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconCategory).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconInvertColor).SetDefaultValue(0.0);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.TestColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.TestColors>(cm =>
|
||||
{
|
||||
Alert = "#FF5D6A",
|
||||
Warning = "#FFAD26",
|
||||
Normal = "#60D61D"
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxNumber).SetDefaultValue(new ColorConfig.StatusBoxNumberColors
|
||||
{
|
||||
Reserved =
|
||||
new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
InUse = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Available = new ColorConfig.AppearanceSettings
|
||||
{ BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Locked = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Transferable = new ColorConfig.AppearanceSettings
|
||||
{ BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Exitus = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Altable = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" }
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxStatusColor).SetDefaultValue(new ColorConfig.StatusBoxNumberColors
|
||||
{
|
||||
Reserved =
|
||||
new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
InUse = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Available = new ColorConfig.AppearanceSettings
|
||||
{ BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Locked = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Transferable = new ColorConfig.AppearanceSettings
|
||||
{ BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Exitus = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" },
|
||||
Altable = new ColorConfig.AppearanceSettings { BackgroundColor = "#FFF84C", TextColor = "#000000" }
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Therapy).SetDefaultValue(new ColorConfig.TherapyColors
|
||||
{
|
||||
Default = new ColorConfig.AppearanceSettings(),
|
||||
Finished = new ColorConfig.AppearanceSettings(),
|
||||
Initialized = new ColorConfig.AppearanceSettings(),
|
||||
InProgress = new ColorConfig.AppearanceSettings()
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Test).SetDefaultValue(new ColorConfig.TestColors
|
||||
{
|
||||
Default = new ColorConfig.AppearanceSettings
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Default).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00A4E1",
|
||||
TextColor = "#FFF"
|
||||
},
|
||||
Finished = new ColorConfig.AppearanceSettings
|
||||
});
|
||||
cm.MapMember(c => c.Initialized).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF"
|
||||
});
|
||||
cm.MapMember(c => c.Finished).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00C49B",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-tick.svg",
|
||||
IconDefault = "icTick"
|
||||
},
|
||||
Initialized = new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF"
|
||||
},
|
||||
Expired = new ColorConfig.AppearanceSettings
|
||||
});
|
||||
cm.MapMember(c => c.Expired).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-clock.svg",
|
||||
IconDefault = "icClock"
|
||||
}
|
||||
}).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Procedure).SetDefaultValue(new ColorConfig.ProcedureColors
|
||||
});
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.ProcedureColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.ProcedureColors>(cm =>
|
||||
{
|
||||
Default = new ColorConfig.AppearanceSettings
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Default).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00A4E1",
|
||||
TextColor = "#FFF"
|
||||
},
|
||||
Finished = new ColorConfig.AppearanceSettings
|
||||
});
|
||||
cm.MapMember(c => c.Initialized).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF"
|
||||
});
|
||||
cm.MapMember(c => c.Finished).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00C49B",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-tick.svg",
|
||||
IconDefault = "icTick"
|
||||
},
|
||||
Initialized = new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF"
|
||||
},
|
||||
Expired = new ColorConfig.AppearanceSettings
|
||||
});
|
||||
cm.MapMember(c => c.Expired).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-clock.svg",
|
||||
IconDefault = "icClock"
|
||||
}
|
||||
}).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.StatusBoxNumberColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.StatusBoxNumberColors>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Reserved).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#FFF84C",
|
||||
TextColor = "#000000"
|
||||
});
|
||||
});
|
||||
cm.MapMember(c => c.InUse).SetDefaultValue(new ColorConfig.AppearanceSettings());
|
||||
cm.MapMember(c => c.Available).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.LevelColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.LevelColors>(cm =>
|
||||
{
|
||||
BackgroundColor = "#57B812",
|
||||
TextColor = "#000000"
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Level1).SetDefaultValue("#FFFFFF");
|
||||
cm.MapMember(c => c.Level2).SetDefaultValue("#FAFF41");
|
||||
cm.MapMember(c => c.Level3).SetDefaultValue("#F5A623");
|
||||
cm.MapMember(c => c.Level4).SetDefaultValue("#C2510F");
|
||||
cm.MapMember(c => c.Level5).SetDefaultValue("#FF5D6A");
|
||||
});
|
||||
cm.MapMember(c => c.Locked).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.TextColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.TextColors>(cm =>
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#000000"
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Normal).SetDefaultValue("#FFFFFF");
|
||||
cm.MapMember(c => c.Warning).SetDefaultValue("#FFAD26");
|
||||
cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
|
||||
cm.MapMember(c => c.Improve).SetDefaultValue("#60D61D");
|
||||
cm.MapMember(c => c.Expired).SetDefaultValue("#333333");
|
||||
});
|
||||
cm.MapMember(c => c.Transferable).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.ArrowColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.ArrowColors>(cm =>
|
||||
{
|
||||
BackgroundColor = "#57B812",
|
||||
TextColor = "#000000"
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Normal).SetDefaultValue("#FFFFFF");
|
||||
cm.MapMember(c => c.Warning).SetDefaultValue("#F5A623");
|
||||
cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
|
||||
cm.MapMember(c => c.Improve).SetDefaultValue("#60D61D");
|
||||
});
|
||||
cm.MapMember(c => c.Exitus).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.IndicatorColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.IndicatorColors>(cm =>
|
||||
{
|
||||
BackgroundColor = "#24BFF9",
|
||||
TextColor = "#000000"
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Empty).SetDefaultValue("#CCCCCC");
|
||||
cm.MapMember(c => c.Warning).SetDefaultValue("#FFAD26");
|
||||
cm.MapMember(c => c.Normal).SetDefaultValue("#60D61D");
|
||||
cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
|
||||
cm.MapMember(c => c.Background).SetDefaultValue("#000000");
|
||||
cm.MapMember(c => c.EmptyBackground).SetDefaultValue("#CCCCCC");
|
||||
});
|
||||
cm.MapMember(c => c.Altable).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.GraphColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.GraphColors>(cm =>
|
||||
{
|
||||
BackgroundColor = "#24BFF9",
|
||||
TextColor = "#000000"
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Normal).SetDefaultValue("#60D61D");
|
||||
cm.MapMember(c => c.Warning).SetDefaultValue("#FFAD26");
|
||||
cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
|
||||
});
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.TherapyColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.TherapyColors>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Default).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00A4E1",
|
||||
TextColor = "#FFF",
|
||||
IconInvertColor = 1
|
||||
});
|
||||
cm.MapMember(c => c.Initialized).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#FFF",
|
||||
TextColor = "#000"
|
||||
});
|
||||
cm.MapMember(c => c.Finished).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#FFF",
|
||||
TextColor = "#000",
|
||||
Icon = "assets/icon/light-theme/ic-tick.svg",
|
||||
IconDefault = "icTick"
|
||||
});
|
||||
cm.MapMember(c => c.InProgress).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#FFF",
|
||||
TextColor = "#000"
|
||||
});
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.AppearanceSettings)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.AppearanceSettings>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.TextColor).SetDefaultValue("#000000");
|
||||
cm.MapMember(c => c.BackgroundColor).SetDefaultValue("#FFFFFF");
|
||||
cm.MapMember(c => c.Icon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconDefault).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconCategory).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconInvertColor).SetDefaultValue(0.0);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.TestColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.TestColors>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Default).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00A4E1",
|
||||
TextColor = "#FFF"
|
||||
});
|
||||
cm.MapMember(c => c.Initialized).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF"
|
||||
});
|
||||
cm.MapMember(c => c.Finished).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00C49B",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-tick.svg",
|
||||
IconDefault = "icTick"
|
||||
});
|
||||
cm.MapMember(c => c.Expired).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-clock.svg",
|
||||
IconDefault = "icClock"
|
||||
});
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.ProcedureColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.ProcedureColors>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Default).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00A4E1",
|
||||
TextColor = "#FFF"
|
||||
});
|
||||
cm.MapMember(c => c.Initialized).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF"
|
||||
});
|
||||
cm.MapMember(c => c.Finished).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#00C49B",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-tick.svg",
|
||||
IconDefault = "icTick"
|
||||
});
|
||||
cm.MapMember(c => c.Expired).SetDefaultValue(new ColorConfig.AppearanceSettings
|
||||
{
|
||||
BackgroundColor = "#ED4965",
|
||||
TextColor = "#FFF",
|
||||
Icon = "assets/icon/light-theme/ic-clock.svg",
|
||||
IconDefault = "icClock"
|
||||
});
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.LevelColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.LevelColors>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Level1).SetDefaultValue("#FFFFFF");
|
||||
cm.MapMember(c => c.Level2).SetDefaultValue("#FAFF41");
|
||||
cm.MapMember(c => c.Level3).SetDefaultValue("#F5A623");
|
||||
cm.MapMember(c => c.Level4).SetDefaultValue("#C2510F");
|
||||
cm.MapMember(c => c.Level5).SetDefaultValue("#FF5D6A");
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.TextColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.TextColors>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Normal).SetDefaultValue("#FFFFFF");
|
||||
cm.MapMember(c => c.Warning).SetDefaultValue("#FFAD26");
|
||||
cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
|
||||
cm.MapMember(c => c.Improve).SetDefaultValue("#60D61D");
|
||||
cm.MapMember(c => c.Expired).SetDefaultValue("#333333");
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.ArrowColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.ArrowColors>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Normal).SetDefaultValue("#FFFFFF");
|
||||
cm.MapMember(c => c.Warning).SetDefaultValue("#F5A623");
|
||||
cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
|
||||
cm.MapMember(c => c.Improve).SetDefaultValue("#60D61D");
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.IndicatorColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.IndicatorColors>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Empty).SetDefaultValue("#CCCCCC");
|
||||
cm.MapMember(c => c.Warning).SetDefaultValue("#FFAD26");
|
||||
cm.MapMember(c => c.Normal).SetDefaultValue("#60D61D");
|
||||
cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
|
||||
cm.MapMember(c => c.Background).SetDefaultValue("#000000");
|
||||
cm.MapMember(c => c.EmptyBackground).SetDefaultValue("#CCCCCC");
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ColorConfig.GraphColors)))
|
||||
BsonClassMap.RegisterClassMap<ColorConfig.GraphColors>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Normal).SetDefaultValue("#60D61D");
|
||||
cm.MapMember(c => c.Warning).SetDefaultValue("#FFAD26");
|
||||
cm.MapMember(c => c.Alert).SetDefaultValue("#FF5D6A");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,34 +7,40 @@ using MongoDB.Bson.Serialization;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a map contributor that provides mapping configuration for communication flow entities by implementing the <see cref="IEntityMapContributor"/> interface.
|
||||
/// </summary>
|
||||
public class ComunicationFlowMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the application's MongoDB-serialized types, including <see cref="Message"/>, <see cref="Queue"/>, <see cref="ApiRequest"/>, <see cref="AdmPanelRequest"/>, <see cref="ApiClients"/>, and <see cref="VideoDto"/>, applying custom mapping rules such as unmapping the <c>Operation</c> member on <see cref="Message"/> and ignoring null values for <c>ObsertationData</c> on <see cref="AdmPanelRequest"/>. Each type is only registered if a class map has not already been registered, preventing duplicate registration.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Message)))
|
||||
BsonClassMap.RegisterClassMap<Message>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.UnmapMember(c => c.Operation);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Queue)))
|
||||
BsonClassMap.RegisterClassMap<Queue>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ApiRequest)))
|
||||
BsonClassMap.RegisterClassMap<ApiRequest>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AdmPanelRequest)))
|
||||
BsonClassMap.RegisterClassMap<AdmPanelRequest>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.ObsertationData).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ApiClients)))
|
||||
BsonClassMap.RegisterClassMap<ApiClients>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(VideoDto)))
|
||||
BsonClassMap.RegisterClassMap<VideoDto>(cm => { cm.AutoMap(); });
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Message)))
|
||||
BsonClassMap.RegisterClassMap<Message>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.UnmapMember(c => c.Operation);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Queue)))
|
||||
BsonClassMap.RegisterClassMap<Queue>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ApiRequest)))
|
||||
BsonClassMap.RegisterClassMap<ApiRequest>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AdmPanelRequest)))
|
||||
BsonClassMap.RegisterClassMap<AdmPanelRequest>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.ObsertationData).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ApiClients)))
|
||||
BsonClassMap.RegisterClassMap<ApiClients>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(VideoDto)))
|
||||
BsonClassMap.RegisterClassMap<VideoDto>(cm => { cm.AutoMap(); });
|
||||
}
|
||||
}
|
||||
@@ -8,74 +8,84 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that provides device-related mapping logic for entities.
|
||||
/// Implements the <see cref="IEntityMapContributor"/> interface to participate in the entity mapping process.
|
||||
/// </summary>
|
||||
public class DeviceMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for <see cref="DeviceActionType"/>, <see cref="DeviceAction"/>, <see cref="DeviceSettings"/>, and <see cref="Device"/> types used in MongoDB serialization.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Each map is only registered if no class map is already registered for the type. The registration applies auto-mapping and customizes serialization for enum members (stored as strings), applies default values for required properties, and configures nullable members to be ignored when null.
|
||||
/// </remarks>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DeviceActionType)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DeviceActionType>(cm => cm.AutoMap() );
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DeviceActionType)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DeviceActionType>(cm => cm.AutoMap() );
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DeviceAction)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DeviceAction>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DeviceActionType.Unknown)
|
||||
.SetSerializer(new EnumSerializer<DeviceActionType>(BsonType.String));
|
||||
cm.MapMember(c => c.ConfigObservationId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AlarmName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValueOnSingleClick)
|
||||
.SetDefaultValue(new object())
|
||||
.SetSerializer(new ComplexObjectValueTypeSerializer());
|
||||
cm.MapMember(c => c.ValueOnDoubleClick)
|
||||
.SetDefaultValue(new object())
|
||||
.SetSerializer(new ComplexObjectValueTypeSerializer());
|
||||
cm.MapMember(c => c.ValueOnHoldClick)
|
||||
.SetDefaultValue(new object())
|
||||
.SetSerializer(new ComplexObjectValueTypeSerializer());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DeviceSettings)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DeviceSettings>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Action).SetDefaultValue(new DeviceAction());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Device)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<Device>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.DeviceType)
|
||||
.SetDefaultValue(DeviceType.Unknown)
|
||||
.SetSerializer(new EnumSerializer<DeviceType>(BsonType.String));
|
||||
cm.MapMember(c => c.Uuid).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MacAddr).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CreatedAt).SetDefaultValue(DateTime.UtcNow);
|
||||
cm.MapMember(c => c.UpdatedAt).SetDefaultValue(DateTime.UtcNow);
|
||||
cm.MapMember(c => c.Key).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Battery).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SerialNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PointOfCareIds).SetDefaultValue(new List<ObjectId>());
|
||||
cm.MapMember(c => c.Connected).SetDefaultValue(false).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Ready).SetDefaultValue(false).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DeviceType)
|
||||
.SetSerializer(new EnumSerializer<DeviceType>(BsonType.String));
|
||||
cm.MapMember(c => c.Settings).SetDefaultValue(new DeviceSettings());
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DeviceAction)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DeviceAction>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DeviceActionType.Unknown)
|
||||
.SetSerializer(new EnumSerializer<DeviceActionType>(BsonType.String));
|
||||
cm.MapMember(c => c.ConfigObservationId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AlarmName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValueOnSingleClick)
|
||||
.SetDefaultValue(new object())
|
||||
.SetSerializer(new ComplexObjectValueTypeSerializer());
|
||||
cm.MapMember(c => c.ValueOnDoubleClick)
|
||||
.SetDefaultValue(new object())
|
||||
.SetSerializer(new ComplexObjectValueTypeSerializer());
|
||||
cm.MapMember(c => c.ValueOnHoldClick)
|
||||
.SetDefaultValue(new object())
|
||||
.SetSerializer(new ComplexObjectValueTypeSerializer());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DeviceSettings)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DeviceSettings>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Action).SetDefaultValue(new DeviceAction());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Device)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<Device>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.DeviceType)
|
||||
.SetDefaultValue(DeviceType.Unknown)
|
||||
.SetSerializer(new EnumSerializer<DeviceType>(BsonType.String));
|
||||
cm.MapMember(c => c.Uuid).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MacAddr).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CreatedAt).SetDefaultValue(DateTime.UtcNow);
|
||||
cm.MapMember(c => c.UpdatedAt).SetDefaultValue(DateTime.UtcNow);
|
||||
cm.MapMember(c => c.Key).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Battery).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SerialNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PointOfCareIds).SetDefaultValue(new List<ObjectId>());
|
||||
cm.MapMember(c => c.Connected).SetDefaultValue(false).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Ready).SetDefaultValue(false).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DeviceType)
|
||||
.SetSerializer(new EnumSerializer<DeviceType>(BsonType.String));
|
||||
cm.MapMember(c => c.Settings).SetDefaultValue(new DeviceSettings());
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,40 +7,46 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that supplies entity map configuration related to display home functionality.
|
||||
/// </summary>
|
||||
public class DisplayHomeConfigContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for <see cref="CardConfig"/> and <see cref="RowCardConfig"/> types if they are not already registered, configuring MongoDB serialization with custom element names, default values, null-ignore behavior, and string-based enum serialization.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CardConfig)))
|
||||
BsonClassMap.RegisterClassMap<CardConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Rows).SetDefaultValue(new List<RowCardConfig>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(RowCardConfig)))
|
||||
BsonClassMap.RegisterClassMap<RowCardConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Cells).SetDefaultValue(new List<Cell>());
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.Border).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderRadius).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Size).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MarginTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MarginBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MarginLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MarginRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.CellType.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String));
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CardConfig)))
|
||||
BsonClassMap.RegisterClassMap<CardConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Rows).SetDefaultValue(new List<RowCardConfig>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(RowCardConfig)))
|
||||
BsonClassMap.RegisterClassMap<RowCardConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Cells).SetDefaultValue(new List<Cell>());
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.Border).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderRadius).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Size).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MarginTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MarginBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MarginLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MarginRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.CellType.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -8,127 +8,137 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor responsible for providing display-related mapping logic for entities.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implements the <see cref="IEntityMapContributor"/> interface to participate in the entity mapping pipeline for display scenarios.
|
||||
/// </remarks>
|
||||
public class DisplayMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for display-related types (Display, DisplayNurse, StandarDisplay, SmartDisplay, PumpDisplay, DisplayConfig, and GroupedField) used for MongoDB serialization.
|
||||
/// </summary>
|
||||
/// <remarks>Configures polymorphic deserialization for DisplayConfig by declaring its known subtypes, sets custom element names for identifiers, applies default values for enum and collection members, omits null or unmapped properties, and uses string-based enum serialization where applicable. Each registration is guarded so it only occurs when the corresponding class map has not already been registered.</remarks>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Display)))
|
||||
BsonClassMap.RegisterClassMap<Display>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.UnmapProperty(c => c.Unit);
|
||||
cm.UnmapProperty(c => c.PointOfCares);
|
||||
cm.UnmapProperty(c => c.DisplayConfig);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.DisplayType.Unknown)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.DisplayType>(BsonType.String));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DisplayNurse)))
|
||||
BsonClassMap.RegisterClassMap<DisplayNurse>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(StandarDisplay)))
|
||||
BsonClassMap.RegisterClassMap<StandarDisplay>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.SectionConfig).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(SmartDisplay)))
|
||||
BsonClassMap.RegisterClassMap<SmartDisplay>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PumpDisplay)))
|
||||
BsonClassMap.RegisterClassMap<PumpDisplay>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DisplayConfig)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<DisplayConfig>(cm =>
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Display)))
|
||||
BsonClassMap.RegisterClassMap<Display>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.UnmapProperty(c => c.Unit);
|
||||
cm.UnmapProperty(c => c.PointOfCares);
|
||||
cm.UnmapProperty(c => c.DisplayConfig);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.DisplayType.Unknown)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.DisplayType>(BsonType.String));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DisplayNurse)))
|
||||
BsonClassMap.RegisterClassMap<DisplayNurse>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(StandarDisplay)))
|
||||
BsonClassMap.RegisterClassMap<StandarDisplay>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.SectionConfig).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(SmartDisplay)))
|
||||
BsonClassMap.RegisterClassMap<SmartDisplay>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PumpDisplay)))
|
||||
BsonClassMap.RegisterClassMap<PumpDisplay>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DisplayConfig)))
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.AddKnownType(typeof(DisplayNurse));
|
||||
cm.AddKnownType(typeof(StandarDisplay));
|
||||
cm.AddKnownType(typeof(SmartDisplay));
|
||||
cm.AddKnownType(typeof(PumpDisplay));
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.DisplayType.Unknown)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.DisplayType>(BsonType.String));
|
||||
cm.MapMember(c => c.MediaFolder).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CardConfigId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CardConfig)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
cm.MapMember(c => c.DetailConfigId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DetailConfig)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
cm.MapMember(c => c.HomeBanner).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FormConfig)
|
||||
.SetDefaultValue(new FormConfig
|
||||
{
|
||||
Admission = new FormItemOverview { Nhc = true },
|
||||
Demographic = new FormItemOverview { Nhc = true },
|
||||
Discharge = new FormItemOverview { Nhc = true },
|
||||
IncomeInfo = new FormItemOverview { Nhc = true }
|
||||
});
|
||||
cm.MapMember(c => c.HasCameras).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HasSound).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsRotationEnabled).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CanChangeCameraMode).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CamerasAreActive).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CameraStreamType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SensorList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationForIndicator).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AlarmFieldList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequestGroupedFieldList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Pumps).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ChartConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GraphLayout).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CardRotatingLayout).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ChartConfigIdList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HomeConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HeaderConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DisplaySectionIdList).SetDefaultValue(new List<ObjectId>());
|
||||
cm.MapMember(c => c.Hospital).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ColorConfig).SetDefaultValue(new ColorConfig());
|
||||
cm.MapMember(c => c.FieldList).SetDefaultValue(new List<Field>());
|
||||
cm.MapMember(c => c.GroupedFieldList).SetDefaultValue(new List<GroupedField>());
|
||||
|
||||
cm.UnmapProperty(c => c.DisplaySectionList);
|
||||
// cm.UnmapProperty(c => c.CardConfig);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<GroupedField>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Names).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Group).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StartTimeShift).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Max);
|
||||
cm.MapMember(c => c.Regularity)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<GroupedObservationEnum.Regularity>(
|
||||
new EnumSerializer<GroupedObservationEnum.Regularity>(BsonType.String)));
|
||||
cm.MapMember(c => c.Since)
|
||||
.SetDefaultValue(GroupedObservationEnum.Since.Last)
|
||||
.SetSerializer(new EnumSerializer<GroupedObservationEnum.Since>(BsonType.String));
|
||||
cm.MapMember(c => c.Result)
|
||||
.SetIgnoreIfNull(true);
|
||||
//.SetSerializer(new EnumSerializer<GroupedObservationEnum.Result>(BsonType.Array));
|
||||
cm.MapMember(c => c.LabelList).SetIgnoreIfNull(true);
|
||||
});
|
||||
BsonClassMap.RegisterClassMap<DisplayConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.AddKnownType(typeof(DisplayNurse));
|
||||
cm.AddKnownType(typeof(StandarDisplay));
|
||||
cm.AddKnownType(typeof(SmartDisplay));
|
||||
cm.AddKnownType(typeof(PumpDisplay));
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.DisplayType.Unknown)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.DisplayType>(BsonType.String));
|
||||
cm.MapMember(c => c.MediaFolder).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CardConfigId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CardConfig)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
cm.MapMember(c => c.DetailConfigId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DetailConfig)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
cm.MapMember(c => c.HomeBanner).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FormConfig)
|
||||
.SetDefaultValue(new FormConfig
|
||||
{
|
||||
Admission = new FormItemOverview { Nhc = true },
|
||||
Demographic = new FormItemOverview { Nhc = true },
|
||||
Discharge = new FormItemOverview { Nhc = true },
|
||||
IncomeInfo = new FormItemOverview { Nhc = true }
|
||||
});
|
||||
cm.MapMember(c => c.HasCameras).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HasSound).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsRotationEnabled).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CanChangeCameraMode).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CamerasAreActive).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CameraStreamType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SensorList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationForIndicator).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AlarmFieldList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequestGroupedFieldList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Pumps).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ChartConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GraphLayout).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CardRotatingLayout).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ChartConfigIdList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HomeConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HeaderConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DisplaySectionIdList).SetDefaultValue(new List<ObjectId>());
|
||||
cm.MapMember(c => c.Hospital).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ColorConfig).SetDefaultValue(new ColorConfig());
|
||||
cm.MapMember(c => c.FieldList).SetDefaultValue(new List<Field>());
|
||||
cm.MapMember(c => c.GroupedFieldList).SetDefaultValue(new List<GroupedField>());
|
||||
|
||||
cm.UnmapProperty(c => c.DisplaySectionList);
|
||||
// cm.UnmapProperty(c => c.CardConfig);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<GroupedField>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Names).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Group).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StartTimeShift).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Max);
|
||||
cm.MapMember(c => c.Regularity)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<GroupedObservationEnum.Regularity>(
|
||||
new EnumSerializer<GroupedObservationEnum.Regularity>(BsonType.String)));
|
||||
cm.MapMember(c => c.Since)
|
||||
.SetDefaultValue(GroupedObservationEnum.Since.Last)
|
||||
.SetSerializer(new EnumSerializer<GroupedObservationEnum.Since>(BsonType.String));
|
||||
cm.MapMember(c => c.Result)
|
||||
.SetIgnoreIfNull(true);
|
||||
//.SetSerializer(new EnumSerializer<GroupedObservationEnum.Result>(BsonType.Array));
|
||||
cm.MapMember(c => c.LabelList).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,46 +4,53 @@ using MongoDB.Bson.Serialization;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor responsible for providing form-related mapping logic for entities.
|
||||
/// Implements the <see cref="IEntityMapContributor"/> interface to participate in the entity mapping process.
|
||||
/// </summary>
|
||||
public class FormMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for <see cref="FormConfig"/> and <see cref="FormItemOverview"/> types used during MongoDB serialization, configuring default values and conditional serialization rules for their members. Each class map is only registered if it has not already been registered, preventing duplicate registrations.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(FormConfig)))
|
||||
BsonClassMap.RegisterClassMap<FormConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Admission).SetDefaultValue(new FormItemOverview());
|
||||
cm.MapMember(c => c.Demographic).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Discharge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IncomeInfo).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(FormItemOverview)))
|
||||
BsonClassMap.RegisterClassMap<FormItemOverview>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Nhc).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.Bed).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.LastName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SecondName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Genre).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Birthday).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Origin).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OriginAux).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Diagnostic).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DiagnosticAux).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Allergy).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Language).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Insulation).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Service).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Destination).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DestinationAux).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AdmDischarge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.NurseDischarge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MedicalDischarge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IncomingDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UciDays).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(FormConfig)))
|
||||
BsonClassMap.RegisterClassMap<FormConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Admission).SetDefaultValue(new FormItemOverview());
|
||||
cm.MapMember(c => c.Demographic).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Discharge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IncomeInfo).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(FormItemOverview)))
|
||||
BsonClassMap.RegisterClassMap<FormItemOverview>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Nhc).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.Bed).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.LastName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SecondName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Genre).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Birthday).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Origin).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OriginAux).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Diagnostic).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DiagnosticAux).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Allergy).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Language).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Insulation).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Service).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Destination).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DestinationAux).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AdmDischarge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.NurseDischarge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MedicalDischarge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IncomingDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UciDays).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -7,259 +7,268 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that provides graph-based mapping logic for entities.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implements the <see cref="IEntityMapContributor"/> contract to participate in entity map configuration within a graph structure.
|
||||
/// </remarks>
|
||||
public class GraphMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the application's chart, graph, and legend configuration types, configuring serialization behavior such as default values, null-ignoring, and enum string serialization. Each registration is guarded by an <see cref="BsonClassMap.IsClassMapRegistered"/> check so the method is idempotent and can be safely called multiple times.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(GraphLayout)))
|
||||
BsonClassMap.RegisterClassMap<GraphLayout>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Layout).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GraphConf).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationName).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ChartSettings)))
|
||||
BsonClassMap.RegisterClassMap<ChartSettings>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.LegendLayoutConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.LegendGrowPriority).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ChartGrowPriority).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ChartConfig)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<ChartConfig>(cm =>
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(GraphLayout)))
|
||||
BsonClassMap.RegisterClassMap<GraphLayout>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Layout).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GraphConf).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationName).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ChartSettings)))
|
||||
BsonClassMap.RegisterClassMap<ChartSettings>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.LegendLayoutConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.LegendGrowPriority).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ChartGrowPriority).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ChartConfig)))
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.BaseConfig).SetDefaultValue(new ChartBaseConfig());
|
||||
cm.MapMember(c => c.AxesConfig).SetDefaultValue(new List<AxisConfig>());
|
||||
cm.MapMember(c => c.SeriesConfig).SetDefaultValue(new List<SeriesConfigBase>());
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<ChartBaseConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Title).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Top).SetDefaultValue("7%");
|
||||
cm.MapMember(c => c.Right).SetDefaultValue("7%");
|
||||
cm.MapMember(c => c.Bottom).SetDefaultValue("7%");
|
||||
cm.MapMember(c => c.Left).SetDefaultValue("7%");
|
||||
cm.MapMember(c => c.Group).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.BorderWidth).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.BorderColor).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.ShowLegend).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.ShowGrid).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.NumValues).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BaselineOffset).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<AxisConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Type)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.AxisType>(BsonType.String))
|
||||
.SetDefaultValue(DisplayConfigEnums.AxisType.Value);
|
||||
cm.MapMember(a => a.KeyName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Position)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.AxisPosition>(BsonType.String))
|
||||
.SetDefaultValue(DisplayConfigEnums.AxisPosition.Left);
|
||||
cm.MapMember(a => a.Min).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Max).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.AxisLine).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.AxisTick).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.AxisLabel).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Silent).SetDefaultValue(true);
|
||||
cm.MapMember(a => a.LabelFormat)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.LabelFormat>(BsonType.String))
|
||||
.SetDefaultValue(DisplayConfigEnums.LabelFormat.Hour);
|
||||
cm.MapMember(a => a.Offset).SetDefaultValue(0.0);
|
||||
cm.MapMember(a => a.CustomLabels).SetDefaultValue(new List<string>());
|
||||
cm.MapMember(a => a.SortLabels).SetDefaultValue(false);
|
||||
cm.MapMember(a => a.Show).SetDefaultValue(true);
|
||||
cm.MapMember(a => a.Regularity)
|
||||
.SetSerializer(new EnumSerializer<GroupedObservationEnum.Regularity>(BsonType.String))
|
||||
.SetDefaultValue(GroupedObservationEnum.Regularity.Hour);
|
||||
});
|
||||
|
||||
|
||||
BsonClassMap.RegisterClassMap<AxisTick>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Show).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Interval).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Length).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<AxisLabel>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Show).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Margin).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.FontSize).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Silent).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<AxisLineStyle>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Color).SetIgnoreIfNull(true);
|
||||
});
|
||||
BsonClassMap.RegisterClassMap<AxisLine>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Show).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.LineStyle).SetIgnoreIfNull(true);
|
||||
});
|
||||
BsonClassMap.RegisterClassMap<SeriesConfigBase>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
// cm.SetIsRootClass(true);
|
||||
// cm.AddKnownType(typeof(CandlestickSeriesConfig));
|
||||
cm.MapMember(s => s.Key).SetElementName("key");
|
||||
cm.MapMember(s => s.Color).SetElementName("color");
|
||||
cm.MapMember(s => s.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.SeriesType.Line)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.SeriesType>(BsonType.String));
|
||||
cm.MapMember(s => s.SourceType)
|
||||
.SetDefaultValue(DisplayConfigEnums.SourceType.Obs)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.SourceType>(BsonType.String));
|
||||
cm.MapMember(s => s.AxesNames)
|
||||
.SetDefaultValue(new List<string>());
|
||||
cm.MapMember(s => s.ShowSymbol).SetDefaultValue(false);
|
||||
cm.MapMember(s => s.ShowColorOnLegend).SetDefaultValue(false);
|
||||
cm.MapMember(s => s.ShowOnLegend).SetDefaultValue(true);
|
||||
cm.MapMember(s => s.Values)
|
||||
.SetDefaultValue(GroupedObservationEnum.Result.Last)
|
||||
.SetSerializer(new EnumSerializer<GroupedObservationEnum.Result>(BsonType.String));
|
||||
cm.MapMember(s => s.MarkerIcon)
|
||||
.SetDefaultValue(DisplayConfigEnums.MarkerIcon.None)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.MarkerIcon>(BsonType.String));
|
||||
cm.MapMember(s => s.VisualMap).SetIgnoreIfNull(true);
|
||||
cm.MapMember(l => l.LineWidth).SetDefaultValue(2);
|
||||
cm.MapMember(l => l.LineStyle).SetDefaultValue("solid");
|
||||
cm.MapMember(v => v.Marker)
|
||||
.SetDefaultValue(DisplayConfigEnums.MarkerIcon.Kangaroo)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.MarkerIcon>(BsonType.String));
|
||||
cm.MapMember(a => a.AboveBaselineColor).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(a => a.BelowBaselineColor).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(a => a.CandleKeyList).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(p => p.LineType).SetIgnoreIfNull(true);
|
||||
});
|
||||
// BsonClassMap.RegisterClassMap<LineSeriesConfig>(cm =>
|
||||
// {
|
||||
// cm.AutoMap();
|
||||
// cm.MapMember(l => l.LineWidth).SetDefaultValue(2);
|
||||
// cm.MapMember(l => l.LineStyle).SetDefaultValue("solid");
|
||||
// });
|
||||
// BsonClassMap.RegisterClassMap<VerticalMarkerSeriesConfig>(cm =>
|
||||
// {
|
||||
// cm.AutoMap();
|
||||
// cm.MapMember(v => v.Marker)
|
||||
// .SetDefaultValue(DisplayConfigEnums.MarkerIcon.Kangaroo)
|
||||
// .SetSerializer(new EnumSerializer<DisplayConfigEnums.MarkerIcon>(BsonType.String));
|
||||
// });
|
||||
// BsonClassMap.RegisterClassMap<AreaSeriesConfig>(cm =>
|
||||
// {
|
||||
// cm.AutoMap();
|
||||
// cm.MapMember(a => a.AboveBaselineColor).SetIgnoreIfDefault(true);
|
||||
// cm.MapMember(a => a.BelowBaselineColor).SetIgnoreIfDefault(true);
|
||||
// });
|
||||
// BsonClassMap.RegisterClassMap<CandlestickSeriesConfig>(cm =>
|
||||
// {
|
||||
// cm.AutoMap();
|
||||
// cm.MapMember(a => a.CandleKeyList).SetIgnoreIfDefault(true);
|
||||
// });
|
||||
// if (!BsonClassMap.IsClassMapRegistered(typeof(LineSeriesConfig)))
|
||||
// {
|
||||
// BsonClassMap.RegisterClassMap<LineSeriesConfig>(cm =>
|
||||
// {
|
||||
// cm.AutoMap();
|
||||
// cm.MapMember(p => p.LineStyle).SetDefaultValue("solid");
|
||||
// cm.MapMember(p => p.LineWidth).SetDefaultValue(2);
|
||||
// cm.MapMember(p => p.LineType).SetIgnoreIfNull(true);
|
||||
// });
|
||||
// }
|
||||
BsonClassMap.RegisterClassMap<Candle>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Key).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(a => a.CandleValueType)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<CandleValueType>(new EnumSerializer<CandleValueType>(BsonType.String)));
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<VisualMap>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(v => v.Show).SetDefaultValue(false);
|
||||
cm.MapMember(v => v.Dimension).SetDefaultValue(0);
|
||||
cm.MapMember(v => v.SerieKey).SetIgnoreIfNull(true);
|
||||
cm.MapMember(v => v.Pieces).SetDefaultValue(new List<Piece>());
|
||||
});
|
||||
BsonClassMap.RegisterClassMap<ChartConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.BaseConfig).SetDefaultValue(new ChartBaseConfig());
|
||||
cm.MapMember(c => c.AxesConfig).SetDefaultValue(new List<AxisConfig>());
|
||||
cm.MapMember(c => c.SeriesConfig).SetDefaultValue(new List<SeriesConfigBase>());
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<ChartBaseConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Title).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Top).SetDefaultValue("7%");
|
||||
cm.MapMember(c => c.Right).SetDefaultValue("7%");
|
||||
cm.MapMember(c => c.Bottom).SetDefaultValue("7%");
|
||||
cm.MapMember(c => c.Left).SetDefaultValue("7%");
|
||||
cm.MapMember(c => c.Group).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.BorderWidth).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.BorderColor).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.ShowLegend).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.ShowGrid).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.NumValues).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BaselineOffset).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<AxisConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Type)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.AxisType>(BsonType.String))
|
||||
.SetDefaultValue(DisplayConfigEnums.AxisType.Value);
|
||||
cm.MapMember(a => a.KeyName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Position)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.AxisPosition>(BsonType.String))
|
||||
.SetDefaultValue(DisplayConfigEnums.AxisPosition.Left);
|
||||
cm.MapMember(a => a.Min).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Max).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.AxisLine).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.AxisTick).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.AxisLabel).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Silent).SetDefaultValue(true);
|
||||
cm.MapMember(a => a.LabelFormat)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.LabelFormat>(BsonType.String))
|
||||
.SetDefaultValue(DisplayConfigEnums.LabelFormat.Hour);
|
||||
cm.MapMember(a => a.Offset).SetDefaultValue(0.0);
|
||||
cm.MapMember(a => a.CustomLabels).SetDefaultValue(new List<string>());
|
||||
cm.MapMember(a => a.SortLabels).SetDefaultValue(false);
|
||||
cm.MapMember(a => a.Show).SetDefaultValue(true);
|
||||
cm.MapMember(a => a.Regularity)
|
||||
.SetSerializer(new EnumSerializer<GroupedObservationEnum.Regularity>(BsonType.String))
|
||||
.SetDefaultValue(GroupedObservationEnum.Regularity.Hour);
|
||||
});
|
||||
|
||||
|
||||
BsonClassMap.RegisterClassMap<AxisTick>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Show).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Interval).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Length).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<AxisLabel>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Show).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Margin).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.FontSize).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.Silent).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<AxisLineStyle>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Color).SetIgnoreIfNull(true);
|
||||
});
|
||||
BsonClassMap.RegisterClassMap<AxisLine>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Show).SetIgnoreIfNull(true);
|
||||
cm.MapMember(a => a.LineStyle).SetIgnoreIfNull(true);
|
||||
});
|
||||
BsonClassMap.RegisterClassMap<SeriesConfigBase>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
// cm.SetIsRootClass(true);
|
||||
// cm.AddKnownType(typeof(CandlestickSeriesConfig));
|
||||
cm.MapMember(s => s.Key).SetElementName("key");
|
||||
cm.MapMember(s => s.Color).SetElementName("color");
|
||||
cm.MapMember(s => s.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.SeriesType.Line)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.SeriesType>(BsonType.String));
|
||||
cm.MapMember(s => s.SourceType)
|
||||
.SetDefaultValue(DisplayConfigEnums.SourceType.Obs)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.SourceType>(BsonType.String));
|
||||
cm.MapMember(s => s.AxesNames)
|
||||
.SetDefaultValue(new List<string>());
|
||||
cm.MapMember(s => s.ShowSymbol).SetDefaultValue(false);
|
||||
cm.MapMember(s => s.ShowColorOnLegend).SetDefaultValue(false);
|
||||
cm.MapMember(s => s.ShowOnLegend).SetDefaultValue(true);
|
||||
cm.MapMember(s => s.Values)
|
||||
.SetDefaultValue(GroupedObservationEnum.Result.Last)
|
||||
.SetSerializer(new EnumSerializer<GroupedObservationEnum.Result>(BsonType.String));
|
||||
cm.MapMember(s => s.MarkerIcon)
|
||||
.SetDefaultValue(DisplayConfigEnums.MarkerIcon.None)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.MarkerIcon>(BsonType.String));
|
||||
cm.MapMember(s => s.VisualMap).SetIgnoreIfNull(true);
|
||||
cm.MapMember(l => l.LineWidth).SetDefaultValue(2);
|
||||
cm.MapMember(l => l.LineStyle).SetDefaultValue("solid");
|
||||
cm.MapMember(v => v.Marker)
|
||||
.SetDefaultValue(DisplayConfigEnums.MarkerIcon.Kangaroo)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.MarkerIcon>(BsonType.String));
|
||||
cm.MapMember(a => a.AboveBaselineColor).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(a => a.BelowBaselineColor).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(a => a.CandleKeyList).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(p => p.LineType).SetIgnoreIfNull(true);
|
||||
});
|
||||
// BsonClassMap.RegisterClassMap<LineSeriesConfig>(cm =>
|
||||
// {
|
||||
// cm.AutoMap();
|
||||
// cm.MapMember(l => l.LineWidth).SetDefaultValue(2);
|
||||
// cm.MapMember(l => l.LineStyle).SetDefaultValue("solid");
|
||||
// });
|
||||
// BsonClassMap.RegisterClassMap<VerticalMarkerSeriesConfig>(cm =>
|
||||
// {
|
||||
// cm.AutoMap();
|
||||
// cm.MapMember(v => v.Marker)
|
||||
// .SetDefaultValue(DisplayConfigEnums.MarkerIcon.Kangaroo)
|
||||
// .SetSerializer(new EnumSerializer<DisplayConfigEnums.MarkerIcon>(BsonType.String));
|
||||
// });
|
||||
// BsonClassMap.RegisterClassMap<AreaSeriesConfig>(cm =>
|
||||
// {
|
||||
// cm.AutoMap();
|
||||
// cm.MapMember(a => a.AboveBaselineColor).SetIgnoreIfDefault(true);
|
||||
// cm.MapMember(a => a.BelowBaselineColor).SetIgnoreIfDefault(true);
|
||||
// });
|
||||
// BsonClassMap.RegisterClassMap<CandlestickSeriesConfig>(cm =>
|
||||
// {
|
||||
// cm.AutoMap();
|
||||
// cm.MapMember(a => a.CandleKeyList).SetIgnoreIfDefault(true);
|
||||
// });
|
||||
// if (!BsonClassMap.IsClassMapRegistered(typeof(LineSeriesConfig)))
|
||||
// {
|
||||
// BsonClassMap.RegisterClassMap<LineSeriesConfig>(cm =>
|
||||
// {
|
||||
// cm.AutoMap();
|
||||
// cm.MapMember(p => p.LineStyle).SetDefaultValue("solid");
|
||||
// cm.MapMember(p => p.LineWidth).SetDefaultValue(2);
|
||||
// cm.MapMember(p => p.LineType).SetIgnoreIfNull(true);
|
||||
// });
|
||||
// }
|
||||
BsonClassMap.RegisterClassMap<Candle>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(a => a.Key).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(a => a.CandleValueType)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<CandleValueType>(new EnumSerializer<CandleValueType>(BsonType.String)));
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<VisualMap>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(v => v.Show).SetDefaultValue(false);
|
||||
cm.MapMember(v => v.Dimension).SetDefaultValue(0);
|
||||
cm.MapMember(v => v.SerieKey).SetIgnoreIfNull(true);
|
||||
cm.MapMember(v => v.Pieces).SetDefaultValue(new List<Piece>());
|
||||
});
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LegendLayoutConfig)))
|
||||
BsonClassMap.RegisterClassMap<LegendLayoutConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Rows).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LegendLayoutRow)))
|
||||
BsonClassMap.RegisterClassMap<LegendLayoutRow>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.GrowPriority).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Columns).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LegendLayoutColumn)))
|
||||
BsonClassMap.RegisterClassMap<LegendLayoutColumn>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Key).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GrowPriority).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Label).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LegendLabel)))
|
||||
BsonClassMap.RegisterClassMap<LegendLabel>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ColorLabel).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ColorIcon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowSymbol).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconType).SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<DisplayConfigEnums.ELegendIconType>(
|
||||
new EnumSerializer<DisplayConfigEnums.ELegendIconType>(BsonType.String)));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Piece)))
|
||||
BsonClassMap.RegisterClassMap<Piece>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(p => p.Opacity).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.LineType)
|
||||
.SetDefaultValue(DisplayConfigEnums.LineType.Solid)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.LineType>(BsonType.String));
|
||||
cm.MapMember(p => p.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Symbol).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.SymbolSize).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Eq).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Neq).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Gt).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Lt).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Gte).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Lte).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LegendLayoutConfig)))
|
||||
BsonClassMap.RegisterClassMap<LegendLayoutConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Rows).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LegendLayoutRow)))
|
||||
BsonClassMap.RegisterClassMap<LegendLayoutRow>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.GrowPriority).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Columns).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LegendLayoutColumn)))
|
||||
BsonClassMap.RegisterClassMap<LegendLayoutColumn>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Key).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GrowPriority).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Label).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LegendLabel)))
|
||||
BsonClassMap.RegisterClassMap<LegendLabel>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ColorLabel).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ColorIcon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowSymbol).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IconType).SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<DisplayConfigEnums.ELegendIconType>(
|
||||
new EnumSerializer<DisplayConfigEnums.ELegendIconType>(BsonType.String)));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Piece)))
|
||||
BsonClassMap.RegisterClassMap<Piece>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(p => p.Opacity).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.LineType)
|
||||
.SetDefaultValue(DisplayConfigEnums.LineType.Solid)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.LineType>(BsonType.String));
|
||||
cm.MapMember(p => p.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Symbol).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.SymbolSize).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Eq).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Neq).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Gt).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Lt).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Gte).SetIgnoreIfNull(true);
|
||||
cm.MapMember(p => p.Lte).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,36 +4,45 @@ using MongoDB.Bson.Serialization;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that participates in entity mapping, providing header-related mapping logic.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implements the <see cref="IEntityMapContributor"/> interface to contribute mapping behavior within the entity mapping pipeline.
|
||||
/// </remarks>
|
||||
public class HeaderMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the <see cref="HeaderConfig"/> type and its nested <see cref="HeaderConfig.HeaderItem"/> type with the MongoDB BsonClassMap serializer, configuring default values and null-ignore behavior for their members. Registration is performed only if a class map for the corresponding type has not already been registered, preventing duplicate registrations.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HeaderConfig)))
|
||||
BsonClassMap.RegisterClassMap<HeaderConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.PartnerLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CompanyLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CenterLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MeddisLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UnitName).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Cameras).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Sensors).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Fullscreen).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Sounds).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Sidebar).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CurrentDateTime).SetDefaultValue(new HeaderConfig.HeaderItem())
|
||||
.SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SectionTitle).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HeaderConfig.HeaderItem)))
|
||||
BsonClassMap.RegisterClassMap<HeaderConfig.HeaderItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.LogoUrl).SetDefaultValue(() => null)
|
||||
.SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsVisible).SetDefaultValue(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HeaderConfig)))
|
||||
BsonClassMap.RegisterClassMap<HeaderConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.PartnerLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CompanyLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CenterLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MeddisLogo).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UnitName).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Cameras).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Sensors).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Fullscreen).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Sounds).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Sidebar).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CurrentDateTime).SetDefaultValue(new HeaderConfig.HeaderItem())
|
||||
.SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SectionTitle).SetDefaultValue(new HeaderConfig.HeaderItem()).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HeaderConfig.HeaderItem)))
|
||||
BsonClassMap.RegisterClassMap<HeaderConfig.HeaderItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.LogoUrl).SetDefaultValue(() => null)
|
||||
.SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsVisible).SetDefaultValue(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,8 @@
|
||||
/// </summary>
|
||||
public interface IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the object-to-object mappings used by the application.
|
||||
/// </summary>
|
||||
void RegisterMaps();
|
||||
}
|
||||
@@ -7,152 +7,161 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a map contributor for the master list entity, providing mapping logic through the <see cref="IEntityMapContributor"/> contract.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Use this contributor when defining or extending the mapping configuration associated with master list entities.
|
||||
/// </remarks>
|
||||
public class MasterListMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for domain types (such as <see cref="Element"/>, <see cref="OptionList"/>, <see cref="MasterList"/>, <see cref="Locale"/>, and their derived option lists) to control their MongoDB serialization. Each registration is performed only when no class map already exists for the type, and applies domain-specific settings including default values, null-ignore rules, discriminator naming, and custom serializers for enums, locale fields, and identifiers.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Element)))
|
||||
BsonClassMap.RegisterClassMap<Element>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.Title).SetDefaultValue(string.Empty);
|
||||
cm.GetMemberMap(c => c.IsRequired).SetDefaultValue(false);
|
||||
cm.GetMemberMap(c => c.IsList).SetDefaultValue(false);
|
||||
cm.GetMemberMap(c => c.ListName).SetDefaultValue(string.Empty);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(OptionListDetails)))
|
||||
BsonClassMap.RegisterClassMap<OptionListDetails>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.OptionType).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconDefault).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconCategory).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconColor).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Description).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(MasterList)))
|
||||
BsonClassMap.RegisterClassMap<MasterList>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.UnmapMember(c => c.ManualObservationName);
|
||||
cm.UnmapMember(c => c.AutoObservationName);
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.GetMemberMap(c => c.DefaultLocale).SetIgnoreIfNull(true).SetSerializer(
|
||||
new NullableSerializer<LocaleEnum>(new EnumSerializer<LocaleEnum>(BsonType.String))
|
||||
);
|
||||
cm.GetMemberMap(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.GetMemberMap(c => c.Description).SetDefaultValue(string.Empty);
|
||||
cm.GetMemberMap(c => c.OptionListDetails).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.CanAddElement).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.ListType)
|
||||
.SetSerializer(new EnumSerializer<MasterListType>(BsonType.String));
|
||||
cm.MapMember(c => c.Options).SetDefaultValue(new List<OptionList>());
|
||||
});
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LocaleItem)))
|
||||
BsonClassMap.RegisterClassMap<LocaleItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.Name).SetIgnoreIfNull(true);
|
||||
});
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Locale)))
|
||||
BsonClassMap.RegisterClassMap<Locale>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.Es).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Pt).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Eng).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Ca).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Zh).SetIgnoreIfNull(true);
|
||||
});
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(OptionList)))
|
||||
BsonClassMap.RegisterClassMap<OptionList>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id").SetSerializer(new NullableSerializer<ObjectId>(new ObjectIdSerializer(BsonType.ObjectId)));;
|
||||
cm.GetMemberMap(c => c.OptionType).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.LocaleItems).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconDefault).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconCategory).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconColor).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Description).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.InitDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.EndDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IsDefault).SetIgnoreIfNull(true);
|
||||
cm.SetDiscriminator(nameof(OptionList));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AltableOptionList)))
|
||||
BsonClassMap.RegisterClassMap<AltableOptionList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(VisitOptionList)))
|
||||
BsonClassMap.RegisterClassMap<VisitOptionList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AccessControlList)))
|
||||
BsonClassMap.RegisterClassMap<AccessControlList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(MobilityOptionList)))
|
||||
BsonClassMap.RegisterClassMap<MobilityOptionList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(TherapeuticCeilingList)))
|
||||
BsonClassMap.RegisterClassMap<TherapeuticCeilingList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PassiveSittingList)))
|
||||
BsonClassMap.RegisterClassMap<PassiveSittingList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(GenericList)))
|
||||
BsonClassMap.RegisterClassMap<GenericList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ProcedureList)))
|
||||
BsonClassMap.RegisterClassMap<ProcedureList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(TestList)))
|
||||
BsonClassMap.RegisterClassMap<TestList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DiagnosisList)))
|
||||
BsonClassMap.RegisterClassMap<DiagnosisList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(OriginList)))
|
||||
BsonClassMap.RegisterClassMap<OriginList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DestinationList)))
|
||||
BsonClassMap.RegisterClassMap<DestinationList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(InternalDestinationList)))
|
||||
BsonClassMap.RegisterClassMap<InternalDestinationList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(TreatmentList)))
|
||||
BsonClassMap.RegisterClassMap<TreatmentList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientStatusList)))
|
||||
BsonClassMap.RegisterClassMap<PatientStatusList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceList)))
|
||||
BsonClassMap.RegisterClassMap<ServiceList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AllergyList)))
|
||||
BsonClassMap.RegisterClassMap<AllergyList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DoctorTypeList)))
|
||||
BsonClassMap.RegisterClassMap<DoctorTypeList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DoctorList)))
|
||||
BsonClassMap.RegisterClassMap<DoctorList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(InsulationList)))
|
||||
BsonClassMap.RegisterClassMap<InsulationList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DischargeStatusList)))
|
||||
BsonClassMap.RegisterClassMap<DischargeStatusList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LanguageBarrierList)))
|
||||
BsonClassMap.RegisterClassMap<LanguageBarrierList>(cm => { cm.AutoMap(); });
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Element)))
|
||||
BsonClassMap.RegisterClassMap<Element>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.Title).SetDefaultValue(string.Empty);
|
||||
cm.GetMemberMap(c => c.IsRequired).SetDefaultValue(false);
|
||||
cm.GetMemberMap(c => c.IsList).SetDefaultValue(false);
|
||||
cm.GetMemberMap(c => c.ListName).SetDefaultValue(string.Empty);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(OptionListDetails)))
|
||||
BsonClassMap.RegisterClassMap<OptionListDetails>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.OptionType).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconDefault).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconCategory).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconColor).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Description).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(MasterList)))
|
||||
BsonClassMap.RegisterClassMap<MasterList>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.UnmapMember(c => c.ManualObservationName);
|
||||
cm.UnmapMember(c => c.AutoObservationName);
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.GetMemberMap(c => c.DefaultLocale).SetIgnoreIfNull(true).SetSerializer(
|
||||
new NullableSerializer<LocaleEnum>(new EnumSerializer<LocaleEnum>(BsonType.String))
|
||||
);
|
||||
cm.GetMemberMap(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.GetMemberMap(c => c.Description).SetDefaultValue(string.Empty);
|
||||
cm.GetMemberMap(c => c.OptionListDetails).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.CanAddElement).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.ListType)
|
||||
.SetSerializer(new EnumSerializer<MasterListType>(BsonType.String));
|
||||
cm.MapMember(c => c.Options).SetDefaultValue(new List<OptionList>());
|
||||
});
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LocaleItem)))
|
||||
BsonClassMap.RegisterClassMap<LocaleItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.Name).SetIgnoreIfNull(true);
|
||||
});
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Locale)))
|
||||
BsonClassMap.RegisterClassMap<Locale>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.Es).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Pt).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Eng).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Ca).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Zh).SetIgnoreIfNull(true);
|
||||
});
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(OptionList)))
|
||||
BsonClassMap.RegisterClassMap<OptionList>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id").SetSerializer(new NullableSerializer<ObjectId>(new ObjectIdSerializer(BsonType.ObjectId)));;
|
||||
cm.GetMemberMap(c => c.OptionType).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.LocaleItems).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconDefault).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconCategory).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IconColor).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Color).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Description).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.InitDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.EndDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.IsDefault).SetIgnoreIfNull(true);
|
||||
cm.SetDiscriminator(nameof(OptionList));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AltableOptionList)))
|
||||
BsonClassMap.RegisterClassMap<AltableOptionList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(VisitOptionList)))
|
||||
BsonClassMap.RegisterClassMap<VisitOptionList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AccessControlList)))
|
||||
BsonClassMap.RegisterClassMap<AccessControlList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(MobilityOptionList)))
|
||||
BsonClassMap.RegisterClassMap<MobilityOptionList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(TherapeuticCeilingList)))
|
||||
BsonClassMap.RegisterClassMap<TherapeuticCeilingList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PassiveSittingList)))
|
||||
BsonClassMap.RegisterClassMap<PassiveSittingList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(GenericList)))
|
||||
BsonClassMap.RegisterClassMap<GenericList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ProcedureList)))
|
||||
BsonClassMap.RegisterClassMap<ProcedureList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(TestList)))
|
||||
BsonClassMap.RegisterClassMap<TestList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DiagnosisList)))
|
||||
BsonClassMap.RegisterClassMap<DiagnosisList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(OriginList)))
|
||||
BsonClassMap.RegisterClassMap<OriginList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DestinationList)))
|
||||
BsonClassMap.RegisterClassMap<DestinationList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(InternalDestinationList)))
|
||||
BsonClassMap.RegisterClassMap<InternalDestinationList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(TreatmentList)))
|
||||
BsonClassMap.RegisterClassMap<TreatmentList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientStatusList)))
|
||||
BsonClassMap.RegisterClassMap<PatientStatusList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceList)))
|
||||
BsonClassMap.RegisterClassMap<ServiceList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(AllergyList)))
|
||||
BsonClassMap.RegisterClassMap<AllergyList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DoctorTypeList)))
|
||||
BsonClassMap.RegisterClassMap<DoctorTypeList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DoctorList)))
|
||||
BsonClassMap.RegisterClassMap<DoctorList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(InsulationList)))
|
||||
BsonClassMap.RegisterClassMap<InsulationList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DischargeStatusList)))
|
||||
BsonClassMap.RegisterClassMap<DischargeStatusList>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(LanguageBarrierList)))
|
||||
BsonClassMap.RegisterClassMap<LanguageBarrierList>(cm => { cm.AutoMap(); });
|
||||
}
|
||||
}
|
||||
@@ -4,25 +4,34 @@ using MongoDB.Bson.Serialization;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a map contributor responsible for contributing mapping logic for notice control entities.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implements the <see cref="IEntityMapContributor"/> interface to participate in the entity mapping process.
|
||||
/// </remarks>
|
||||
public class NoticeControlMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the <see cref="Notice"/>, <see cref="StaffInfo"/>, and <see cref="MedicalStaffConfig"/> types if they have not already been registered, configuring element names, automatic mapping, and null-ignore behavior where applicable.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Notice)))
|
||||
BsonClassMap.RegisterClassMap<Notice>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(StaffInfo)))
|
||||
BsonClassMap.RegisterClassMap<StaffInfo>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(MedicalStaffConfig)))
|
||||
BsonClassMap.RegisterClassMap<MedicalStaffConfig>(cm =>
|
||||
{
|
||||
cm.MapMember(c => c.HasTeams).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StaffAmount).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Notice)))
|
||||
BsonClassMap.RegisterClassMap<Notice>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(StaffInfo)))
|
||||
BsonClassMap.RegisterClassMap<StaffInfo>(cm => { cm.AutoMap(); });
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(MedicalStaffConfig)))
|
||||
BsonClassMap.RegisterClassMap<MedicalStaffConfig>(cm =>
|
||||
{
|
||||
cm.MapMember(c => c.HasTeams).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StaffAmount).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,24 +4,33 @@ using MongoDB.Bson.Serialization;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that participates in entity mapping for observation units by implementing the <see cref="IEntityMapContributor"/> contract.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Used to register or supply mapping logic specific to observation unit entities within the entity mapping framework.
|
||||
/// </remarks>
|
||||
public class ObsUnitMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for <see cref="ConfigUnits"/> and <see cref="ConfigUnitItem"/> types if they have not already been registered, configuring how their members are serialized to MongoDB documents.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConfigUnits)))
|
||||
BsonClassMap.RegisterClassMap<ConfigUnits>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id").SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Items).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConfigUnitItem)))
|
||||
BsonClassMap.RegisterClassMap<ConfigUnitItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Value).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConfigUnits)))
|
||||
BsonClassMap.RegisterClassMap<ConfigUnits>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id").SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Items).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConfigUnitItem)))
|
||||
BsonClassMap.RegisterClassMap<ConfigUnitItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Value).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -11,279 +11,288 @@ using static adas_core.Domain.Models.GroupedObservation;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that provides entity mapping logic for observations.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implements the <see cref="IEntityMapContributor"/> interface to participate in the entity mapping process.
|
||||
/// </remarks>
|
||||
public class ObservationMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the observation-related domain types used by the application. Each registration is guarded by an <see cref="BsonClassMap.IsClassMapRegistered"/> check so the method is safe to invoke multiple times, configuring element names, ignoring null members, unmapping non-persisted members, and supplying custom enum and complex-object serializers where required.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(BasePatientObservation)))
|
||||
BsonClassMap.RegisterClassMap<BasePatientObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientId).SetElementName("patientid");
|
||||
cm.MapMember(c => c.UserId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ClinicalEpisode).SetIgnoreIfNull(true);
|
||||
|
||||
cm.UnmapMember(c => c.Patient);
|
||||
cm.MapMember(c => c.SystemId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CodingSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ParentData).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.Time);
|
||||
cm.MapMember(c => c.EndTime).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Units).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.CheckObservations);
|
||||
|
||||
cm.UnmapMember(c => c.CreateObservation);
|
||||
|
||||
|
||||
cm.MapMember(c => c.PatientId).SetElementName("patientid");
|
||||
cm.MapMember(c => c.EndTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(BasePatientObservationValue)))
|
||||
BsonClassMap.RegisterClassMap<BasePatientObservationValue>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Value)
|
||||
.SetDefaultValue(new object())
|
||||
.SetSerializer(new ComplexObjectValueTypeSerializer());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientObservation)))
|
||||
BsonClassMap.RegisterClassMap<PatientObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Max).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Min).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxWarn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MinWarn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.WarnColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AlertColor).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.ShowOnExpired);
|
||||
cm.MapMember(c => c.InsertMode)
|
||||
.SetDefaultValue(ObservationEnum.InsertMode.Auto)
|
||||
.SetSerializer(new EnumSerializer<ObservationEnum.InsertMode>(BsonType.String));
|
||||
cm.UnmapMember(c => c.Persist);
|
||||
cm.MapMember(c => c.ColorOnExpired).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.MessageTime);
|
||||
|
||||
cm.MapMember(c => c.Result).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Status)
|
||||
.SetDefaultValue(StatusEnum.Type.Ok)
|
||||
.SetSerializer(new EnumSerializer<StatusEnum.Type>(BsonType.String));
|
||||
cm.UnmapMember(c => c.Level);
|
||||
cm.UnmapMember(c => c.Expires);
|
||||
cm.MapMember(c => c.Expired).SetDefaultValue(false);
|
||||
cm.UnmapMember(c => c.UiConfiguration);
|
||||
cm.UnmapMember(c => c.Alarm);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ParentDataClass)))
|
||||
BsonClassMap.RegisterClassMap<ParentDataClass>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.CodingSystem).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Name).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ObservationData)))
|
||||
BsonClassMap.RegisterClassMap<ObservationData>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.CodingSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Text).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Time).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Value).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ObservationsRequest)))
|
||||
BsonClassMap.RegisterClassMap<ObservationsRequest>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.PatientNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationNames).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StartTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PageNumber).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.PageSize).SetDefaultValue(10);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DemoConfig)))
|
||||
BsonClassMap.RegisterClassMap<DemoConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.ValueOption)
|
||||
.SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConfigObservation)))
|
||||
BsonClassMap.RegisterClassMap<ConfigObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.DemoConfig).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConfigObservation)))
|
||||
BsonClassMap.RegisterClassMap<ConfigObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CodingSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OriginalName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ParentCode).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ParentCodingSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ParentName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Units).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ArrowType)
|
||||
.SetSerializer(new EnumSerializer<ObservationEnum.ArrowType>(BsonType.String))
|
||||
.SetDefaultValue(ObservationEnum.ArrowType.Default);
|
||||
cm.MapMember(c => c.ShowArrow).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ShowValue).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ForceUnits).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.MinAlert).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxAlert).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxWarn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MinWarn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.WarnColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AlertColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AlertValues).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.WarningValues).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ForceWarn).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.ForceAlert).SetDefaultValue(false);
|
||||
|
||||
cm.MapMember(c => c.Alert).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Expires).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowOnExpired).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(c => c.Persist).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ColorOnExpired).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RetentionPolicy)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<RetentionPolicy>(new EnumSerializer<RetentionPolicy>(BsonType.String)));
|
||||
|
||||
cm.MapMember(c => c.RetentionPolicyValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.LevelCondition).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Grouped).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UiConfiguration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Alarm).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Description).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequiredValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Preconditions).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CheckObservations).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.CreateObservation).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.InsertMode)
|
||||
.SetDefaultValue(ObservationEnum.InsertMode.Auto)
|
||||
.SetSerializer(new EnumSerializer<ObservationEnum.InsertMode>(BsonType.String));
|
||||
|
||||
cm.MapMember(c => c.TimeFromMessageTime).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(c => c.ColorRanges).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConfigObservation.ColorRange)))
|
||||
BsonClassMap.RegisterClassMap<ConfigObservation.ColorRange>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(s => s.ValueType)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<ObservationEnum.ValueType>(
|
||||
new EnumSerializer<ObservationEnum.ValueType>(BsonType.String)));
|
||||
cm.MapMember(s => s.Min).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.Max).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.MatchText).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.MatchBoolean).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.MinDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.MaxDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.Label).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(GroupedObservation)))
|
||||
BsonClassMap.RegisterClassMap<GroupedObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.PatientId);
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Group).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Observations).SetDefaultValue(new List<GroupedObservationObs>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(GroupedObservationObs)))
|
||||
BsonClassMap.RegisterClassMap<GroupedObservationObs>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.First).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Last).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Min).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Max).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.MinAlert).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxAlert).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Average).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Sum).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Count).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HalfHour).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.LastFilled).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Time);
|
||||
cm.MapMember(c => c.Shift).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShiftDate);
|
||||
cm.MapMember(c => c.IsFilled);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(GroupedObservationObsValue)))
|
||||
BsonClassMap.RegisterClassMap<GroupedObservationObsValue>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(StatusEnum.Type.Ok)
|
||||
.SetSerializer(new EnumSerializer<StatusEnum.Type>(BsonType.String));
|
||||
cm.MapMember(c => c.Value);
|
||||
cm.MapMember(c => c.Time).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PredictMedicationObservation)))
|
||||
BsonClassMap.RegisterClassMap<PredictMedicationObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.MedicineText).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.DegreeSimilarity);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ObservationTextRule)))
|
||||
BsonClassMap.RegisterClassMap<ObservationTextRule>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.ValueType)
|
||||
.SetDefaultValue(ObservationEnum.ValueType.String)
|
||||
.SetSerializer(new EnumSerializer<ObservationEnum.ValueType>(BsonType.String));
|
||||
cm.MapMember(c => c.Value).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MatchText).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MatchBoolean).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MatchNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MatchDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Label).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MinDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MinNum).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxNum).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConditionsConfig)))
|
||||
BsonClassMap.RegisterClassMap<ConditionsConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Condition).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FieldCondition).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(BasePatientObservation)))
|
||||
BsonClassMap.RegisterClassMap<BasePatientObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientId).SetElementName("patientid");
|
||||
cm.MapMember(c => c.UserId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ClinicalEpisode).SetIgnoreIfNull(true);
|
||||
|
||||
cm.UnmapMember(c => c.Patient);
|
||||
cm.MapMember(c => c.SystemId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CodingSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ParentData).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.Time);
|
||||
cm.MapMember(c => c.EndTime).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Units).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.CheckObservations);
|
||||
|
||||
cm.UnmapMember(c => c.CreateObservation);
|
||||
|
||||
|
||||
cm.MapMember(c => c.PatientId).SetElementName("patientid");
|
||||
cm.MapMember(c => c.EndTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(BasePatientObservationValue)))
|
||||
BsonClassMap.RegisterClassMap<BasePatientObservationValue>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Value)
|
||||
.SetDefaultValue(new object())
|
||||
.SetSerializer(new ComplexObjectValueTypeSerializer());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientObservation)))
|
||||
BsonClassMap.RegisterClassMap<PatientObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Max).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Min).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxWarn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MinWarn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.WarnColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AlertColor).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.ShowOnExpired);
|
||||
cm.MapMember(c => c.InsertMode)
|
||||
.SetDefaultValue(ObservationEnum.InsertMode.Auto)
|
||||
.SetSerializer(new EnumSerializer<ObservationEnum.InsertMode>(BsonType.String));
|
||||
cm.UnmapMember(c => c.Persist);
|
||||
cm.MapMember(c => c.ColorOnExpired).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.MessageTime);
|
||||
|
||||
cm.MapMember(c => c.Result).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Status)
|
||||
.SetDefaultValue(StatusEnum.Type.Ok)
|
||||
.SetSerializer(new EnumSerializer<StatusEnum.Type>(BsonType.String));
|
||||
cm.UnmapMember(c => c.Level);
|
||||
cm.UnmapMember(c => c.Expires);
|
||||
cm.MapMember(c => c.Expired).SetDefaultValue(false);
|
||||
cm.UnmapMember(c => c.UiConfiguration);
|
||||
cm.UnmapMember(c => c.Alarm);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ParentDataClass)))
|
||||
BsonClassMap.RegisterClassMap<ParentDataClass>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.GetMemberMap(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.CodingSystem).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Name).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ObservationData)))
|
||||
BsonClassMap.RegisterClassMap<ObservationData>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.CodingSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Text).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Time).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Value).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ObservationsRequest)))
|
||||
BsonClassMap.RegisterClassMap<ObservationsRequest>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.PatientNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationNames).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StartTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PageNumber).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.PageSize).SetDefaultValue(10);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(DemoConfig)))
|
||||
BsonClassMap.RegisterClassMap<DemoConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.ValueOption)
|
||||
.SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConfigObservation)))
|
||||
BsonClassMap.RegisterClassMap<ConfigObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.DemoConfig).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConfigObservation)))
|
||||
BsonClassMap.RegisterClassMap<ConfigObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CodingSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OriginalName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ParentCode).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ParentCodingSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ParentName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Units).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ArrowType)
|
||||
.SetSerializer(new EnumSerializer<ObservationEnum.ArrowType>(BsonType.String))
|
||||
.SetDefaultValue(ObservationEnum.ArrowType.Default);
|
||||
cm.MapMember(c => c.ShowArrow).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ShowValue).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ForceUnits).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.MinAlert).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxAlert).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxWarn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MinWarn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.WarnColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AlertColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AlertValues).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.WarningValues).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ForceWarn).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.ForceAlert).SetDefaultValue(false);
|
||||
|
||||
cm.MapMember(c => c.Alert).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Expires).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowOnExpired).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(c => c.Persist).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ColorOnExpired).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RetentionPolicy)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<RetentionPolicy>(new EnumSerializer<RetentionPolicy>(BsonType.String)));
|
||||
|
||||
cm.MapMember(c => c.RetentionPolicyValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.LevelCondition).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Grouped).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UiConfiguration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Alarm).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Description).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequiredValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Preconditions).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CheckObservations).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.CreateObservation).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.InsertMode)
|
||||
.SetDefaultValue(ObservationEnum.InsertMode.Auto)
|
||||
.SetSerializer(new EnumSerializer<ObservationEnum.InsertMode>(BsonType.String));
|
||||
|
||||
cm.MapMember(c => c.TimeFromMessageTime).SetIgnoreIfDefault(true);
|
||||
cm.MapMember(c => c.ColorRanges).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConfigObservation.ColorRange)))
|
||||
BsonClassMap.RegisterClassMap<ConfigObservation.ColorRange>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(s => s.ValueType)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<ObservationEnum.ValueType>(
|
||||
new EnumSerializer<ObservationEnum.ValueType>(BsonType.String)));
|
||||
cm.MapMember(s => s.Min).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.Max).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.MatchText).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.MatchBoolean).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.MinDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.MaxDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.Color).SetIgnoreIfNull(true);
|
||||
cm.MapMember(s => s.Label).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(GroupedObservation)))
|
||||
BsonClassMap.RegisterClassMap<GroupedObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.PatientId);
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Group).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Observations).SetDefaultValue(new List<GroupedObservationObs>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(GroupedObservationObs)))
|
||||
BsonClassMap.RegisterClassMap<GroupedObservationObs>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.First).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Last).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Min).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Max).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.MinAlert).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxAlert).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Average).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Sum).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Count).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HalfHour).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.LastFilled).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Time);
|
||||
cm.MapMember(c => c.Shift).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShiftDate);
|
||||
cm.MapMember(c => c.IsFilled);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(GroupedObservationObsValue)))
|
||||
BsonClassMap.RegisterClassMap<GroupedObservationObsValue>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(StatusEnum.Type.Ok)
|
||||
.SetSerializer(new EnumSerializer<StatusEnum.Type>(BsonType.String));
|
||||
cm.MapMember(c => c.Value);
|
||||
cm.MapMember(c => c.Time).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PredictMedicationObservation)))
|
||||
BsonClassMap.RegisterClassMap<PredictMedicationObservation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.MedicineText).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.DegreeSimilarity);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ObservationTextRule)))
|
||||
BsonClassMap.RegisterClassMap<ObservationTextRule>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.ValueType)
|
||||
.SetDefaultValue(ObservationEnum.ValueType.String)
|
||||
.SetSerializer(new EnumSerializer<ObservationEnum.ValueType>(BsonType.String));
|
||||
cm.MapMember(c => c.Value).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MatchText).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MatchBoolean).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MatchNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MatchDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Label).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MinDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MinNum).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.MaxNum).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ConditionsConfig)))
|
||||
BsonClassMap.RegisterClassMap<ConditionsConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Condition).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FieldCondition).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -9,237 +9,243 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that participates in the mapping configuration of the <see cref="Patient"/> entity by implementing the <see cref="IEntityMapContributor"/> interface.
|
||||
/// </summary>
|
||||
public class PatientMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the domain model types (Patient, Person, PatientLocation, and related entities) to configure their MongoDB serialization, including auto-mapping, null-value handling, enum string serialization, dictionary serialization, and ID member mapping. Skips registration for types that already have a registered class map.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HistoricalLocation)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<HistoricalLocation>(cm =>
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HistoricalLocation)))
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.AdmTime);
|
||||
cm.MapMember(c => c.PatientLocation);
|
||||
});
|
||||
BsonClassMap.RegisterClassMap<HistoricalLocation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.AdmTime);
|
||||
cm.MapMember(c => c.PatientLocation);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Patient)))
|
||||
BsonClassMap.RegisterClassMap<Patient>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.GetMemberMap(c => c.PatientNumber).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PatientId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.AdmTime).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DischargeStatus).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Altable).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Origin).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.OriginAux).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Diagnosis).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DiagnosisAux).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Visits).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.AccessControl).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Insulation).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PatientStatus).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Mobility).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.TherapeuticCeiling).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Procedures).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Tests).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Treatment).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Doctors).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Allergies).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.LanguageBarrier).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PassiveSitting).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DisTime).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Person).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.AttendingDoctor).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.LastObservationDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.CreationDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.UpdateDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.ArchiveDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PointOfCareId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.UnitId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.HistoricalLocations).SetIgnoreIfNull(true);
|
||||
|
||||
// No mapear estos campos
|
||||
cm.UnmapMember(c => c.Bed);
|
||||
cm.UnmapMember(c => c.UnitString);
|
||||
cm.UnmapMember(c => c.Room);
|
||||
cm.UnmapMember(c => c.PointOfCare);
|
||||
cm.UnmapMember(c => c.Location);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Person)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<Person>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.LastName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FirstName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SecondName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BirthDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Language).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.Gender)
|
||||
.SetDefaultValue(PatientEnum.Gender.Unknown)
|
||||
.SetSerializer(new EnumSerializer<PatientEnum.Gender>(BsonType.String));
|
||||
|
||||
cm.MapMember(c => c.Ids).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.HistoricalIds)
|
||||
.SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<HistoricalId>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Time).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PatientIds)
|
||||
.SetSerializer(
|
||||
new DictionaryInterfaceImplementerSerializer<Dictionary<string, string>, string, string>(
|
||||
DictionaryRepresentation.Document))
|
||||
.SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientLocation)))
|
||||
BsonClassMap.RegisterClassMap<PatientLocation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.UnitName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Bed).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Room).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientLocationAction)))
|
||||
BsonClassMap.RegisterClassMap<PatientLocationAction>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Location).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Action)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<ActionsEnum.ResourceAction>(
|
||||
new EnumSerializer<ActionsEnum.ResourceAction>(BsonType.String)));
|
||||
});
|
||||
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientIncomeData)))
|
||||
BsonClassMap.RegisterClassMap<PatientIncomeData>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Diagnosis).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DiagnosisAux).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Origin).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OriginAux).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AdmTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientIcca)))
|
||||
BsonClassMap.RegisterClassMap<PatientIcca>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Location).SetDefaultValue(new PatientLocation(string.Empty, string.Empty));
|
||||
cm.MapMember(c => c.PatientNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PatientId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AdmitTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientAllergiesValue)))
|
||||
BsonClassMap.RegisterClassMap<PatientAllergiesValue>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Notes).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Value).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientIntravenousLinesValue)))
|
||||
BsonClassMap.RegisterClassMap<PatientIntravenousLinesValue>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Duration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Action).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Location).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.InsertTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RemoveTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientDiagnosis)))
|
||||
BsonClassMap.RegisterClassMap<PatientDiagnosis>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.SetIgnoreExtraElements(true);
|
||||
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientId);
|
||||
cm.MapMember(c => c.Time);
|
||||
cm.MapMember(c => c.UpdateDate).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.MessageTime);
|
||||
cm.MapMember(c => c.CodingSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Description).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Label).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.State).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Category).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StartTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndTime).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.DiagnosisCode);
|
||||
cm.UnmapMember(c => c.DiagnosisSystem);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientDrainagesValue)))
|
||||
BsonClassMap.RegisterClassMap<PatientDrainagesValue>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Location).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Volume).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Height).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientCarePlan)))
|
||||
BsonClassMap.RegisterClassMap<PatientCarePlan>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientId);
|
||||
cm.MapMember(c => c.PointOfCareId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PatientNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UserId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CarePlan).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Description).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Time).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.Action)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<ActionsEnum.CrudAction>(
|
||||
new EnumSerializer<ActionsEnum.CrudAction>(BsonType.String)));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Admission)))
|
||||
BsonClassMap.RegisterClassMap<Admission>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.UnmapMember(c => c.PatientLocation);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Discharge)))
|
||||
BsonClassMap.RegisterClassMap<Discharge>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.UnmapMember(c => c.Patient);
|
||||
cm.UnmapMember(c => c.PatientLocation);
|
||||
cm.MapMember(c => c.MedicalDischarge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AdminDischarge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.NurseDischarge).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Patient)))
|
||||
BsonClassMap.RegisterClassMap<Patient>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.GetMemberMap(c => c.PatientNumber).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PatientId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.AdmTime).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DischargeStatus).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Altable).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Origin).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.OriginAux).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Diagnosis).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DiagnosisAux).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Visits).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.AccessControl).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Insulation).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PatientStatus).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Mobility).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.TherapeuticCeiling).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Procedures).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Tests).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Treatment).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Doctors).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Allergies).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.LanguageBarrier).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PassiveSitting).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DisTime).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Person).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.AttendingDoctor).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.LastObservationDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.CreationDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.UpdateDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.ArchiveDate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PointOfCareId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.UnitId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.HistoricalLocations).SetIgnoreIfNull(true);
|
||||
|
||||
// No mapear estos campos
|
||||
cm.UnmapMember(c => c.Bed);
|
||||
cm.UnmapMember(c => c.UnitString);
|
||||
cm.UnmapMember(c => c.Room);
|
||||
cm.UnmapMember(c => c.PointOfCare);
|
||||
cm.UnmapMember(c => c.Location);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Person)))
|
||||
{
|
||||
BsonClassMap.RegisterClassMap<Person>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.LastName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FirstName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SecondName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BirthDate).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Language).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.Gender)
|
||||
.SetDefaultValue(PatientEnum.Gender.Unknown)
|
||||
.SetSerializer(new EnumSerializer<PatientEnum.Gender>(BsonType.String));
|
||||
|
||||
cm.MapMember(c => c.Ids).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.HistoricalIds)
|
||||
.SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
BsonClassMap.RegisterClassMap<HistoricalId>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Time).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PatientIds)
|
||||
.SetSerializer(
|
||||
new DictionaryInterfaceImplementerSerializer<Dictionary<string, string>, string, string>(
|
||||
DictionaryRepresentation.Document))
|
||||
.SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientLocation)))
|
||||
BsonClassMap.RegisterClassMap<PatientLocation>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.UnitName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Bed).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Room).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientLocationAction)))
|
||||
BsonClassMap.RegisterClassMap<PatientLocationAction>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Location).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Action)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<ActionsEnum.ResourceAction>(
|
||||
new EnumSerializer<ActionsEnum.ResourceAction>(BsonType.String)));
|
||||
});
|
||||
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientIncomeData)))
|
||||
BsonClassMap.RegisterClassMap<PatientIncomeData>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Diagnosis).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DiagnosisAux).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Origin).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OriginAux).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AdmTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientIcca)))
|
||||
BsonClassMap.RegisterClassMap<PatientIcca>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Location).SetDefaultValue(new PatientLocation(string.Empty, string.Empty));
|
||||
cm.MapMember(c => c.PatientNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PatientId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AdmitTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientAllergiesValue)))
|
||||
BsonClassMap.RegisterClassMap<PatientAllergiesValue>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Notes).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Value).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientIntravenousLinesValue)))
|
||||
BsonClassMap.RegisterClassMap<PatientIntravenousLinesValue>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Duration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Action).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Location).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.InsertTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RemoveTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientDiagnosis)))
|
||||
BsonClassMap.RegisterClassMap<PatientDiagnosis>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.SetIgnoreExtraElements(true);
|
||||
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientId);
|
||||
cm.MapMember(c => c.Time);
|
||||
cm.MapMember(c => c.UpdateDate).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.MessageTime);
|
||||
cm.MapMember(c => c.CodingSystem).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Description).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Label).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.State).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Category).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StartTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndTime).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.DiagnosisCode);
|
||||
cm.UnmapMember(c => c.DiagnosisSystem);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientDrainagesValue)))
|
||||
BsonClassMap.RegisterClassMap<PatientDrainagesValue>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Type).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Location).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Volume).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Height).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientCarePlan)))
|
||||
BsonClassMap.RegisterClassMap<PatientCarePlan>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientId);
|
||||
cm.MapMember(c => c.PointOfCareId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PatientNumber).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UserId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.CarePlan).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Description).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Time).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.Action)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<ActionsEnum.CrudAction>(
|
||||
new EnumSerializer<ActionsEnum.CrudAction>(BsonType.String)));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Admission)))
|
||||
BsonClassMap.RegisterClassMap<Admission>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.UnmapMember(c => c.PatientLocation);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Discharge)))
|
||||
BsonClassMap.RegisterClassMap<Discharge>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.UnmapMember(c => c.Patient);
|
||||
cm.UnmapMember(c => c.PatientLocation);
|
||||
cm.MapMember(c => c.MedicalDischarge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AdminDischarge).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.NurseDischarge).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -9,88 +9,97 @@ using LightBeacon = adas_core.Domain.Models.MongoModels.LightBeacon;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Provides a proof-of-concept implementation of the <see cref="IEntityMapContributor"/> interface for contributing entity mapping logic.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class serves as a demonstrative or experimental implementation of entity map contribution behavior, intended to validate the contract defined by <see cref="IEntityMapContributor"/>.
|
||||
/// </remarks>
|
||||
public class PoCMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for PointOfCare-related types (PointOfCare, PointOfCareConfiguration, PoCMapping, PoCMappingItem, and PoCSettings) with the MongoDB driver, configuring serialization options such as element names, default values, null handling, and enum string serialization. Each registration is performed only if a class map for the type has not already been registered.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PointOfCare)))
|
||||
BsonClassMap.RegisterClassMap<PointOfCare>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Room).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Bed).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Hall).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UnitId);
|
||||
cm.MapMember(c => c.Configuration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Status)
|
||||
.SetSerializer(new EnumSerializer<StatusEnum.PointOfCare>(BsonType.String));
|
||||
cm.MapMember(c => c.AdmissionId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsActive).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsVisible).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.UnitName);
|
||||
cm.UnmapMember(c => c.Unit);
|
||||
cm.UnmapMember(c => c.Location);
|
||||
cm.UnmapMember(c => c.Observations);
|
||||
cm.UnmapMember(c => c.HasPatient);
|
||||
cm.UnmapMember(c => c.Patientid);
|
||||
cm.UnmapMember(c => c.Patient);
|
||||
cm.UnmapMember(c => c.Admission);
|
||||
|
||||
});
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PointOfCareConfiguration)))
|
||||
BsonClassMap.RegisterClassMap<PointOfCareConfiguration>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.BeaconIdList)
|
||||
.SetDefaultValue(new List<ObjectId>());
|
||||
cm.MapMember(c => c.CameraIdList)
|
||||
.SetDefaultValue(new List<ObjectId>());
|
||||
cm.MapMember(c => c.RelayIdList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Id).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.BeaconList)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
|
||||
cm.MapMember(c => c.CameraList)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
|
||||
cm.MapMember(c => c.RelayList)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PoCMapping)))
|
||||
BsonClassMap.RegisterClassMap<PoCMapping>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PointOfCares).SetDefaultValue(new List<PoCMappingItem>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PoCMappingItem)))
|
||||
BsonClassMap.RegisterClassMap<PoCMappingItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.NewPoC).SetElementName("new");
|
||||
cm.MapMember(c => c.OriginalPoC).SetElementName("original");
|
||||
cm.MapMember(c => c.Beds).SetDefaultValue(new List<List<string>>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PoCSettings)))
|
||||
BsonClassMap.RegisterClassMap<PoCSettings>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientLocation).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ManualRelayStatus)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<RelayEnum.Status>(
|
||||
new EnumSerializer<RelayEnum.Status>(BsonType.String)));
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PointOfCare)))
|
||||
BsonClassMap.RegisterClassMap<PointOfCare>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Room).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Bed).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Hall).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UnitId);
|
||||
cm.MapMember(c => c.Configuration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Status)
|
||||
.SetSerializer(new EnumSerializer<StatusEnum.PointOfCare>(BsonType.String));
|
||||
cm.MapMember(c => c.AdmissionId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsActive).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsVisible).SetIgnoreIfNull(true);
|
||||
cm.UnmapMember(c => c.UnitName);
|
||||
cm.UnmapMember(c => c.Unit);
|
||||
cm.UnmapMember(c => c.Location);
|
||||
cm.UnmapMember(c => c.Observations);
|
||||
cm.UnmapMember(c => c.HasPatient);
|
||||
cm.UnmapMember(c => c.Patientid);
|
||||
cm.UnmapMember(c => c.Patient);
|
||||
cm.UnmapMember(c => c.Admission);
|
||||
|
||||
});
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PointOfCareConfiguration)))
|
||||
BsonClassMap.RegisterClassMap<PointOfCareConfiguration>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.BeaconIdList)
|
||||
.SetDefaultValue(new List<ObjectId>());
|
||||
cm.MapMember(c => c.CameraIdList)
|
||||
.SetDefaultValue(new List<ObjectId>());
|
||||
cm.MapMember(c => c.RelayIdList).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Id).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.BeaconList)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
|
||||
cm.MapMember(c => c.CameraList)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
|
||||
cm.MapMember(c => c.RelayList)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetIsRequired(false);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PoCMapping)))
|
||||
BsonClassMap.RegisterClassMap<PoCMapping>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PointOfCares).SetDefaultValue(new List<PoCMappingItem>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PoCMappingItem)))
|
||||
BsonClassMap.RegisterClassMap<PoCMappingItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.NewPoC).SetElementName("new");
|
||||
cm.MapMember(c => c.OriginalPoC).SetElementName("original");
|
||||
cm.MapMember(c => c.Beds).SetDefaultValue(new List<List<string>>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PoCSettings)))
|
||||
BsonClassMap.RegisterClassMap<PoCSettings>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientLocation).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ManualRelayStatus)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<RelayEnum.Status>(
|
||||
new EnumSerializer<RelayEnum.Status>(BsonType.String)));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,9 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a contributor that provides mapping logic for pump-related entities within an entity mapping context.
|
||||
/// </summary>
|
||||
public class PumpMapContributor : IEntityMapContributor
|
||||
{
|
||||
public void RegisterMaps()
|
||||
|
||||
@@ -7,42 +7,49 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an entity map contributor that relays or forwards mapping contributions from an underlying source.
|
||||
/// Implements the <see cref="IEntityMapContributor"/> contract to participate in entity mapping workflows.
|
||||
/// </summary>
|
||||
public class RelayContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the BSON class map for the <see cref="Relay"/> type, defining how its properties are serialized and stored in MongoDB. The registration is performed only when no class map is already registered for the type, and it configures default values, string-based enum serialization, and null-ignoring behavior for optional members.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Relay)))
|
||||
BsonClassMap.RegisterClassMap<Relay>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(RelayEnum.Type.Door)
|
||||
.SetSerializer(new EnumSerializer<RelayEnum.Type>(BsonType.String));
|
||||
cm.MapMember(c => c.Driver).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Ip).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Port).SetDefaultValue(0);
|
||||
cm.MapMember(c => c.RelayNumber).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.RelayName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Total).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.RefreshTime).SetDefaultValue(60);
|
||||
cm.MapMember(c => c.Open).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.Status)
|
||||
.SetDefaultValue(RelayEnum.Status.NotInitialized)
|
||||
.SetSerializer(new EnumSerializer<RelayEnum.Status>(BsonType.String));
|
||||
cm.MapMember(c => c.Username).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Password).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Mode)
|
||||
.SetDefaultValue(RelayEnum.Mode.OpenedOnClosedOff)
|
||||
.SetSerializer(new EnumSerializer<RelayEnum.Mode>(BsonType.String));
|
||||
cm.MapMember(c => c.RebootDelay).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Cache).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.InUse).SetIgnoreIfNull(true).SetIsRequired(false);
|
||||
cm.MapMember(c => c.ManualRelayStatus)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<RelayEnum.Status>(
|
||||
new EnumSerializer<RelayEnum.Status>(BsonType.String)));
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Relay)))
|
||||
BsonClassMap.RegisterClassMap<Relay>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(RelayEnum.Type.Door)
|
||||
.SetSerializer(new EnumSerializer<RelayEnum.Type>(BsonType.String));
|
||||
cm.MapMember(c => c.Driver).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Ip).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Port).SetDefaultValue(0);
|
||||
cm.MapMember(c => c.RelayNumber).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.RelayName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Total).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.RefreshTime).SetDefaultValue(60);
|
||||
cm.MapMember(c => c.Open).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.Status)
|
||||
.SetDefaultValue(RelayEnum.Status.NotInitialized)
|
||||
.SetSerializer(new EnumSerializer<RelayEnum.Status>(BsonType.String));
|
||||
cm.MapMember(c => c.Username).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Password).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Mode)
|
||||
.SetDefaultValue(RelayEnum.Mode.OpenedOnClosedOff)
|
||||
.SetSerializer(new EnumSerializer<RelayEnum.Mode>(BsonType.String));
|
||||
cm.MapMember(c => c.RebootDelay).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Cache).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.InUse).SetIgnoreIfNull(true).SetIsRequired(false);
|
||||
cm.MapMember(c => c.ManualRelayStatus)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<RelayEnum.Status>(
|
||||
new EnumSerializer<RelayEnum.Status>(BsonType.String)));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -7,85 +7,91 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Provides row-level mapping contributions to the entity mapping process by implementing the IEntityMapContributor interface.
|
||||
/// </summary>
|
||||
public class RowMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for <see cref="RowBoxLayout"/>, <see cref="RowDetailsConfig"/>, and <see cref="ObservationRowBoxLayout"/>, configuring default values, enum string serialization, and null-ignoring behavior for nullable members. Each map is registered only if no class map has already been registered for the corresponding type.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(RowBoxLayout)))
|
||||
BsonClassMap.RegisterClassMap<RowBoxLayout>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1D);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.CellType.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String));
|
||||
cm.MapMember(c => c.SubType)
|
||||
.SetDefaultValue(DisplayConfigEnums.WebDisplayCellSubtype.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.WebDisplayCellSubtype>(BsonType.String));
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Observations)
|
||||
.SetDefaultValue(new List<ObservationRowBoxLayout>());
|
||||
cm.MapMember(c => c.Direction)
|
||||
.SetDefaultValue(DisplayConfigEnums.DirectionEnum.Row)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.DirectionEnum>(BsonType.String));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(RowDetailsConfig)))
|
||||
BsonClassMap.RegisterClassMap<RowDetailsConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Cells).SetDefaultValue(new List<CellDetails>());
|
||||
cm.MapMember(c => c.Rows).SetDefaultValue(new List<RowDetailsConfig>());
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1.0);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DialogConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type).SetDefaultValue(DisplayConfigEnums.RowType.Demographic)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.RowType>(BsonType.String));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ObservationRowBoxLayout)))
|
||||
BsonClassMap.RegisterClassMap<ObservationRowBoxLayout>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.TextRules).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ChartSettings).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1D);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.CellType.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String));
|
||||
cm.MapMember(c => c.SubType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Icon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GridColumn).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.IsColumn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsStatic).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GraphConf).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Names).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Observations).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Border).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderRadius).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValuePathKey).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValuePathNested).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Size).SetDefaultValue(15.0);
|
||||
cm.MapMember(c => c.Format).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Length).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Direction)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<DisplayConfigEnums.DirectionEnum>(
|
||||
new EnumSerializer<DisplayConfigEnums.DirectionEnum>(BsonType.String)));
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(RowBoxLayout)))
|
||||
BsonClassMap.RegisterClassMap<RowBoxLayout>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1D);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.CellType.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String));
|
||||
cm.MapMember(c => c.SubType)
|
||||
.SetDefaultValue(DisplayConfigEnums.WebDisplayCellSubtype.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.WebDisplayCellSubtype>(BsonType.String));
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Observations)
|
||||
.SetDefaultValue(new List<ObservationRowBoxLayout>());
|
||||
cm.MapMember(c => c.Direction)
|
||||
.SetDefaultValue(DisplayConfigEnums.DirectionEnum.Row)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.DirectionEnum>(BsonType.String));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(RowDetailsConfig)))
|
||||
BsonClassMap.RegisterClassMap<RowDetailsConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Cells).SetDefaultValue(new List<CellDetails>());
|
||||
cm.MapMember(c => c.Rows).SetDefaultValue(new List<RowDetailsConfig>());
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1.0);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DialogConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type).SetDefaultValue(DisplayConfigEnums.RowType.Demographic)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.RowType>(BsonType.String));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ObservationRowBoxLayout)))
|
||||
BsonClassMap.RegisterClassMap<ObservationRowBoxLayout>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.TextRules).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ChartSettings).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ShowTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GrowPriority).SetDefaultValue(1D);
|
||||
cm.MapMember(c => c.Type)
|
||||
.SetDefaultValue(DisplayConfigEnums.CellType.Default)
|
||||
.SetSerializer(new EnumSerializer<DisplayConfigEnums.CellType>(BsonType.String));
|
||||
cm.MapMember(c => c.SubType).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Icon).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GridColumn).SetDefaultValue(1);
|
||||
cm.MapMember(c => c.IsColumn).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.IsStatic).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.GraphConf).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Names).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ObservationTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Observations).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BgColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingBottom).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PaddingRight).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Border).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderRadius).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValuePathKey).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.ValuePathNested).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Size).SetDefaultValue(15.0);
|
||||
cm.MapMember(c => c.Format).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Length).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Direction)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(new NullableSerializer<DisplayConfigEnums.DirectionEnum>(
|
||||
new EnumSerializer<DisplayConfigEnums.DirectionEnum>(BsonType.String)));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -8,62 +8,68 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that participates in section-based entity mapping by implementing the <see cref="IEntityMapContributor"/> interface.
|
||||
/// </summary>
|
||||
public class SectionMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the BSON class maps for the <see cref="Section"/>, <see cref="Section.SectionItem"/>, <see cref="SectionConfig"/>, and <see cref="MinimalDisplaySection"/> types, configuring their MongoDB serialization behavior such as required fields, default values, null-ignoring members, and custom serializers. Each class map is registered only if it has not already been registered, preventing duplicate registrations.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Section)))
|
||||
BsonClassMap.RegisterClassMap<Section>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c._id);
|
||||
cm.MapMember(c => c.Id)
|
||||
.SetIsRequired(true)
|
||||
.SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.SectionTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PointOfCare).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.LastUpdate).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.Configuration)
|
||||
.SetSerializer(new DictionaryBsonConverter());
|
||||
cm.MapMember(c => c.SectionConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DesignProperties).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PointOfCareList)
|
||||
.SetDefaultValue(new Dictionary<string, List<PointOfCare>>());
|
||||
cm.MapMember(c => c.Items).SetDefaultValue(new List<Section.SectionItem>());
|
||||
cm.MapMember(c => c.Status)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<StatusEnum.Type>(new EnumSerializer<StatusEnum.Type>(BsonType.String)));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Section.SectionItem)))
|
||||
BsonClassMap.RegisterClassMap<Section.SectionItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Group).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Boxes).SetDefaultValue(new List<Box>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(SectionConfig)))
|
||||
BsonClassMap.RegisterClassMap<SectionConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Columns).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Rows).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RefreshValues).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RefreshConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Steps).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DesignProperties).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(MinimalDisplaySection)))
|
||||
BsonClassMap.RegisterClassMap<MinimalDisplaySection>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetDefaultValue(ObjectId.GenerateNewId());
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.IsSelected).SetDefaultValue(false);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Section)))
|
||||
BsonClassMap.RegisterClassMap<Section>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c._id);
|
||||
cm.MapMember(c => c.Id)
|
||||
.SetIsRequired(true)
|
||||
.SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.SectionTitle).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PointOfCare).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.LastUpdate).SetIgnoreIfNull(true);
|
||||
|
||||
cm.MapMember(c => c.Configuration)
|
||||
.SetSerializer(new DictionaryBsonConverter());
|
||||
cm.MapMember(c => c.SectionConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DesignProperties).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.PointOfCareList)
|
||||
.SetDefaultValue(new Dictionary<string, List<PointOfCare>>());
|
||||
cm.MapMember(c => c.Items).SetDefaultValue(new List<Section.SectionItem>());
|
||||
cm.MapMember(c => c.Status)
|
||||
.SetIgnoreIfNull(true)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<StatusEnum.Type>(new EnumSerializer<StatusEnum.Type>(BsonType.String)));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Section.SectionItem)))
|
||||
BsonClassMap.RegisterClassMap<Section.SectionItem>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Group).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Boxes).SetDefaultValue(new List<Box>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(SectionConfig)))
|
||||
BsonClassMap.RegisterClassMap<SectionConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Columns).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Rows).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RefreshValues).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RefreshConfig).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Steps).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.DesignProperties).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(MinimalDisplaySection)))
|
||||
BsonClassMap.RegisterClassMap<MinimalDisplaySection>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetDefaultValue(ObjectId.GenerateNewId());
|
||||
cm.MapMember(c => c.Name).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.IsSelected).SetDefaultValue(false);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,57 +4,63 @@ using MongoDB.Bson.Serialization;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an entity map contributor that provides mapping configuration for service configuration entities.
|
||||
/// </summary>
|
||||
public class ServiceConfigMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for service configuration-related types, including <see cref="ServiceConfig"/>, <see cref="ServiceConfigService"/>, <see cref="ServiceConfigServiceSection"/>, <see cref="ServiceConfigTheme"/>, and <see cref="ServiceConfigThemeTimetable"/>, configuring their serialization elements, default values, and null-ignoring behavior. Each registration is guarded by a check that ensures the map is only registered if it has not been registered previously.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfig)))
|
||||
BsonClassMap.RegisterClassMap<ServiceConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.StrId).SetElementName("id")
|
||||
.SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Service).SetDefaultValue(new List<ServiceConfigService>());
|
||||
cm.MapMember(c => c.Theme).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxObservations).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Score).SetDefaultValue(string.Empty);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigService)))
|
||||
BsonClassMap.RegisterClassMap<ServiceConfigService>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Screen).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Sections).SetDefaultValue(new List<ServiceConfigServiceSection>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigServiceSection)))
|
||||
BsonClassMap.RegisterClassMap<ServiceConfigServiceSection>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.BoxId).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Box).SetDefaultValue(string.Empty);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigTheme)))
|
||||
BsonClassMap.RegisterClassMap<ServiceConfigTheme>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.DefaultTheme).SetElementName("default")
|
||||
.SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Timetables).SetDefaultValue(new List<ServiceConfigThemeTimetable>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigThemeTimetable)))
|
||||
BsonClassMap.RegisterClassMap<ServiceConfigThemeTimetable>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Theme).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.StartDay).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.EndDay).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.StartHour).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.EndHour).SetDefaultValue(string.Empty);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfig)))
|
||||
BsonClassMap.RegisterClassMap<ServiceConfig>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.StrId).SetElementName("id")
|
||||
.SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Service).SetDefaultValue(new List<ServiceConfigService>());
|
||||
cm.MapMember(c => c.Theme).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxObservations).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Score).SetDefaultValue(string.Empty);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigService)))
|
||||
BsonClassMap.RegisterClassMap<ServiceConfigService>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Screen).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Sections).SetDefaultValue(new List<ServiceConfigServiceSection>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigServiceSection)))
|
||||
BsonClassMap.RegisterClassMap<ServiceConfigServiceSection>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.BoxId).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Box).SetDefaultValue(string.Empty);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigTheme)))
|
||||
BsonClassMap.RegisterClassMap<ServiceConfigTheme>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.DefaultTheme).SetElementName("default")
|
||||
.SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Timetables).SetDefaultValue(new List<ServiceConfigThemeTimetable>());
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(ServiceConfigThemeTimetable)))
|
||||
BsonClassMap.RegisterClassMap<ServiceConfigThemeTimetable>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Theme).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.StartDay).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.EndDay).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.StartHour).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.EndHour).SetDefaultValue(string.Empty);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,42 +4,51 @@ using MongoDB.Bson.Serialization;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Provides a standard implementation of the <see cref="IEntityMapContributor"/> interface.
|
||||
/// </summary>
|
||||
public class StandardMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for <see cref="HistoricalConfigChanges"/> and <see cref="UiFontData"/> types
|
||||
/// used during MongoDB serialization, skipping any types that are already registered. For
|
||||
/// <see cref="UiFontData"/>, several nullable UI configuration members are configured to be ignored
|
||||
/// when null to avoid persisting default values.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HistoricalConfigChanges)))
|
||||
BsonClassMap.RegisterClassMap<HistoricalConfigChanges>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
//cm.MapMember(c => c.Id)
|
||||
// .SetSerializer(new ObjectIdSerializer(BsonType.String));
|
||||
//cm.GetMemberMap(c => c.ConfigType)
|
||||
// .SetSerializer(new NullableSerializer<ConfigTypes>(new EnumSerializer<ConfigTypes>(BsonType.String)));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(UiFontData)))
|
||||
BsonClassMap.RegisterClassMap<UiFontData>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.WidthStepBed).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HeightStepBed).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeMediumValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeHeaderValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeLittleValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeMicroValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeNanoValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeLittleTextValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeLittleName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeUnit).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BackGroundColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxMarginTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxMarginBot).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxMarginLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxMarginRight).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(HistoricalConfigChanges)))
|
||||
BsonClassMap.RegisterClassMap<HistoricalConfigChanges>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
//cm.MapMember(c => c.Id)
|
||||
// .SetSerializer(new ObjectIdSerializer(BsonType.String));
|
||||
//cm.GetMemberMap(c => c.ConfigType)
|
||||
// .SetSerializer(new NullableSerializer<ConfigTypes>(new EnumSerializer<ConfigTypes>(BsonType.String)));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(UiFontData)))
|
||||
BsonClassMap.RegisterClassMap<UiFontData>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.WidthStepBed).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.HeightStepBed).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeMediumValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeHeaderValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeLittleValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeMicroValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeNanoValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeLittleTextValue).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeLittleName).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FontSizeUnit).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BorderColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BackGroundColor).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxMarginTop).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxMarginBot).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxMarginLeft).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.BoxMarginRight).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -8,109 +8,122 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a contributor that participates in entity mapping for treatment-related entities by implementing the <see cref="IEntityMapContributor"/> contract.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class is intended to be used as a mapping contributor within an entity mapping pipeline, providing configuration logic specific to treatment entities.</remarks>
|
||||
public class TreatmentMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the BSON class maps required to serialize and deserialize the patient treatment
|
||||
/// domain models (such as PatientTreatment, Medicine, Code, CodeStatus, Note, TreatmentRoute,
|
||||
/// Entity, CodeAction, and PredictMedicationObservation) to and from MongoDB. Each map is only
|
||||
/// registered when no class map already exists for the corresponding type, and the registrations
|
||||
/// define custom element names, default values, null-ignoring behavior, and specialized
|
||||
/// serializers for object identifiers and enum values.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientTreatment)))
|
||||
BsonClassMap.RegisterClassMap<PatientTreatment>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientId)
|
||||
.SetSerializer(new ObjectIdSerializer(BsonType.String))
|
||||
.SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OrderControl)
|
||||
.SetSerializer(new EnumSerializer<OrderControlType>(BsonType.String));
|
||||
cm.MapMember(c => c.PlacerOrder).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FillerOrder).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OrderStatus).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.OrderTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StartTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequestedGiveCodes).SetDefaultValue(new List<Code>());
|
||||
cm.MapMember(c => c.RequestedGiveTreatment).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.RequestedGiveCodesStatus).SetDefaultValue(new List<CodeStatus>());
|
||||
cm.MapMember(c => c.RequestedGiveAmountMinimum).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequestedGiveAmountMaximum).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequestedGiveUnits).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequestedDosageForm).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Notes).SetDefaultValue(new List<Note>());
|
||||
cm.MapMember(c => c.Routes).SetDefaultValue(new List<TreatmentRoute>());
|
||||
cm.MapMember(c => c.SingleDose).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.BoloPom).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.MessageTime);
|
||||
cm.MapMember(c => c.SystemId).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Entity)))
|
||||
BsonClassMap.RegisterClassMap<Entity>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.EntityIdentifier).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.NamespaceId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UniversalId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UniversalIdType).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Code)))
|
||||
BsonClassMap.RegisterClassMap<Code>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Identifier).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Text).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.CodingSystem).SetDefaultValue(string.Empty);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CodeStatus)))
|
||||
BsonClassMap.RegisterClassMap<CodeStatus>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Status).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AdministrationTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndAdministrationTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Note)))
|
||||
BsonClassMap.RegisterClassMap<Note>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.CommentType).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Comment).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.EnteredTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(TreatmentRoute)))
|
||||
BsonClassMap.RegisterClassMap<TreatmentRoute>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Route).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Medicine)))
|
||||
BsonClassMap.RegisterClassMap<Medicine>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Codes).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Notes).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Group).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CodeAction)))
|
||||
BsonClassMap.RegisterClassMap<CodeAction>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Code).SetIsRequired(true);
|
||||
cm.MapMember(c => c.Action)
|
||||
.SetSerializer(new EnumSerializer<ActionsEnum.ResourceAction>(BsonType.String));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PredictMedicationObservation)))
|
||||
BsonClassMap.RegisterClassMap<PredictMedicationObservation>(cm => { cm.AutoMap(); });
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PatientTreatment)))
|
||||
BsonClassMap.RegisterClassMap<PatientTreatment>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.PatientId)
|
||||
.SetSerializer(new ObjectIdSerializer(BsonType.String))
|
||||
.SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OrderControl)
|
||||
.SetSerializer(new EnumSerializer<OrderControlType>(BsonType.String));
|
||||
cm.MapMember(c => c.PlacerOrder).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.FillerOrder).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.OrderStatus).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.OrderTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StartTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequestedGiveCodes).SetDefaultValue(new List<Code>());
|
||||
cm.MapMember(c => c.RequestedGiveTreatment).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.RequestedGiveCodesStatus).SetDefaultValue(new List<CodeStatus>());
|
||||
cm.MapMember(c => c.RequestedGiveAmountMinimum).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequestedGiveAmountMaximum).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequestedGiveUnits).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.RequestedDosageForm).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Notes).SetDefaultValue(new List<Note>());
|
||||
cm.MapMember(c => c.Routes).SetDefaultValue(new List<TreatmentRoute>());
|
||||
cm.MapMember(c => c.SingleDose).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.BoloPom).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.MessageTime);
|
||||
cm.MapMember(c => c.SystemId).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Entity)))
|
||||
BsonClassMap.RegisterClassMap<Entity>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.EntityIdentifier).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.NamespaceId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UniversalId).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.UniversalIdType).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Code)))
|
||||
BsonClassMap.RegisterClassMap<Code>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Identifier).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Text).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.CodingSystem).SetDefaultValue(string.Empty);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CodeStatus)))
|
||||
BsonClassMap.RegisterClassMap<CodeStatus>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Code).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Status).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.AdministrationTime).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.EndAdministrationTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Note)))
|
||||
BsonClassMap.RegisterClassMap<Note>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.CommentType).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.Comment).SetDefaultValue(string.Empty);
|
||||
cm.MapMember(c => c.EnteredTime).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(TreatmentRoute)))
|
||||
BsonClassMap.RegisterClassMap<TreatmentRoute>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Route).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Medicine)))
|
||||
BsonClassMap.RegisterClassMap<Medicine>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id");
|
||||
cm.MapMember(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Codes).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Notes).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Type).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.Group).SetIgnoreIfNull(true);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(CodeAction)))
|
||||
BsonClassMap.RegisterClassMap<CodeAction>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.Code).SetIsRequired(true);
|
||||
cm.MapMember(c => c.Action)
|
||||
.SetSerializer(new EnumSerializer<ActionsEnum.ResourceAction>(BsonType.String));
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(PredictMedicationObservation)))
|
||||
BsonClassMap.RegisterClassMap<PredictMedicationObservation>(cm => { cm.AutoMap(); });
|
||||
}
|
||||
}
|
||||
@@ -7,88 +7,99 @@ using MongoDB.Bson.Serialization.Serializers;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils.MongoMaps;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an entity mapping contributor that provides mapping configuration for units.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implements <see cref="IEntityMapContributor"/> to integrate unit-specific mapping logic into the entity mapping pipeline.
|
||||
/// </remarks>
|
||||
public class UnitMapContributor : IEntityMapContributor
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers BSON class maps for the <see cref="Unit"/> and <see cref="UnitConfiguration"/> types used in MongoDB serialization.
|
||||
/// Each registration is performed only if no class map has been previously registered for the target type, and configures
|
||||
/// field-level mappings, default values, ignored properties, and custom serializers as required by the domain model.
|
||||
/// </summary>
|
||||
public void RegisterMaps()
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Unit)))
|
||||
BsonClassMap.RegisterClassMap<Unit>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id").SetIsRequired(true);
|
||||
cm.GetMemberMap(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.LastUpdate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PointOfCareIds).SetIgnoreIfNull(true);
|
||||
|
||||
cm.UnmapMember(c => c.PocCount);
|
||||
|
||||
cm.MapMember(c => c.Status)
|
||||
.SetDefaultValue(StatusEnum.Type.Ok)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<StatusEnum.Type>(new EnumSerializer<StatusEnum.Type>(BsonType.String)));
|
||||
cm.MapMember(c => c.Configuration).SetDefaultValue(new UnitConfiguration());
|
||||
|
||||
cm.GetMemberMap(c => c.AltableOptionListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.AllergyListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DestinationListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.InternalDestinationListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DiagnosisListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DoctorListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DoctorTypeListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.InsulationListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.MobilityOptionListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.OriginListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PatientStatusListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.ProcedureListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.TestListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.ServiceListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.TherapeuticCeilingListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.TreatmentListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.VisitOptionListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.AccessControlListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.LanguageBarrierListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DischargeStatusListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PassiveSittingListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.GenericListId).SetIgnoreIfNull(true);
|
||||
|
||||
// No mapear estos campos
|
||||
cm.UnmapProperty(c => c.AllergyList);
|
||||
cm.UnmapProperty(c => c.DestinationList);
|
||||
cm.UnmapProperty(c => c.DiagnosisList);
|
||||
cm.UnmapProperty(c => c.DoctorList);
|
||||
cm.UnmapProperty(c => c.DoctorTypeList);
|
||||
cm.UnmapProperty(c => c.InsulationList);
|
||||
cm.UnmapProperty(c => c.MobilityOptionList);
|
||||
cm.UnmapProperty(c => c.OriginList);
|
||||
cm.UnmapProperty(c => c.PatientStatusList);
|
||||
cm.UnmapProperty(c => c.ProcedureList);
|
||||
cm.UnmapProperty(c => c.TestList);
|
||||
cm.UnmapProperty(c => c.AltableOptionList);
|
||||
cm.UnmapProperty(c => c.DischargeStatusList);
|
||||
cm.UnmapProperty(c => c.ServiceList);
|
||||
cm.UnmapProperty(c => c.TherapeuticCeilingList);
|
||||
cm.UnmapProperty(c => c.TreatmentList);
|
||||
cm.UnmapProperty(c => c.VisitOptionList);
|
||||
cm.UnmapProperty(c => c.PassiveSittingList);
|
||||
cm.UnmapProperty(c => c.GenericList);
|
||||
cm.UnmapProperty(c => c.LanguageBarrierList);
|
||||
cm.UnmapProperty(c => c.PointOfCares);
|
||||
cm.UnmapProperty(c => c.InternalDestinationList);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(UnitConfiguration)))
|
||||
BsonClassMap.RegisterClassMap<UnitConfiguration>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.AutoAdt).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.ManualDischarge).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ManualAdmit).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ManualMove).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ManualEdit).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.PlanDisplayConfiguration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SmartDisplayConfiguration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StandarDisplayConfiguration).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
{
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(Unit)))
|
||||
BsonClassMap.RegisterClassMap<Unit>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapIdMember(c => c.Id).SetElementName("_id").SetIsRequired(true);
|
||||
cm.GetMemberMap(c => c.Title).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.Name).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.LastUpdate).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PointOfCareIds).SetIgnoreIfNull(true);
|
||||
|
||||
cm.UnmapMember(c => c.PocCount);
|
||||
|
||||
cm.MapMember(c => c.Status)
|
||||
.SetDefaultValue(StatusEnum.Type.Ok)
|
||||
.SetSerializer(
|
||||
new NullableSerializer<StatusEnum.Type>(new EnumSerializer<StatusEnum.Type>(BsonType.String)));
|
||||
cm.MapMember(c => c.Configuration).SetDefaultValue(new UnitConfiguration());
|
||||
|
||||
cm.GetMemberMap(c => c.AltableOptionListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.AllergyListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DestinationListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.InternalDestinationListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DiagnosisListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DoctorListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DoctorTypeListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.InsulationListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.MobilityOptionListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.OriginListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PatientStatusListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.ProcedureListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.TestListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.ServiceListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.TherapeuticCeilingListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.TreatmentListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.VisitOptionListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.AccessControlListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.LanguageBarrierListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.DischargeStatusListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.PassiveSittingListId).SetIgnoreIfNull(true);
|
||||
cm.GetMemberMap(c => c.GenericListId).SetIgnoreIfNull(true);
|
||||
|
||||
// No mapear estos campos
|
||||
cm.UnmapProperty(c => c.AllergyList);
|
||||
cm.UnmapProperty(c => c.DestinationList);
|
||||
cm.UnmapProperty(c => c.DiagnosisList);
|
||||
cm.UnmapProperty(c => c.DoctorList);
|
||||
cm.UnmapProperty(c => c.DoctorTypeList);
|
||||
cm.UnmapProperty(c => c.InsulationList);
|
||||
cm.UnmapProperty(c => c.MobilityOptionList);
|
||||
cm.UnmapProperty(c => c.OriginList);
|
||||
cm.UnmapProperty(c => c.PatientStatusList);
|
||||
cm.UnmapProperty(c => c.ProcedureList);
|
||||
cm.UnmapProperty(c => c.TestList);
|
||||
cm.UnmapProperty(c => c.AltableOptionList);
|
||||
cm.UnmapProperty(c => c.DischargeStatusList);
|
||||
cm.UnmapProperty(c => c.ServiceList);
|
||||
cm.UnmapProperty(c => c.TherapeuticCeilingList);
|
||||
cm.UnmapProperty(c => c.TreatmentList);
|
||||
cm.UnmapProperty(c => c.VisitOptionList);
|
||||
cm.UnmapProperty(c => c.PassiveSittingList);
|
||||
cm.UnmapProperty(c => c.GenericList);
|
||||
cm.UnmapProperty(c => c.LanguageBarrierList);
|
||||
cm.UnmapProperty(c => c.PointOfCares);
|
||||
cm.UnmapProperty(c => c.InternalDestinationList);
|
||||
});
|
||||
|
||||
if (!BsonClassMap.IsClassMapRegistered(typeof(UnitConfiguration)))
|
||||
BsonClassMap.RegisterClassMap<UnitConfiguration>(cm =>
|
||||
{
|
||||
cm.AutoMap();
|
||||
cm.MapMember(c => c.AutoAdt).SetDefaultValue(false);
|
||||
cm.MapMember(c => c.ManualDischarge).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ManualAdmit).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ManualMove).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.ManualEdit).SetDefaultValue(true);
|
||||
cm.MapMember(c => c.PlanDisplayConfiguration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.SmartDisplayConfiguration).SetIgnoreIfNull(true);
|
||||
cm.MapMember(c => c.StandarDisplayConfiguration).SetIgnoreIfNull(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ using MongoDB.Driver;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Provides utility methods for interacting with MongoDB.
|
||||
/// </summary>
|
||||
public class MongoUtils
|
||||
{
|
||||
public static async Task EnsureIndexes<TDocument>(IMongoCollection<TDocument> collection,
|
||||
|
||||
@@ -7,88 +7,135 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Converts <see cref="PatientObservationAlarm"/> instances to and from JSON representation.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Implements <see cref="IBsonSerializer"/> to provide BSON serialization and deserialization support for <see cref="PatientObservationAlarm"/> objects.
|
||||
/// </remarks>
|
||||
public class PatientObservationAlarmConverter : JsonConverter<PatientObservationAlarm>, IBsonSerializer
|
||||
{
|
||||
/// <summary>
|
||||
/// Deserializes a BSON value into a .NET object using the supplied deserialization context and arguments.
|
||||
/// </summary>
|
||||
/// <param name="context">The BSON deserialization context that provides access to the reader and configuration.</param>
|
||||
/// <param name="args">The deserialization arguments that influence how the value is read and converted.</param>
|
||||
/// <returns>The deserialized .NET object produced from the BSON input.</returns>
|
||||
/// <exception cref="NotImplementedException">Always thrown because the deserialization logic has not been implemented yet.</exception>
|
||||
public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified value to BSON format using the provided serialization context and arguments.
|
||||
/// </summary>
|
||||
/// <param name="context">The BSON serialization context that holds the writer and configuration for the serialization operation.</param>
|
||||
/// <param name="args">The BSON serialization arguments containing additional information that influences the serialization behavior.</param>
|
||||
/// <param name="value">The object to be serialized into BSON.</param>
|
||||
/// <exception cref="System.NotImplementedException">Thrown because the method has not yet been implemented.</exception>
|
||||
public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Type ValueType => typeof(PatientObservationAlarm);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes a JSON token into a <see cref="PatientObservationAlarm"/> instance. Returns <c>null</c> when the JSON token is <see cref="JsonToken.Null"/>, otherwise extracts the <c>value</c> property from the JSON object and constructs a new alarm, falling back to a default <see cref="object"/> when the value is missing.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> positioned at the JSON token to read.</param>
|
||||
/// <param name="objectType">The type of the object being deserialized.</param>
|
||||
/// <param name="existingValue">The existing value of the object being deserialized, or <c>null</c> if none exists.</param>
|
||||
/// <param name="hasExistingValue">Indicates whether <paramref name="existingValue"/> contains a value to be used during deserialization.</param>
|
||||
/// <param name="serializer">The <see cref="JsonSerializer"/> used for nested object deserialization.</param>
|
||||
/// <returns>A <see cref="PatientObservationAlarm"/> populated from the JSON, or <c>null</c> if the JSON token is <see cref="JsonToken.Null"/>.</returns>
|
||||
public override PatientObservationAlarm? ReadJson(JsonReader reader, Type objectType,
|
||||
PatientObservationAlarm? existingValue,
|
||||
bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.Null)
|
||||
return null;
|
||||
|
||||
// Implement your custom deserialization logic here
|
||||
var jsonObject = JObject.Load(reader);
|
||||
// Deserialize properties from jsonObject to PatientObservationAlarm object
|
||||
|
||||
// Example: Deserialize 'Value' property
|
||||
var value = jsonObject.GetValue("value")?.ToObject<object>();
|
||||
|
||||
return new PatientObservationAlarm
|
||||
PatientObservationAlarm? existingValue,
|
||||
bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
Value = value ?? new object()
|
||||
// Other property assignments...
|
||||
};
|
||||
}
|
||||
|
||||
public new void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
var jo = JObject.FromObject(value);
|
||||
|
||||
// Add [JsonConverter(typeof(StringEnumConverter))] attribute to specified properties
|
||||
AddStringEnumConverterAttribute(value, "eventPhase");
|
||||
AddStringEnumConverterAttribute(value, "state");
|
||||
AddStringEnumConverterAttribute(value, "priority");
|
||||
AddStringEnumConverterAttribute(value, "type");
|
||||
|
||||
jo.Property("messageTime")?.Remove();
|
||||
jo.Property("expired")?.Remove();
|
||||
jo.WriteTo(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddStringEnumConverterAttribute(object value, string propertyName)
|
||||
{
|
||||
var prop = value.GetType().GetProperty(propertyName);
|
||||
var attr = new JsonConverterAttribute(typeof(StringEnumConverter));
|
||||
|
||||
if (prop != null)
|
||||
{
|
||||
var attrs = prop.GetCustomAttributes(false);
|
||||
|
||||
// Check if the attribute is not already applied
|
||||
if (Array.Find(attrs, a => a is JsonConverterAttribute) == null)
|
||||
if (reader.TokenType == JsonToken.Null)
|
||||
return null;
|
||||
|
||||
// Implement your custom deserialization logic here
|
||||
var jsonObject = JObject.Load(reader);
|
||||
// Deserialize properties from jsonObject to PatientObservationAlarm object
|
||||
|
||||
// Example: Deserialize 'Value' property
|
||||
var value = jsonObject.GetValue("value")?.ToObject<object>();
|
||||
|
||||
return new PatientObservationAlarm
|
||||
{
|
||||
// Create a new array that includes the existing attributes and the new one
|
||||
var newAttrs = new object[attrs.Length + 1];
|
||||
Array.Copy(attrs, newAttrs, attrs.Length);
|
||||
newAttrs[attrs.Length] = attr;
|
||||
Value = value ?? new object()
|
||||
// Other property assignments...
|
||||
};
|
||||
}
|
||||
|
||||
// Use reflection to set the new attributes array
|
||||
var field = typeof(PropertyInfo).GetField("m_customAttributes",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
field?.SetValue(prop, newAttrs);
|
||||
/// <summary>
|
||||
/// Serializes the specified object to JSON, applying the <see cref="StringEnumConverter"/> to the <c>eventPhase</c>, <c>state</c>, <c>priority</c>, and <c>type</c> properties, while excluding the <c>messageTime</c> and <c>expired</c> properties from the output. Does nothing when the <paramref name="value"/> is <see langword="null"/>.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="JsonWriter"/> to which the JSON output is written.</param>
|
||||
/// <param name="value">The object to serialize; if <see langword="null"/>, the method performs no action.</param>
|
||||
/// <param name="serializer">The <see cref="JsonSerializer"/> used to assist with the conversion.</param>
|
||||
public new void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
var jo = JObject.FromObject(value);
|
||||
|
||||
// Add [JsonConverter(typeof(StringEnumConverter))] attribute to specified properties
|
||||
AddStringEnumConverterAttribute(value, "eventPhase");
|
||||
AddStringEnumConverterAttribute(value, "state");
|
||||
AddStringEnumConverterAttribute(value, "priority");
|
||||
AddStringEnumConverterAttribute(value, "type");
|
||||
|
||||
jo.Property("messageTime")?.Remove();
|
||||
jo.Property("expired")?.Remove();
|
||||
jo.WriteTo(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="StringEnumConverter"/> JSON converter attribute to the specified property of the given object, if one is not already present. Uses reflection to inject the attribute into the property's internal custom attributes array, avoiding the need to recompile the type with the attribute applied.
|
||||
/// </summary>
|
||||
/// <param name="value">The object instance whose type is inspected to locate the target property.</param>
|
||||
/// <param name="propertyName">The name of the property to which the <see cref="StringEnumConverter"/> attribute will be added.</param>
|
||||
private static void AddStringEnumConverterAttribute(object value, string propertyName)
|
||||
{
|
||||
var prop = value.GetType().GetProperty(propertyName);
|
||||
var attr = new JsonConverterAttribute(typeof(StringEnumConverter));
|
||||
|
||||
if (prop != null)
|
||||
{
|
||||
var attrs = prop.GetCustomAttributes(false);
|
||||
|
||||
// Check if the attribute is not already applied
|
||||
if (Array.Find(attrs, a => a is JsonConverterAttribute) == null)
|
||||
{
|
||||
// Create a new array that includes the existing attributes and the new one
|
||||
var newAttrs = new object[attrs.Length + 1];
|
||||
Array.Copy(attrs, newAttrs, attrs.Length);
|
||||
newAttrs[attrs.Length] = attr;
|
||||
|
||||
// Use reflection to set the new attributes array
|
||||
var field = typeof(PropertyInfo).GetField("m_customAttributes",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
field?.SetValue(prop, newAttrs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the JSON representation of a PatientObservationAlarm using the specified writer and serializer.
|
||||
/// </summary>
|
||||
/// <param name="writer">The JsonWriter to which the JSON output is written.</param>
|
||||
/// <param name="value">The PatientObservationAlarm value to serialize.</param>
|
||||
/// <param name="serializer">The JsonSerializer used during the serialization process.</param>
|
||||
/// <exception cref="NotImplementedException">The method has not been implemented.</exception>
|
||||
public override void WriteJson(JsonWriter writer, PatientObservationAlarm? value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/*How to use it:
|
||||
|
||||
@@ -7,62 +7,103 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Provides conversion logic for <see cref="PatientObservation"/> values, supporting JSON serialization through <see cref="JsonConverter{T}"/> and BSON serialization through <see cref="IBsonSerializer"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The optional <see cref="Type"/> constructor parameter specifies the target value type used during conversion.
|
||||
/// </remarks>
|
||||
public class PatientObservationConverter(Type? valueType) : JsonConverter<PatientObservation>, IBsonSerializer
|
||||
{
|
||||
/// <summary>
|
||||
/// Deserializes a BSON value using the provided deserialization context and arguments.
|
||||
/// </summary>
|
||||
/// <param name="context">The deserialization context that provides the BSON reader and configuration.</param>
|
||||
/// <param name="args">The deserialization arguments containing additional information for the operation.</param>
|
||||
/// <returns>An object representing the deserialized value.</returns>
|
||||
/// <exception cref="NotImplementedException">Always thrown because the method is not yet implemented.</exception>
|
||||
public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified value into a BSON format using the provided serialization context and arguments. This implementation is not yet provided and currently throws a <see cref="NotImplementedException"/>.
|
||||
/// </summary>
|
||||
/// <param name="context">The BSON serialization context that provides access to the writer and configuration used during serialization.</param>
|
||||
/// <param name="args">The BSON serialization arguments containing additional information that may influence the serialization process.</param>
|
||||
/// <param name="value">The object to be serialized into BSON.</param>
|
||||
/// <exception cref="NotImplementedException">Thrown because the serialization logic has not been implemented.</exception>
|
||||
public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Type? ValueType { get; } = valueType;
|
||||
|
||||
/// <summary>
|
||||
/// Serializes a <see cref="PatientObservation"/> instance to JSON, applying a string enum converter to the <c>Status</c> property and excluding the <c>MessageTime</c> property from the output. If the supplied value is <c>null</c>, nothing is written to the <paramref name="writer"/>.
|
||||
/// </summary>
|
||||
/// <param name="writer">The JSON writer that receives the serialized output.</param>
|
||||
/// <param name="value">The patient observation to serialize. When <c>null</c>, the method performs no serialization.</param>
|
||||
/// <param name="serializer">The JSON serializer used during the conversion process.</param>
|
||||
public override void WriteJson(JsonWriter writer, PatientObservation? value, JsonSerializer serializer)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
var jo = JObject.FromObject(value);
|
||||
|
||||
// Add [JsonConverter(typeof(StringEnumConverter))] attribute to specified properties
|
||||
AddStringEnumConverterAttribute(value, "Status");
|
||||
|
||||
jo.Property("MessageTime")?.Remove();
|
||||
jo.WriteTo(writer);
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddStringEnumConverterAttribute(object value, string propertyName)
|
||||
{
|
||||
var prop = value.GetType().GetProperty(propertyName);
|
||||
var attr = new JsonConverterAttribute(typeof(StringEnumConverter));
|
||||
|
||||
if (prop != null)
|
||||
{
|
||||
var attrs = prop.GetCustomAttributes(false);
|
||||
|
||||
// Check if the attribute is not already applied
|
||||
if (Array.Find(attrs, a => a is JsonConverterAttribute) == null)
|
||||
if (value != null)
|
||||
{
|
||||
// Create a new array that includes the existing attributes and the new one
|
||||
var newAttrs = new object[attrs.Length + 1];
|
||||
Array.Copy(attrs, newAttrs, attrs.Length);
|
||||
newAttrs[attrs.Length] = attr;
|
||||
|
||||
// Use reflection to set the new attributes array
|
||||
var field = typeof(PropertyInfo).GetField("m_customAttributes",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
field?.SetValue(prop, newAttrs);
|
||||
var jo = JObject.FromObject(value);
|
||||
|
||||
// Add [JsonConverter(typeof(StringEnumConverter))] attribute to specified properties
|
||||
AddStringEnumConverterAttribute(value, "Status");
|
||||
|
||||
jo.Property("MessageTime")?.Remove();
|
||||
jo.WriteTo(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a JsonConverterAttribute for StringEnumConverter to the specified property if one is not already present. If the property cannot be found on the object's type, the method does nothing.
|
||||
/// </summary>
|
||||
/// <param name="value">The object instance whose property should be annotated.</param>
|
||||
/// <param name="propertyName">The name of the property to which the StringEnumConverter attribute should be added.</param>
|
||||
private static void AddStringEnumConverterAttribute(object value, string propertyName)
|
||||
{
|
||||
var prop = value.GetType().GetProperty(propertyName);
|
||||
var attr = new JsonConverterAttribute(typeof(StringEnumConverter));
|
||||
|
||||
if (prop != null)
|
||||
{
|
||||
var attrs = prop.GetCustomAttributes(false);
|
||||
|
||||
// Check if the attribute is not already applied
|
||||
if (Array.Find(attrs, a => a is JsonConverterAttribute) == null)
|
||||
{
|
||||
// Create a new array that includes the existing attributes and the new one
|
||||
var newAttrs = new object[attrs.Length + 1];
|
||||
Array.Copy(attrs, newAttrs, attrs.Length);
|
||||
newAttrs[attrs.Length] = attr;
|
||||
|
||||
// Use reflection to set the new attributes array
|
||||
var field = typeof(PropertyInfo).GetField("m_customAttributes",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
field?.SetValue(prop, newAttrs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes a JSON representation into a <see cref="PatientObservation"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> to read the JSON from.</param>
|
||||
/// <param name="objectType">The type of the object being deserialized.</param>
|
||||
/// <param name="existingValue">The existing value of the object to populate, or <see langword="null"/> if none.</param>
|
||||
/// <param name="hasExistingValue">Indicates whether <paramref name="existingValue"/> contains a value to reuse.</param>
|
||||
/// <param name="serializer">The <see cref="JsonSerializer"/> used to read nested values.</param>
|
||||
/// <returns>A <see cref="PatientObservation"/> instance produced from the JSON.</returns>
|
||||
/// <exception cref="NotImplementedException">Thrown because the method has not been implemented yet.</exception>
|
||||
public override PatientObservation ReadJson(JsonReader reader, Type objectType, PatientObservation? existingValue,
|
||||
bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -9,73 +9,120 @@ using JsonConverterAttribute = Newtonsoft.Json.JsonConverterAttribute;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Provides JSON conversion for <see cref="PumpObservation"/> instances and supports BSON serialization through the <see cref="IBsonSerializer"/> interface.
|
||||
/// </summary>
|
||||
public class PatientPumpObservationConverter : JsonConverter<PumpObservation>, IBsonSerializer
|
||||
{
|
||||
/// <summary>
|
||||
/// Deserializes a BSON value into a .NET object using the provided deserialization context and arguments.
|
||||
/// </summary>
|
||||
/// <param name="context">The BSON deserialization context that provides access to the reader and configuration.</param>
|
||||
/// <param name="args">The deserialization arguments containing additional settings for the operation.</param>
|
||||
/// <returns>The deserialized object.</returns>
|
||||
/// <exception cref="NotImplementedException">Thrown when the method is invoked, as the deserialization logic has not been implemented.</exception>
|
||||
public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified value into BSON format using the provided serialization context and arguments.
|
||||
/// This method is not yet implemented and currently throws an exception when invoked.
|
||||
/// </summary>
|
||||
/// <param name="context">The BSON serialization context that provides the writer and configuration for the operation.</param>
|
||||
/// <param name="args">The BSON serialization arguments that influence the serialization behavior.</param>
|
||||
/// <param name="value">The object to be serialized into BSON.</param>
|
||||
/// <exception cref="NotImplementedException">Thrown because the method has not been implemented.</exception>
|
||||
public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Type ValueType => typeof(PatientObservationAlarm);
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes a JSON representation into a <see cref="PumpObservation"/> instance.
|
||||
/// This implementation is not yet provided and always throws an exception.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> to read JSON from.</param>
|
||||
/// <param name="objectType">The type of the object to deserialize.</param>
|
||||
/// <param name="existingValue">The existing value of the object being read, or <c>null</c> if there is no existing value.</param>
|
||||
/// <param name="hasExistingValue">A value indicating whether <paramref name="existingValue"/> has a value.</param>
|
||||
/// <param name="serializer">The <see cref="JsonSerializer"/> used for deserialization.</param>
|
||||
/// <returns>A <see cref="PumpObservation"/> instance reconstructed from the JSON data.</returns>
|
||||
/// <exception cref="NotImplementedException">Thrown because the method has not been implemented yet.</exception>
|
||||
public override PumpObservation ReadJson(JsonReader reader, Type objectType,
|
||||
PumpObservation? existingValue,
|
||||
bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public new void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
if (value != null)
|
||||
PumpObservation? existingValue,
|
||||
bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
var jo = JObject.FromObject(value);
|
||||
|
||||
// Add [JsonConverter(typeof(StringEnumConverter))] attribute to specified properties
|
||||
AddStringEnumConverterAttribute(value, "Event");
|
||||
AddStringEnumConverterAttribute(value, "Status");
|
||||
AddStringEnumConverterAttribute(value, "PumpMode");
|
||||
AddStringEnumConverterAttribute(value, "InfusingStatus");
|
||||
AddStringEnumConverterAttribute(value, "AlarmMode");
|
||||
|
||||
jo.WriteTo(writer);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, PumpObservation? value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static void AddStringEnumConverterAttribute(object value, string propertyName)
|
||||
{
|
||||
var prop = value.GetType().GetProperty(propertyName);
|
||||
var attr = new JsonConverterAttribute(typeof(StringEnumConverter));
|
||||
|
||||
if (prop != null)
|
||||
/// <summary>
|
||||
/// Serializes the specified value to JSON, applying string enum conversion to the Event, Status, PumpMode, InfusingStatus, and AlarmMode properties. No output is written when the value is null.
|
||||
/// </summary>
|
||||
/// <param name="writer">The JSON writer to which the serialized object is written.</param>
|
||||
/// <param name="value">The object to serialize; if null, the method does nothing.</param>
|
||||
/// <param name="serializer">The JSON serializer used as context for the conversion.</param>
|
||||
public new void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
var attrs = prop.GetCustomAttributes(false);
|
||||
|
||||
// Check if the attribute is not already applied
|
||||
if (Array.Find(attrs, a => a is JsonConverterAttribute) == null)
|
||||
if (value != null)
|
||||
{
|
||||
// Create a new array that includes the existing attributes and the new one
|
||||
var newAttrs = new object[attrs.Length + 1];
|
||||
Array.Copy(attrs, newAttrs, attrs.Length);
|
||||
newAttrs[attrs.Length] = attr;
|
||||
|
||||
// Use reflection to set the new attributes array
|
||||
var field = typeof(PropertyInfo).GetField("m_customAttributes",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
field?.SetValue(prop, newAttrs);
|
||||
var jo = JObject.FromObject(value);
|
||||
|
||||
// Add [JsonConverter(typeof(StringEnumConverter))] attribute to specified properties
|
||||
AddStringEnumConverterAttribute(value, "Event");
|
||||
AddStringEnumConverterAttribute(value, "Status");
|
||||
AddStringEnumConverterAttribute(value, "PumpMode");
|
||||
AddStringEnumConverterAttribute(value, "InfusingStatus");
|
||||
AddStringEnumConverterAttribute(value, "AlarmMode");
|
||||
|
||||
jo.WriteTo(writer);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes a <see cref="PumpObservation"/> instance to JSON. This override is not yet implemented and will always throw.
|
||||
/// </summary>
|
||||
/// <param name="writer">The JSON writer used to emit the serialized output.</param>
|
||||
/// <param name="value">The <see cref="PumpObservation"/> to serialize, or <see langword="null"/> if no value is available.</param>
|
||||
/// <param name="serializer">The <see cref="JsonSerializer"/> providing serialization context and options.</param>
|
||||
/// <exception cref="NotImplementedException">Always thrown because the method has not been implemented.</exception>
|
||||
public override void WriteJson(JsonWriter writer, PumpObservation? value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <see cref="JsonConverterAttribute"/> of type <see cref="StringEnumConverter"/> to the specified property, ensuring that enum values are serialized as their string names rather than numeric values. If the property already has a <see cref="JsonConverterAttribute"/> applied, no changes are made.
|
||||
/// </summary>
|
||||
/// <param name="value">The object instance whose property will be inspected for the attribute.</param>
|
||||
/// <param name="propertyName">The name of the property to which the converter attribute will be added.</param>
|
||||
private static void AddStringEnumConverterAttribute(object value, string propertyName)
|
||||
{
|
||||
var prop = value.GetType().GetProperty(propertyName);
|
||||
var attr = new JsonConverterAttribute(typeof(StringEnumConverter));
|
||||
|
||||
if (prop != null)
|
||||
{
|
||||
var attrs = prop.GetCustomAttributes(false);
|
||||
|
||||
// Check if the attribute is not already applied
|
||||
if (Array.Find(attrs, a => a is JsonConverterAttribute) == null)
|
||||
{
|
||||
// Create a new array that includes the existing attributes and the new one
|
||||
var newAttrs = new object[attrs.Length + 1];
|
||||
Array.Copy(attrs, newAttrs, attrs.Length);
|
||||
newAttrs[attrs.Length] = attr;
|
||||
|
||||
// Use reflection to set the new attributes array
|
||||
var field = typeof(PropertyInfo).GetField("m_customAttributes",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
field?.SetValue(prop, newAttrs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*How to use it:
|
||||
|
||||
@@ -7,57 +7,98 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Provides JSON conversion for the <see cref="Person"/> type via <see cref="JsonConverter{T}"/> and also implements BSON serialization through <see cref="IBsonSerializer"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The primary constructor accepts a <see cref="Type"/> that represents the value type associated with this converter.
|
||||
/// </remarks>
|
||||
public class PersonConverter(Type valueType) : JsonConverter<Person>, IBsonSerializer
|
||||
{
|
||||
/// <summary>
|
||||
/// Deserializes a BSON value into a .NET object using the provided context and arguments.
|
||||
/// </summary>
|
||||
/// <param name="context">The BSON deserialization context.</param>
|
||||
/// <param name="args">The BSON deserialization arguments.</param>
|
||||
/// <returns>The deserialized object.</returns>
|
||||
/// <exception cref="NotImplementedException">Always thrown because the method is not yet implemented.</exception>
|
||||
public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the specified object to BSON format using the provided serialization context and arguments. The method is not implemented and always throws an exception.
|
||||
/// </summary>
|
||||
/// <param name="context">The BSON serialization context that provides the writer and configuration for the operation.</param>
|
||||
/// <param name="args">The BSON serialization arguments containing additional settings for the serialization.</param>
|
||||
/// <param name="value">The object to be serialized to BSON.</param>
|
||||
/// <exception cref="NotImplementedException">Always thrown because the method has not been implemented yet.</exception>
|
||||
public void Serialize(BsonSerializationContext context, BsonSerializationArgs args, object value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Type ValueType { get; } = valueType;
|
||||
|
||||
/// <summary>
|
||||
/// Serializes a <see cref="Person"/> instance to JSON, ensuring the <c>Gender</c> property is written using string-based enum representation. Does nothing when the provided value is <see langword="null"/>.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="JsonWriter"/> to which the JSON representation is written.</param>
|
||||
/// <param name="value">The <see cref="Person"/> instance to serialize. If <see langword="null"/>, the method returns without writing anything.</param>
|
||||
/// <param name="serializer">The <see cref="JsonSerializer"/> used during the conversion to a <see cref="JObject"/>.</param>
|
||||
public override void WriteJson(JsonWriter writer, Person? value, JsonSerializer serializer)
|
||||
{
|
||||
if (value == null) return;
|
||||
|
||||
var jo = JObject.FromObject(value);
|
||||
|
||||
// Add [JsonConverter(typeof(StringEnumConverter))] attribute to specified properties
|
||||
AddStringEnumConverterAttribute(value, "Gender");
|
||||
|
||||
jo.WriteTo(writer);
|
||||
}
|
||||
{
|
||||
if (value == null) return;
|
||||
|
||||
var jo = JObject.FromObject(value);
|
||||
|
||||
// Add [JsonConverter(typeof(StringEnumConverter))] attribute to specified properties
|
||||
AddStringEnumConverterAttribute(value, "Gender");
|
||||
|
||||
jo.WriteTo(writer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a StringEnumConverter JSON converter attribute to the specified property if one is not already applied, ensuring enum values are serialized as strings. The method returns silently if the property is not found on the value's type or if a JsonConverterAttribute is already present.
|
||||
/// </summary>
|
||||
/// <param name="value">The object instance whose property's attributes will be inspected and modified.</param>
|
||||
/// <param name="propertyName">The name of the property to which the converter attribute will be added.</param>
|
||||
private static void AddStringEnumConverterAttribute(object value, string propertyName)
|
||||
{
|
||||
var prop = value.GetType().GetProperty(propertyName);
|
||||
var attr = new JsonConverterAttribute(typeof(StringEnumConverter));
|
||||
|
||||
if (prop == null) return;
|
||||
var attrs = prop.GetCustomAttributes(false);
|
||||
|
||||
// Check if the attribute is not already applied
|
||||
if (Array.Find(attrs, a => a is JsonConverterAttribute) != null) return;
|
||||
|
||||
// Create a new array that includes the existing attributes and the new one
|
||||
var newAttrs = new object[attrs.Length + 1];
|
||||
Array.Copy(attrs, newAttrs, attrs.Length);
|
||||
newAttrs[attrs.Length] = attr;
|
||||
|
||||
// Use reflection to set the new attributes array
|
||||
var field = typeof(PropertyInfo).GetField("m_customAttributes",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
field?.SetValue(prop, newAttrs);
|
||||
}
|
||||
{
|
||||
var prop = value.GetType().GetProperty(propertyName);
|
||||
var attr = new JsonConverterAttribute(typeof(StringEnumConverter));
|
||||
|
||||
if (prop == null) return;
|
||||
var attrs = prop.GetCustomAttributes(false);
|
||||
|
||||
// Check if the attribute is not already applied
|
||||
if (Array.Find(attrs, a => a is JsonConverterAttribute) != null) return;
|
||||
|
||||
// Create a new array that includes the existing attributes and the new one
|
||||
var newAttrs = new object[attrs.Length + 1];
|
||||
Array.Copy(attrs, newAttrs, attrs.Length);
|
||||
newAttrs[attrs.Length] = attr;
|
||||
|
||||
// Use reflection to set the new attributes array
|
||||
var field = typeof(PropertyInfo).GetField("m_customAttributes",
|
||||
BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
field?.SetValue(prop, newAttrs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the JSON representation of a <see cref="Person"/> object. This override is not yet implemented.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
|
||||
/// <param name="objectType">The type of the object to deserialize.</param>
|
||||
/// <param name="existingValue">The existing value of the object being read, or <c>null</c> if there is no existing value.</param>
|
||||
/// <param name="hasExistingValue">A value indicating whether <paramref name="existingValue"/> has a value.</param>
|
||||
/// <param name="serializer">The <see cref="JsonSerializer"/> calling the method.</param>
|
||||
/// <returns>A <see cref="Person"/> instance deserialized from the JSON.</returns>
|
||||
/// <exception cref="NotImplementedException">Always thrown because the method has not been implemented.</exception>
|
||||
public override Person ReadJson(JsonReader reader, Type objectType, Person? existingValue, bool hasExistingValue,
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -8,34 +8,45 @@ using ILogger = Serilog.ILogger;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Handles errors that occur during RabbitMQ message consumption and publishes them using the configured publisher service.
|
||||
/// </summary>
|
||||
public class RabbitConsumerErrorHandler(IPublisherService publisherService)
|
||||
{
|
||||
private const int MaxRetries = 2;
|
||||
private static readonly ILogger Logger = Log.ForContext<RabbitConsumerErrorHandler>();
|
||||
|
||||
/// <summary>
|
||||
/// Processes a received message by invoking the next handler in the pipeline, and on failure logs the error,
|
||||
/// serializes the message body to a string, and delegates to the retry handler using the message properties,
|
||||
/// received info, and the captured exception.
|
||||
/// </summary>
|
||||
/// <param name="message">The deserialized message whose body is inspected or re-serialized for retry handling.</param>
|
||||
/// <param name="receivedInfo">Information about the message receipt, passed to the retry handler.</param>
|
||||
/// <param name="next">The asynchronous delegate representing the next step in the processing pipeline.</param>
|
||||
public async Task HandleAsync<T>(
|
||||
Message<T> message,
|
||||
MessageReceivedInfo receivedInfo,
|
||||
Func<Task> next)
|
||||
{
|
||||
try
|
||||
Message<T> message,
|
||||
MessageReceivedInfo receivedInfo,
|
||||
Func<Task> next)
|
||||
{
|
||||
await next();
|
||||
try
|
||||
{
|
||||
await next();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logger.Error(exception, "Consumer error {Message}", exception.Message);
|
||||
|
||||
var properties = message.Properties;
|
||||
|
||||
var body = Encoding.UTF8.GetString(
|
||||
message.Body is byte[] bytes
|
||||
? bytes
|
||||
: Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message.Body)));
|
||||
|
||||
HandleRetries(receivedInfo, properties, body, exception);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logger.Error(exception, "Consumer error {Message}", exception.Message);
|
||||
|
||||
var properties = message.Properties;
|
||||
|
||||
var body = Encoding.UTF8.GetString(
|
||||
message.Body is byte[] bytes
|
||||
? bytes
|
||||
: Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message.Body)));
|
||||
|
||||
HandleRetries(receivedInfo, properties, body, exception);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleRetries(
|
||||
MessageReceivedInfo receivedInfo,
|
||||
@@ -102,44 +113,58 @@ public class RabbitConsumerErrorHandler(IPublisherService publisherService)
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the retry count from the message properties headers. Returns the deserialized integer value when a "retries" header containing a byte array is present, or 0 when the headers are missing, the key is not found, or the value is not a byte array.
|
||||
/// </summary>
|
||||
/// <param name="properties">The message properties whose headers are inspected for the "retries" entry.</param>
|
||||
/// <returns>The number of retries parsed from the "retries" header, or 0 if the header is absent or not a byte array.</returns>
|
||||
private int GetRetries(MessageProperties properties)
|
||||
{
|
||||
if (properties.Headers != null &&
|
||||
properties.Headers.TryGetValue("retries", out var retriesObj) &&
|
||||
retriesObj is byte[] bytes)
|
||||
{
|
||||
return BitConverter.ToInt32(bytes, 0);
|
||||
if (properties.Headers != null &&
|
||||
properties.Headers.TryGetValue("retries", out var retriesObj) &&
|
||||
retriesObj is byte[] bytes)
|
||||
{
|
||||
return BitConverter.ToInt32(bytes, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new error message that preserves the original message properties and attaches exception details for downstream processing or dead-letter handling.
|
||||
/// </summary>
|
||||
/// <param name="receivedInfo">The metadata of the original received message, including exchange, routing key, and queue information used to identify the error source.</param>
|
||||
/// <param name="originalProperties">The properties of the original message from which delivery mode, content type, correlation id, and message id are copied.</param>
|
||||
/// <param name="body">The raw body of the original message that caused the error.</param>
|
||||
/// <param name="exception">The exception that was raised, whose message is included in the error payload.</param>
|
||||
/// <param name="headers">The headers to associate with the resulting error message.</param>
|
||||
/// <returns>A <see cref="Message{Error}"/> containing the constructed error and the propagated message properties.</returns>
|
||||
private static Message<Error> CreateErrorMessage(
|
||||
MessageReceivedInfo receivedInfo,
|
||||
MessageProperties originalProperties,
|
||||
string body,
|
||||
Exception exception,
|
||||
Dictionary<string, object> headers)
|
||||
{
|
||||
var props = new MessageProperties
|
||||
MessageReceivedInfo receivedInfo,
|
||||
MessageProperties originalProperties,
|
||||
string body,
|
||||
Exception exception,
|
||||
Dictionary<string, object> headers)
|
||||
{
|
||||
Headers = headers,
|
||||
DeliveryMode = originalProperties.DeliveryMode,
|
||||
ContentType = originalProperties.ContentType,
|
||||
CorrelationId = originalProperties.CorrelationId,
|
||||
MessageId = originalProperties.MessageId
|
||||
};
|
||||
|
||||
var error = new Error(
|
||||
body,
|
||||
exception.Message,
|
||||
receivedInfo.Exchange,
|
||||
receivedInfo.RoutingKey,
|
||||
receivedInfo.Queue,
|
||||
DateTime.UtcNow,
|
||||
props
|
||||
);
|
||||
|
||||
return new Message<Error>(error, props);
|
||||
}
|
||||
var props = new MessageProperties
|
||||
{
|
||||
Headers = headers,
|
||||
DeliveryMode = originalProperties.DeliveryMode,
|
||||
ContentType = originalProperties.ContentType,
|
||||
CorrelationId = originalProperties.CorrelationId,
|
||||
MessageId = originalProperties.MessageId
|
||||
};
|
||||
|
||||
var error = new Error(
|
||||
body,
|
||||
exception.Message,
|
||||
receivedInfo.Exchange,
|
||||
receivedInfo.RoutingKey,
|
||||
receivedInfo.Queue,
|
||||
DateTime.UtcNow,
|
||||
props
|
||||
);
|
||||
|
||||
return new Message<Error>(error, props);
|
||||
}
|
||||
}
|
||||
@@ -4,26 +4,43 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace adas_core.Infrastructure.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an implementation of <see cref="IErrorMessageSerializer"/> tailored for use with RabbitMQ, responsible for serializing error messages into a format suitable for transport over RabbitMQ.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class serves as the RabbitMQ-specific concrete realization of the <see cref="IErrorMessageSerializer"/> contract.
|
||||
/// </remarks>
|
||||
public class RabbitIErrorMessageSerializer : IErrorMessageSerializer
|
||||
{
|
||||
/// <summary>
|
||||
/// Deserializes a JSON-encoded string by unescaping its JSON representation and converts the result to a UTF-8 byte array.
|
||||
/// Returns <c>null</c> when the deserialized string is <c>null</c>.
|
||||
/// </summary>
|
||||
/// <param name="messageBody">The JSON-encoded string to unescape and convert.</param>
|
||||
/// <returns>A UTF-8 encoded byte array of the unescaped string, or <c>null</c> if the deserialized value is <c>null</c>.</returns>
|
||||
public byte[]? Deserialize(string messageBody)
|
||||
{
|
||||
var unescapedJsonString = JsonConvert.DeserializeObject<string>(messageBody);
|
||||
|
||||
return unescapedJsonString != null ? Encoding.UTF8.GetBytes(unescapedJsonString) : null;
|
||||
}
|
||||
{
|
||||
var unescapedJsonString = JsonConvert.DeserializeObject<string>(messageBody);
|
||||
|
||||
return unescapedJsonString != null ? Encoding.UTF8.GetBytes(unescapedJsonString) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to deserialize the UTF-8 decoded message body as a JSON string, returning the original stringified content if deserialization fails.
|
||||
/// </summary>
|
||||
/// <param name="messageBody">The raw byte array representing the message body to be deserialized.</param>
|
||||
/// <returns>The deserialized JSON string if successful; otherwise, the raw UTF-8 decoded string. Returns <see langword="null"/> if the deserialized JSON value is null.</returns>
|
||||
public string? Serialize(byte[] messageBody)
|
||||
{
|
||||
var stringifiedMsgBody = Encoding.UTF8.GetString(messageBody);
|
||||
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<string>(stringifiedMsgBody);
|
||||
var stringifiedMsgBody = Encoding.UTF8.GetString(messageBody);
|
||||
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject<string>(stringifiedMsgBody);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return stringifiedMsgBody;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return stringifiedMsgBody;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,28 @@
|
||||
|
||||
namespace adas_core.Infrastructure.Utils;
|
||||
|
||||
/// <summary>
|
||||
/// Provides static utility methods for working with types.
|
||||
/// </summary>
|
||||
public static class TypesUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves the driver <see cref="Type"/> associated with the specified device type and device.
|
||||
/// Supports "Relay" (mapped to adas-core.module.Relays) and "LightBeacon" (mapped to adas-core.module.LightBeacons) device types.
|
||||
/// </summary>
|
||||
/// <param name="deviceType">The category of the device used to determine the appropriate driver type.</param>
|
||||
/// <param name="device">The specific device identifier used when resolving the driver type.</param>
|
||||
/// <returns>The <see cref="Type"/> of the driver that corresponds to the given device type.</returns>
|
||||
/// <exception cref="AdasException">Thrown when the provided <paramref name="deviceType"/> is not a recognized value.</exception>
|
||||
public static Type GetDriver(string deviceType, string device)
|
||||
{
|
||||
return deviceType switch
|
||||
{
|
||||
"Relay" => GetType("adas-core.module.Relays", device, deviceType),
|
||||
"LightBeacon" => GetType("adas-core.module.LightBeacons", device, deviceType),
|
||||
_ => throw new AdasException($"Device type {deviceType} not found")
|
||||
};
|
||||
}
|
||||
return deviceType switch
|
||||
{
|
||||
"Relay" => GetType("adas-core.module.Relays", device, deviceType),
|
||||
"LightBeacon" => GetType("adas-core.module.LightBeacons", device, deviceType),
|
||||
_ => throw new AdasException($"Device type {deviceType} not found")
|
||||
};
|
||||
}
|
||||
|
||||
private static Type GetType(string typeName, string device, string deviceType)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user