/// <summary>
 /// Called when a new doctor is binded to the connected patient.
 /// </summary>
 /// <param name="doctor">The doctor.</param>
 public void OnDoctorBinded(LightDoctorDto doctor)
 {
     if (this.DoctorBinded != null)
     {
         this.DoctorBinded(this, new EventArgs<LightDoctorDto>(doctor));
     }
 }
        /// <summary>
        /// Adds the specified doctor to the specified patient.
        /// </summary>
        /// <param name="patient">The patient.</param>
        /// <param name="doctor">The doctor.</param>
        /// <exception cref="EntityNotFoundException">If there's no link between the doctor and the patient</exception>
        public void AddDoctorTo(LightPatientDto patient, LightDoctorDto doctor)
        {
            var patientEntity = this.Session.Get<Patient>(patient.Id);
            var doctorEntity = this.Session.Get<Doctor>(doctor.Id);

            new Updator(this.Session).AddDoctorTo(patientEntity, doctorEntity);
        }
 /// <summary>
 /// Removes the link that existed between the specified patient and the specified doctor.
 /// </summary>
 /// <exception cref="EntityNotFoundException">If there's no link between the doctor and the patient</exception>
 /// <param name="patient">The patient.</param>
 /// <param name="doctor">The doctor.</param>
 public void RemoveDoctorFor(LightPatientDto patient, LightDoctorDto doctor)
 {
     new Remover(this.Session).Remove(doctor, patient);
 }
        /// <summary>
        /// Determines whether the specified patient has the specified doctor.
        /// </summary>
        /// <param name="patient">The patient.</param>
        /// <param name="doctor">The doctor.</param>
        /// <returns>
        ///   <c>true</c> if the specified patient has the doctor; otherwise, <c>false</c>.
        /// </returns>
        public bool HasDoctor(LightPatientDto patient, LightDoctorDto doctor)
        {
            var entity = (from p in this.Session.Query<Patient>()
                          where p.Id == patient.Id
                          select p).Single();

            return (from d in entity.Doctors
                    where d.Id == doctor.Id
                    select d).Count() > 0;
        }
 public UnbindDoctorAction(IPatientDataComponent component, LightPatientDto patient, LightDoctorDto doctor)
     : base(component, patient, doctor)
 {
 }
Beispiel #6
0
        /// <summary>
        /// Create the specified item into the database
        /// </summary>
        /// <param name="item">The item to add in the database</param>
        public long Create(LightDoctorDto item)
        {
            Assert.IsNotNull(item, "item");

            var found = (from p in this.Session.Query<Doctor>()
                         where p.Id == item.Id
                         select p).ToList().Count() > 0;
            if (found) throw new ExistingItemException();

            var entity = Mapper.Map<LightDoctorDto, Doctor>(item);
            item.Id = (long)this.Session.Save(entity);
            return item.Id;
        }
        private void Replace(IEnumerable<LightDoctorDto> doubloons, LightDoctorDto withDoctor, IEnumerable<Patient> preloadedPatients)
        {
            var updator = new Updator(this.Session);

            //Select the Id of doubloons and be sure the replacement is not in the list of items to remove
            var ids = (from d in doubloons
                       where d.Id != withDoctor.Id
                       select d.Id).ToList();

            // Find the replacement doctor
            var newDoctor = this.Session.Get<Doctor>(withDoctor.Id);

            //Find the patients that has on of the doubloons
            if (preloadedPatients == null) { preloadedPatients = this.Session.Query<Patient>().ToList(); }
            var patients = (from pat in preloadedPatients
                            where pat.Doctors.Where(e => ids.Contains(e.Id)).Count() > 0
                            select pat);
            // Replace the doubloons with the replacement patient
            foreach (var patient in patients)
            {
                //foreach (var doctor in patient.Doctors)
                for (int i = 0; i < patient.Doctors.Count; i++)
                {
                    var doctor = patient.Doctors[i];
                    if (ids.Contains(doctor.Id))
                    {
                        var toRemove = this.Session.Get<Doctor>(doctor.Id);
                        patient.Doctors.Remove(toRemove);
                        updator.AddDoctorTo(patient, newDoctor);
                        this.Session.Update(patient);
                    }
                }
            }
            // Remove old not used doctors
            foreach (var id in ids)
            {
                var doctor = this.Session.Get<Doctor>(id);
                if (doctor != null) { this.Session.Delete(doctor); }
            }
        }
        private IEnumerable<LightDoctorDto> GetDoubloonsOf(LightDoctorDto doctor, IQueryable<Doctor> query)
        {
            if (query == null) { query = this.Session.Query<Doctor>(); }

            var entities = (from doc in query
                            where doc.FirstName == doctor.FirstName
                               && doc.LastName == doctor.LastName
                               && doc.Specialisation.Id == doctor.Specialisation.Id
                               && doc.Id != doctor.Id
                            select doc).AsEnumerable();
            return Mapper.Map<IEnumerable<Doctor>, IEnumerable<LightDoctorDto>>(entities);
        }
 /// <summary>
 /// Finds the patients older than the specified age.
 /// </summary>
 /// <param name="age">The age of the patient in years.</param>
 /// <returns></returns>
 public void Replace(IEnumerable<LightDoctorDto> doubloons, LightDoctorDto withDoctor)
 {
     this.Replace(doubloons, withDoctor, null);
 }
 /// <summary>
 /// Gets the full doctor from the specified light dto.
 /// </summary>
 /// <param name="light">The light doctor dto.</param>
 /// <returns></returns>
 public DoctorDto GetFullDoctor(LightDoctorDto light)
 {
     var entity = (from p in this.Session.Query<Doctor>()
                   where p.Id == light.Id
                   select p).Single();
     return Mapper.Map<Doctor, DoctorDto>(entity);
 }
 /// <summary>
 /// Gets the doubloons of the specified doctor.
 /// </summary>
 /// <param name="doctor">The doctor that will be useds to find doubloons.</param>
 /// <param name="query">preloaded query to help optimisation.</param>
 /// <returns>
 /// An enumeration of doctor that are doubloons with the specified doctor
 /// </returns>
 public IEnumerable<LightDoctorDto> GetDoubloonsOf(LightDoctorDto doctor)
 {
     return this.GetDoubloonsOf(doctor, null);
 }