using adas_core.Domain.Enums; using adas_core.Domain.Models.BsonConverters; using adas_core.Domain.Models.MongoModels; using adas_core.Infrastructure.Utils.MongoMaps.Interfaz; using MongoDB.Bson; using MongoDB.Bson.Serialization; using MongoDB.Bson.Serialization.Serializers; using Stream = adas_core.Domain.Models.MongoModels.Stream; namespace adas_core.Infrastructure.Utils.MongoMaps; /// /// Provides configuration mapping contributions for box entities, implementing the interface to participate in entity map setup. /// public class BoxConfigMapContributor : IEntityMapContributor { /// /// Registers the BSON class maps used to control how and instances are serialized to and from MongoDB. Each registration is only performed when no class map is already registered for the target type, and the mappings exclude properties that should not be persisted, rename persisted members where needed, apply to the Configuration member of , and configure null/default-value handling for members. /// /// public void RegisterMaps() { if (!BsonClassMap.IsClassMapRegistered(typeof(Box))) BsonClassMap.RegisterClassMap(cm => { cm.AutoMap(); cm.UnmapMember(c => c.PointOfCare); //Esto hace que ignora la propiedad en la serialización del Bson cm.MapMember(c => c.Bed).SetElementName("name"); cm.UnmapMember(c => c.IsActive); cm.UnmapMember(c => c.IsVisible); cm.MapMember(c => c.Configuration) .SetSerializer(new DictionaryBsonConverter()) .SetIgnoreIfNull(true); cm.UnmapMember(c => c.Location); cm.UnmapMember(c => c.HasPatient); cm.UnmapMember(c => c.Patientid); cm.UnmapMember(c => c.Patient); cm.UnmapMember(c => c.AttendingDoctor); cm.UnmapMember(c => c.Type); cm.UnmapMember(c => c.Observations); cm.UnmapMember(c => c.Medication); }); if (!BsonClassMap.IsClassMapRegistered(typeof(Sensor))) BsonClassMap.RegisterClassMap(cm => { cm.AutoMap(); cm.MapMember(c => c.Name).SetIgnoreIfNull(true); cm.MapMember(c => c.Title).SetIgnoreIfNull(true); cm.MapMember(c => c.OnlyNumbers).SetDefaultValue(true); cm.MapMember(c => c.IsGeneral).SetDefaultValue(true); }); } }