Esempio n. 1
0
        public bool CreateChargeCaptureAppointments(List <CernerAppointment> appointments)
        {
            var patientRepository = _uow.GetRepository <Patient>();
            List <CernerAppointment> updatedAppointments = new List <CernerAppointment>();
            var doctorRepository               = _uow.GetRepository <Doctor>();
            var locationRepository             = _uow.GetRepository <Location>();
            List <Appointment> newAppointments = new List <Appointment>();

            foreach (var item in appointments)
            {
                if (item.AppointmentStatus != "cancelled" && item.PatientId != null && item.PractitionerId != null && item.LocationId != null)
                {
                    var patient = patientRepository.Queryable().Where(x => x.ExternalKey3 == item.PatientId).FirstOrDefault();
                    if (patient != null)
                    {
                        var doctor = doctorRepository.Queryable().Where(x => x.ExternalKey3 == item.PractitionerId).FirstOrDefault();
                        if (doctor != null)
                        {
                            var         location    = locationRepository.Queryable().Where(x => x.ExternalKey3 == item.LocationId).FirstOrDefault();
                            Appointment appointment = new Appointment();
                            appointment.Participants = new List <Participant>();

                            appointment.AccountId    = patient.AccountId;
                            appointment.Comments     = item.Comment;
                            appointment.Description  = item.Description;
                            appointment.Duration     = item.DurationInMinutes;
                            appointment.EndingTime   = item.EndDate;
                            appointment.ExternalKey3 = item.CernerIntegrationId;
                            appointment.IsCancelled  = false;
                            appointment.Reason       = (item.Reason != null ? item.Reason : "Integrated from cerner");
                            appointment.StartingTime = item.StartDate;

                            switch (item.AppointmentStatus)
                            {
                            case "proposed":
                                appointment.Status = AppointmentStatus.Proposed;
                                break;

                            case "pending":
                                appointment.Status = AppointmentStatus.Pending;
                                break;

                            case "booked":
                                appointment.Status = AppointmentStatus.Booked;
                                break;

                            case "arrived":
                                appointment.Status = AppointmentStatus.Arrived;
                                break;

                            case "fulfilled":
                                appointment.Status = AppointmentStatus.Fulfilled;
                                break;

                            case "cancelled":
                                appointment.Status = AppointmentStatus.Cancelled;
                                break;

                            case "noshow":
                                appointment.Status = AppointmentStatus.NoShow;
                                break;

                            default:
                                break;
                            }

                            //Participant - Patient
                            appointment.Participants.Add(new Participant()
                            {
                                AccountId     = patient.AccountId,
                                AppointmentId = appointment.AppointmentId,
                                Type          = ParticipantType.Patient,
                                PatientId     = patient.PatientId,
                                Required      = true
                            });

                            //Participant - Practitionar
                            appointment.Participants.Add(new Participant()
                            {
                                AccountId     = patient.AccountId,
                                AppointmentId = appointment.AppointmentId,
                                Type          = ParticipantType.Provider,
                                DoctorId      = doctor.DoctorId,
                                Required      = true
                            });
                            //Participant - Location
                            appointment.Participants.Add(new Participant()
                            {
                                AccountId     = patient.AccountId,
                                AppointmentId = appointment.AppointmentId,
                                Type          = ParticipantType.Location,
                                LocationId    = location.LocationId,
                                Required      = true
                            });

                            newAppointments.Add(appointment);
                            updatedAppointments.Add(item);
                        }
                    }
                }
            }
            if (newAppointments.Count > 0)
            {
                _appointmentServices.CreateAppointmentFromCerner(newAppointments);
                foreach (var item in updatedAppointments)
                {
                    UpdateAppointment(item);
                }
            }
            return(true);
        }