예제 #1
0
        public override object Get(int companyId)
        {
            BO.VisitReports visitreports = new BO.VisitReports();

            var patients = _context.UserCompanies.Where(usrcomp => usrcomp.CompanyID == companyId).Select(usr => usr.UserID).ToList();
            var cases    = _context.Cases.Where(cs => patients.Contains(cs.PatientId)).Select(cse => cse.Id).ToList();
            var visits   = _context.PatientVisits.Where(vis => cases.Contains((int)vis.CaseId) &&
                                                        (vis.IsDeleted.HasValue == false || (vis.IsDeleted.HasValue == true && vis.IsDeleted.Value == false))).ToList();

            var scheduledvisits = _context.PatientVisits.Where(vis => cases.Contains((int)vis.CaseId) &&
                                                               vis.VisitStatusId == 1 &&
                                                               (vis.IsDeleted.HasValue == false || (vis.IsDeleted.HasValue == true && vis.IsDeleted.Value == false))).ToList();

            var completedvisits = _context.PatientVisits.Where(vis => cases.Contains((int)vis.CaseId) &&
                                                               vis.VisitStatusId == 2 &&
                                                               (vis.IsDeleted.HasValue == false || (vis.IsDeleted.HasValue == true && vis.IsDeleted.Value == false))).ToList();

            var noshowvisits = _context.PatientVisits.Where(vis => cases.Contains((int)vis.CaseId) &&
                                                            vis.VisitStatusId == 4 &&
                                                            (vis.IsDeleted.HasValue == false || (vis.IsDeleted.HasValue == true && vis.IsDeleted.Value == false))).ToList();

            visitreports.TotalVisits     = visits.Count;
            visitreports.CompletedVisits = completedvisits.Count;
            visitreports.NoShowVisits    = noshowvisits.Count;
            visitreports.ScheduledVisits = scheduledvisits.Count;
            visitreports.ProviderName    = _context.Companies.Where(comp => comp.id == companyId).FirstOrDefault().Name.ToString();

            return((object)visitreports);
        }
예제 #2
0
        public override object GetByPatientId(int patientId)
        {
            BO.VisitReports visitreports = new BO.VisitReports();

            var cases  = _context.Cases.Where(cs => cs.PatientId == patientId).Select(cse => cse.Id).ToList();
            var visits = _context.PatientVisits.Where(vis => cases.Contains((int)vis.CaseId) &&
                                                      (vis.IsDeleted.HasValue == false || (vis.IsDeleted.HasValue == true && vis.IsDeleted.Value == false))).ToList();

            var scheduledvisits = _context.PatientVisits.Where(vis => cases.Contains((int)vis.CaseId) &&
                                                               vis.VisitStatusId == 1 &&
                                                               (vis.IsDeleted.HasValue == false || (vis.IsDeleted.HasValue == true && vis.IsDeleted.Value == false))).ToList();

            var completedvisits = _context.PatientVisits.Where(vis => cases.Contains((int)vis.CaseId) &&
                                                               vis.VisitStatusId == 2 &&
                                                               (vis.IsDeleted.HasValue == false || (vis.IsDeleted.HasValue == true && vis.IsDeleted.Value == false))).ToList();

            var noshowvisits = _context.PatientVisits.Where(vis => cases.Contains((int)vis.CaseId) &&
                                                            vis.VisitStatusId == 4 &&
                                                            (vis.IsDeleted.HasValue == false || (vis.IsDeleted.HasValue == true && vis.IsDeleted.Value == false))).ToList();

            var caldarids = _context.PatientVisits.Where(vis => cases.Contains((int)vis.CaseId) &&
                                                         (vis.IsDeleted.HasValue == false || (vis.IsDeleted.HasValue == true && vis.IsDeleted.Value == false)))
                            .Select(cal => cal.CalendarEventId).ToList();

            var nextScheduleVisit = _context.CalendarEvents.Where(calendar => caldarids.Contains(calendar.Id) && calendar.EventStart > DateTime.UtcNow)
                                    .OrderByDescending(cl => cl.EventStart).AsEnumerable()
                                    .Reverse()
                                    .FirstOrDefault().EventStart.ToString("dd-MMM-yyyy hh:mm tt");

            visitreports.TotalVisits     = visits.Count;
            visitreports.CompletedVisits = completedvisits.Count;
            visitreports.NoShowVisits    = noshowvisits.Count;
            visitreports.ScheduledVisits = scheduledvisits.Count;
            visitreports.NextVisit       = nextScheduleVisit.ToString();
            visitreports.ProviderName    = _context.Companies.Where(comp => comp.id ==
                                                                    (_context.UserCompanies.Where(usrcmp => usrcmp.UserID == patientId).Select(cp => cp.CompanyID).FirstOrDefault()))
                                           .FirstOrDefault().Name.ToString();
            visitreports.PatientName = _context.Users.Where(usr => usr.id == patientId).FirstOrDefault().FirstName + " " + _context.Users.Where(usr => usr.id == patientId).FirstOrDefault().LastName;

            return((object)visitreports);
        }