using adas_core.Domain.Enums; using MongoDB.Bson; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace adas_core.Domain.Models; /// /// A JSON converter that handles the serialization and deserialization of objects to and from JSON format. /// public class PatientAppointment : JsonConverter { public ObjectId Id { get; set; } public ObjectId PatientId { get; set; } public Person? Patient { get; set; } public List Timings { get; set; } = []; public DateTime? CreateTime { get; set; } public DateTime UpdateTime { get; set; } public Entity? PlacerOrder { get; set; } public Entity? FillerOrder { get; set; } public string? EventReason { get; set; } public string? AppointmentReason { get; set; } public string? AppointmentType { get; set; } public OperationType? AppointmentOperationType { get; set; } public OperationType? AppointmentStatus { get; set; } public double Duration { get; set; } public string? VisitNumber { get; set; } public string? PatientClass { get; set; } public bool EpisodeActivation { get; set; } = false; public Person? PlacerContact { get; set; } public Person? FillerContact { get; set; } public List ResourceGroups { get; set; } = []; public List Allergies { get; set; } = []; /// /// Applies the configured actions to each resource group, optionally pulling existing data from the provided database appointment. /// When is supplied and has a matching resource group, the actions are applied against the persisted data; otherwise the group is processed with a null source. /// /// The optional persisted whose resource groups provide the source data for the actions. May be null or have fewer resource groups than the current list. /// The list of instances with services, resources, locations, and personnel populated after applying the configured actions. public List ApplyResourceGroups(PatientAppointment? apdb = null) { var i = 0; ResourceGroups = ResourceGroups.Select(rg => { var rgdb = apdb != null && apdb.ResourceGroups.Count > i ? apdb.ResourceGroups[i] : null; rg.Services = CodeAction.Apply(rgdb?.Services, rg.ServicesActions); rg.Resources = CodeAction.Apply(rgdb?.Resources, rg.ResourcesActions); rg.Locations = PatientLocationAction.Apply(rgdb?.Locations, rg.LocationsActions); rg.Personnel = PersonResourceAction.Apply(rgdb?.Personnel, rg.PersonnelActions); return rg; }).ToList(); return ResourceGroups; } /// /// Determines whether the converter can convert the specified type, supporting only the type. /// /// The type to check for converter support. /// true if is ; otherwise, false. public override bool CanConvert(Type objectType) { return objectType == typeof(PatientAppointment); } /// /// Serializes the given value to JSON while excluding the "Id" property from the output. If the value is null, nothing is written to the writer. /// /// The JSON writer to which the serialized output is written. /// The object to serialize. A null value results in no output being written. /// The JSON serializer used to perform the conversion. public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) { if (value != null) { var jo = JObject.FromObject(value); jo.Property("Id")?.Remove(); jo.WriteTo(writer); } } /// /// Reads the JSON representation of an object using the specified reader and serializer. /// This override is not yet implemented and currently throws a . /// /// The used to read the JSON content. /// The type of the object being deserialized. /// The existing value of the object being read, or null if no value exists. /// The invoking the converter. /// An object representing the deserialized value. /// Always thrown, as the method has not been implemented. public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer) { throw new NotImplementedException(); } } /// /// Represents a resource group that aggregates data and operations related to patient appointments. /// /// /// This class serves as a container or grouping mechanism for resources associated with managing patient appointment information. /// public class PatientAppointmentResourceGroup { public List? Services { get; set; } public List? Resources { get; set; } public List? Locations { get; set; } public List? Personnel { get; set; } /** * ApiRequest resource actions */ public List? ServicesActions { get; set; } public List? ResourcesActions { get; set; } public List? LocationsActions { get; set; } public List? PersonnelActions { get; set; } } /// /// Represents allergy information, serving as a model or container for allergy-related data. /// public class Allergies { public Code? AllergenType { get; set; } public Code? Allergen { get; set; } }