Example #1
0
        public async Task <IReadOnlyList <Appointment> > GetAllUpcomingForDoctorAsync(DoctorId doctorId,
                                                                                      CancellationToken cancellation = default)
        {
            var context = await _dbContextProvider.GetAsync();

            var now = _systemClockService.UtcNow;

            return(await context.AppointmentTables
                   .Where(x => x.AppointmentAt >= now)
                   .Where(x => x.DoctorId == doctorId.Value)
                   .Select(x => new Appointment(new AppointmentId(x.AppointmentId), new DoctorId(x.DoctorId), new PatientId(x.PatientId),
                                                x.AppointmentAt, new AppointmentDuration(x.Duration)))
                   .ToListAsync(cancellation));
        }
        public async Task <IReadOnlyList <DoctorAvailability> > GetAllForDoctorAsync(DoctorId doctorId,
                                                                                     CancellationToken cancellationToken = default)
        {
            var context = await _dbContextProvider.GetAsync();

            return(await context.DoctorAvailabilityTables
                   .Where(x => x.DoctorId == doctorId.Value)
                   .Select(x => new DoctorAvailability(new DoctorAvailabilityId(x.DoctorAvailabilityId), new DoctorId(x.DoctorId), x.DayOfWeek,
                                                       new TimeOfDay(x.StartsAt), new TimeOfDay(x.EndsAt)))
                   .ToListAsync(cancellationToken));
        }
        public async Task <Patient> GetByIdAsync(PatientId patientId, CancellationToken cancellation = default)
        {
            var context = await _dbContextProvider.GetAsync();

            var patientTable = await context.PatientTables.SingleOrDefaultAsync(x => x.PatientId == patientId.Value, cancellation);

            if (patientTable == null)
            {
                return(null);
            }

            return(new Patient(new PatientId(patientTable.PatientId), patientTable.Name));
        }
        public async Task <Doctor> GetByIdAsync(DoctorId doctorId, CancellationToken cancellation = default)
        {
            var context = await _dbContextProvider.GetAsync();

            var doctorTable = await context.DoctorTables.SingleOrDefaultAsync(x => x.DoctorId == doctorId.Value, cancellation);

            if (doctorTable == null)
            {
                return(null);
            }

            return(new Doctor(new DoctorId(doctorTable.DoctorId), doctorTable.Name));
        }
        public async Task <IQueryable <AppointmentTable> > GetAppointmentTablesAsync(CancellationToken cancellation = default)
        {
            var context = await _dbContextProvider.GetAsync();

            return(context.Set <AppointmentTable>());
        }