public int AddPatientAppointments(PatientAppointment p, bool sendEvent = true) { int returnVal = 0; try { if (p.CreatedBy == 0) { p.CreatedBy = SessionManager.UserId; } } catch { } PatientAppointment appointment = new PatientAppointment() { PatientId = p.PatientId, PatientMasterVisitId = p.PatientMasterVisitId, AppointmentDate = p.AppointmentDate, Description = p.Description, ReasonId = p.ReasonId, DifferentiatedCareId = p.DifferentiatedCareId, ServiceAreaId = p.ServiceAreaId, StatusId = p.StatusId, StatusDate = DateTime.Now, CreatedBy = p.CreatedBy }; var sameDayAppointmentExists = _appointment.GetAppointmentByType(p.PatientId, p.PatientMasterVisitId, p.AppointmentDate, p.ReasonId); if (sameDayAppointmentExists.Count > 0) { sameDayAppointmentExists[0].Description = p.Description; sameDayAppointmentExists[0].DifferentiatedCareId = p.DifferentiatedCareId; sameDayAppointmentExists[0].ServiceAreaId = p.ServiceAreaId; sameDayAppointmentExists[0].StatusId = p.StatusId; _appointment.UpdatePatientAppointments(sameDayAppointmentExists[0]); } else { returnVal = _appointment.AddPatientAppointments(appointment); } if (returnVal > 0 && sendEvent) { PatientLookupManager patientLookup = new PatientLookupManager(); var patient = patientLookup.GetPatientDetailSummary(p.PatientId); MessageEventArgs args = new MessageEventArgs() { FacilityId = patient.FacilityId, EntityId = returnVal, PatientId = appointment.PatientId, MessageType = MessageType.AppointmentScheduling, EventOccurred = "Patient Appointment Scheduled" }; Publisher.RaiseEventAsync(this, args).ConfigureAwait(false); } return(returnVal); }