Exemple #1
0
        /// <summary>
        /// Update an existing appointment for a patient
        /// </summary>
        /// <returns></returns>
        public Task <AppointmentBookResults> UpdateAppointmentAsync(AddOrUpdateAppointmentData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            return(_apptBooking.UpdateAppointmentAsync(data));
        }
Exemple #2
0
        /// <summary>
        /// If the patient is not currently registered with this Medical Practitioner, create the new PatientsMedicalPractitioner link
        /// </summary>
        /// <param name="data"></param>
        /// <param name="patient"></param>
        /// <param name="medicalPractitioner"></param>
        /// <returns></returns>
        private async Task RegisterPatientIfNotRegisteredToMedicalPractitioner(
            AddOrUpdateAppointmentData data, Patient patient, User medicalPractitioner)
        {
            var patientMedicalPractitionerLink = new PatientsMedicalPractitioner()
            {
                Patient             = patient,
                MedicalPractitioner = medicalPractitioner.EmployeeDetails
            };

            var newPatientMedicalPractitionerLink = await
                                                    _patientsMedicalPractitionerDal.AddAsync(patientMedicalPractitionerLink);

            if (newPatientMedicalPractitionerLink == null)
            {
                _log.LogError(
                    $"Failed to register patient with Medical Practitioner. \"PatientId\"={data.PatientId}, \"MedicalPractitionerId\"={data.MedicalPractitionerId}");
            }
        }
Exemple #3
0
        /// <summary>
        /// Update an existing appointment for a patient
        /// </summary>
        /// <returns></returns>
        public async Task <AppointmentBookResults> UpdateAppointmentAsync(AddOrUpdateAppointmentData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            // Get the results of the completed tasks
            var currentAppointmentSlot = await _apptSlotDal.GetEntityAsync(data.SlotId);

            //var currentAppointmentSlotFiltered = await _apptSlotDal.FilterAsync(x => x.Id == data.SlotId); ;
            //var currentAppointmentSlot = currentAppointmentSlotFiltered.FirstOrDefault();
            if (currentAppointmentSlot == null)
            {
                _log.LogError($"Unable to load current AppointmentSlot for Appointment to be updated. \"AppointmentId\"={data.AppointmentId} \"PatientId\"={data.PatientId}, \"MedicalPractitioner\"={data.MedicalPractitionerId}");
                return(new AppointmentBookResults()
                {
                    ResultCode = ServiceResultStatusCode.Failed
                });
            }

            var affectedSession = await _sessionDal.GetSessionThatOwnsSlot(data.NewSlotId);

            var newAppointmentSlot = await _apptSlotDal.GetEntityAsync(data.NewSlotId);

            if (newAppointmentSlot == null)
            {
                _log.LogError($"Unable to load proposed new AppointmentSlot for Appointment to be updated. \"AppointmentId\"={data.AppointmentId}, \"MedicalPractitioner\"={data.MedicalPractitionerId}");
                return(new AppointmentBookResults()
                {
                    ResultCode = ServiceResultStatusCode.Failed
                });
            }

            var medicalPractitioner = await _userDal.GetEntityAsync(affectedSession.MedicalPractitionerId);

            if (medicalPractitioner == null)
            {
                _log.LogError($"Unable to load MedicalPractitioner for Appointment to be updated. \"AppointmentId\"={data.AppointmentId} , \"MedicalPractitioner\"={data.MedicalPractitionerId}");
                return(new AppointmentBookResults()
                {
                    ResultCode = ServiceResultStatusCode.Failed
                });
            }

            var patientId = currentAppointmentSlot.PatientId ?? 0;

            if (patientId < 1)
            {
                _log.LogError($"Unable to load PatientId for Appointment to be updated. \"AppointmentId\"={data.AppointmentId}, \"MedicalPractitioner\"={data.MedicalPractitionerId}");
                return(new AppointmentBookResults()
                {
                    ResultCode = ServiceResultStatusCode.Failed
                });
            }

            var patient = await _patientDal.GetEntityAsync(patientId);

            if (patient == null)
            {
                _log.LogError($"Unable to load Patient for Appointment to be updated. \"AppointmentId\"={data.AppointmentId} \"PatientId\"={data.PatientId}, \"MedicalPractitioner\"={data.MedicalPractitionerId}");
                return(new AppointmentBookResults()
                {
                    ResultCode = ServiceResultStatusCode.Failed
                });
            }

            var patientRegisteredWithMedicalPractitioner = _patientsMedicalPractitionerDal.CheckEntityExistsAsync(currentAppointmentSlot.Patient.Id, medicalPractitioner.Id);

            newAppointmentSlot.Patient              = patient;
            newAppointmentSlot.AppointmentState     = AppointmentState.PendingPatientArrival;
            newAppointmentSlot.State                = SlotState.Booked;
            currentAppointmentSlot.Patient          = null;
            currentAppointmentSlot.State            = SlotState.Available;
            currentAppointmentSlot.AppointmentState = AppointmentState.Available;


            var appointmentSlots = new List <AppointmentSlot>
            {
                newAppointmentSlot,
                currentAppointmentSlot,
            };

            // Save the list of updated appointment slots
            await _apptSlotDal.Update(appointmentSlots);

            // If patient not already Registered with MedicalPractitioner do so now
            if (!patientRegisteredWithMedicalPractitioner)
            {
                await RegisterPatientIfNotRegisteredToMedicalPractitioner(data, patient, medicalPractitioner);
            }

            return(new AppointmentBookResults()
            {
                ResultCode = ServiceResultStatusCode.Success,
                AppointmentsDetails = new List <AppointmentDetails>()
                {
                    new AppointmentDetails(medicalPractitioner, newAppointmentSlot)
                }
            });
        }
Exemple #4
0
        /// <summary>
        /// Book a new appointment for a patient
        /// </summary>
        /// <returns></returns>
        public async Task <AppointmentBookResults> BookAppointmentAsync(AddOrUpdateAppointmentData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            // Get the results of the completed tasks
            var appointmentSlot = await _apptSlotDal.GetEntityAsync(data.SlotId);

            if (appointmentSlot == null)
            {
                _log.LogError($"Unable to load AppointmentSlot for Appointment to be updated. \"AppointmentId\"={data.AppointmentId} \"PatientId\"={data.PatientId}, \"MedicalPractitioner\"={data.MedicalPractitionerId}");
                return(new AppointmentBookResults()
                {
                    ResultCode = ServiceResultStatusCode.Failed
                });
            }

            var medicalPractitioner = await _userDal.GetEntityAsync(data.MedicalPractitionerId);

            if (medicalPractitioner == null)
            {
                _log.LogError($"Unable to load MedicalPractitioner for Appointment to be updated. \"AppointmentId\"={data.AppointmentId} \"PatientId\"={data.PatientId}, \"MedicalPractitioner\"={data.MedicalPractitionerId}");
                return(new AppointmentBookResults()
                {
                    ResultCode = ServiceResultStatusCode.Failed
                });
            }

            var patient = await _patientDal.GetEntityAsync(data.PatientId);

            if (patient == null)
            {
                _log.LogError($"Unable to load Patient for Appointment to be updated. \"AppointmentId\"={data.AppointmentId} \"PatientId\"={data.PatientId}, \"MedicalPractitioner\"={data.MedicalPractitionerId}");
                return(new AppointmentBookResults()
                {
                    ResultCode = ServiceResultStatusCode.Failed
                });
            }

            var patientRegisteredWithMedicalPractitioner = _patientsMedicalPractitionerDal.CheckEntityExistsAsync(data.PatientId, data.MedicalPractitionerId);

            // Create a new Appointment and add it to the AppointmentSlot to make the booking
            appointmentSlot.Patient          = patient;
            appointmentSlot.AppointmentState = AppointmentState.PendingPatientArrival;

            // update the status of the slot to pending patient arrival to indicate it is booked
            appointmentSlot.State = SlotState.Booked;

            if (!patientRegisteredWithMedicalPractitioner)
            {
                await RegisterPatientIfNotRegisteredToMedicalPractitioner(data, patient, medicalPractitioner);
            }

            // Collect the result of the slot update task
            var slotUpdateResult = await _apptSlotDal.UpdateAsync(appointmentSlot);

            if (slotUpdateResult != null)
            {
                return(new AppointmentBookResults()
                {
                    ResultCode = ServiceResultStatusCode.Success,
                    AppointmentsDetails = new List <AppointmentDetails>()
                    {
                        new AppointmentDetails(medicalPractitioner, slotUpdateResult)
                    }
                });
            }

            return(new AppointmentBookResults()
            {
                ResultCode = ServiceResultStatusCode.Failed
            });
        }