Esempio n. 1
0
        public async Task <List <Appointment> > FilterByDoctorIdPatientIdAsync(string doctorid, string patientid, string from = "", string to = "")
        {
            DateTime fromDate, toDate;

            if (!DateTime.TryParse(from, out fromDate))
            {
                fromDate = DateTime.UtcNow.Date;
            }
            if (!DateTime.TryParse(to, out toDate))
            {
                toDate = DateTime.UtcNow.Date.AddDays(2);
            }
            List <Appointment> appointments;

            if (doctorid != "" && patientid != "")
            {
                appointments = (await Respository.GetItemsAsync(x => x.DoctorId == doctorid && x.PatientId == patientid && x.AppointmentDate >= fromDate && x.AppointmentDate <= toDate)).OrderBy(x => x.AppointmentDate).ThenBy(x => x.AppointmentTimeSlot).ToList();
            }
            else if (doctorid != "")
            {
                appointments = (await Respository.GetItemsAsync(x => x.DoctorId == doctorid && x.AppointmentDate >= fromDate && x.AppointmentDate <= toDate)).OrderBy(x => x.AppointmentDate).ThenBy(x => x.AppointmentTimeSlot).ToList();
            }
            else if (patientid != "")
            {
                appointments = (await Respository.GetItemsAsync(x => x.PatientId == patientid && x.AppointmentDate >= fromDate && x.AppointmentDate <= toDate)).OrderBy(x => x.AppointmentDate).ThenBy(x => x.AppointmentTimeSlot).ToList();
            }
            else
            {
                appointments = (await Respository.GetItemsAsync(x => x.AppointmentDate >= fromDate && x.AppointmentDate <= toDate)).OrderBy(x => x.AppointmentDate).ThenBy(x => x.AppointmentTimeSlot).ToList();
            }
            return(appointments);
        }
Esempio n. 2
0
        /// <summary>
        /// Get Event Clusters
        /// Only the last 3 events are returned
        /// </summary>
        /// <returns>List of Event Clusters</returns>
        public async Task <IEnumerable <EventClusterModel> > GetEventClusters()
        {
            IEnumerable <EventClusterDAO> eventClusters = await _repoEventClusters.GetItemsAsync(
                p => p.ClosureDate.Value == null || (p.EndDate.Value != null && p.EndDate > DateTime.UtcNow),
                p => new EventClusterDAO()
            {
                Id     = p.Id,
                Events = new EventDAOObject[] {
                    p.Events[0],
                    p.Events[1],
                    p.Events[2]
                },     //Used to force only the first 3 entries
                EventCount  = p.EventCount,
                EventType   = p.EventType,
                StartDate   = p.StartDate,
                EndDate     = p.EndDate,
                UpdateDate  = p.UpdateDate,
                ClosureDate = p.ClosureDate,
                Device      = p.Device
            }
                );

            var orderedEventClusters = eventClusters.OrderByDescending(p => p.StartDate);

            return(_mapper.Map <IEnumerable <EventClusterModel> >(orderedEventClusters));
        }
Esempio n. 3
0
        public async Task <IActionResult> GetCommonTemplates()
        {
            Domain.Model.User currentUser = await EnsureCurrentUser();

            string userId = currentUser.Id.ToLower();

            IEnumerable <Template> commonTemplates = await _templateRepo.GetItemsAsync(
                p => p.DocType == TemplateDocumentType.CommonTemplate ||
                (p.IsReusableTemplate && p.UserId.ToLower() == userId), p => new Template()
            {
                Id                 = p.Id,
                Name               = p.Name,
                Description        = p.Description,
                CategoryId         = p.CategoryId,
                SubcategoryId      = p.SubcategoryId,
                IsReusableTemplate = p.IsReusableTemplate
            });     //Force documentdb to query only these fields

            if (commonTemplates == null)
            {
                logger.LogError("API GetCommonTemplates error: CommonTemplates not found.");
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            return(Ok(commonTemplates));
        }
Esempio n. 4
0
        /// <summary>
        /// Delete all messages from the collection "Message" before attempting a new simulation
        /// </summary>
        /// <returns></returns>
        private async Task DeleteOldCosmosMessages()
        {
            IEnumerable <CosmosDBMessage> messageEnum = await _MessageRepo.GetItemsAsync(p => p.IoTHub != null && p.IoTHub.ConnectionDeviceId == AppConfig.IoTHub.SimulatorDeviceName);

            if (messageEnum != null)
            {
                IEnumerator <CosmosDBMessage> enumerator = messageEnum.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    await _MessageRepo.DeleteItemAsync(enumerator.Current.Id.ToString());
                }
            }
            return;
        }
        /// <summary>
        /// Get the list of devices in a light model for map display
        /// </summary>
        /// <returns>List of devices</returns>
        public async Task <IEnumerable <DeviceMapModel> > GetDevicesForMap()
        {
            IEnumerable <DeviceDAO> devices = await _repoDevices.GetItemsAsync(
                p => p.Enabled && p.Sensor,
                p => new DeviceDAO()
            {
                Id             = p.Id,
                DeviceType     = p.DeviceType,
                Geolocation    = p.Geolocation,
                LastAccessTime = p.LastAccessTime
            }
                );

            return(_mapper.Map <IEnumerable <DeviceMapModel> >(devices));
        }
        public async Task <IActionResult> GetCustomGroups()
        {
            try
            {
                logger.LogInformation("Get custom groups called");

                var customGroups = await _GroupsRepo.GetItemsAsync();

                return(Ok(customGroups));
            }
            catch (Exception e)
            {
                logger.LogError("Get custom groups - Exception: {message}", e.Message);
                throw;
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Get a list of data object from one starting date to another
 /// </summary>
 /// <typeparam name="T">Type of the repository</typeparam>
 /// <param name="repository">ICosmosDBRepository object</param>
 /// <param name="minDate">Minimum date</param>
 /// <param name="maxDate">Maximum date</param>
 /// <returns>List of repository objects</returns>
 private async Task <IEnumerable <T> > GetListBetweenDates <T>(ICosmosDBRepository <T> repository, DateTime?minDate, DateTime?maxDate) where T : IEntityDAO
 {
     if (minDate != null && maxDate != null)
     {
         return(await repository.GetItemsAsync(p => p.CreationDate >= minDate.Value && p.CreationDate <= maxDate.Value));
     }
     if (minDate == null && maxDate != null)
     {
         return(await repository.GetItemsAsync(p => p.CreationDate <= maxDate.Value));
     }
     if (minDate != null && maxDate == null)
     {
         return(await repository.GetItemsAsync(p => p.CreationDate >= minDate.Value));
     }
     return(await repository.GetItemsAsync());
 }
        /// <summary>
        /// Get a list of responses light objects
        /// </summary>
        /// <returns>List of Response Light Model</returns>
        public async Task <IEnumerable <ResponseLightModel> > GetResponses()
        {
            IEnumerable <ResponseDAO> responses = await _repoResponses.GetItemsAsync(
                p => p.ResponseState == 1 || (p.EndDate.Value != null && p.EndDate > DateTime.UtcNow.AddDays(-1)),
                p => new ResponseDAO()
            {
                Id                    = p.Id,
                ActionPlan            = p.ActionPlan,
                CreationDate          = p.CreationDate,
                EndDate               = p.EndDate,
                EventClusterIds       = p.EventClusterIds,
                Geolocation           = p.Geolocation,
                PrimaryEventClusterId = p.PrimaryEventClusterId,
                ResponderUserId       = p.ResponderUserId,
                ResponseState         = p.ResponseState
            }
                );

            return(_mapper.Map <IEnumerable <ResponseLightModel> >(responses));
        }
Esempio n. 9
0
        public async Task <IActionResult> GetCategories()
        {
            IEnumerable <Category> categories = await _categoryRepo.GetItemsAsync(p => p.DocType == TemplateDocumentType.Category);

            if (categories == null)
            {
                logger.LogError("API GetCategories error: Categories not found.");
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            return(Ok(categories));
        }
        /// <summary>
        /// Get all the actions plans
        /// </summary>
        /// <returns>List of Action Plans</returns>
        public async Task <IEnumerable <ActionPlanListModel> > GetActionPlans()
        {
            IEnumerable <ActionPlanDAO> plans = await _repoActionPlans.GetItemsAsync(
                p => p.IsActive,
                p => new ActionPlanDAO()
            {
                Id          = p.Id,
                Name        = p.Name,
                Color       = p.Color,
                Icon        = p.Icon,
                Description = p.Description
            }
                );

            return(_mapper.Map <IEnumerable <ActionPlanListModel> >(plans));
        }
Esempio n. 11
0
        public async Task <byte[]> GetRegistrations()
        {
            byte[] resultFile = null;
            using (var memStream = new MemoryStream())
            {
                using (var sw = new StreamWriter(memStream))
                {
                    var writer        = new CsvWriter(sw);
                    var registrations = await _repoRegistrations.GetItemsAsync();

                    foreach (var registration in registrations)
                    {
                        foreach (var eventObj in registration.Events)
                        {
                            writer.WriteField(eventObj.EventId);
                            writer.WriteField(eventObj.LocationId);
                            writer.WriteField(registration.Email);
                            writer.WriteField(registration.FirstName);
                            writer.WriteField(registration.LastName);
                            writer.WriteField(registration.ZipCode);
                            writer.WriteField(eventObj.Date);

                            writer.WriteField(eventObj.Donations.Count);
                            foreach (var donationObj in eventObj.Donations)
                            {
                                writer.WriteField(donationObj.DonationType);
                                writer.WriteField(donationObj.Amount);
                                writer.WriteField(donationObj.Reference ?? string.Empty);
                            }

                            writer.NextRecord();
                        }
                    }
                }
                resultFile = memStream.ToArray();
            }
            if (resultFile != null)
            {
                return(resultFile); //File(resultFile, "text/csv", $"extract_registrations_{DateTime.UtcNow.ToString("yyyy_MM_dd")}.csv");
            }
            return(null);           //StatusCode((int)HttpStatusCode.InternalServerError);
        }
Esempio n. 12
0
        public async Task <IEnumerable <NoteTemplateModel> > GetNoteTemplates(string eventId, bool forceRefresh = false)
        {
            IEnumerable <NoteTemplateModel> noteTemplates = null;

            if (!_dictNoteTemplates.ContainsKey(eventId) || !_config.UseCache || (_config.UseCache && forceRefresh))
            {
                noteTemplates = await _repoNoteTemplates.GetItemsAsync(p => p.EventId == eventId);

                if (noteTemplates == null)
                {
                    _logger.LogDebug($"GetNoteTemplates: No note templates found.");
                }
                _dictNoteTemplates[eventId] = noteTemplates;
            }
            else
            {
                noteTemplates = _dictNoteTemplates[eventId];
            }
            return(noteTemplates);
        }
Esempio n. 13
0
        /// <summary>
        /// Get notifications by Response Id
        /// </summary>
        /// <param name="responseId">Response Id</param>
        /// <returns>List of notifications</returns>
        public async Task <IEnumerable <NotificationModel> > GetNotifications(Guid responseId)
        {
            var notifications = await _repoNotifications.GetItemsAsync(p => p.ResponseId == responseId.ToString(),
                                                                       p => new NotificationDAO()
            {
                Id               = p.Id,
                CreationDate     = p.CreationDate,
                NotificationText = p.NotificationText,
                ResponseId       = p.ResponseId,
                Status           = p.Status,
                Tags             = p.Tags,
                Title            = p.Title,
                UpdateDate       = p.UpdateDate,
                User             = p.User
            }
                                                                       );

            IEnumerable <NotificationModel> output = _mapper.Map <IEnumerable <NotificationModel> >(notifications);

            return(output);
        }
Esempio n. 14
0
        public async Task Run()
        {
            try
            {
                //Load event to test
                EventModel vEvent = await _repoEvents.GetItemAsync(_config.EventId);

                //Load note templates
                IEnumerable <NoteTemplateModel> noteTemplatesEnum = await _repoNoteTemplates.GetItemsAsync();

                _nodeTemplates = new List <NoteTemplateModel>();
                foreach (var noteTemplate in noteTemplatesEnum)
                {
                    _nodeTemplates.Add(noteTemplate);
                }

                //Set up timers for buttons / notes
                foreach (EventLocationModel eventLocation in vEvent.EventLocations)
                {
                    Timer newTimer = new Timer();
                    newTimer.Elapsed += (sender, e) => SendButtonMessage(sender, e, newTimer, vEvent.Id, eventLocation.Id);
                    newTimer.Interval = _rand.Next(_config.TimerMin, _config.TimerMax);
                    newTimer.Start();
                    _timers.Add(newTimer);

                    Timer newTimerNotes = new Timer();
                    newTimerNotes.Elapsed += (sender, e) => SendNoteMessage(sender, e, newTimerNotes, vEvent.Id, eventLocation.Id);
                    newTimerNotes.Interval = _rand.Next(_config.TimerMin, _config.TimerMax);
                    newTimerNotes.Start();
                    _timers.Add(newTimerNotes);
                }

                Console.WriteLine("Press a key to exit.");
                Console.Read();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }
        }
Esempio n. 15
0
 public async Task <IEnumerable <EventModel> > GetEvents()
 {
     return(await _repoEvents.GetItemsAsync());
 }
        /// <summary>
        /// Retrieve templates based on the current user and associate a category with it.
        /// </summary>
        /// <returns>List of user templates associated with their category</returns>
        private async Task <IEnumerable <GroupedTemplate> > GetUserTemplatesGroupedByCategories()
        {
            Log.Information("Get User templates Called");

            try
            {
                if (_CacheGroupedTemplate != null && (_LoadTemplatesCommand.Parameter == null || _LoadTemplatesCommand.Parameter.ToString() != "refresh"))
                {
                    return(_CacheGroupedTemplate);
                }

                //Get current user
                User currentUser = _UserService.GetCurrentUser();

                //Get all categories
                List <GroupedTemplate> groupTemplates = new List <GroupedTemplate>();
                IEnumerable <Category> enumCategories = await _CategoryRepo.GetItemsAsync(p => p.DocType == TemplateDocumentType.Category);

                if (enumCategories == null)
                {
                    throw new Exception("The list of categories could not be found. Make sure that Cosmos DB is properly configured.");
                }
                Category[] categories = enumCategories.ToArray();

                //Get user templates based on current user ID
                IEnumerable <Template> enumTemplates = await _TemplateRepo.GetItemsAsync(p => p.DocType == TemplateDocumentType.User && p.UserId == currentUser.Id, p => new Template()
                {
                    Id            = p.Id,
                    Name          = p.Name,
                    Description   = p.Description,
                    SubcategoryId = p.SubcategoryId,
                    CategoryId    = p.CategoryId
                });

                if (enumTemplates == null)
                {
                    throw new Exception("The list of templates could not be found. Make sure that Cosmos DB is properly configured.");
                }

                //Associate user template and category. It is needed to get the proper icon and color in the UI.
                IEnumerator <Template> template = enumTemplates.GetEnumerator();
                while (template.MoveNext())
                {
                    Template        currentTemplate = template.Current;
                    GroupedTemplate group           = group = new GroupedTemplate()
                    {
                        Category = categories.First(p => p.Id == currentTemplate.CategoryId),
                        Template = currentTemplate
                    };
                    groupTemplates.Add(group);
                }

                //Cache the result as it won't change, unless the user forces a refresh or signs out.
                _CacheGroupedTemplate = groupTemplates;

                return(groupTemplates);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                throw new Exception(e.Message, e);
            }
        }
        public async Task <IEnumerable <ConversationReference> > GetConversationsFromUser(string userId)
        {
            var result = await _repoChatUserSessions.GetItemsAsync(p => p.Id == userId);

            return(Mapper.Map <IEnumerable <ConversationReference> >(result));
        }
Esempio n. 18
0
        public async Task <IActionResult> Index()
        {
            var items = await _cosmosDBRepository.GetItemsAsync(d => !d.Completed);

            return(View(items));
        }
Esempio n. 19
0
        public async Task <IEnumerable <models.product> > Get()
        {
            var items = await _cosmosDBRepository.GetItemsAsync(d => d.Id != null);

            return(items);
        }
        public async Task <IEnumerable <ChatReportModel> > GetChatReportsFromUser(string userId)
        {
            IEnumerable <ChatReportDAO> reportEntities = await _repoChatReports.GetItemsAsync(p => p.User.Id == userId);

            return(Mapper.Map <IEnumerable <ChatReportModel> >(reportEntities));
        }
Esempio n. 21
0
        public async Task <List <Patient> > FilterByNameAsync(string searchname)
        {
            List <Patient> patients = (await Respository.GetItemsAsync(x => x.Name.ToLower().Contains(searchname.ToLower()))).ToList();

            return(patients);
        }